This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch fix/gc
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git

commit c443182e5a803ff250f4581806ecc07c511b8536
Author: wu-sheng <wu.sh...@foxmail.com>
AuthorDate: Mon Apr 9 16:02:15 2018 +0800

    Fix the count of gc is incorrect.
---
 .../skywalking/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 5582ce2..2789be9 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<GarbageCollectorMXBean> beans;
 
+    private long lastGCCount = 0;
+    private long lastCollectionTime = 0;
+
     public GCModule(List<GarbageCollectorMXBean> 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()
             );
         }

-- 
To stop receiving notification emails like this one, please contact
wush...@apache.org.

Reply via email to