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<String, String> classNames = new HashMap<>(); final HashMap<String, Integer> 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<MethodExecution> children) { return false; } }); } for (String objId: callCounts.keySet()) { System.out.println(objId + ":" + classNames.get(objId) + ":" + callCounts.get(objId)); } } }