From 1261e03c9b7e88b4c5cc94ddc14c9d77c2c11c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Mon, 9 Apr 2018 18:53:08 +0800 Subject: [PATCH] Fix the count of gc is incorrect. (#1054) --- .../apm/agent/core/jvm/gc/GCModule.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCModule.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCModule.java index 5582ce2f0..2789be9cd 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCModule.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/gc/GCModule.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.agent.core.jvm.gc; import java.lang.management.GarbageCollectorMXBean; @@ -31,6 +30,9 @@ import org.apache.skywalking.apm.network.proto.GCPhrase; public abstract class GCModule implements GCMetricAccessor { private List beans; + private long lastGCCount = 0; + private long lastCollectionTime = 0; + public GCModule(List beans) { this.beans = beans; } @@ -49,10 +51,18 @@ public abstract class GCModule implements GCMetricAccessor { continue; } + long collectionCount = bean.getCollectionCount(); + long gcCount = collectionCount - lastGCCount; + lastGCCount = collectionCount; + + long time = bean.getCollectionTime(); + long gcTime = time - lastCollectionTime; + lastCollectionTime = time; + gcList.add( GC.newBuilder().setPhrase(phrase) - .setCount(bean.getCollectionCount()) - .setTime(bean.getCollectionTime()) + .setCount(gcCount) + .setTime(gcTime) .build() ); }