[jboss-cvs] JBoss Profiler SVN: r456 - in branches/JBossProfiler2: src/main/org/jboss/profiler/client and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 21 11:30:52 EDT 2008


Author: jesper.pedersen
Date: 2008-05-21 11:30:52 -0400 (Wed, 21 May 2008)
New Revision: 456

Modified:
   branches/JBossProfiler2/doc/README.txt
   branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java
Log:
Initial version of the caller report

Modified: branches/JBossProfiler2/doc/README.txt
===================================================================
--- branches/JBossProfiler2/doc/README.txt	2008-05-19 20:16:49 UTC (rev 455)
+++ branches/JBossProfiler2/doc/README.txt	2008-05-21 15:30:52 UTC (rev 456)
@@ -21,6 +21,7 @@
    x Classes
    x Methods
    x Hotspots
+   x Caller
    x PerThread
    x PerClass
 

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java	2008-05-19 20:16:49 UTC (rev 455)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java	2008-05-21 15:30:52 UTC (rev 456)
@@ -205,6 +205,7 @@
       dumpHotspots(info, directory);
       dumpPackages(info, directory);
       dumpClasses(classes, info, snapshot.getAllocations(), directory);
+      dumpCaller(snapshot.getThreads(), directory);
     }
   }
 
@@ -743,4 +744,123 @@
     bw.flush();
     bw.close();
   }
+
+  /**
+   * Dump the caller information to a file writer
+   * @param threads The threads
+   * @param directory The directory
+   * @exception Exception If an error occurs
+   */
+  protected void dumpCaller(List<ThreadInfo> threads, String directory) throws Exception {
+    File f = new File(directory + "caller");
+    f.mkdirs();
+
+    Map<String, Map<String, CombinedFrameInfo>> data = new HashMap<String, Map<String, CombinedFrameInfo>>();
+
+    for (ThreadInfo ti: threads) {
+      for (FrameInfo fi: ti.getFrames()) {
+        getCallerInformation(fi, data);
+      }
+    }
+
+    DecimalFormat df = new DecimalFormat("#0.00");
+
+    Iterator dit = data.entrySet().iterator();
+    while (dit.hasNext()) {
+      Map.Entry entry = (Map.Entry)dit.next();
+
+      String key = (String)entry.getKey();
+      Map<String, CombinedFrameInfo> value = (Map<String, CombinedFrameInfo>)entry.getValue();
+
+      FileWriter ftw = new FileWriter(directory + "caller" + File.separator + 
+                                      key.replace('/', '.') + ".txt");
+      BufferedWriter bw = new BufferedWriter(ftw, 8192);
+
+      Map<String, List<CombinedFrameInfo>> m = new HashMap<String, List<CombinedFrameInfo>>();
+
+      Iterator vit = value.values().iterator();
+      while (vit.hasNext()) {
+        CombinedFrameInfo cfi = (CombinedFrameInfo)vit.next();
+
+        List<CombinedFrameInfo> l = m.get(cfi.getClassName());
+        if (l == null) {
+          l = new ArrayList<CombinedFrameInfo>();
+          m.put(cfi.getClassName(), l);
+        }
+        l.add(cfi);
+      }
+
+      Iterator mit = m.entrySet().iterator();
+      while (mit.hasNext()) {
+        Map.Entry mentry = (Map.Entry)mit.next();
+        
+        String methodName = (String)mentry.getKey();
+        List<CombinedFrameInfo> callers = (List<CombinedFrameInfo>)mentry.getValue();
+
+        Collections.sort(callers, new CombinedFrameComparator(CombinedFrameComparator.TOTAL_TIME));
+
+        bw.write(methodName + ":" + NEW_LINE);
+        for (int i = 1; i < methodName.length() + 2; i++) {
+          bw.write("-");
+        }
+        bw.write(NEW_LINE);
+
+        bw.write("Count\tMs\tMethod");
+        bw.write(NEW_LINE);
+
+        int count = 0;
+
+        for (CombinedFrameInfo cfi : callers) {
+          if (cfi.getTotalTime() > threshold) {
+            bw.write(cfi.getCount() + "\t");
+            bw.write(df.format(cfi.getTotalTime()) + "\t");
+            bw.write(cfi.getPrettyName());
+            bw.write(NEW_LINE);
+          } else {
+            count++;
+          }
+        }
+
+        if (count > 0) {
+          bw.write(NEW_LINE);
+          bw.write(count + " methods below threshold." + NEW_LINE);          
+        }
+
+        bw.write(NEW_LINE);
+      }
+
+      bw.flush();
+      bw.close();
+    }
+  }
+
+  /**
+   * Get caller information
+   * @param fi The frame
+   * @param data The data
+   */
+  protected void getCallerInformation(FrameInfo fi, Map<String, Map<String, CombinedFrameInfo>> data) {
+    Map<String, CombinedFrameInfo> entry = data.get(fi.getMethod().getClassName());
+    if (entry == null) {
+      entry = new HashMap<String, CombinedFrameInfo>();
+      data.put(fi.getMethod().getClassName(), entry);
+    }
+    if (fi.getParent() != null) {
+      String parentName = Util.getPrettyName(fi.getParent().getMethod());
+      CombinedFrameInfo cfi = entry.get(parentName);
+      if (cfi == null) {
+        cfi = new CombinedFrameInfo(Util.getPrettyName(fi.getMethod()), parentName);
+        entry.put(parentName, cfi);
+      }
+
+      cfi.increaseCount(fi.getParent().getCount());
+      cfi.increaseTotalTime(Math.nanoToMilli(fi.getParent().getNetTime()));
+    }
+
+    if (fi.getChildren() != null && fi.getChildren().size() > 0) {
+      for (FrameInfo child : fi.getChildren()) {
+        getCallerInformation(child, data);
+      }
+    }
+  }
 }




More information about the jboss-cvs-commits mailing list