JVM HPROF 笔记

HPROF 是一个 DDL 格式的工具, 用来做 JVM heap 和 CPU profiling 的,在每个 JDK 里面都有. 它把 profiling 信息要么写到文件, 要么以二进制或 ASCII 码格式写到 socket. 这些 profiling 工具可以被其它工具使用.

HPROF is a tool for heap and CPU profiling shipped with every JDK release. It is a dynamic-link library (DLL) that interfaces with the Java Virtual Machine (JVM) using the Java Virtual Machine Tool Interface (JVM TI). The tool writes profiling information either to a file or to a socket in ASCII or binary format. This information can be further processed by a profiler front end tool.

The HPROF tool is capable of presenting CPU usage, heap allocation statistics, and monitor contention profiles. In addition, it can report complete heap dumps and states of all the monitors and threads in the JVM. In terms of diagnosing problems, HPROF is useful when analyzing performance, lock contention, memory leaks, and other issues.

源代码在: $JAVA_HOME/demo/jvmti/hprof 目录
常用命令:

  1. java -agentlib:hprof=help
  2. java -agentlib:hprof ToBeProfiledClass
  3. java -agentlib:hprof=heap=sites ToBeProfiledClass
  4. java -agentlib:hprof=cpu=samples,interval=20,depth=3 classname
  5. java -agentlib:hprof=heap=sites classname

Option Name and Value Description Default


heap=dump|sites|all heap profiling all
cpu=samples|times|old CPU usage off
monitor=y|n monitor contention n
format=a|b text(txt) or binary output a
file= write data to file java.hprof[{.txt}]
net=: send data over a socket off
depth= stack trace depth 4
interval= sample interval in ms 10
cutoff= 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
msa=y|n Solaris micro state accounting n
force=y|n force output to y
verbose=y|n print messages about dumps y

标签: none

添加新评论