How do I connect to a Java command-line tool with the YourKit Java Profiler?

Posted by Daryl Spitzer on Stack Overflow See other posts from Stack Overflow or by Daryl Spitzer
Published on 2010-04-01T21:19:14Z Indexed on 2010/04/01 21:23 UTC
Read the original article Hit count: 443

Filed under:
|
|
|

I've build a command-line tool in Java, which I would now like to profile with YourKit. I launch the command-line tool with something like:

$ java -classpath .:foo.bar.jar com.foobar.tools.TheTool arg1 arg2 arg3

It runs to completion in less than 2 seconds.

After reading http://www.yourkit.com/docs/80/help/agent.jsp, I tried the following:

$ java -agentpath:/home/dspitzer/yjp-8.0.24/bin/linux-x86-32/libyjpagent.so -classpath .:foo.bar.jar com.foobar.tools.TheTool arg1 arg2 arg3

...and I get:

[YourKit Java Profiler 8.0.24] JVMTI version 3001016d; 14.3-b01; Sun Microsystems Inc.; mixed mode, sharing; Linux; 32-bit JVM
[YourKit Java Profiler 8.0.24] Profiler agent is listening on port 10001...
[YourKit Java Profiler 8.0.24] *** HINT ***: To get profiling results, connect to the application from the profiler UI
...

But I guess YourKit is designed to only connect to running application.

How should I modify my command-line tool to allow connection from YourKit?

  1. I could add a command-line option that will have it pause for input, and I won't press return for it to continue until I've connected to it from YourKit.
  2. Is there a YourKit API that I could add to my tool that would cause it to block until I've connected with YourKit?
  3. Is there a YourKit API or a java command-line option that would create a profiling "snapshot" that I could load and analyze later (after the command-line tool has completed) with YourKit?

© Stack Overflow or respective owner

Related posts about java

Related posts about yourkit