changeset 1386:eba61e9f1d2a

7901856: safepoints profiler should report application stopped time
author shade
date Mon, 05 Dec 2016 12:49:50 +0100
parents 2e94f4ff263b
children 1e15cc553559
files jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerUtils.java jmh-core/src/main/java/org/openjdk/jmh/profile/SafepointsProfiler.java
diffstat 2 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerUtils.java	Thu Dec 01 12:23:24 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerUtils.java	Mon Dec 05 12:49:50 2016 +0100
@@ -95,4 +95,15 @@
         }
     }
 
+    public static long measuredTimeMs(BenchmarkResult br) {
+        BenchmarkResultMetaData md = br.getMetadata();
+        if (md != null) {
+            // try to ask harness itself:
+            return md.getStopTime() - md.getMeasurementTime();
+        } else {
+            // metadata is not available, let's make a guess:
+            IterationParams mp = br.getParams().getMeasurement();
+            return mp.getCount() * mp.getTime().convertTo(TimeUnit.MILLISECONDS);
+        }
+    }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/SafepointsProfiler.java	Thu Dec 01 12:23:24 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/SafepointsProfiler.java	Mon Dec 05 12:49:50 2016 +0100
@@ -74,6 +74,7 @@
     @Override
     public Collection<? extends Result> afterTrial(BenchmarkResult br, long pid, File stdOut, File stdErr) {
         long skip = ProfilerUtils.warmupDelayMs(br);
+        long measuredTime = ProfilerUtils.measuredTimeMs(br);
 
         List<ParsedData> ds = new ArrayList<>();
 
@@ -108,7 +109,12 @@
             }
         }
 
-        Collection<SafepointProfilerResult> results = new ArrayList<>();
+        Collection<Result> results = new ArrayList<>();
+
+        results.add(new ScalarResult(Defaults.PREFIX + "safepoints.app.stopped",
+                pauseBuff.getStatistics(100).getSum() / TimeUnit.MILLISECONDS.toNanos(measuredTime),
+                "%", AggregationPolicy.AVG));
+
         results.add(new SafepointProfilerResult("pause", pauseBuff));
 
         // JDK 7 does not have TTSP measurements, ignore the zero metric: