java.util.Stack stack = new java.util.Stack();
HashMap hashMethods = new HashMap();
HashMap hashCallings = new HashMap();
GraphCallings graph = new GraphCallings();
// para ajudar na referencia entre chamadas
GraphReference referenceKey = new GraphReference();
int numberOfPaths = path.length;
long oldMethod = 0;
int level = 0;
// root
if (numberOfPaths == 0) {
oldMethod = consolidacao.getSpyMethod().getMethodID();
GraphMethod newMethod = new GraphMethod((JBPMethod) spyMethods
.get(consolidacao.getSpyMethod()), level++, createURL(
rootMethod, null, null));
hashMethods.put(newMethod, newMethod);
}
GraphMethod methodKey = new GraphMethod();
for (int i = 0; i < numberOfPaths; i++) {
consolidacao = consolidacao.getCalledCount(path[i]);
if (i >= (numberOfPaths - 1)) {
methodKey.setMethodId(path[i].getMethodID());
methodKey.setLevel(level++);
//Long methodKey = new Long(path[i].getMethodID());
GraphMethod calledGraphMethod = (GraphMethod) hashMethods
.get(methodKey);
if (calledGraphMethod == null) {
calledGraphMethod = new GraphMethod((JBPMethod) spyMethods
.get(path[i]), level++, createURL(rootMethod,
stack, path[i]));
hashMethods.put(calledGraphMethod, calledGraphMethod);
}
if (oldMethod != 0) {
referenceKey.setMethodCallee(oldMethod);
referenceKey.setMethodCalled(path[i].getMethodID());
if (hashCallings.get(referenceKey) == null) {
double percenptual = (double) consolidacao
.getTotalElapsedClock()
/ (double) rootMethod.getTotalElapsedClock()
* (double) 100;
GraphReference ref = new GraphReference(level - 1,
oldMethod, level, path[i].getMethodID(),
percenptual, (double) consolidacao
.getTotalClocks()
/ (double) rootMethod.getTotalClock()
* (double) 100);
hashCallings.put(ref, ref);
}
}
oldMethod = path[i].getMethodID();
}
stack.push(path[i]);
}
JBPMethod methodConsolidado = consolidacao.getSpyMethod();
methodConsolidado = (JBPMethod) spyMethods.get(methodConsolidado);
generateCallingsRecursive(level, oldMethod, rootMethod, consolidacao,
hashMethods, hashCallings, referenceKey, stack);
TreeSet treeSet = new TreeSet(new CompareMethods());
treeSet.addAll(hashMethods.values());
ArrayList listMethods = new ArrayList();
listMethods.addAll(treeSet);
ArrayList listRefs = new ArrayList();
listRefs.addAll(hashCallings.values());
graph.setMethods(listMethods);
graph.setReferences(listRefs);
graph.printDebug();
return graph;
}