automatically open memory Snapshot

Questions about YourKit Java Profiler
Post Reply
mgroth49
Posts: 8
Joined: Sat Nov 12, 2022 3:42 pm

automatically open memory Snapshot

Post by mgroth49 »

I have successfully captured a memory snapshot through the API:

Code: Select all

import com.yourkit.api.controller.Controller;

public class ApiDemo1 {
  public static void main(final String[] args) throws Exception {
    // Create the controller to profile the application itself.
    // To profile another application use the builder's methods host() and port() instead of self().
    final Controller controller = Controller.newBuilder().self().build();

    final String snapshotFilePath = controller.captureMemorySnapshot();
    System.out.println("Own memory snapshot captured: " + snapshotFilePath);
  }
}

Now, this was also done when this very java process was already connected to the YourKit GUI via the `agentpath` parameter.

By manually opening `snapshotFilePath` in the GUI, I can see the snapshot. It looks as I expect.

However, I would like the snapshot to open automatically. I looked through the API javadocs, but could not find any functions that allow direct control over the YourKit GUI. Is there a way I can, in essence, do something like `controller.openMemorySnapshot(snapshotFilePath)`. Is it possible?
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: automatically open memory Snapshot

Post by Anton Katilin »

Hi,

There is no API for launching the profiler UI and opening a snapshot.

You can do this by running the command "<profiler executable> -open <snapshot file path>". If you want to do this programmatically from Java, please use Runtime.exec() or java.lang.ProcessBuilder.

Best regards,
Anton
mgroth49
Posts: 8
Joined: Sat Nov 12, 2022 3:42 pm

Re: automatically open memory Snapshot

Post by mgroth49 »

Awesome, thanks!
Post Reply