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
...
(And then the tool runs to completion and exits.)
I guess (by default, at least) YourKit is designed to only connect to running application.
How should I modify my command-line tool to allow connection from YourKit?
There is no way to pause profiled application until profiler "connects"; you simply do not need to do so.
Instead, please do the following:
Turn on desired profiling modes from startup. For example, if you need to profile CPU usage, start either CPU sampling or CPU tracing with corresponding startup options "sampling" or "tracing". See http://www.yourkit.com/docs/80/help/additional_agent_options.jsp
If profiled application is short-running, enable snapshot capture on exit with "onexit=snapshot" startup option. Later open captured snapshot in the profiler UI for analysis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With