Search in sources :

Example 21 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.

the class ConfigureCpuProfilerAction method setPackages.

/**
     * Sets the packages.
     * 
     * @param packages The packages
     * @param monitor The progress monitor
     * @return The packages string with delimiter ','
     */
String setPackages(Set<String> packages, IProgressMonitor monitor) {
    IActiveJvm jvm = cpuSection.getJvm();
    if (jvm != null) {
        try {
            jvm.getCpuProfiler().setProfiledPackages(packages);
            if (jvm.getCpuProfiler().getProfilerType() == ProfilerType.BCI && jvm.getCpuProfiler().getState() == ProfilerState.RUNNING) {
                jvm.getCpuProfiler().transformClasses(monitor);
            }
        } catch (JvmCoreException e) {
            Activator.log(Messages.setProfiledPackagesFailedMsg, e);
        } catch (InterruptedException e) {
        // do nothing
        }
    }
    StringBuffer buffer = new StringBuffer();
    for (String item : packages) {
        if (buffer.length() > 0) {
            buffer.append(',');
        }
        buffer.append(item);
    }
    return buffer.toString();
}
Also used : IActiveJvm(org.talend.designer.runtime.visualization.IActiveJvm) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 22 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.

the class SuspendCpuProfilingAction method performRun.

/*
     * @see AbstractJobAction#performRun(IProgressMonitor)
     */
@Override
protected IStatus performRun(IProgressMonitor monitor) {
    IActiveJvm jvm = section.getJvm();
    if (jvm == null) {
        return Status.CANCEL_STATUS;
    }
    try {
        jvm.getCpuProfiler().suspend();
    } catch (JvmCoreException e) {
        Activator.log(Messages.suspendingCpuProfilingFailedMsg, e);
    }
    resumeAction.setEnabled(true);
    return Status.OK_STATUS;
}
Also used : IActiveJvm(org.talend.designer.runtime.visualization.IActiveJvm) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 23 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.

the class DumpHprofAction method getInitialFileName.

/**
     * Gets the initial file name.
     * 
     * @param jvm The active JVM
     * @return The file name, or <tt>null</tt> if file name is specified
     * @throws JvmCoreException
     */
String getInitialFileName(IActiveJvm jvm) throws JvmCoreException {
    ObjectName objectName;
    try {
        objectName = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
    } catch (MalformedObjectNameException e) {
        throw new JvmCoreException(IStatus.ERROR, e.getMessage(), e);
    } catch (NullPointerException e) {
        throw new JvmCoreException(IStatus.ERROR, e.getMessage(), e);
    }
    //$NON-NLS-1$
    TabularData initialName = (TabularData) jvm.getMBeanServer().getAttribute(objectName, "SystemProperties");
    //$NON-NLS-1$
    CompositeData compisiteData = initialName.get(new Object[] { "user.home" });
    String home = compisiteData.values().toArray(new String[0])[1];
    StringBuffer initialFileName = new StringBuffer(home);
    initialFileName.append(File.separator).append(new Date().getTime()).append('.').append(SnapshotType.Hprof.getExtension());
    return initialFileName.toString();
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CompositeData(javax.management.openmbean.CompositeData) Date(java.util.Date) ObjectName(javax.management.ObjectName) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) TabularData(javax.management.openmbean.TabularData)

Example 24 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException in project tdi-studio-se by Talend.

the class MBeanServer method dump.

/**
     * Dumps the profile data into file.
     * 
     * @param type The snapshot type
     * @param dumpFileName The dump file name
     * @param monitor The progress monitor
     * @return The file store
     * @throws JvmCoreException
     */
private IFileStore dump(SnapshotType type, String dumpFileName, IProgressMonitor monitor) throws JvmCoreException {
    String simpleFileName;
    if (dumpFileName == null) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(new Date().getTime()).append('.').append(type.getExtension());
        simpleFileName = stringBuffer.toString();
    } else {
        simpleFileName = new File(dumpFileName).getName();
    }
    IFileStore fileStore = Util.getFileStore(simpleFileName, jvm.getBaseDirectory());
    // restore the terminated JVM if already removed
    AbstractJvm abstractJvm = jvm;
    if (!((Host) jvm.getHost()).getJvms().contains(jvm)) {
        jvm.saveJvmProperties();
        abstractJvm = (AbstractJvm) ((Host) jvm.getHost()).addTerminatedJvm(jvm.getPid(), jvm.getPort(), jvm.getMainClass());
    }
    OutputStream os = null;
    try {
        if (type == SnapshotType.Heap || type == SnapshotType.Thread) {
            String dump = getDumpString(type);
            os = fileStore.openOutputStream(EFS.NONE, null);
            os.write(dump.getBytes());
        } else if (type == SnapshotType.Hprof && jvm.isRemote()) {
            ObjectName objectName = getObjectName(DATA_TRANSFER_MXBEAN_NAME);
            os = fileStore.openOutputStream(EFS.NONE, null);
            byte[] bytes;
            int offset = 0;
            final int SIZE = 4096;
            //$NON-NLS-1$ //$NON-NLS-2$
            final String[] SIGNATURES = new String[] { String.class.getCanonicalName(), "int", "int" };
            do {
                bytes = (byte[]) invoke(objectName, "read", new Object[] { //$NON-NLS-1$
                dumpFileName, offset, SIZE }, SIGNATURES);
                os.write(bytes);
                offset += SIZE;
                if (monitor != null && monitor.isCanceled()) {
                    break;
                }
            } while (bytes.length > 0);
        }
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        Snapshot snapshot = new Snapshot(fileStore, abstractJvm);
        abstractJvm.addSnapshot(snapshot);
        JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.ShapshotTaken, abstractJvm, snapshot));
    } catch (CoreException e) {
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.openOutputStreamFailedMsg, fileStore.toURI().getPath()), e);
    } catch (IOException e) {
        try {
            fileStore.delete(EFS.NONE, null);
        } catch (CoreException e1) {
        // do nothing
        }
        throw new JvmCoreException(IStatus.ERROR, NLS.bind(Messages.dumpFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
    return fileStore;
}
Also used : OutputStream(java.io.OutputStream) IHost(org.talend.designer.runtime.visualization.IHost) IOException(java.io.IOException) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) Date(java.util.Date) ObjectName(javax.management.ObjectName) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) File(java.io.File)

Example 25 with JvmCoreException

use of org.talend.designer.runtime.visualization.JvmCoreException 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

JvmCoreException (org.talend.designer.runtime.visualization.JvmCoreException)64 IOException (java.io.IOException)16 IActiveJvm (org.talend.designer.runtime.visualization.IActiveJvm)14 Method (java.lang.reflect.Method)11 ObjectName (javax.management.ObjectName)10 IFileStore (org.eclipse.core.filesystem.IFileStore)6 CoreException (org.eclipse.core.runtime.CoreException)6 IMonitoredMXBeanGroup (org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup)6 File (java.io.File)5 Properties (java.util.Properties)5 IPath (org.eclipse.core.runtime.IPath)5 OutputStream (java.io.OutputStream)4 JMException (javax.management.JMException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IHost (org.talend.designer.runtime.visualization.IHost)4 JvmModelEvent (org.talend.designer.runtime.visualization.JvmModelEvent)4 Date (java.util.Date)3 Timer (java.util.Timer)3 TimerTask (java.util.TimerTask)3 RGB (org.eclipse.swt.graphics.RGB)3