Search in sources :

Example 1 with CallTreeNode

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;
}
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)

Example 2 with CallTreeNode

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;
}
Also used : CallTreeNode(org.talend.designer.runtime.visualization.internal.core.cpu.CallTreeNode)

Example 3 with CallTreeNode

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);
}
Also used : CallTreeNode(org.talend.designer.runtime.visualization.internal.core.cpu.CallTreeNode)

Aggregations

CallTreeNode (org.talend.designer.runtime.visualization.internal.core.cpu.CallTreeNode)3 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 CpuModel (org.talend.designer.runtime.visualization.internal.core.cpu.CpuModel)1 MethodNode (org.talend.designer.runtime.visualization.internal.core.cpu.MethodNode)1