use of org.talend.designer.runtime.visualization.internal.core.cpu.CallTreeNode 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;
}
use of org.talend.designer.runtime.visualization.internal.core.cpu.CallTreeNode in project tdi-studio-se by Talend.
the class MBeanServer method updateFrameNode.
/**
* Updates the frame node.
*
* @param callTreeThreadNode The call tree thread node
* @param currentFrameNode The current frame node
* @param methodName The method name
* @param isNewStack True if the given method is new stack
* @param period The sampling period
* @param isLeaf True if the given method name is leaf
* @return The frame node
*/
private CallTreeNode updateFrameNode(ThreadNode<CallTreeNode> callTreeThreadNode, CallTreeNode currentFrameNode, String methodName, boolean isNewStack, long period, boolean isLeaf) {
CallTreeNode frameNode;
if (currentFrameNode == null) {
frameNode = (CallTreeNode) callTreeThreadNode.getChild(methodName);
} else {
frameNode = currentFrameNode.getChild(methodName);
}
if (frameNode == null) {
if (currentFrameNode == null) {
frameNode = new CallTreeNode(jvm.getCpuProfiler().getCpuModel(), methodName, period, 1, callTreeThreadNode);
callTreeThreadNode.addChild(frameNode);
} else {
frameNode = new CallTreeNode(jvm.getCpuProfiler().getCpuModel(), methodName, period, 1, currentFrameNode, callTreeThreadNode);
currentFrameNode.addChild(frameNode);
}
} else {
if (isNewStack) {
frameNode.setInvocationCount(frameNode.getInvocationCount() + 1);
}
frameNode.setTotalTime(frameNode.getTotalTime() + period);
}
if (isLeaf) {
frameNode.setSelfTime(frameNode.getSelfTime() + period);
}
return frameNode;
}
use of org.talend.designer.runtime.visualization.internal.core.cpu.CallTreeNode in project tdi-studio-se by Talend.
the class MBeanServer method updateCpuModel.
/**
* Updates the CPU model.
*
* @param stackTrace The stack trace
* @param callTreeThreadNode The call tree thread node
* @param hotSpotThreadNode The hot spot thread node
* @param profiledPackages The profiled packages
* @param period The actual sampling period
*/
private void updateCpuModel(ThreadNode<CallTreeNode> callTreeThreadNode, ThreadNode<MethodNode> hotSpotThreadNode, Set<String> profiledPackages, StackTraceElement[] stackTrace, long period) {
String threadName = callTreeThreadNode.getName();
StackTraceElement[] previousStackTrace = previousStackTraces.get(threadName);
boolean isNewStack = false;
CallTreeNode currentFrameNode = null;
boolean isRootStack = true;
for (int i = 0; i < stackTrace.length; i++) {
if (!isProfiledPackage(stackTrace[i].getClassName(), profiledPackages)) {
continue;
}
String methodName = //$NON-NLS-1$
stackTrace[i].getClassName() + "." + stackTrace[i].getMethodName() + //$NON-NLS-1$
"()";
if (previousStackTrace == null || i >= previousStackTrace.length || !stackTrace[i].equals(previousStackTrace[i])) {
isNewStack = true;
}
updateMethodNode(hotSpotThreadNode, methodName, isNewStack, period);
currentFrameNode = updateFrameNode(callTreeThreadNode, currentFrameNode, methodName, isNewStack, period, i == stackTrace.length - 1);
hotSpotThreadNode.setTotalTime(hotSpotThreadNode.getTotalTime() + period);
if (isRootStack) {
callTreeThreadNode.setTotalTime(callTreeThreadNode.getTotalTime() + period);
}
isRootStack = false;
}
previousStackTraces.put(threadName, stackTrace);
}
Aggregations