java8的jps,jstat,jstack,jmp,jinfo,jhat使用详解及Java自带可视化监控与故障分析工具的介绍
概述
JDK提供的免费的JVM监控与故障处理工具有:
- jps:JVM Process Status Tool, 显示指定系统内所有的HotSpot虚拟机进程
- jstat:JVM Statistics Monitoring Tool, 用于收集HotSpot虚拟机各方面的运行数据
- jinfo:Configuration Info for java,显示虚拟机配置信息.
- jmap:Memory Map for Java,生成虚拟机的内存转储快照(heapdump文件)
- jhat:JVM Heap Dump Browser, 用于分析heapdump文件,它会创建一个Http/HTML服务器,让用户可以在浏览器上查看分析结果
- jstack:Stack Trace for java,显示虚拟机的线程快照
jps: 虚拟机进程状况工具
命令格式:
- -q:只输出LVMID,省略主类的名称
- -m:输出虚拟机进程启动时传递给主类main()函数的参数
- -l:输出主类的全名,如果进程执行的是jar包,输出jar的完全路径名
- -v:输出虚拟机进程启动时jvm参数
jstat:虚拟机统计信息监视工具
命令格式:
class
: Displays statistics about the behavior of the class loader.
compiler
: Displays statistics about the behavior of the Java HotSpot VM Just-in-Time compiler.
gc
: Displays statistics about the behavior of the garbage collected heap.
gccapacity
: Displays statistics about the capacities of the generations and their corresponding spaces.
gccause
: Displays a summary about garbage collection statistics (same as -gcutil
),
with the cause of the last and current (when applicable) garbage collection events.
gcnew
: Displays statistics of the behavior of the new generation.
gcnewcapacity
: Displays statistics about the sizes of the new generations and its corresponding spaces.
gcold
: Displays statistics about the behavior of the old generation and metaspace statistics.
gcoldcapacity
: Displays statistics about the sizes of the old generation.
gcmetacapacity
: Displays statistics about the sizes of the metaspace.
gcutil
: Displays a summary about garbage collection statistics.
printcompilation
: Displays Java HotSpot VM compilation method statistics.
jdk8 jstat 选项的输出说明:
- -class option
-
Class loader statistics.
Loaded
: Number of classes loaded.Bytes
: Number of kBs loaded.Unloaded
: Number of classes unloaded.Bytes
: Number of Kbytes unloaded.Time
: Time spent performing class loading and unloading operations. - -compiler option
-
Java HotSpot VM Just-in-Time compiler statistics.
Compiled
: Number of compilation tasks performed.Failed
: Number of compilations tasks failed.Invalid
: Number of compilation tasks that were invalidated.Time
: Time spent performing compilation tasks.FailedType
: Compile type of the last failed compilation.FailedMethod
: Class name and method of the last failed compilation. - -gc option
-
Garbage-collected heap statistics.
S0C
: Current survivor space 0 capacity (kB).S1C
: Current survivor space 1 capacity (kB).S0U
: Survivor space 0 utilization (kB).S1U
: Survivor space 1 utilization (kB).EC
: Current eden space capacity (kB).EU
: Eden space utilization (kB).OC
: Current old space capacity (kB).OU
: Old space utilization (kB).MC
: Metaspace capacity (kB).MU
: Metacspace utilization (kB).CCSC
: Compressed class space capacity (kB).CCSU
: Compressed class space used (kB).YGC
: Number of young generation garbage collection events.YGCT
: Young generation garbage collection time.FGC
: Number of full GC events.FGCT
: Full garbage collection time.GCT
: Total garbage collection time. - -gccapacity option
-
Memory pool generation and space capacities.
NGCMN
: Minimum new generation capacity (kB).NGCMX
: Maximum new generation capacity (kB).NGC
: Current new generation capacity (kB).S0C
: Current survivor space 0 capacity (kB).S1C
: Current survivor space 1 capacity (kB).EC
: Current eden space capacity (kB).OGCMN
: Minimum old generation capacity (kB).OGCMX
: Maximum old generation capacity (kB).OGC
: Current old generation capacity (kB).OC
: Current old space capacity (kB).MCMN
: Minimum metaspace capacity (kB).MCMX
: Maximum metaspace capacity (kB).MC
: Metaspace capacity (kB).CCSMN
: Compressed class space minimum capacity (kB).CCSMX
: Compressed class space maximum capacity (kB).CCSC
: Compressed class space capacity (kB).YGC
: Number of young generation GC events.FGC
: Number of full GC events. - -gccause option
-
This option displays the same summary of garbage collection statistics as the
-gcutil
option, but includes the causes of the last garbage collection event and (when applicable) the current garbage collection event. In addition to the columns listed for-gcutil
, this option adds the following columns.LGCC
: Cause of last garbage collectionGCC
: Cause of current garbage collection - -gcnew option
-
New generation statistics.
S0C
: Current survivor space 0 capacity (kB).S1C
: Current survivor space 1 capacity (kB).S0U
: Survivor space 0 utilization (kB).S1U
: Survivor space 1 utilization (kB).TT
: Tenuring threshold.MTT
: Maximum tenuring threshold.DSS
: Desired survivor size (kB).EC
: Current eden space capacity (kB).EU
: Eden space utilization (kB).YGC
: Number of young generation GC events.YGCT
: Young generation garbage collection time. - -gcnewcapacity option
-
New generation space size statistics.
NGCMN
: Minimum new generation capacity (kB).NGCMX
: Maximum new generation capacity (kB).NGC
: Current new generation capacity (kB).S0CMX
: Maximum survivor space 0 capacity (kB).S0C
: Current survivor space 0 capacity (kB).S1CMX
: Maximum survivor space 1 capacity (kB).S1C
: Current survivor space 1 capacity (kB).ECMX
: Maximum eden space capacity (kB).EC
: Current eden space capacity (kB).YGC
: Number of young generation GC events.FGC
: Number of full GC events. - -gcold option
-
Old generation and metaspace behavior statistics.
MC
: Metaspace capacity (kB).MU
: Metaspace utilization (kB).CCSC
: Compressed class space capacity (kB).CCSU
: Compressed class space used (kB).OC
: Current old space capacity (kB).OU
: Old space utilization (kB).YGC
: Number of young generation GC events.FGC
: Number of full GC events.FGCT
: Full garbage collection time.GCT
: Total garbage collection time. - -gcoldcapacity option
-
Old generation size statistics.
OGCMN
: Minimum old generation capacity (kB).OGCMX
: Maximum old generation capacity (kB).OGC
: Current old generation capacity (kB).OC
: Current old space capacity (kB).YGC
: Number of young generation GC events.FGC
: Number of full GC events.FGCT
: Full garbage collection time.GCT
: Total garbage collection time. - -gcmetacapacity option
-
Metaspace size statistics.
MCMN
: Minimum metaspace capacity (kB).MCMX
: Maximum metaspace capacity (kB).MC
: Metaspace capacity (kB).CCSMN
: Compressed class space minimum capacity (kB).CCSMX
: Compressed class space maximum capacity (kB).YGC
: Number of young generation GC events.FGC
: Number of full GC events.FGCT
: Full garbage collection time.GCT
: Total garbage collection time. - -gcutil option
-
Summary of garbage collection statistics.
S0
: Survivor space 0 utilization as a percentage of the space's current capacity.S1
: Survivor space 1 utilization as a percentage of the space's current capacity.E
: Eden space utilization as a percentage of the space's current capacity.O
: Old space utilization as a percentage of the space's current capacity.M
: Metaspace utilization as a percentage of the space's current capacity.CCS
: Compressed class space utilization as a percentage.YGC
: Number of young generation GC events.YGCT
: Young generation garbage collection time.FGC
: Number of full GC events.FGCT
: Full garbage collection time.GCT
: Total garbage collection time. - -printcompilation option
-
Java HotSpot VM compiler method statistics.
Compiled
: Number of compilation tasks performed by the most recently compiled method.Size
: Number of bytes of byte code of the most recently compiled method.Type
: Compilation type of the most recently compiled method.Method
: Class name and method name identifying the most recently compiled method. Class name uses slash (/) instead of dot (.) as a name space separator. Method name is the method within the specified class. The format for these two fields is consistent with the HotSpot-XX:+PrintCompilation
option.
jinfo:java配置信息工具
命令格式:
jinfo [ option ] pid
jinfo [ option ] executable core
jinfo [ option ] [ servier-id ] remote-hostname-or-IP
选项:
- no-option
-
Prints both command-line flags and system property name-value pairs.
- -flag name
-
Prints the name and value of the specified command-line flag.
- -flag [+|-]name
-
enables or disables the specified Boolean command-line flag.
- -flag name=value
-
Sets the specified command-line flag to the specified value.
- -flags
-
Prints command-line flags passed to the JVM.
- -sysprops
-
Prints Java system properties as name-value pairs.
- -h
-
Prints a help message.
- -help
-
Prints a help message.
参数说明:
- pid
-
The process ID for which the configuration information is to be printed. The process must be a Java process. To get a list of Java processes running on a machine, use the
jps
(1) command. - executable
-
The Java executable from which the core dump was produced.
- core
-
The core file for which the configuration information is to be printed.
- remote-hostname-or-IP
-
The remote debug server
hostname
orIP
address. Seejsadebugd
(1). - server-id
-
An optional unique ID to use when multiple debug servers are running on the same remote host.
jmap:Java内存映像工具
命令格式:
jmap [ options ] pid
jmap [ options ] executable core
jmap [ options ] [ pid ] server-id@ ] remote-hostname-or-IP
选项:
<no option>When no option is used, the jmap
command prints shared object mappings. For each shared object loaded in the
target JVM, the start address, size of the mapping, and the full path of the shared object file are printed. This behavior is similar to the Oracle Solaris pmap
utility.
Dumps the Java heap in hprof binary format to filename. The live suboption is optional, but when specified, only the active objects in the heap are dumped. To browse the heap dump, you can use the jhat(1) command
to read the generated file.
Prints information about objects that are awaiting finalization.
-heapPrints a heap summary of the garbage collection used, the head configuration, and generation-wise heap usage. In addition, the number and size of interned Strings are printed.
-histo[:live]Prints a histogram of the heap. For each Java class, the number of objects, memory size in bytes, and the fully qualified class names are printed. The JVM internal class names are printed with an asterisk (*) prefix.
If the live
suboption is specified, then only active objects are counted.
Prints class loader wise statistics of Java heap. For each class loader, its name, how active it is, address, parent class loader, and the number and size of classes it has loaded are printed.
-FForce. Use this option with the jmap -dump
or jmap
-histo
option when the pid does not respond. The live
suboption is not supported in this mode.
Prints a help message.
-helpPrints a help message.
参数说明:
The process ID for which the memory map is to be printed. The process must be a Java process. To get a list of Java processes running on a machine, use the jps
(1) command.
The Java executable from which the core dump was produced.
coreThe core file for which the memory map is to be printed.
remote-hostname-or-IPThe remote debug server hostname
or IP
address.
See jsadebugd
(1).
An optional unique ID to use when multiple debug servers are running on the same remote host.
jhat:虚拟机堆转储快照分析工具
命令格式:
jhat [ options ] heap-dump-file
选项:
- -stack false|true
-
Turns off tracking object allocation call stack. If allocation site information is not available in the heap dump, then you have to set this flag to
false
. The default istrue
. - -refs false|true
-
Turns off tracking of references to objects. Default is
true
. By default, back pointers, which are objects that point to a specified object such as referrers or incoming references, are calculated for all objects in the heap. - -port port-number
-
Sets the port for the
jhat
HTTP server. Default is 7000. - -exclude exclude-file
-
Specifies a file that lists data members that should be excluded from the reachable objects query. For example, if the file lists
java.lang.String.value
, then, then whenever the list of objects that are reachable from a specific objecto
are calculated, reference paths that involvejava.lang.String.value
field are not considered. - -baseline exclude-file
-
Specifies a baseline heap dump. Objects in both heap dumps with the same object ID are marked as not being new. Other objects are marked as new. This is useful for comparing two different heap dumps.
- -debug int
-
Sets the debug level for this tool. A level of 0 means no debug output. Set higher values for more verbose modes.
- -version
-
Reports the release number and exits
- -h
-
Displays a help message and exits.
- -help
-
Displays a help message and exits.
- -Jflag
-
Passes
flag
to the Java Virtual Machine on which thejhat
command is running. For example,-J-Xmx512m
to use a maximum heap size of 512 MB.
参数说明:
Java binary heap dump file to be browsed. For a dump file that contains multiple heap dumps, you can specify which dump in the file by appending #<number>
to
the file name, for example, myfile.hprof#3
.
jstack:Java堆栈跟踪工具
命令格式:
jstack [ options ] pid
jstack [ options ] executable core
jstack [ options ] [ server-id@ ] remote-hostname-or-IP
选项:
Force a stack dump when jstack
[-l
] pid
does
not respond.
Long listing. Prints additional information about locks such as a list of owned java.util.concurrent ownable synchronizers. See the AbstractOwnableSynchronizer class description at http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/AbstractOwnableSynchronizer.html
-mPrints a mixed mode stack trace that has both Java and native C/C++ frames.
-hPrints a help message.
-helpPrints a help message.
参数说明:
The process ID for which the stack trace is printed. The process must be a Java process. To get a list of Java processes running on a machine, use the jps
(1) command.
The Java executable from which the core dump was produced.
coreThe core file for which the stack trace is to be printed.
remote-hostname-or-IPThe remote debug server hostname
or IP
address.
See jsadebugd
(1).
An optional unique ID to use when multiple debug servers are running on the same remote host.
JConsole:Java监视与管理控制台
VisualVM:多合一故障处理工具
VisualVM基于NetBeans平台开发,一开始就具备了插件扩展功能的特性,通过插件扩展支持,VisualVM可以做到:
- 显示虚拟机进程以及进程的配置,环境信息(jps, jinfo)
- 监视应用程序的CPU,GC,堆,方法区以及线程的信息(jstat,jstack)
- dump以及分析堆转储快照(jmap,jhat)
- 方法级的程序运行性能分析,找出被调用最多,运行时间最长的方法
- 离线程序快照:收集程序的运行时配置,线程dump,内存dump等信息建立一个快照,可以将快照发送开发者处进行Bug反馈
- 其他plugins的无限的可能性……