Skip to content
Snippets Groups Projects
Commit cbe36cd8 authored by Chris Larsen's avatar Chris Larsen
Browse files

[core] Add the Utils.getGCTotalTime() method for showing how long

the JVM spent in GC. It now prints the time and percent of time in
the final output.
Also fix cases where the garbage collector implementation returns
-1 if the count or time isn't implemented.
parent 7f0259f9
No related branches found
No related tags found
No related merge requests found
......@@ -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());
......
......@@ -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;
}
}
......@@ -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);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment