JvmMonitor: Report jvm/gc/cpu in nanos. (#13383)

Our documentation says we report this in nanos, and we actually did
prior to #12481. This patch restores the prior behavior.
This commit is contained in:
Gian Merlino 2022-11-17 23:03:16 -08:00 committed by GitHub
parent 6ccf31490e
commit 092e769dd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -187,7 +187,7 @@ public class JvmMonitor extends FeedDefiningMonitor
private final GarbageCollectorMXBean gcBean;
private long lastInvocations = 0;
private long lastCpuNanos = 0;
private long lastCpuMillis = 0;
private static final String GC_YOUNG_GENERATION_NAME = "young";
private static final String GC_OLD_GENERATION_NAME = "old";
@ -268,10 +268,10 @@ public class JvmMonitor extends FeedDefiningMonitor
emitter.emit(builder.build("jvm/gc/count", newInvocations - lastInvocations));
lastInvocations = newInvocations;
long newCpuNanos = gcBean.getCollectionTime();
emitter.emit(builder.build("jvm/gc/cpu", newCpuNanos - lastCpuNanos));
lastCpuNanos = newCpuNanos;
// getCollectionTime is in milliseconds; we report jvm/gc/cpu in nanoseconds.
long newCpuMillis = gcBean.getCollectionTime();
emitter.emit(builder.build("jvm/gc/cpu", (newCpuMillis - lastCpuMillis) * 1_000_000L));
lastCpuMillis = newCpuMillis;
}
}