I profile running Java applications often with VisualVM but it needs X to run on the machine.
I know I can connect through management port but that will be an offline sampled profiling which is not enough for me.
So I'm looking for a solution with which I can profile the CPU usage of the methods of a running Java application from command-line. It's enough for me to collect data on the server and then the collected data can be analyzed on a different machine.
Update:
It seems I need to be more specific. I want to profile a running Java application from command line, I don't want to stop it and rerun it.
Best Answer
The jvmtop application is a convenient tool for profiling from the commandline. No need to stop the jvm. Usage:
Will give you output like this which will be updating while the app runs:
The advantage is that it does not take the use of instrumentation. The classes of the to-be-profiled jvm will not be altered.
If you are looking for something more visual then have a look at jvm-mon which is based on jvmtop