diff --git a/core/src/main/java/com/yahoo/ycsb/Client.java b/core/src/main/java/com/yahoo/ycsb/Client.java index c7ff4952d44e7f806c09f688c294ed639ab86cf0..0e0991189832847aed740944f31d167b885cde6a 100644 --- a/core/src/main/java/com/yahoo/ycsb/Client.java +++ b/core/src/main/java/com/yahoo/ycsb/Client.java @@ -76,6 +76,7 @@ class StatusThread extends Thread private double _maxLoadAvg; private double _minLoadAvg = Double.MAX_VALUE; private long lastGCCount = 0; + private long lastGCTime = 0; /** * Creates a new StatusThread without JVM stat tracking. @@ -274,7 +275,10 @@ class StatusThread extends Thread final long gcs = Utils.getGCTotalCollectionCount(); _measurements.measure("GCS", (int)(gcs - lastGCCount)); + final long gcTime = Utils.getGCTotalTime(); + _measurements.measure("GCS_TIME", (int)(gcTime - lastGCTime)); lastGCCount = gcs; + lastGCTime = gcTime; } /** @return The maximum threads running during the test. */ @@ -693,6 +697,9 @@ public class Client exporter.write("OVERALL", "Throughput(ops/sec)", throughput); exporter.write("TOTAL_GCs", "Count", Utils.getGCTotalCollectionCount()); + final long gcTime = Utils.getGCTotalTime(); + exporter.write("TOTAL_GC_TIME", "Time(ms)", gcTime); + exporter.write("TOTAL_GC_TIME_%", "Time(%)", ((double)gcTime / runtime) * (double)100); if (statusthread != null && statusthread.trackJVMStats()) { exporter.write("MAX_MEM_USED", "MBs", statusthread.getMaxUsedMem()); exporter.write("MIN_MEM_USED", "MBs", statusthread.getMinUsedMem()); diff --git a/core/src/main/java/com/yahoo/ycsb/Utils.java b/core/src/main/java/com/yahoo/ycsb/Utils.java index 219906770dfdc89fc0bd54ec30dd0a86d8c3642f..a6af3e173d7e6c210bd069b81bbf67ec22568cbe 100644 --- a/core/src/main/java/com/yahoo/ycsb/Utils.java +++ b/core/src/main/java/com/yahoo/ycsb/Utils.java @@ -219,8 +219,25 @@ public class Utils ManagementFactory.getGarbageCollectorMXBeans(); long count = 0; for (final GarbageCollectorMXBean bean : gcBeans) { + if (bean.getCollectionCount() < 0) { + continue; + } count += bean.getCollectionCount(); } return count; } + + /** @return The total time, in milliseconds, spent in GC. */ + public static long getGCTotalTime() { + final List<GarbageCollectorMXBean> gcBeans = + ManagementFactory.getGarbageCollectorMXBeans(); + long time = 0; + for (final GarbageCollectorMXBean bean : gcBeans) { + if (bean.getCollectionTime() < 0) { + continue; + } + time += bean.getCollectionTime(); + } + return time; + } } diff --git a/core/src/test/java/com/yahoo/ycsb/TestUtils.java b/core/src/test/java/com/yahoo/ycsb/TestUtils.java index 7121313781c85c681b72a738a87f874947c7e422..f9fddf7610503f5e3b64e533d67208b589b13b9e 100644 --- a/core/src/test/java/com/yahoo/ycsb/TestUtils.java +++ b/core/src/test/java/com/yahoo/ycsb/TestUtils.java @@ -110,6 +110,8 @@ public class TestUtils { Utils.getSystemLoadAverage(); // This will probably be zero but should never be negative. assertTrue(Utils.getGCTotalCollectionCount() >= 0); + // Could be zero similar to GC total collection count + assertTrue(Utils.getGCTotalTime() >= 0); } /**