Fix the count of gc is incorrect. (#1054)

This commit is contained in:
吴晟 Wu Sheng 2018-04-09 18:53:08 +08:00 committed by GitHub
parent 1052f7292f
commit 1261e03c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 3 deletions

View File

@ -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()
);
}