|
18 | 18 |
|
19 | 19 | package org.apache.skywalking.apm.agent.core.jvm.gc; |
20 | 20 |
|
| 21 | +import org.apache.skywalking.apm.network.language.agent.v3.GC; |
| 22 | +import org.apache.skywalking.apm.network.language.agent.v3.GCPhase; |
| 23 | + |
21 | 24 | import java.lang.management.GarbageCollectorMXBean; |
| 25 | +import java.util.LinkedList; |
22 | 26 | import java.util.List; |
23 | 27 |
|
24 | | -public class ZGCModule extends GCModule { |
| 28 | +public class ZGCModule implements GCMetricAccessor { |
| 29 | + private List<GarbageCollectorMXBean> beans; |
| 30 | + |
| 31 | + private long lastNormalGCCount = 0; |
| 32 | + private long lastNormalGCTime = 0; |
25 | 33 |
|
26 | 34 | public ZGCModule(List<GarbageCollectorMXBean> beans) { |
27 | | - super(beans); |
| 35 | + this.beans = beans; |
28 | 36 | } |
29 | 37 |
|
30 | 38 | @Override |
31 | | - protected String getOldGCName() { |
32 | | - return null; |
33 | | - } |
| 39 | + public List<GC> getGCList() { |
| 40 | + List<GC> gcList = new LinkedList<GC>(); |
| 41 | + for (GarbageCollectorMXBean bean : beans) { |
| 42 | + String name = bean.getName(); |
| 43 | + long gcCount = 0; |
| 44 | + long gcTime = 0; |
| 45 | + if (name.equals("ZGC")) { |
| 46 | + long collectionCount = bean.getCollectionCount(); |
| 47 | + gcCount = collectionCount - lastNormalGCCount; |
| 48 | + lastNormalGCCount = collectionCount; |
34 | 49 |
|
35 | | - @Override |
36 | | - protected String getNewGCName() { |
37 | | - return null; |
38 | | - } |
| 50 | + long time = bean.getCollectionTime(); |
| 51 | + gcTime = time - lastNormalGCTime; |
| 52 | + lastNormalGCTime = time; |
| 53 | + } else if (name.equals("ZGC Cycles")) { |
| 54 | + long collectionCount = bean.getCollectionCount(); |
| 55 | + gcCount = collectionCount - lastNormalGCCount; |
| 56 | + lastNormalGCCount = collectionCount; |
| 57 | + } else if (name.equals(" ZGC Pauses")) { |
| 58 | + long time = bean.getCollectionTime(); |
| 59 | + gcTime = time - lastNormalGCTime; |
| 60 | + lastNormalGCTime = time; |
| 61 | + } else { |
| 62 | + continue; |
| 63 | + } |
| 64 | + gcList.add(GC.newBuilder().setPhase(GCPhase.NORMAL).setCount(gcCount).setTime(gcTime).build()); |
| 65 | + } |
39 | 66 |
|
40 | | - @Override |
41 | | - protected String getNormalGCName() { |
42 | | - return "ZGC"; |
| 67 | + return gcList; |
43 | 68 | } |
44 | 69 | } |
0 commit comments