Search in sources :

Example 1 with AbstractJvm

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

the class CpuProfiler method dump.

/*
     * @see ICpuProfiler#dump()
     */
@Override
public IFileStore dump() throws JvmCoreException {
    String dump = cpuModel.getCpuDumpString(//$NON-NLS-1$
    jvm.getPid() + "@" + jvm.getHost().getName(), jvm.getMainClass(), jvm.getMBeanServer().getJvmArguments());
    StringBuffer fileName = new StringBuffer();
    fileName.append(new Date().getTime()).append('.').append(SnapshotType.Cpu.getExtension());
    IFileStore fileStore = Util.getFileStore(fileName.toString(), 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 {
        os = fileStore.openOutputStream(EFS.NONE, null);
        os.write(dump.getBytes());
        Snapshot snapshot = new Snapshot(fileStore, abstractJvm);
        abstractJvm.addSnapshot(snapshot);
        JvmModel.getInstance().fireJvmModelChangeEvent(new JvmModelEvent(State.ShapshotTaken, jvm, 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.dumpCpuProfileDataFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
    return fileStore;
}
Also used : Snapshot(org.talend.designer.runtime.visualization.internal.core.Snapshot) CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) AbstractJvm(org.talend.designer.runtime.visualization.internal.core.AbstractJvm) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) Host(org.talend.designer.runtime.visualization.internal.core.Host) IOException(java.io.IOException) JvmModelEvent(org.talend.designer.runtime.visualization.JvmModelEvent) Date(java.util.Date) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Aggregations

IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 CoreException (org.eclipse.core.runtime.CoreException)1 JvmCoreException (org.talend.designer.runtime.visualization.JvmCoreException)1 JvmModelEvent (org.talend.designer.runtime.visualization.JvmModelEvent)1 AbstractJvm (org.talend.designer.runtime.visualization.internal.core.AbstractJvm)1 Host (org.talend.designer.runtime.visualization.internal.core.Host)1 Snapshot (org.talend.designer.runtime.visualization.internal.core.Snapshot)1