Search in sources :

Example 1 with CpuModel

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;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) CpuModel(org.talend.designer.runtime.visualization.internal.core.cpu.CpuModel) CallTreeNode(org.talend.designer.runtime.visualization.internal.core.cpu.CallTreeNode) IOException(java.io.IOException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) ThreadInfo(java.lang.management.ThreadInfo) MethodNode(org.talend.designer.runtime.visualization.internal.core.cpu.MethodNode)

Aggregations

IOException (java.io.IOException)1 ThreadInfo (java.lang.management.ThreadInfo)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 JvmCoreException (org.talend.designer.runtime.visualization.JvmCoreException)1 CallTreeNode (org.talend.designer.runtime.visualization.internal.core.cpu.CallTreeNode)1 CpuModel (org.talend.designer.runtime.visualization.internal.core.cpu.CpuModel)1 MethodNode (org.talend.designer.runtime.visualization.internal.core.cpu.MethodNode)1