[JVM 性能分析工具]
:jps 基础工具
:jstack 查看某个Java进程内的线程堆栈信息
:jmap jmap导出堆内存,然后使用jhat来进行分析
:jhat jmap导出堆内存,然后使用jhat来进行分析
:jstat JVM统计监测工具
:hprof hprof能够展现CPU使用率,统计堆内存使用情况
一、jstack 线程、jmap 内存、jstat 性能
[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
[jmap 内存分析 - Java Memory Map]
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
[jstat 性能分析]
Usage: jstat -help|-options
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Definitions:
<option> An option reported by the -options option
<vmid> Virtual Machine Identifier. A vmid takes the following form:
<lvmid>[@<hostname>[:<port>]]
Where <lvmid> is the local vm identifier for the target
Java virtual machine, typically a process id; <hostname> is
the name of the host running the target Java virtual machine;
and <port> is the port number for the rmiregistry on the
target host. See the jvmstat documentation for a more complete
description of the Virtual Machine Identifier.
<lines> Number of samples between header lines.
<interval> Sampling interval. The following forms are allowed:
<n>["ms"|"s"]
Where <n> is an integer and the suffix specifies the units as
milliseconds("ms") or seconds("s"). The default units are "ms".
<count> Number of samples to take before terminating.
-J<flag> Pass <flag> directly to the runtime system.
二、jstack 线程
得到运行java程序的java stack和native stack的信息,得知当前线程的运行情况
[]
: jps # 获取进程PID
: jstack [option] PID
-> -l # long listings,会打印出额外的锁信息,在发生死锁时可以用jstack -l pid来观察锁持有情况
-> -m # mixed mode,不仅会输出Java堆栈信息,还会输出C/C++堆栈信息(比如Native方法)
[线程状态]
死锁,Deadlock(重点关注)
等待资源,Waiting on condition(重点关注)
等待获取监视器,Waiting on monitor entry(重点关注)
阻塞,Blocked(重点关注)
执行中,Runnable
暂停,Suspended
对象等待中,Object.wait() 或 TIMED_WAITING
停止,Parked
三、jmap 内存
得到运行java程序的内存分配的详细情况。例如实例个数,大小等
[JVM内存状态]
: jmap -heap [pid]
# 注意的是在使用CMS GC 情况下,jmap -heap的执行有可能会导致JAVA 进程挂起
[JVM堆中对象详细占用情况]
: jmap -histo [pid]
[导出整个JVM 中内存信息]
: jmap -dump:format=b,file=文件名 [pid]
# jhat是sun 1.6及以上版本中自带的一个用于分析JVM 堆DUMP 文件的工具,基于此工具可分析JVM HEAP 中对象的内存占用情况
# jhat -J-Xmx1024M [file] 执行后等待console 中输入start HTTP server on port 7000 即可使用浏览器访问 IP:7000
四、jstat 性能
得到classloader,compiler,gc相关信息。可以时时监控资源和性能
[]
:jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数]