下面列出了java.lang.management.CompilationMXBean#getTotalCompilationTime ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void sense(final MetricContext metricContext)
{
CompilationMXBean mxBean = ManagementFactory.getCompilationMXBean();
// Compilation time may not be supported on some platforms, skip if so.
if (!mxBean.isCompilationTimeMonitoringSupported()) {
return;
}
long total = mxBean.getTotalCompilationTime();
metricContext.record(TOTAL_COMPILATION_TIME, total, Unit.MILLISECOND);
metricContext.record(COMPILATION_TIME, total - prevTotal, Unit.MILLISECOND);
this.prevTotal = total;
}
/**
* Returns the total time of asynchronous JIT compilation in milliseconds.
*
* @return JIT compile time
*/
public static long getJITCompileTime(){
long ret = -1; //unsupported
CompilationMXBean cmx = ManagementFactory.getCompilationMXBean();
if( cmx.isCompilationTimeMonitoringSupported() )
{
ret = cmx.getTotalCompilationTime();
ret += jitCompileTime; //add from remote processes
}
return ret;
}
@Override
protected IMonitoringRecord[] createNewMonitoringRecords(final long timestamp, final String hostname, final String vmName,
final IMonitoringController monitoringCtr) {
if (!monitoringCtr.isProbeActivated(SignatureFactory.createJVMCompilationSignature())) {
return new IMonitoringRecord[] {};
}
final CompilationMXBean compilationBean = ManagementFactory.getCompilationMXBean();
return new IMonitoringRecord[] { new CompilationRecord(timestamp, hostname, vmName, compilationBean.getName(), compilationBean.getTotalCompilationTime()), };
}
/**
* Returns the total time of asynchronous JIT compilation in milliseconds.
*
* @return JIT compile time
*/
public static long getJITCompileTime(){
long ret = -1; //unsupported
CompilationMXBean cmx = ManagementFactory.getCompilationMXBean();
if( cmx.isCompilationTimeMonitoringSupported() )
{
ret = cmx.getTotalCompilationTime();
ret += jitCompileTime; //add from remote processes
}
return ret;
}
public void run() {
TelemetryDataDto telemetryDataDto = new TelemetryDataDto();
telemetryDataDto.time = System.currentTimeMillis();
Runtime runtime = Runtime.getRuntime();
telemetryDataDto.freeMemory = runtime.freeMemory();
telemetryDataDto.maxMemory = runtime.maxMemory();
telemetryDataDto.totalMemory = runtime.totalMemory();
ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
telemetryDataDto.loadedClassCount = classLoadingMXBean.getLoadedClassCount();
telemetryDataDto.classCount = classLoadingMXBean.getTotalLoadedClassCount();
telemetryDataDto.unloadedClassCount = classLoadingMXBean.getUnloadedClassCount();
CompilationMXBean compilationMXBean = ManagementFactory.getCompilationMXBean();
telemetryDataDto.totalCompilationTime = compilationMXBean.getTotalCompilationTime();
if (null != profiler)
profiler.sendMessage(new TelemetryDataMessage(telemetryDataDto));
}