Skip to content
Snippets Groups Projects
Commit d19d10d7 authored by Christian Wulf's avatar Christian Wulf
Browse files

MooBench is now able to log the heap memory and gc collection count

parent 5d06c06d
No related branches found
No related tags found
No related merge requests found
...@@ -10,8 +10,15 @@ ...@@ -10,8 +10,15 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>de.walware.statet.r.builders.RSupport</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>de.walware.statet.base.StatetNature</nature>
<nature>de.walware.statet.r.RNature</nature>
</natures> </natures>
</projectDescription> </projectDescription>
...@@ -35,11 +35,12 @@ public final class BenchmarkingThreadNano implements BenchmarkingThread { ...@@ -35,11 +35,12 @@ public final class BenchmarkingThreadNano implements BenchmarkingThread {
private final long methodTime; private final long methodTime;
private final int recursionDepth; private final int recursionDepth;
private final long[] timings; private final long[] executionTimes;
private final long[] usedHeapMemory;
private final MemoryMXBean memory; private final MemoryMXBean memory;
private final long[] usedHeapMemory;
private final long[] gcCollectionCountDiffs;
private final List<GarbageCollectorMXBean> collector; private final List<GarbageCollectorMXBean> collector;
public BenchmarkingThreadNano(final MonitoredClass mc, final int totalCalls, public BenchmarkingThreadNano(final MonitoredClass mc, final int totalCalls,
...@@ -50,40 +51,47 @@ public final class BenchmarkingThreadNano implements BenchmarkingThread { ...@@ -50,40 +51,47 @@ public final class BenchmarkingThreadNano implements BenchmarkingThread {
this.methodTime = methodTime; this.methodTime = methodTime;
this.recursionDepth = recursionDepth; this.recursionDepth = recursionDepth;
// for monitoring execution times // for monitoring execution times
this.timings = new long[totalCalls]; this.executionTimes = new long[totalCalls];
// for monitoring memory consumption // for monitoring memory consumption
this.memory = ManagementFactory.getMemoryMXBean(); this.memory = ManagementFactory.getMemoryMXBean();
this.usedHeapMemory = new long[totalCalls]; this.usedHeapMemory = new long[totalCalls];
// for monitoring the garbage collector // for monitoring the garbage collector
this.gcCollectionCountDiffs = new long[totalCalls];
this.collector = ManagementFactory.getGarbageCollectorMXBeans(); this.collector = ManagementFactory.getGarbageCollectorMXBeans();
} }
public String print(final int index, final String separatorString) { public String print(final int index, final String separatorString) {
return "" + this.timings[index] /* + separatorString + this.usedHeapMemory[index] */; return String.format("%d%s%d%s%d",
this.executionTimes[index], separatorString,
this.usedHeapMemory[index], separatorString,
this.gcCollectionCountDiffs[index]);
} }
public final void run() { public final void run() {
long start_ns; long start_ns;
long stop_ns; long stop_ns;
final long gcBefore; long lastGcCount = this.computeGcCollectionCount();
final long gcAfter; long currentGcCount;
for (int i = 0; i < this.totalCalls; i++) { for (int i = 0; i < this.totalCalls; i++) {
// gcBefore = this.computeGcCollectionCount();
start_ns = this.getCurrentTimestamp(); start_ns = this.getCurrentTimestamp();
this.mc.monitoredMethod(this.methodTime, this.recursionDepth); this.mc.monitoredMethod(this.methodTime, this.recursionDepth);
stop_ns = this.getCurrentTimestamp(); stop_ns = this.getCurrentTimestamp();
// gcAfter = this.computeGcCollectionCount(); currentGcCount = this.computeGcCollectionCount();
// save execution time // save execution time
this.timings[i] = stop_ns - start_ns; this.executionTimes[i] = stop_ns - start_ns;
// save heap memory
this.usedHeapMemory[i] = this.memory.getHeapMemoryUsage().getUsed();
// save gc collection count
this.gcCollectionCountDiffs[i] = currentGcCount - lastGcCount;
lastGcCount = currentGcCount;
// print progress
if ((i % 100000) == 0) { if ((i % 100000) == 0) {
System.out.println(i); // NOPMD (System.out) System.out.println(i); // NOPMD (System.out)
} }
// save heap memory
this.usedHeapMemory[i] = this.memory.getHeapMemoryUsage().getUsed();
} }
this.doneSignal.countDown(); this.doneSignal.countDown();
......
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