changeset 899:90b9bf0da12d

profilers: clearly separate profiled and total counters.
author shade
date Tue, 08 Jul 2014 17:01:30 +0400
parents 2f7e02bfeb19
children fbccf73cf083
files jmh-core/src/main/java/org/openjdk/jmh/profile/ClassloaderProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/CompilerProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/GCProfiler.java
diffstat 3 files changed, 26 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/ClassloaderProfiler.java	Mon Jul 07 16:11:37 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/ClassloaderProfiler.java	Tue Jul 08 17:01:30 2014 +0400
@@ -75,20 +75,30 @@
         long loaded;
         long unloaded;
         ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
+
+        int loadedClassCount;
         try {
-            loaded = cl.getLoadedClassCount() - loadedClasses;
+            loadedClassCount = cl.getLoadedClassCount();
+            loaded = loadedClassCount - loadedClasses;
         } catch (UnsupportedOperationException e) {
             loaded = -1;
+            loadedClassCount = -1;
         }
+
+        long unloadedClassCount;
         try {
-            unloaded = cl.getUnloadedClassCount() - unloadedClasses;
+            unloadedClassCount = cl.getUnloadedClassCount();
+            unloaded = unloadedClassCount - unloadedClasses;
         } catch (UnsupportedOperationException e) {
             unloaded = -1;
+            unloadedClassCount = -1;
         }
 
         return Arrays.asList(
-                new ProfilerResult("@classload.loaded", loaded, "classes", AggregationPolicy.AVG),
-                new ProfilerResult("@classload.unloaded", unloaded, "classes", AggregationPolicy.AVG)
+                new ProfilerResult("@classload.loaded.profiled", loaded, "classes", AggregationPolicy.SUM),
+                new ProfilerResult("@classload.unloaded.profiled", unloaded, "classes", AggregationPolicy.SUM),
+                new ProfilerResult("@classload.loaded.total", loadedClassCount, "classes", AggregationPolicy.MAX),
+                new ProfilerResult("@classload.unloaded.total", unloadedClassCount, "classes", AggregationPolicy.MAX)
         );
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/CompilerProfiler.java	Mon Jul 07 16:11:37 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/CompilerProfiler.java	Tue Jul 08 17:01:30 2014 +0400
@@ -81,7 +81,8 @@
         }
 
         return Arrays.asList(
-                new ProfilerResult("@compiler.time", compTime, "ms", AggregationPolicy.AVG)
+                new ProfilerResult("@compiler.time.profiled", compTime, "ms", AggregationPolicy.SUM),
+                new ProfilerResult("@compiler.time.total", comp.getTotalCompilationTime(), "ms", AggregationPolicy.MAX)
         );
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/GCProfiler.java	Mon Jul 07 16:11:37 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/GCProfiler.java	Tue Jul 08 17:01:30 2014 +0400
@@ -37,9 +37,8 @@
 import java.util.concurrent.TimeUnit;
 
 public class GCProfiler implements InternalProfiler {
-    private long startGCCount;
-    private long startGCTime;
-    private long startTime;
+    private long beforeGCCount;
+    private long beforeGCTime;
 
     @Override
     public String getDescription() {
@@ -58,35 +57,30 @@
 
     @Override
     public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) {
-        this.startTime = System.nanoTime();
         long gcTime = 0;
         long gcCount = 0;
         for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
             gcCount += bean.getCollectionCount();
             gcTime += bean.getCollectionTime();
         }
-        this.startGCCount = gcCount;
-        this.startGCTime = gcTime;
+        this.beforeGCCount = gcCount;
+        this.beforeGCTime = gcTime;
     }
 
     @Override
     public Collection<? extends Result> afterIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) {
-        long endTime = System.nanoTime();
-        long gcTime = -startGCTime;
-        long gcCount = -startGCCount;
+        long gcTime = 0;
+        long gcCount = 0;
         for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
             gcCount += bean.getCollectionCount();
             gcTime += bean.getCollectionTime();
         }
 
         return Arrays.asList(
-                new ProfilerResult("@gc.count",
-                        gcCount,
-                        "counts", AggregationPolicy.AVG),
-
-                new ProfilerResult("@gc.time",
-                        100.0 * gcTime / TimeUnit.NANOSECONDS.toMillis(endTime - startTime),
-                        "%", AggregationPolicy.AVG)
+                new ProfilerResult("@gc.count.profiled", gcCount - beforeGCCount, "counts", AggregationPolicy.SUM),
+                new ProfilerResult("@gc.count.total", gcCount, "counts", AggregationPolicy.MAX),
+                new ProfilerResult("@gc.time.profiled", 100.0 * (gcTime - beforeGCTime), "ms", AggregationPolicy.SUM),
+                new ProfilerResult("@gc.time.total", 100.0 * gcTime, "ms", AggregationPolicy.MAX)
         );
     }