-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: add BufferPool metrice; reduce MyPerf4J-ASM.jar size; upgrade a…
…sm version to 7.0; upgrade to 2.1.0
- Loading branch information
LinShunKang
committed
Nov 4, 2018
1 parent
495dc3c
commit 7f56fc1
Showing
21 changed files
with
434 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
MyPerf4J-Base/src/main/java/cn/myperf4j/base/metric/JvmBufferPoolMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cn.myperf4j.base.metric; | ||
|
||
import java.lang.management.BufferPoolMXBean; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/11/1 | ||
*/ | ||
public class JvmBufferPoolMetrics extends Metrics { | ||
|
||
private static final long serialVersionUID = 1308517280962399791L; | ||
|
||
private String name; | ||
|
||
private long count; | ||
|
||
private long memoryUsed; | ||
|
||
private long memoryCapacity; | ||
|
||
public JvmBufferPoolMetrics(BufferPoolMXBean mxBean) { | ||
this.name = mxBean.getName(); | ||
this.count = mxBean.getCount(); | ||
this.memoryUsed = mxBean.getMemoryUsed(); | ||
this.memoryCapacity = mxBean.getTotalCapacity(); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public long getCount() { | ||
return count; | ||
} | ||
|
||
public long getMemoryUsed() { | ||
return memoryUsed; | ||
} | ||
|
||
public long getMemoryCapacity() { | ||
return memoryCapacity; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JvmBufferPoolMetrics{" + | ||
"name='" + name + '\'' + | ||
", count=" + count + | ||
", memoryUsed=" + memoryUsed + | ||
", memoryCapacity=" + memoryCapacity + | ||
'}'; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...J-Base/src/main/java/cn/myperf4j/base/metric/formatter/JvmBufferPoolMetricsFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.myperf4j.base.metric.formatter; | ||
|
||
import cn.myperf4j.base.metric.JvmBufferPoolMetrics; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/8/21 | ||
*/ | ||
public interface JvmBufferPoolMetricsFormatter extends MetricsFormatter<JvmBufferPoolMetrics> { | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...ain/java/cn/myperf4j/base/metric/formatter/impl/DefaultJvmBufferPoolMetricsFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cn.myperf4j.base.metric.formatter.impl; | ||
|
||
import cn.myperf4j.base.metric.JvmBufferPoolMetrics; | ||
import cn.myperf4j.base.metric.formatter.JvmBufferPoolMetricsFormatter; | ||
import cn.myperf4j.base.util.DateFormatUtils; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by LinShunkang on 1919/8/21 | ||
*/ | ||
public class DefaultJvmBufferPoolMetricsFormatter implements JvmBufferPoolMetricsFormatter { | ||
|
||
@Override | ||
public String format(List<JvmBufferPoolMetrics> metricsList, long startMillis, long stopMillis) { | ||
String dataTitleFormat = "%-19s%19s%19s%19s%n"; | ||
StringBuilder sb = new StringBuilder((metricsList.size() + 2) * (3 * 19 + 64)); | ||
sb.append("MyPerf4J JVM BufferPool Metrics [").append(DateFormatUtils.format(startMillis)).append(", ").append(DateFormatUtils.format(stopMillis)).append("]").append(String.format("%n")); | ||
sb.append(String.format(dataTitleFormat, "Name", "Count", "MemoryUsed", "MemoryCapacity")); | ||
if (metricsList.isEmpty()) { | ||
return sb.toString(); | ||
} | ||
|
||
String dataFormat = "%-19s%19d%19d%19d%n"; | ||
for (int i = 0; i < metricsList.size(); ++i) { | ||
JvmBufferPoolMetrics metrics = metricsList.get(i); | ||
sb.append(String.format(dataFormat, | ||
metrics.getName(), | ||
metrics.getCount(), | ||
metrics.getMemoryUsed(), | ||
metrics.getMemoryCapacity())); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...rc/main/java/cn/myperf4j/base/metric/processor/AbstractJvmBufferPoolMetricsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cn.myperf4j.base.metric.processor; | ||
|
||
import cn.myperf4j.base.config.ProfilingConfig; | ||
import cn.myperf4j.base.log.ILogger; | ||
import cn.myperf4j.base.log.LoggerFactory; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/8/25 | ||
*/ | ||
public abstract class AbstractJvmBufferPoolMetricsProcessor implements JvmBufferPoolMetricsProcessor { | ||
|
||
protected ILogger logger = LoggerFactory.getLogger(ProfilingConfig.getInstance().getBufferPoolMetricsFile()); | ||
|
||
@Override | ||
public void beforeProcess(long processId, long startMillis, long stopMillis) { | ||
//empty | ||
} | ||
|
||
@Override | ||
public void afterProcess(long processId, long startMillis, long stopMillis) { | ||
logger.flushLog(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...J-Base/src/main/java/cn/myperf4j/base/metric/processor/JvmBufferPoolMetricsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.myperf4j.base.metric.processor; | ||
|
||
import cn.myperf4j.base.metric.JvmBufferPoolMetrics; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/8/21 | ||
*/ | ||
public interface JvmBufferPoolMetricsProcessor extends MetricsProcessor<JvmBufferPoolMetrics> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ava/cn/myperf4j/base/metric/processor/influxdb/InfluxDBJvmBufferPoolMetricsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cn.myperf4j.base.metric.processor.influxdb; | ||
|
||
import cn.myperf4j.base.config.ProfilingConfig; | ||
import cn.myperf4j.base.metric.JvmBufferPoolMetrics; | ||
import cn.myperf4j.base.metric.processor.AbstractJvmBufferPoolMetricsProcessor; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/8/25 | ||
*/ | ||
public class InfluxDBJvmBufferPoolMetricsProcessor extends AbstractJvmBufferPoolMetricsProcessor { | ||
|
||
private ThreadLocal<StringBuilder> sbThreadLocal = new ThreadLocal<StringBuilder>() { | ||
@Override | ||
protected StringBuilder initialValue() { | ||
return new StringBuilder(128); | ||
} | ||
}; | ||
|
||
@Override | ||
public void process(JvmBufferPoolMetrics metrics, long processId, long startMillis, long stopMillis) { | ||
StringBuilder sb = sbThreadLocal.get(); | ||
try { | ||
logger.log(createLineProtocol(metrics, startMillis * 1000 * 1000L, sb)); | ||
} finally { | ||
sb.setLength(0); | ||
} | ||
} | ||
|
||
private String createLineProtocol(JvmBufferPoolMetrics metrics, long startNanos, StringBuilder sb) { | ||
sb.append("jvm_buffer_pool_metrics") | ||
.append(",AppName=").append(ProfilingConfig.getInstance().getAppName()) | ||
.append(",PoolName=").append(metrics.getName()) | ||
.append(" Count=").append(metrics.getCount()).append("i") | ||
.append(",MemoryUsed=").append(metrics.getMemoryUsed()).append("i") | ||
.append(",MemoryCapacity=").append(metrics.getMemoryCapacity()).append("i") | ||
.append(" ").append(startNanos); | ||
return sb.toString(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
.../main/java/cn/myperf4j/base/metric/processor/log/LoggerJvmBufferPoolMetricsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cn.myperf4j.base.metric.processor.log; | ||
|
||
import cn.myperf4j.base.metric.JvmBufferPoolMetrics; | ||
import cn.myperf4j.base.metric.formatter.JvmBufferPoolMetricsFormatter; | ||
import cn.myperf4j.base.metric.formatter.impl.DefaultJvmBufferPoolMetricsFormatter; | ||
import cn.myperf4j.base.metric.processor.AbstractJvmBufferPoolMetricsProcessor; | ||
import cn.myperf4j.base.util.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/8/25 | ||
*/ | ||
public class LoggerJvmBufferPoolMetricsProcessor extends AbstractJvmBufferPoolMetricsProcessor { | ||
|
||
private ConcurrentHashMap<Long, List<JvmBufferPoolMetrics>> metricsMap = new ConcurrentHashMap<>(8); | ||
|
||
private JvmBufferPoolMetricsFormatter metricsFormatter = new DefaultJvmBufferPoolMetricsFormatter(); | ||
|
||
@Override | ||
public void beforeProcess(long processId, long startMillis, long stopMillis) { | ||
metricsMap.put(processId, new ArrayList<JvmBufferPoolMetrics>(2)); | ||
} | ||
|
||
@Override | ||
public void process(JvmBufferPoolMetrics metrics, long processId, long startMillis, long stopMillis) { | ||
List<JvmBufferPoolMetrics> metricsList = metricsMap.get(processId); | ||
if (metricsList != null) { | ||
metricsList.add(metrics); | ||
} else { | ||
Logger.error("LoggerJvmBufferPoolMetricsProcessor.process(" + processId + ", " + startMillis + ", " + stopMillis + "): metricsList is null!!!"); | ||
} | ||
} | ||
|
||
@Override | ||
public void afterProcess(long processId, long startMillis, long stopMillis) { | ||
List<JvmBufferPoolMetrics> metricsList = metricsMap.remove(processId); | ||
if (metricsList != null) { | ||
logger.logAndFlush(metricsFormatter.format(metricsList, startMillis, stopMillis)); | ||
} else { | ||
Logger.error("LoggerJvmBufferPoolMetricsProcessor.afterProcess(" + processId + ", " + startMillis + ", " + stopMillis + "): metricsList is null!!!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.