Profiling a running Java application in command line
Profiling a running Java application in command line
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.
Answer by Sanjay T. Sharma for Profiling a running Java application in command line
We have used hprof on our servers and it definitely is better than sysouts in case you can't run a full fledged VisualVM session.
Examples of using hprof are plenty out there:
- http://www.javalobby.org/java/forums/t19612.html
- https://coderwall.com/p/il3h4g/easy-profiling-java-from-command-line
- http://www.brendangregg.com/blog/2014-06-09/java-cpu-sampling-using-hprof.html
Answer by chubbsondubs for Profiling a running Java application in command line
You can run most commercial profilers remotely so an agent is run on the server then connect to that agent through a client on your dev machine. My absolute favorite profiler is JProfiler. It's fairly reasonable purchase, and it's very stable (which not all commercial profilers that's true).
http://www.ej-technologies.com/products/jprofiler/overview.html
Other commercial profilers that are stable, but not my favorite are YourKIT.
Those smaller vendors make good tools. These tools will provide you tons of information about method timings, memory use, GC, etc. Much more than jconsole.
Answer by Mike Dunlavey for Profiling a running Java application in command line
Can you collect 10 or 20 stack samples with jstack? Then if Foo is a method, its overall time usage is the fraction of samples containing it. Its CPU usage is the fraction of those samples that don't terminate in I/O or a system call. Its "self time" is the fraction of samples in which it itself is the terminus.
I don't need anything pretty. I either run it under the IDE and collect them that way, or use something like jstack that snapshots the stack of a running app.
That's the random-pause technique.
Answer by rogerdpack for Profiling a running Java application in command line
Looks like the "built-in" way to profile a java app from the command line is to start it with profiling command line parameters, like
$ java -Xrunhprof:cpu=samples,file=myprogram.hprof
Then examine the file "myprogram.hprof" with some GUI tool (or web server tool like jhat) or command line tool after the process exits.
Unfortunately this won't help in your case (since you want to attach then detach) so some of the other answers might work, though you could use the above and have it sample infrequently and still use this method with low slowdown/impact overall.
ref: http://thunderguy.com/semicolon/2004/04/18/profiling-a-java-program-easily/
Answer by Andrejs for Profiling a running Java application in command line
jvmtop is a convenient tool for profiling from the commandline. No need to stop the jvm:
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.
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment