提交 03e3eb11 编写于 作者: X Xin,Zhang 提交者: wu-sheng

Fix the GC value is incorrect (#1147)

上级 1ced58d6
......@@ -30,8 +30,10 @@ 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;
private long lastOGCCount = 0;
private long lastYGCCount = 0;
private long lastOGCCollectionTime = 0;
private long lastYGCCollectionTime = 0;
public GCModule(List<GarbageCollectorMXBean> beans) {
this.beans = beans;
......@@ -43,22 +45,30 @@ public abstract class GCModule implements GCMetricAccessor {
for (GarbageCollectorMXBean bean : beans) {
String name = bean.getName();
GCPhrase phrase;
long gcCount = 0;
long gcTime = 0;
if (name.equals(getNewGCName())) {
phrase = GCPhrase.NEW;
long collectionCount = bean.getCollectionCount();
gcCount = collectionCount - lastYGCCount;
lastYGCCount = collectionCount;
long time = bean.getCollectionTime();
gcTime = time - lastYGCCollectionTime;
lastYGCCollectionTime = time;
} else if (name.equals(getOldGCName())) {
phrase = GCPhrase.OLD;
long collectionCount = bean.getCollectionCount();
gcCount = collectionCount - lastOGCCount;
lastOGCCount = collectionCount;
long time = bean.getCollectionTime();
gcTime = time - lastOGCCollectionTime;
lastOGCCollectionTime = time;
} else {
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(gcCount)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册