jps(Java Virtual Machine Process Status Tool)
-q 不输出类名、Jar名和传入main方法的参数
-m 输出传入main方法的参数(输出全部参数)
-l 输出main类或Jar的全限名
-v 输出传入JVM的参数
jstack
jstack主要用来查看某个Java进程内的线程堆栈信息。
jstack [option] pid
jstack [option] executable core
jstack [option] [server-id@]remote-hostname-or-ip
-l long listings,会打印出额外的锁信息,在发生死锁时可以用jstack -l pid来观察锁持有情况
-m mixed mode,不仅会输出Java堆栈信息,还会输出C/C++堆栈信息(比如Native方法)
jmap(Memory Map)和jhat(Java Heap Analysis Tool)
# 如果运行在64位JVM上,可能需要指定-J-d64命令选项参数
# 打印进程的类加载器和类加载器加载的持久代对象信息,输出:类加载器名称、对象是否存活(不可靠)、对象地址、父类加载器、已加载的类大小等信息
jmap -permstat pid
# 查看进程堆内存使用情况,包括使用的GC算法、堆配置参数和各代中堆内存使用情况
jmap -heap pid
# 查看堆内存中的对象数目、大小统计直方图,如果带上live则只统计活对象
jmap -histo[:live] pid
# 将jmap信息保存至文件中
jmap -dump:format=b,file=dumpFileName pid
jmap -dump:format=b,file=./spark.jmap 45161
# 通过jhat进行查看
jhat -port 9988 -J-Xmx2048m ./spark.jmap
jstat(JVM统计监测工具)
jstat [ generalOption | outputOptions vmid [interval[s|ms] [count]] ]
# 输出结果代表字段
S0C、S1C、S0U、S1U:Survivor 0/1区容量(Capacity)和使用量(Used)
EC、EU:Eden区容量和使用量
OC、OU:年老代容量和使用量
PC、PU:永久代容量和使用量
YGC、YGT:年轻代GC次数和GC耗时
FGC、FGCT:Full GC次数和Full GC耗时
GCT:GC总耗时
hprof(Heap/CPU Profiling Tool)
java -agentlib:hprof[=options] ToBeProfiledClass
java -Xrunprof[:options] ToBeProfiledClass
javac -J-agentlib:hprof[=options] ToBeProfiledClass
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=<file> write data to file java.hprof[.txt]
net=<host>:<port> send data over a socket off
depth=<size> stack trace depth 4
interval=<ms> sample interval in ms 10
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
msa=y|n Solaris micro state accounting n
force=y|n force output to <file> y
verbose=y|n print messages about dumps y
Profile
If you only like to generate JVM flame graphs, the following tools are needed:
JDK9 or JDK8 update 60 build 19
Honest Profiler, https://github.com/jvm-profiling-tools/honest-profiler/wiki
Flame graph tool, https://github.com/brendangregg/FlameGraph
参考:
- Java in Flames, Netflix Blog, https://medium.com/netflix-techblog/java-in-flames-e763b3d32166
- CPU Flame Graphs, Brendan Gregg Blog,http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html
- Linux Perf examples, Brendan Gregg Blog, http://www.brendangregg.com/perf.html
- Honest Profiler, Richard Warburton,https://github.com/jvm-profiling-tools/honest-profiler/wiki
- perf-map-agent, https://github.com/jvm-profiling-tools/perf-map-agent
- Presentation about Java Flamegraphs, Nitsan Wakart,https://2017.javazone.no/program/56179b136b91458a843383e13fd2efa1
网友评论