changeset 837:3afac862a651

profilers: perfasm to save perf data if requested.
author shade
date Thu, 26 Jun 2014 17:12:13 +0400
parents 8ffbc0429d53
children aa0e1b1fc6d3
files jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java jmh-core/src/main/java/org/openjdk/jmh/util/FileUtils.java
diffstat 2 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Jun 26 16:38:24 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Jun 26 17:12:13 2014 +0400
@@ -79,6 +79,9 @@
     /** Delay collection for given time; -1 to detect automatically */
     private static final int DELAY_MSEC = Integer.getInteger("jmh.perfasm.delayMs", -1);
 
+    /** Save perf output to file */
+    private static final String SAVE_PERF_OUTPUT = System.getProperty("jmh.perfasm.savePerfTo");
+
     private static final boolean IS_SUPPORTED;
     private static final Collection<String> INIT_MSGS;
 
@@ -241,6 +244,15 @@
             pw.println();
         }
 
+        if (SAVE_PERF_OUTPUT != null) {
+            try {
+                FileUtils.copy(perfParsedData, SAVE_PERF_OUTPUT);
+                pw.println("Perf output saved to " + SAVE_PERF_OUTPUT);
+            } catch (IOException e) {
+                pw.println("Unable to save perf output to " + SAVE_PERF_OUTPUT);
+            }
+        }
+
         /**
          * 4. Figure out generated code regions
          */
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/FileUtils.java	Thu Jun 26 16:38:24 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/FileUtils.java	Thu Jun 26 17:12:13 2014 +0400
@@ -29,9 +29,7 @@
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -200,4 +198,19 @@
         return result;
     }
 
+    public static void copy(String src, String dst) throws IOException {
+        FileInputStream fis = new FileInputStream(src);
+        FileOutputStream fos = new FileOutputStream(dst);
+
+        byte[] buf = new byte[8192];
+        int read;
+        while ((read = fis.read(buf)) != -1) {
+            fos.write(buf, 0, read);
+        }
+
+        fos.flush();
+        fos.close();
+
+        fis.close();
+    }
 }