1、jstack
Usage:
jstack [-l] <pid>
(to connect to running process)
jstack -F [-m] [-l] <pid>
(to connect to a hung process)
jstack [-m] [-l] <executable> <core>
(to connect to a core file)
jstack [-m] [-l] [server_id@]<remote server IP or hostname>
(to connect to a remote debug server)
Options:
-F to force a thread dump. Use when jstack <pid> does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message
-F 参数强制导出线程栈,一般在线程被挂起(堵塞)时使用
-m 打印java和本地线程栈帧,native指java调用c/c++本地接口
-l 字面翻译:打印额外信息和锁,实际导出最好加上该选项
-h 列出帮助信息
案例
jstack -F -m -l 1180 > dumpStack.txt
线程栈消息文件分析工具
https://publib.boulder.ibm.com/httpserv/cookbook/Major_Tools-IBM_Thread_and_Monitor_Dump_Analyzer_TMDA.html
过往分析文章
https://blog.csdn.net/ffyyhh995511/article/details/132810006
使用场景
1:java应用占用cpu高
2:排查线程阻塞或挂起
3:查看线程运行情况,例如死锁
2、jmap
jmap
Usage:
jmap [option] <pid>
(to connect to running process)
jmap [option] <executable <core>
(to connect to a core file)
jmap [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
<none> to print same info as Solaris pmap
-heap to print java heap summary
-histo[:live] to print histogram of java object heap; if the "live"
suboption is specified, only count live objects
-clstats to print class loader statistics
-finalizerinfo to print information on objects awaiting finalization
-dump:<dump-options> to dump java heap in hprof binary format
dump-options:
live dump only live objects; if not specified,
all objects in the heap are dumped.
format=b binary format
file=<file> dump heap to <file>
Example: jmap -dump:live,format=b,file=heap.bin <pid>
-F force. Use with -dump:<dump-options> <pid> or -histo
to force a heap dump or histogram when <pid> does not
respond. The "live" suboption is not supported
in this mode.
-h | -help to print this help message
-J<flag> to pass <flag> directly to the runtime system
hprof 文件是 Java 的 内存快照文件(Heap Profile的缩写),格式为xxx.hprof
-histo:live只打印存活的堆对象的柱状图统计信息,现实中不实用也不常用
-finalizerinfo 打印正在等待被回收的对象信息
-F 强制dump出栈信息,不支持live选项
dump在实际中常被用到
命令案例
jmap -dump:live,format=b,file=heap.bin <pid> 文件后缀是bin
jmap -dump:live,format=b,file=heap.hprof <pid> 文件后缀是hprof
内存堆消息文件分析工具
eclipse mat插件
过往分析文章
todo
使用场景
1:分析 OOM: OutOfMemoryError(堆)内存不足错误
2:JVM设置 -XX:+HeapDumpOnOutOfMemoryError 参数时打印的内容,该参数指应用出现oom自动dump出hprof文件
jvm堆栈资料
https://blog.csdn.net/wang0907/article/details/130544919