Skip to content

Commit 815eeba

Browse files
Fix bug with reporting negative allocation rate
1 parent e190fa0 commit 815eeba

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

build.boot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(task-options!
22
pom {:project 'com.clojure-goes-fast/jvm-alloc-rate-meter
3-
:version "0.1.3"
3+
:version "0.1.4-SNAPSHOT"
44
:description "Measure JVM heap allocation rate in real time"
55
:url "http://github.com/clojure-goes-fast/jvm-alloc-rate-meter"
66
:scm {:url "http://github.com/clojure-goes-fast/jvm-alloc-rate-meter"}

src/jvm_alloc_rate_meter/MeterThread.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,24 @@ public void run() {
3939
BigInteger lastThreadAllocated = BigInteger.valueOf(-1);
4040
try {
4141
while (doRun) {
42-
long heapUsage = usedHeap();
43-
long gcCounts = gcCounts();
44-
BigInteger threadAllocated = allocatedByAllThreads();
4542
long time = System.currentTimeMillis();
46-
4743
double multiplier = 1000.0 / (time - lastTime);
44+
45+
long heapUsage = usedHeap();
46+
long gcCounts = gcCounts();
4847
long deltaUsage = heapUsage - lastHeapUsage;
4948

49+
BigInteger threadAllocated = allocatedByAllThreads();
50+
BigInteger deltaAllocated = threadAllocated.subtract(lastThreadAllocated);
51+
5052
if (lastTime != 0) {
5153
if ((gcCounts == lastGcCounts) && (deltaUsage >= 0)) {
5254
long rate = Math.round(deltaUsage * multiplier);
5355
callback.accept(rate);
5456
} else if (threadAllocated.compareTo(BigInteger.ZERO) >= 0 &&
5557
lastThreadAllocated.compareTo(BigInteger.ZERO) >= 0 &&
56-
threadAllocated.compareTo(BigInteger.ZERO) >= 0) {
57-
long rate = Math.round(threadAllocated.subtract(lastThreadAllocated).longValue() * multiplier);
58+
deltaAllocated.compareTo(BigInteger.ZERO) >= 0) {
59+
long rate = Math.round(deltaAllocated.longValue() * multiplier);
5860
callback.accept(rate);
5961
} else {
6062
// Apparently, neither approach did well, just skip this

0 commit comments

Comments
 (0)