use of org.talend.designer.runtime.visualization.internal.core.cpu.CpuModel in project tdi-studio-se by Talend.
the class MBeanServer method sampleProfilingData.
/**
* Samples the profiling data.
*
* @throws JvmCoreException
*/
void sampleProfilingData() throws JvmCoreException {
if (!checkReachability()) {
return;
}
ThreadMXBean threadMXBean;
try {
threadMXBean = (ThreadMXBean) getMXBean(ThreadMXBean.class, ManagementFactory.THREAD_MXBEAN_NAME);
} catch (IOException e) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getMBeanFailedMsg, ManagementFactory.THREAD_MXBEAN_NAME), e);
}
if (threadMXBean == null) {
throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.getMBeanFailedMsg, ManagementFactory.THREAD_MXBEAN_NAME), null);
}
CpuModel cpuModel = (CpuModel) jvm.getCpuProfiler().getCpuModel();
long samplingTime = System.currentTimeMillis();
long actualSamplingPeriodInMilliSeconds;
if (previousSamplingTime == 0) {
actualSamplingPeriodInMilliSeconds = samplingPeriod;
} else {
actualSamplingPeriodInMilliSeconds = samplingTime - previousSamplingTime;
}
Set<String> profiledPackages = jvm.getCpuProfiler().getProfiledPackages();
for (ThreadInfo threadInfo : threadMXBean.dumpAllThreads(true, false)) {
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
String threadName = threadInfo.getThreadName();
if (//$NON-NLS-1$
stackTrace.length > 0 && !threadName.startsWith("JMX ") && !threadName.startsWith("RMI ")) {
//$NON-NLS-1$
ThreadNode<CallTreeNode> callTreeThreadNode = cpuModel.getCallTreeThread(threadName);
ThreadNode<MethodNode> hotSpotThreadNode = cpuModel.getHotSpotThread(threadName);
if (callTreeThreadNode == null) {
callTreeThreadNode = new ThreadNode<CallTreeNode>(threadName);
}
if (hotSpotThreadNode == null) {
hotSpotThreadNode = new ThreadNode<MethodNode>(threadName);
}
updateCpuModel(callTreeThreadNode, hotSpotThreadNode, profiledPackages, invertStackTrace(stackTrace), actualSamplingPeriodInMilliSeconds);
if (callTreeThreadNode.hasChildren()) {
cpuModel.addCallTreeThread(callTreeThreadNode);
}
if (hotSpotThreadNode.hasChildren()) {
cpuModel.addHotSpotThread(hotSpotThreadNode);
}
}
}
previousSamplingTime = samplingTime;
}
Aggregations