Support jdk17 zgc (#541)

This commit is contained in:
xu1009 2023-06-01 13:06:15 +08:00 committed by GitHub
parent d074a0a063
commit 97337063f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 43 deletions

View File

@ -5,6 +5,7 @@ Release Notes.
8.17.0
------------------
* Support Jdk17 ZGC metric collect
#### Documentation

View File

@ -36,8 +36,4 @@ public class CMSGCModule extends GCModule {
return "ParNew";
}
@Override
protected String getNormalGCName() {
return null;
}
}

View File

@ -36,8 +36,4 @@ public class G1GCModule extends GCModule {
return "G1 Young Generation";
}
@Override
protected String getNormalGCName() {
return null;
}
}

View File

@ -18,11 +18,12 @@
package org.apache.skywalking.apm.agent.core.jvm.gc;
import org.apache.skywalking.apm.network.language.agent.v3.GC;
import org.apache.skywalking.apm.network.language.agent.v3.GCPhase;
import java.lang.management.GarbageCollectorMXBean;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.network.language.agent.v3.GC;
import org.apache.skywalking.apm.network.language.agent.v3.GCPhase;
public abstract class GCModule implements GCMetricAccessor {
private List<GarbageCollectorMXBean> beans;
@ -31,8 +32,6 @@ public abstract class GCModule implements GCMetricAccessor {
private long lastYGCCount = 0;
private long lastOGCCollectionTime = 0;
private long lastYGCCollectionTime = 0;
private long lastNormalGCCount = 0;
private long lastNormalGCTime = 0;
public GCModule(List<GarbageCollectorMXBean> beans) {
this.beans = beans;
@ -64,15 +63,6 @@ public abstract class GCModule implements GCMetricAccessor {
long time = bean.getCollectionTime();
gcTime = time - lastOGCCollectionTime;
lastOGCCollectionTime = time;
} else if (name.equals(getNormalGCName())) {
phase = GCPhase.NORMAL;
long collectionCount = bean.getCollectionCount();
gcCount = collectionCount - lastNormalGCCount;
lastNormalGCCount = collectionCount;
long time = bean.getCollectionTime();
gcTime = time - lastNormalGCTime;
lastNormalGCTime = time;
} else {
continue;
}
@ -87,5 +77,4 @@ public abstract class GCModule implements GCMetricAccessor {
protected abstract String getNewGCName();
protected abstract String getNormalGCName();
}

View File

@ -36,9 +36,4 @@ public class ParallelGCModule extends GCModule {
return "PS Scavenge";
}
@Override
protected String getNormalGCName() {
return null;
}
}

View File

@ -36,8 +36,4 @@ public class SerialGCModule extends GCModule {
return "Copy";
}
@Override
protected String getNormalGCName() {
return null;
}
}

View File

@ -18,27 +18,52 @@
package org.apache.skywalking.apm.agent.core.jvm.gc;
import org.apache.skywalking.apm.network.language.agent.v3.GC;
import org.apache.skywalking.apm.network.language.agent.v3.GCPhase;
import java.lang.management.GarbageCollectorMXBean;
import java.util.LinkedList;
import java.util.List;
public class ZGCModule extends GCModule {
public class ZGCModule implements GCMetricAccessor {
private List<GarbageCollectorMXBean> beans;
private long lastNormalGCCount = 0;
private long lastNormalGCTime = 0;
public ZGCModule(List<GarbageCollectorMXBean> beans) {
super(beans);
this.beans = beans;
}
@Override
protected String getOldGCName() {
return null;
}
public List<GC> getGCList() {
List<GC> gcList = new LinkedList<GC>();
for (GarbageCollectorMXBean bean : beans) {
String name = bean.getName();
long gcCount = 0;
long gcTime = 0;
if (name.equals("ZGC")) {
long collectionCount = bean.getCollectionCount();
gcCount = collectionCount - lastNormalGCCount;
lastNormalGCCount = collectionCount;
@Override
protected String getNewGCName() {
return null;
}
long time = bean.getCollectionTime();
gcTime = time - lastNormalGCTime;
lastNormalGCTime = time;
} else if (name.equals("ZGC Cycles")) {
long collectionCount = bean.getCollectionCount();
gcCount = collectionCount - lastNormalGCCount;
lastNormalGCCount = collectionCount;
} else if (name.equals(" ZGC Pauses")) {
long time = bean.getCollectionTime();
gcTime = time - lastNormalGCTime;
lastNormalGCTime = time;
} else {
continue;
}
gcList.add(GC.newBuilder().setPhase(GCPhase.NORMAL).setCount(gcCount).setTime(gcTime).build());
}
@Override
protected String getNormalGCName() {
return "ZGC";
return gcList;
}
}