changeset 1380:33924b860fd0

7901848: safepoints profiler breaks when benchmark metadata is not available
author shade
date Tue, 29 Nov 2016 16:06:36 +0100
parents d9597f5532cc
children 0315ed60dd58
files jmh-core/src/main/java/org/openjdk/jmh/profile/AbstractPerfAsmProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfNormProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerUtils.java jmh-core/src/main/java/org/openjdk/jmh/profile/SafepointsProfiler.java
diffstat 4 files changed, 19 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/AbstractPerfAsmProfiler.java	Tue Nov 29 15:53:41 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/AbstractPerfAsmProfiler.java	Tue Nov 29 16:06:36 2016 +0100
@@ -29,7 +29,6 @@
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
 import org.openjdk.jmh.infra.BenchmarkParams;
-import org.openjdk.jmh.infra.IterationParams;
 import org.openjdk.jmh.results.*;
 import org.openjdk.jmh.util.*;
 
@@ -334,16 +333,7 @@
 
         long delayNs;
         if (delayMsec == -1) { // not set
-            BenchmarkResultMetaData md = br.getMetadata();
-            if (md != null) {
-                // try to ask harness itself:
-                delayNs = TimeUnit.MILLISECONDS.toNanos(md.getMeasurementTime() - md.getStartTime());
-            } else {
-                // metadata is not available, let's make a guess:
-                IterationParams wp = br.getParams().getWarmup();
-                delayNs = wp.getCount() * wp.getTime().convertTo(TimeUnit.NANOSECONDS)
-                        + TimeUnit.SECONDS.toNanos(1); // loosely account for the JVM lag
-            }
+            delayNs = TimeUnit.MILLISECONDS.toNanos(ProfilerUtils.warmupDelayMs(br));
         } else {
             delayNs = TimeUnit.MILLISECONDS.toNanos(delayMsec);
         }
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfNormProfiler.java	Tue Nov 29 15:53:41 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfNormProfiler.java	Tue Nov 29 16:06:36 2016 +0100
@@ -29,7 +29,6 @@
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
 import org.openjdk.jmh.infra.BenchmarkParams;
-import org.openjdk.jmh.infra.IterationParams;
 import org.openjdk.jmh.results.*;
 import org.openjdk.jmh.util.*;
 
@@ -179,16 +178,7 @@
 
     public long getDelay(BenchmarkResult br) {
         if (delayMs == -1) { // not set
-            BenchmarkResultMetaData md = br.getMetadata();
-            if (md != null) {
-                // try to ask harness itself:
-                return TimeUnit.MILLISECONDS.toNanos(md.getMeasurementTime() - md.getStartTime());
-            } else {
-                // metadata is not available, let's make a guess:
-                IterationParams wp = br.getParams().getWarmup();
-                return wp.getCount() * wp.getTime().convertTo(TimeUnit.NANOSECONDS)
-                        + TimeUnit.SECONDS.toNanos(1); // loosely account for the JVM lag
-            }
+            return TimeUnit.MILLISECONDS.toNanos(ProfilerUtils.warmupDelayMs(br));
         } else {
             return TimeUnit.MILLISECONDS.toNanos(delayMs);
         }
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerUtils.java	Tue Nov 29 15:53:41 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerUtils.java	Tue Nov 29 16:06:36 2016 +0100
@@ -28,9 +28,13 @@
 import joptsimple.OptionParser;
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
+import org.openjdk.jmh.infra.IterationParams;
+import org.openjdk.jmh.results.BenchmarkResult;
+import org.openjdk.jmh.results.BenchmarkResultMetaData;
 
 import java.io.IOException;
 import java.io.StringWriter;
+import java.util.concurrent.TimeUnit;
 
 class ProfilerUtils {
 
@@ -78,5 +82,17 @@
         return set;
     }
 
+    public static long warmupDelayMs(BenchmarkResult br) {
+        BenchmarkResultMetaData md = br.getMetadata();
+        if (md != null) {
+            // try to ask harness itself:
+            return md.getMeasurementTime() - md.getStartTime();
+        } else {
+            // metadata is not available, let's make a guess:
+            IterationParams wp = br.getParams().getWarmup();
+            return wp.getCount() * wp.getTime().convertTo(TimeUnit.MILLISECONDS)
+                    + TimeUnit.SECONDS.toMillis(1); // loosely account for the JVM lag
+        }
+    }
 
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/SafepointsProfiler.java	Tue Nov 29 15:53:41 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/SafepointsProfiler.java	Tue Nov 29 16:06:36 2016 +0100
@@ -33,7 +33,6 @@
 import java.io.IOException;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
-import java.text.NumberFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
@@ -74,7 +73,7 @@
 
     @Override
     public Collection<? extends Result> afterTrial(BenchmarkResult br, long pid, File stdOut, File stdErr) {
-        long skip = br.getMetadata().getMeasurementTime() - br.getMetadata().getStartTime();
+        long skip = ProfilerUtils.warmupDelayMs(br);
 
         List<ParsedData> ds = new ArrayList<>();