changeset 838:aa0e1b1fc6d3

profilers: perfasm to save annotated assembly if requested.
author shade
date Thu, 26 Jun 2014 17:34:06 +0400
parents 3afac862a651
children 1406a31681a6
files jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java
diffstat 1 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Jun 26 17:12:13 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Jun 26 17:34:06 2014 +0400
@@ -82,6 +82,9 @@
     /** Save perf output to file */
     private static final String SAVE_PERF_OUTPUT = System.getProperty("jmh.perfasm.savePerfTo");
 
+    /** Save perf output to file */
+    private static final String SAVE_ASM_OUTPUT = System.getProperty("jmh.perfasm.saveAsmTo");
+
     private static final boolean IS_SUPPORTED;
     private static final Collection<String> INIT_MSGS;
 
@@ -354,6 +357,34 @@
         pw.println("<unknown>");
         pw.println();
 
+        /**
+         * Print annotated assembly, if needed:
+         */
+        if (SAVE_ASM_OUTPUT != null) {
+            FileOutputStream asm = null;
+            try {
+                asm = new FileOutputStream(SAVE_ASM_OUTPUT);
+                PrintWriter pwAsm = new PrintWriter(asm);
+                for (ASMLine line : assembly.lines) {
+                    for (String event : EVENTS) {
+                        int count = (line.addr != null) ? events.get(event).count(line.addr) : 0;
+                        if (count > 0) {
+                            pwAsm.printf("%6.2f%%  ", 100.0 * count / totalCounts.get(event));
+                        } else {
+                            pwAsm.printf("%9s", "");
+                        }
+                    }
+                    pwAsm.println(line.code);
+                }
+                pwAsm.flush();
+                asm.close();
+
+                pw.println("Annotated assembly saved to " + SAVE_ASM_OUTPUT);
+            } catch (IOException e) {
+                pw.println("Unable to save annotated assembly to " + SAVE_ASM_OUTPUT);
+            }
+        }
+
         pw.flush();
         pw.close();