java命令行HPROF Profiler

The HPROF Profiler

The Heap and CPU Profiling Agent (HPROF)是JAVA2 SDK自带的一个简单的profiler代理,它通过与Java Virtual Machine Profiler Interface (JVMPI) 交互,将profiling信息通过本地文件或socket输出ASCII或二进制格式的流。

HPROF可以监控CPU使用率,堆分配统计。除此之外,还可以报告JVM所有监视器和线程的完整的堆的dump状态。

HPROF的JVM参数的语法如下:

-Xrunhprof[:help]|[:param=value,param2=value2, ...]

示例:

-Xrunhprof:file=log.txt,thread=y,depth=

The file parameter determines where the stack dump is written.

file参数决定dump的堆栈写入到那个文件。

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
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

一个javac的示例

Command used: javac -J-agentlib:hprof=cpu=samples Hello.java

CPU SAMPLES BEGIN (total = ) Fri Oct  ::
rank self accum count trace method
53.17% 53.17% java.util.zip.ZipFile.getEntry
17.46% 70.63% java.util.zip.ZipFile.getNextEntry
5.56% 76.19% java.lang.ClassLoader.defineClass2
3.97% 80.16% java.io.UnixFileSystem.list
2.38% 82.54% java.lang.Shutdown.halt0
1.59% 84.13% java.util.zip.ZipEntry.initFields
1.59% 85.71% java.lang.String.substring
1.59% 87.30% java.util.zip.ZipFile.open
0.79% 88.10% com.sun.tools.javac.code.Type$ErrorType.<init>
0.79% 88.89% java.util.zip.ZipFile.ensureOpen

参考 http://docs.oracle.com/cd/E19798-01/821-1752/beafo/index.html

http://*.com/questions/11737013/java-profile-tool-without-gui

上一篇:Android 常见Crash Log汇总


下一篇:Django常用命令总结