changeset 866:26ae863294fa

profilers: perfasm, code touchups, #2.
author shade
date Fri, 27 Jun 2014 18:38:51 +0400
parents b82f81fb1040
children d5037ea5da57
files jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java
diffstat 1 files changed, 14 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Fri Jun 27 18:34:56 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Fri Jun 27 18:38:51 2014 +0400
@@ -323,11 +323,7 @@
                     for (ASMLine line : r.code) {
                         for (String event : EVENTS) {
                             long count = (line.addr != null) ? events.get(event).count(line.addr) : 0;
-                            if (count > 0) {
-                                pw.printf("%6.2f%%  ", 100.0 * count / events.getTotalEvents(event));
-                            } else {
-                                pw.printf("%9s", "");
-                            }
+                            printLine(pw, events, event, count);
                         }
                         pw.println(line.code);
                     }
@@ -335,12 +331,7 @@
 
                 printDottedLine(pw, null);
                 for (String event : EVENTS) {
-                    long count = r.getEventCount(events, event);
-                    if (count > 0) {
-                        pw.printf("%6.2f%%  ", 100.0 * count / events.getTotalEvents(event));
-                    } else {
-                        pw.printf("%9s", "");
-                    }
+                    printLine(pw, events, event, r.getEventCount(events, event));
                 }
                 pw.println("<total for region " + cnt + ">");
                 pw.println();
@@ -360,12 +351,7 @@
         for (Region r : regions) {
             if (shown++ < SHOW_TOP) {
                 for (String event : EVENTS) {
-                    long count = r.getEventCount(events, event);
-                    if (count > 0) {
-                        pw.printf("%6.2f%%  ", 100.0 * count / events.getTotalEvents(event));
-                    } else {
-                        pw.printf("%9s", "");
-                    }
+                    printLine(pw, events, event, r.getEventCount(events, event));
                 }
                 pw.printf("[0x%x:0x%x] in %s%n", r.begin, r.end, r.method);
             } else {
@@ -380,24 +366,14 @@
 
         if (regions.size() - SHOW_TOP > 0) {
             for (String event : EVENTS) {
-                long count = other.count(event);
-                if (count > 0) {
-                    pw.printf("%6.2f%%  ", 100.0 * count / events.getTotalEvents(event));
-                } else {
-                    pw.printf("%9s", "");
-                }
+                printLine(pw, events, event, other.count(event));
             }
             pw.println("<...other " + (regions.size() - SHOW_TOP) + " warm regions...>");
         }
         printDottedLine(pw, null);
 
         for (String event : EVENTS) {
-            long count = accounted.count(event);
-            if (count > 0) {
-                pw.printf("%6.2f%%  ", 100.0 * count / events.getTotalEvents(event));
-            } else {
-                pw.printf("%9s", "");
-            }
+            printLine(pw, events, event, accounted.count(event));
         }
         pw.println("<totals>");
         pw.println();
@@ -447,11 +423,7 @@
                 for (ASMLine line : assembly.lines) {
                     for (String event : EVENTS) {
                         long count = (line.addr != null) ? events.get(event).count(line.addr) : 0;
-                        if (count > 0) {
-                            pwAsm.printf("%6.2f%%  ", 100.0 * count / events.getTotalEvents(event));
-                        } else {
-                            pwAsm.printf("%9s", "");
-                        }
+                        printLine(pwAsm, events, event, count);
                     }
                     pwAsm.println(line.code);
                 }
@@ -470,6 +442,14 @@
         return new PerfResult(sw.toString());
     }
 
+    static void printLine(PrintWriter pw, PerfEvents events, String event, long count) {
+        if (count > 0) {
+            pw.printf("%6.2f%%  ", 100.0 * count / events.getTotalEvents(event));
+        } else {
+            pw.printf("%9s", "");
+        }
+    }
+
     void printDottedLine(PrintWriter pw, String header) {
         final int HEADER_WIDTH = 100;