diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/objectGraphAnalyzer/ObjectCallCounter.java b/org.ntlab.traceAnalyzer/src/org/ntlab/objectGraphAnalyzer/ObjectCallCounter.java new file mode 100644 index 0000000..67ca244 --- /dev/null +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/objectGraphAnalyzer/ObjectCallCounter.java @@ -0,0 +1,74 @@ +package org.ntlab.objectGraphAnalyzer; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.ntlab.trace.IMethodExecutionVisitor; +import org.ntlab.trace.MethodExecution; +import org.ntlab.trace.ThreadInstance; +import org.ntlab.trace.Trace; +import org.ntlab.trace.TraceJSON; + +public class ObjectCallCounter { + + /** + * @param args + */ + public static void main(String[] args) { + TraceJSON trace = new TraceJSON("traces\\jEditNormal.trace"); + final HashMap classNames = new HashMap<>(); + final HashMap callCounts = new HashMap<>(); + + for (ThreadInstance thread: trace.getAllThreads().values()) { + thread.traverseMethodExecutionsBackward(new IMethodExecutionVisitor() { + @Override + public boolean preVisitThread(ThreadInstance thread) { + return false; + } + + @Override + public boolean preVisitMethodExecution(MethodExecution methodExecution) { + String objId = methodExecution.getThisObjId(); + if (!Trace.isNull(objId)) { + String key = objId + ":" + methodExecution.getSignature(); + if (classNames.get(key) == null) { + classNames.put(key, methodExecution.getThisClassName()); + } + if (callCounts.get(key) == null) { + callCounts.put(key, 1); + } else { + callCounts.put(key, callCounts.get(key) + 1); + } + } else { + String className = methodExecution.getThisClassName(); + String key = className + ":" + methodExecution.getSignature(); + if (classNames.get(key) == null) { + classNames.put(key, className); + } + if (callCounts.get(key) == null) { + callCounts.put(key, 1); + } else { + callCounts.put(key, callCounts.get(key) + 1); + } + } + return false; + } + + @Override + public boolean postVisitThread(ThreadInstance thread) { + return false; + } + + @Override + public boolean postVisitMethodExecution(MethodExecution methodExecution, ArrayList children) { + return false; + } + }); + } + + for (String objId: callCounts.keySet()) { + System.out.println(objId + ":" + classNames.get(objId) + ":" + callCounts.get(objId)); + } + } + +}