The Heap and CPU Profiling Agent (HPROF)是JAVA2 SDK自帶的一個簡單的profiler代理,它經過與Java Virtual Machine Profiler Interface (JVMPI) 交互,將profiling信息經過本地文件或socket輸出ASCII或二進制格式的流。html
HPROF能夠監控CPU使用率,堆分配統計。除此以外,還能夠報告JVM全部監視器和線程的完整的堆的dump狀態。java
HPROF的JVM參數的語法以下:oracle
-Xrunhprof[:help]|[:param=value,param2=value2, ...]
示例:socket
-Xrunhprof:file=log.txt,thread=y,depth=3
The file parameter determines where the stack dump is written.ui
file參數決定dump的堆棧寫入到那個文件。spa
HPROF的詳細參數以下:線程
Hprof usage: -Xrunhprof[:help]|[:<option>=<value>, ...] Option Name and Value Description Default --------------------- ----------- ------- heap=dump|sites|all heap profiling all cpu=samples|old CPU usage off format=a|b ascii or binary output a file=<file> write data to file java.hprof (.txt for ascii) net=<host>:<port> send data over a socket write to file depth=<size> stack trace depth 4 cutoff=<value> output cutoff point 0.0001 lineno=y|n line number in traces? y thread=y|n thread in traces? n doe=y|n dump on exit? y
Command used: javac -J-agentlib:hprof=cpu=samples Hello.java CPU SAMPLES BEGIN (total = 126) Fri Oct 22 12:12:14 2004 rank self accum count trace method 1 53.17% 53.17% 67 300027 java.util.zip.ZipFile.getEntry 2 17.46% 70.63% 22 300135 java.util.zip.ZipFile.getNextEntry 3 5.56% 76.19% 7 300111 java.lang.ClassLoader.defineClass2 4 3.97% 80.16% 5 300140 java.io.UnixFileSystem.list 5 2.38% 82.54% 3 300149 java.lang.Shutdown.halt0 6 1.59% 84.13% 2 300136 java.util.zip.ZipEntry.initFields 7 1.59% 85.71% 2 300138 java.lang.String.substring 8 1.59% 87.30% 2 300026 java.util.zip.ZipFile.open 9 0.79% 88.10% 1 300118 com.sun.tools.javac.code.Type$ErrorType.<init> 10 0.79% 88.89% 1 300134 java.util.zip.ZipFile.ensureOpen
參考 http://docs.oracle.com/cd/E19798-01/821-1752/beafo/index.html代理
http://stackoverflow.com/questions/11737013/java-profile-tool-without-guicode
http://www.cnblogs.com/ggjucheng/p/3352332.htmlorm