Skip to content

Commit

Permalink
Core&Base:完善JVM相关监控
Browse files Browse the repository at this point in the history
  • Loading branch information
linshunkang committed Aug 22, 2018
1 parent f26f3c6 commit 5eaadf6
Show file tree
Hide file tree
Showing 21 changed files with 607 additions and 282 deletions.
3 changes: 1 addition & 2 deletions MyPerf4J-ASM/src/main/java/cn/myperf4j/asm/ASMBootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ public static ASMBootstrap getInstance() {
@Override
public AbstractRecorderMaintainer doInitRecorderMaintainer() {
boolean accurateMode = ProfilingConfig.getInstance().isAccurateMode();
long milliTimeSlice = ProfilingConfig.getInstance().getMilliTimeSlice();
int backupRecorderCount = ProfilingConfig.getInstance().getBackupRecorderCount();

ASMRecorderMaintainer maintainer = ASMRecorderMaintainer.getInstance();
if (maintainer.initial(processor, accurateMode, backupRecorderCount, milliTimeSlice)) {
if (maintainer.initial(processor, accurateMode, backupRecorderCount)) {
return maintainer;
}
return null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ public class ProfilingConfig {

private static final ProfilingConfig instance = new ProfilingConfig();

private String perStatsProcessor;
private String methodMetricsProcessor;

private String classMetricsProcessor;

private String gcMetricsProcessor;

private String memoryMetricsProcessor;

private String threadMetricsProcessor;

private String recorderMode;

Expand Down Expand Up @@ -46,12 +54,44 @@ public static ProfilingConfig getInstance() {
return instance;
}

public String getPerStatsProcessor() {
return perStatsProcessor;
public String getMethodMetricsProcessor() {
return methodMetricsProcessor;
}

public void setMethodMetricsProcessor(String methodMetricsProcessor) {
this.methodMetricsProcessor = methodMetricsProcessor;
}

public String getClassMetricsProcessor() {
return classMetricsProcessor;
}

public void setClassMetricsProcessor(String classMetricsProcessor) {
this.classMetricsProcessor = classMetricsProcessor;
}

public String getGcMetricsProcessor() {
return gcMetricsProcessor;
}

public void setGcMetricsProcessor(String gcMetricsProcessor) {
this.gcMetricsProcessor = gcMetricsProcessor;
}

public String getMemoryMetricsProcessor() {
return memoryMetricsProcessor;
}

public void setMemoryMetricsProcessor(String memoryMetricsProcessor) {
this.memoryMetricsProcessor = memoryMetricsProcessor;
}

public String getThreadMetricsProcessor() {
return threadMetricsProcessor;
}

public void setPerStatsProcessor(String perStatsProcessor) {
this.perStatsProcessor = perStatsProcessor;
public void setThreadMetricsProcessor(String threadMetricsProcessor) {
this.threadMetricsProcessor = threadMetricsProcessor;
}

public String getRecorderMode() {
Expand Down Expand Up @@ -162,7 +202,11 @@ public ProfilingParams getProfilingParam(String methodName) {
@Override
public String toString() {
return "ProfilingConfig{" +
"perStatsProcessor='" + perStatsProcessor + '\'' +
"methodMetricsProcessor='" + methodMetricsProcessor + '\'' +
", classMetricsProcessor='" + classMetricsProcessor + '\'' +
", gcMetricsProcessor='" + gcMetricsProcessor + '\'' +
", memoryMetricsProcessor='" + memoryMetricsProcessor + '\'' +
", threadMetricsProcessor='" + threadMetricsProcessor + '\'' +
", recorderMode='" + recorderMode + '\'' +
", backupRecorderCount=" + backupRecorderCount +
", milliTimeSlice=" + milliTimeSlice +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ public interface PropertyKeys {

String PRO_FILE_NAME = "MyPerf4JPropFile";

String PERF_STATS_PROCESSOR = "MethodMetricsProcessor";
String METHOD_METRICS_PROCESSOR = "MethodMetricsProcessor";

String CLASS_METRICS_PROCESSOR = "ClassMetricsProcessor";

String GC_METRICS_PROCESSOR = "GCMetricsProcessor";

String MEM_METRICS_PROCESSOR = "MemMetricsProcessor";

String THREAD_METRICS_PROCESSOR = "ThreadMetricsProcessor";

String RECORDER_MODE = "RecorderMode";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.myperf4j.base.constant;

import cn.myperf4j.base.metric.processor.impl.StdoutMethodMetricProcessor;
import cn.myperf4j.base.metric.processor.impl.*;

/**
* Created by LinShunkang on 2018/4/27
Expand All @@ -17,7 +17,15 @@ public interface PropertyValues {

int MAX_BACKUP_RECORDERS_COUNT = 8;

String DEFAULT_PERF_STATS_PROCESSOR = StdoutMethodMetricProcessor.class.getName();
String DEFAULT_METHOD_PROCESSOR = StdoutMethodMetricProcessor.class.getName();

String DEFAULT_CLASS_PROCESSOR = StdoutJVMClassMetricsProcessor.class.getName();

String DEFAULT_GC_PROCESSOR = StdoutJVMGCMetricsProcessor.class.getName();

String DEFAULT_MEM_PROCESSOR = StdoutJVMMemoryMetricsProcessor.class.getName();

String DEFAULT_THREAD_PROCESSOR = StdoutJVMThreadMetricsProcessor.class.getName();

long DEFAULT_TIME_SLICE = 60 * 1000L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ public class JVMClassMetrics extends Metrics {

private long unloaded;

public JVMClassMetrics(long total, long loaded, long unloaded) {
this.total = total;
this.loaded = loaded;
this.unloaded = unloaded;
}

public JVMClassMetrics(ClassLoadingMXBean bean) {
this(bean.getTotalLoadedClassCount(), bean.getLoadedClassCount(), bean.getUnloadedClassCount());
}

public long getTotal() {
return total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ public class JVMGCMetrics extends Metrics {

private String gcName;

private int collectCount;
private long collectCount;

private int collectTime;
private long collectTime;

public JVMGCMetrics(String gcName, long collectCount, long collectTime) {
this.gcName = gcName;
this.collectCount = collectCount;
this.collectTime = collectTime;
}

public JVMGCMetrics(GarbageCollectorMXBean bean) {
this(bean.getName(), bean.getCollectionCount(), bean.getCollectionTime());
}

public String getGcName() {
return gcName;
Expand All @@ -25,19 +35,19 @@ public void setGcName(String gcName) {
this.gcName = gcName;
}

public int getCollectCount() {
public long getCollectCount() {
return collectCount;
}

public void setCollectCount(int collectCount) {
public void setCollectCount(long collectCount) {
this.collectCount = collectCount;
}

public int getCollectTime() {
public long getCollectTime() {
return collectTime;
}

public void setCollectTime(int collectTime) {
public void setCollectTime(long collectTime) {
this.collectTime = collectTime;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ public class JVMMemoryMetrics extends Metrics {

private long heapMax;

public JVMMemoryMetrics(long nonHeapInit, long nonHeapUsed, long nonHeapCommitted, long nonHeapMax, long heapInit, long heapUsed, long heapCommitted, long heapMax) {
this.nonHeapInit = nonHeapInit;
this.nonHeapUsed = nonHeapUsed;
this.nonHeapCommitted = nonHeapCommitted;
this.nonHeapMax = nonHeapMax;
this.heapInit = heapInit;
this.heapUsed = heapUsed;
this.heapCommitted = heapCommitted;
this.heapMax = heapMax;
}

private long codeCacheInit;

private long codeCacheUsed;

private long codeCacheCommitted;

private long codeCacheMax;

public JVMMemoryMetrics(MemoryUsage nonHeapMem, MemoryUsage heapMem) {
this(nonHeapMem.getInit(), nonHeapMem.getUsed(), nonHeapMem.getCommitted(), nonHeapMem.getMax(),
heapMem.getInit(), heapMem.getUsed(), heapMem.getCommitted(), heapMem.getMax());
}

public long getNonHeapInit() {
return nonHeapInit;
Expand Down Expand Up @@ -105,38 +112,6 @@ public void setHeapMax(long heapMax) {
this.heapMax = heapMax;
}

public long getCodeCacheInit() {
return codeCacheInit;
}

public void setCodeCacheInit(long codeCacheInit) {
this.codeCacheInit = codeCacheInit;
}

public long getCodeCacheUsed() {
return codeCacheUsed;
}

public void setCodeCacheUsed(long codeCacheUsed) {
this.codeCacheUsed = codeCacheUsed;
}

public long getCodeCacheCommitted() {
return codeCacheCommitted;
}

public void setCodeCacheCommitted(long codeCacheCommitted) {
this.codeCacheCommitted = codeCacheCommitted;
}

public long getCodeCacheMax() {
return codeCacheMax;
}

public void setCodeCacheMax(long codeCacheMax) {
this.codeCacheMax = codeCacheMax;
}

@Override
public String toString() {
return "JVMMemoryMetrics{" +
Expand All @@ -148,15 +123,12 @@ public String toString() {
", heapUsed=" + heapUsed +
", heapCommitted=" + heapCommitted +
", heapMax=" + heapMax +
", codeCacheInit=" + codeCacheInit +
", codeCacheUsed=" + codeCacheUsed +
", codeCacheCommitted=" + codeCacheCommitted +
", codeCacheMax=" + codeCacheMax +
'}';
}

/**
* -XX:+UseG1GC
*
* @param args
*/
public static void main(String[] args) {
Expand Down
Loading

0 comments on commit 5eaadf6

Please sign in to comment.