changeset 835:014838b0d314

profilers: user-defined delays for perf profilers.
author shade
date Thu, 26 Jun 2014 15:40:05 +0400
parents 3b60786edbb1
children 8ffbc0429d53
files jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java
diffstat 2 files changed, 28 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Jun 26 15:14:51 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Jun 26 15:40:05 2014 +0400
@@ -76,6 +76,9 @@
     /** Merge margin: the regions separated by less than the margin are considered the same */
     private static final int MERGE_MARGIN = Integer.getInteger("jmh.perfasm.mergeMargin", 32);
 
+    /** Delay collection for given time; -1 to detect automatically */
+    private static final int DELAY_MSEC = Integer.getInteger("jmh.perfasm.delayMs", -1);
+
     private static final boolean IS_SUPPORTED;
     private static final Collection<String> INIT_MSGS;
 
@@ -210,11 +213,16 @@
          * 3. Read out perf output
          */
 
-        long delaySec = (params.getWarmup().getCount() *
-                params.getWarmup().getTime().convertTo(TimeUnit.SECONDS))
-                + 1; // loosely account for the JVM lag
+        long delayNs;
+        if (DELAY_MSEC == -1) { // not set
+            delayNs = params.getWarmup().getCount() *
+                            params.getWarmup().getTime().convertTo(TimeUnit.NANOSECONDS)
+                            + TimeUnit.SECONDS.toNanos(1); // loosely account for the JVM lag
+        } else {
+            delayNs = TimeUnit.MILLISECONDS.toNanos(DELAY_MSEC);
+        }
 
-        Map<String, Multiset<Long>> events = readEvents(delaySec);
+        Map<String, Multiset<Long>> events = readEvents(delayNs);
 
         if (!events.isEmpty()) {
             pw.println("Perf output processed:");
@@ -499,7 +507,7 @@
         }
     }
 
-    Map<String, Multiset<Long>> readEvents(long skipSeconds) {
+    Map<String, Multiset<Long>> readEvents(long skipNs) {
         try {
             FileInputStream fis = new FileInputStream(perfParsedData);
             BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
@@ -509,6 +517,7 @@
                 events.put(evName, new TreeMultiset<Long>());
             }
 
+            double skipSec = 1.0 * skipNs / TimeUnit.SECONDS.toNanos(1);
             Double startTime = null;
 
             String line;
@@ -523,7 +532,7 @@
                         if (startTime == null) {
                             startTime = time;
                         } else {
-                            if (time - startTime < skipSeconds) {
+                            if (time - startTime < skipSec) {
                                 continue;
                             }
                         }
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java	Thu Jun 26 15:14:51 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java	Thu Jun 26 15:40:05 2014 +0400
@@ -49,6 +49,9 @@
 
 public class LinuxPerfProfiler implements ExternalProfiler {
 
+    /** Delay collection for given time; -1 to detect automatically */
+    private static final int DELAY_MSEC = Integer.getInteger("jmh.perf.delayMs", -1);
+
     private static final boolean IS_SUPPORTED;
     private static final boolean IS_DELAYED;
     private static final Collection<String> INIT_MSGS;
@@ -63,11 +66,16 @@
 
     @Override
     public Collection<String> addJVMInvokeOptions(BenchmarkParams params) {
-        long delay = TimeUnit.NANOSECONDS.toMillis(
-                params.getWarmup().getCount() *
-                params.getWarmup().getTime().convertTo(TimeUnit.NANOSECONDS)
-                + 1000 // loosely account for the JVM lag
-        );
+        long delay;
+        if (DELAY_MSEC == -1) { // not set
+            delay = TimeUnit.NANOSECONDS.toMillis(
+                    params.getWarmup().getCount() *
+                            params.getWarmup().getTime().convertTo(TimeUnit.NANOSECONDS)
+                            + TimeUnit.SECONDS.toMillis(1) // loosely account for the JVM lag
+            );
+        } else {
+            delay = DELAY_MSEC;
+        }
 
         if (IS_DELAYED) {
             return Arrays.asList("perf", "stat", "-d", "-d", "-d", "-D " + delay);