Fix the GC value is incorrect (#1147)
This commit is contained in:
parent
1ced58d6f8
commit
03e3eb11d5
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue