-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LinShunKang
committed
Oct 20, 2018
1 parent
af0b3a3
commit 8d1bade
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
MyPerf4J-Core/src/test/java/MyPerf4J/AbstractBootstrapTest.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,62 @@ | ||
package MyPerf4J; | ||
|
||
import cn.myperf4j.base.config.ProfilingParams; | ||
import cn.myperf4j.base.constant.PropertyKeys; | ||
import cn.myperf4j.base.util.file.AutoRollingFileWriter; | ||
import cn.myperf4j.base.util.file.MinutelyRollingFileWriter; | ||
import cn.myperf4j.core.AbstractBootstrap; | ||
import cn.myperf4j.core.recorder.AbstractRecorderMaintainer; | ||
import cn.myperf4j.core.recorder.Recorders; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import static cn.myperf4j.base.constant.PropertyValues.METRICS_PROCESS_TYPE_INFLUX_DB; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/10/20 | ||
*/ | ||
public class AbstractBootstrapTest { | ||
|
||
@Test | ||
public void test() { | ||
initPropertiesFile(METRICS_PROCESS_TYPE_INFLUX_DB); | ||
boolean initial = new AbstractBootstrap() { | ||
@Override | ||
public AbstractRecorderMaintainer doInitRecorderMaintainer() { | ||
return new AbstractRecorderMaintainer() { | ||
@Override | ||
public boolean initOther() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void addRecorder(int methodTagId, ProfilingParams params) { | ||
for (int i = 0; i < recordersList.size(); ++i) { | ||
Recorders recorders = recordersList.get(i); | ||
recorders.setRecorder(methodTagId, createRecorder(methodTagId, params.getMostTimeThreshold(), params.getOutThresholdCount())); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean initOther() { | ||
return true; | ||
} | ||
}.initial(); | ||
|
||
Assert.assertTrue(initial); | ||
|
||
} | ||
|
||
private void initPropertiesFile(int metricsProcessorType) { | ||
String propertiesFile = "/tmp/MyPerf4J.properties"; | ||
System.setProperty(PropertyKeys.PRO_FILE_NAME, propertiesFile); | ||
AutoRollingFileWriter writer = new MinutelyRollingFileWriter(propertiesFile); | ||
writer.write("AppName=MyPerf4JTest\n"); | ||
writer.write("IncludePackages=MyPerf4J\n"); | ||
writer.write("MetricsProcessorType=" + metricsProcessorType + "\n"); | ||
writer.write("MillTimeSlice=1000\n"); | ||
writer.closeFile(true); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
MyPerf4J-Core/src/test/java/MyPerf4J/JvmMetricsSchedulerTest.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,40 @@ | ||
package MyPerf4J; | ||
|
||
import cn.myperf4j.base.Scheduler; | ||
import cn.myperf4j.base.config.MyProperties; | ||
import cn.myperf4j.base.config.ProfilingConfig; | ||
import cn.myperf4j.base.constant.PropertyKeys; | ||
import cn.myperf4j.base.constant.PropertyValues; | ||
import cn.myperf4j.base.metric.processor.*; | ||
import cn.myperf4j.core.scheduler.JvmMetricsScheduler; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Created by LinShunkang on 2018/10/19 | ||
*/ | ||
public class JvmMetricsSchedulerTest { | ||
|
||
@Test | ||
public void test() { | ||
init(); | ||
|
||
int processorType = PropertyValues.METRICS_PROCESS_TYPE_STDOUT; | ||
JvmClassMetricsProcessor classProcessor = MetricsProcessorFactory.getClassMetricsProcessor(processorType); | ||
JvmGCMetricsProcessor gcProcessor = MetricsProcessorFactory.getGCMetricsProcessor(processorType); | ||
JvmMemoryMetricsProcessor memoryProcessor = MetricsProcessorFactory.getMemoryMetricsProcessor(processorType); | ||
JvmThreadMetricsProcessor threadProcessor = MetricsProcessorFactory.getThreadMetricsProcessor(processorType); | ||
Scheduler scheduler = new JvmMetricsScheduler(classProcessor, gcProcessor, memoryProcessor, threadProcessor); | ||
long startMills = System.currentTimeMillis(); | ||
scheduler.run(startMills, startMills + 60 * 1000); | ||
} | ||
|
||
private void init() { | ||
ProfilingConfig config = ProfilingConfig.getInstance(); | ||
config.setMethodMetricsFile("/tmp/metrics.log"); | ||
config.setClassMetricsFile("/tmp/metrics.log"); | ||
config.setGcMetricsFile("/tmp/metrics.log"); | ||
config.setMemoryMetricsFile("/tmp/metrics.log"); | ||
config.setThreadMetricsFile("/tmp/metrics.log"); | ||
config.setLogRollingTimeUnit("DAILY"); | ||
} | ||
} |