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