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 offlin
The jvmtop application is a convenient tool for profiling from the commandline. No need to stop the jvm. Usage:
jvmtop.sh --profile
Will give you output like this which will be updating while the app runs:
Profiling PID 24015: org.apache.catalina.startup.Bootstrap
36.16% ( 57.57s) hudson.model.AbstractBuild.calcChangeSet()
30.36% ( 48.33s) hudson.scm.SubversionChangeLogParser.parse()
7.14% ( 11.37s) org.kohsuke.stapler.jelly.JellyClassTearOff.parseScript()
...
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