Ejemplo n.º 1
0
  /*
   * @see Action#run()
   */
  @Override
  public void run() {
    IActiveJvm jvm = section.getJvm();
    if (jvm == null) {
      return;
    }

    // get file name for remote host
    final String fileName[] = new String[1];
    final boolean transfer[] = new boolean[] {false};

    try {
      if (jvm.isRemote()) {
        final FileNameInputDialog dialog =
            new FileNameInputDialog(
                section.getPart().getSite().getShell(),
                getInitialFileName(jvm),
                isAgentLoaded(jvm));

        Display.getDefault()
            .syncExec(
                new Runnable() {
                  @Override
                  public void run() {
                    if (dialog.open() == Window.OK) {
                      fileName[0] = dialog.getFileName();
                      transfer[0] = dialog.isFileTransfered();
                    }
                  }
                });

        if (fileName[0] == null) {
          return;
        }
      }
    } catch (JvmCoreException e) {
      Activator.log(Messages.dumpHeapDataFailedMsg, e);
      return;
    }

    dumpHprof(fileName[0], transfer[0]);
  }
Ejemplo n.º 2
0
  /**
   * 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);
    }

    TabularData initialName =
        (TabularData)
            jvm.getMBeanServer().getAttribute(objectName, "SystemProperties"); // $NON-NLS-1$
    CompositeData compisiteData = initialName.get(new Object[] {"user.home"}); // $NON-NLS-1$
    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();
  }
Ejemplo n.º 3
0
 /**
  * Gets the state indicating if agent is loaded.
  *
  * @param jvm The JVM
  * @return <tt>true</tt> if agent is loaded
  */
 boolean isAgentLoaded(IActiveJvm jvm) {
   ProfilerState state = jvm.getCpuProfiler().getState(ProfilerType.BCI);
   return state == ProfilerState.READY || state == ProfilerState.RUNNING;
 }