Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a console profiler for Java?

Is there a gprof-like profiler for Java that can be run from the terminal in Linux? All tools I have found are GUI programs and I need run it from the terminal.

like image 402
R.Omar Avatar asked Jun 20 '12 16:06

R.Omar


People also ask

Is Eclipse profiler a Java profiler?

The Eclipse Test & Performance Tools Platform (TPTP) Profiling tool can be used to profile Eclipse plug-ins, local Java(TM) applications or complex applications running on multiple hosts and different platforms.

What is HotSpot profiler in Java?

The HotSpot profiler looks for "hot spots" in the code, i.e. methods that the JVM spends a significant amount of time running, and then compiles those methods into native generated code.


2 Answers

The JVM has a built-in profiler called HPROF. You can enable it on the command line like this:

java -agentlib:hprof=file=hprof.txt,cpu=samples MyClass

This will dump profile information out to a text file when the program finishes. In addition to profiling CPU usage, it can also track heap usage.

like image 109
ataylor Avatar answered Oct 06 '22 00:10

ataylor


The open-source tool jvmtop contains a terminal profiler and might be worth a look:

JvmTop 0.7.0 alpha - 15:16:34,  amd64,  8 cpus, Linux 2.6.32-27, load avg 0.41
 http://code.google.com/p/jvmtop

 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()
   6.25% (     9.95s) net.sf.json.JSONObject.write()
   3.13% (     4.98s) ....kohsuke.stapler.jelly.CustomTagLibrary.loadJellyScri()
like image 29
MRalwasser Avatar answered Oct 05 '22 22:10

MRalwasser