概述
jstat
命令可以查看堆内存各部分的使用量,以及加载类的数量。命令的格式如下:
jstat [-命令选项] [vmid] [间隔时间/默认单位是ms毫秒] [查询次数]
注意:jdk版本是jdk1.8
详述
详细格式可以输入jstat -help
命令查看:
[root@root ~]# jstat -help
Usage: jstat -help|-options
jstat - [-t] [-h] [ []]
Definitions:
An option reported by the -options option
Virtual Machine Identifier. A vmid takes the following form:
[@[:]]
Where is the local vm identifier for the target
Java virtual machine, typically a process id; is
the name of the host running the target Java virtual machine;
and 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.
Number of samples between header lines.
Sampling interval. The following forms are allowed:
["ms"|"s"]
Where is an integer and the suffix specifies the units as
milliseconds("ms") or seconds("s"). The default units are "ms".
Number of samples to take before terminating.
-J Pass directly to the runtime system.
option
选项有哪些,可以使用jstat -options
命令查看:
[root@infra2-test-k8s ~]# jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation
option参数说明:
-class: 类加载的行为统计 Displays statistics about the behavior of the class loader.
-compiler: HotSpt JIT编译器行为统计 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: 各个垃圾回收代容量(young,old,meta)和他们相应的空间统计。isplays statistics about the capacities of the generations and their corresponding spaces.
-gccause: 垃圾收集统计概述(同-gcutil),附加最近两次垃圾回收事件的原因。Displays a summary about garbage collection statistics (same as -gcutil), with the cause of the last and current (when applicable) garbage collection events.
-gcmetacapacity: 统计元空间使用情况 Displays statistics about the sizes of the metaspace.
-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.
-gcutil: 显示各个各代内存使用百分比 Displays a summary about garbage collection statistics.
-printcompilation: Hotspot方法编译统计情况 Displays Java HotSpot VM compilation method statistics.
jstat命令简单使用及说明(后面的英文为官方文档原文)
为了方便直观,我们直接使用jps
命令,查看所有的Java进程以及进程id:
[root@root ~]# jps -l
1 org.apache.catalina.startup.Bootstrap
17546 sun.tools.jps.Jps
jps命令格式:jps [options ] [ hostid ]
[options]选项 : -q:仅输出VM标识符,不包括classname,jar name,arguments in main method -m:输出main method的参数 -l:输出完全的包名,应用主类名,jar的完全路径名 -v:输出jvm参数 -V:输出通过flag文件传递到JVM中的参数(.hotspotrc文件或-XX:Flags=所指定的文件 -Joption:传递参数到vm,例如:-J-Xms512m
jstat -class : 类加载的行为统计 Class loader statistics.
[root@root ~]# jstat -class 1
Loaded Bytes Unloaded Bytes Time
24301 45978.0 277 411.9 44.91
参数说明:
Loaded :加载class的数量 Number of classes loaded.
Bytes : 加载class的大小(单位KB)Number of kBs loaded.
Unloaded :卸载class的数量 Number of classes unloaded.
Bytes: 卸载class的大小(单位KB) Number of Kbytes unloaded.
Time : 加载和卸载class所耗费的时间 Time spent performing class loading and unloading operations.
jstat -compiler :HotSpt JIT编译器行为统计 Java HotSpot VM Just-in-Time compiler statistics.
[root@root ~]# jstat -compiler 1
Compiled Failed Invalid Time FailedType FailedMethod
31073 3 0 182.63 1 com/mysql/jdbc/AbandonedConnectionCleanupThread run
参数说明:
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.
jstat -gc:垃圾回收堆的行为统计 Garbage-collected heap statistics.
[root@root ~]# jstat -gc 1
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
17472.0 17472.0 0.0 1248.6 139776.0 7359.2 349568.0 233485.7 149632.0 144590.5 16768.0 15863.7 1119 11.856 11 2.871 14.727
参数说明:
S0C : 第一个幸存区的总容量(KB)Current survivor space 0 capacity (kB).
S1C : 第二个幸存区的总容量(KB)Current survivor space 1 capacity (kB).
S0U : 第一个幸存区已使用的容量(KB)Survivor space 0 utilization (kB).
S1U : 第二个幸存区已使用的容量(KB)Survivor space 1 utilization (kB).
EC : 伊甸区的总容量(KB)Current eden space capacity (kB).
EU : 伊甸区已使用容量(KB)Eden space utilization (kB).
OC : 老年区的总容量(KB)Current old space capacity (kB).
OU:老年代使用大小(KB)Old space utilization (kB).
MC : 元空间的总容量(KB)Metaspace capacity (kB).
MU : 元空间已使用容量(KB)Metacspace utilization (kB).
CCSC : 压缩类空间总容量(KB)Compressed class space capacity (kB).
CCSU : 压缩类空间已使用总容量(KB)Compressed class space used (kB).
YGC : 新生代GC次数Number of young generation garbage collection events.
YGCT :新生代GC总耗费时间Young generation garbage collection time.
FGC : FullGC次数Number of full GC events.
FGCT : FullGC总耗费时间Full garbage collection time.
GCT : GC总耗费时间Total garbage collection time.
jstat -gccapacity : 各个回收区内存情况 Memory pool generation and space capacities.
[root@root ~]# jstat -gccapacity 1
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
10880.0 174720.0 174720.0 17472.0 17472.0 139776.0 21888.0 349568.0 349568.0 349568.0 0.0 1181696.0 149632.0 0.0 1048576.0 16768.0 1119 11
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:年轻代gc次数 Number of young generation GC events.
FGC:老年代GC(FullGC)次数 Number of full GC events.
jstat -gccause :垃圾收集统计概述 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.
[root@root ~]# jstat -gccause 1
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC
6.67 0.00 90.76 66.79 96.66 94.62 1130 11.949 11 2.871 14.820 Allocation Failure No GC
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 : 新生代GC次数 Number of young generation GC events.
FGC : 老年代GC次数 Number of full GC events.
LGCC :最近一次GC原因 Cause of last garbage collection
GCC : 当前GC原因 Cause of current garbage collection
jstat -gcnew : 显示新生代统计信息 New generation statistics.
[root@root ~]# jstat -gcnew 1
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
17472.0 17472.0 0.0 1350.4 15 15 8736.0 139776.0 73826.1 1131 11.957
S0C : 第一幸存区总空间大小(KB)Current survivor space 0 capacity (kB).
S1C : 第二幸存区总空间大小(KB)Current survivor space 1 capacity (kB).
S0U : 第一幸存区已使用空间大小(KB)Survivor space 0 utilization (kB).
S1U : 第二幸存区已使用空间大小(KB)Survivor space 1 utilization (kB).
TT : 提升阈值 Tenuring threshold.
MTT : 最大阈值 Maximum tenuring threshold.
DSS : 预期survivor区域大小 (KB) Desired survivor size (kB).
EC : 伊甸区总空间大小(KB)Current eden space capacity (kB).
EU : 伊甸区已使用空间大小(KB)Eden space utilization (kB).
YGC:年轻代gc次数 Number of young generation GC events.
YGCT :新生代GC总耗费时间 Young generation garbage collection time.
jstat -gcnewcapacity : 统计新生代及内存使用情况 New generation space size statistics.
[root@root ~]# jstat -gcnewcapacity 1
NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC
10880.0 174720.0 174720.0 17472.0 17472.0 17472.0 17472.0 139776.0 139776.0 1131 11
NGCMN : 新生代最小空间大小(KB)Minimum new generation capacity (kB).
NGCMX : 新生代最大空间大小(KB)Maximum new generation capacity (kB).
NGC : 当前新生代空间大小(KB) Current new generation capacity (kB).
S0CMX : 第一幸存区最大空间大小(KB)Maximum survivor space 0 capacity (kB).
S0C : 第一幸存区当前空间大小(KB)Current survivor space 0 capacity (kB).
S1CMX : 第二幸存区最大空间大小(KB)Maximum survivor space 1 capacity (kB).
S1C : 第二幸存区当前空间大小(KB)Current survivor space 1 capacity (kB).
ECMX : 伊甸区最大空间大小(KB)Maximum eden space capacity (kB).
EC : 伊甸区当前空间大小(KB)Current eden space capacity (kB).
YGC : 新生代GC次数 Number of young generation GC events.
FGC : 老年代GC次数 Number of full GC events.
jstat -gcold : 统计老年代和元空间使用情况 Old generation and metaspace behavior statistics.
[root@root ~]# jstat -gcold 1
MC MU CCSC CCSU OC OU YGC FGC FGCT GCT
149632.0 144638.0 16768.0 15866.4 349568.0 233488.9 1132 11 2.871 14.841
MC : 元空间总大小(KB)Metaspace capacity (kB).
MU : 元空间已使用大小(KB)Metaspace utilization (kB).
CCSC : 压缩类空间总大小(KB) Compressed class space capacity (kB).
CCSU : 压缩类空间已使用大小(KB)Compressed class space used (kB).
OC : 老年区空间总大小(KB) Current old space capacity (kB).
OU : 老年区已使用大小(KB)Old space utilization (kB).
YGC : 新生代GC次数 Number of young generation GC events.
FGC : 老年代GC次数 Number of full GC events.
FGCT : 老年代GC总耗时 Full garbage collection time.
GCT : GC总耗时 Total garbage collection time.
jstat -gcoldcapacity : 统计老年代内存使用情况 Old generation size statistics.
[root@root ~]# jstat -gcoldcapacity 1
OGCMN OGCMX OGC OC YGC FGC FGCT GCT
21888.0 349568.0 349568.0 349568.0 1132 11 2.871 14.841
OGCMN :老年区占用最小空间(KB)Minimum old generation capacity (kB).
OGCMX : 老年区占用最大空间(KB)Maximum old generation capacity (kB).
OGC : 当前老年区空间(KB)Current old generation capacity (kB).
OC : 当前老年区空间(KB)Current old space capacity (kB).
YGC :新生代GC次数 Number of young generation GC events.
FGC : 老年代GC次数 Number of full GC events.
FGCT : 老年代GC总耗时 Full garbage collection time.
GCT : GC总耗时 Total garbage collection time.
gc -gcmetacapacity :元空间使用情况 Metaspace size statistics.
[root@root ~]# jstat -gcmetacapacity 1
MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT GCT
0.0 1181696.0 149632.0 0.0 1048576.0 16768.0 1131 11 2.871 14.828
MCMN : 元空间最小空间大小(KB) Minimum metaspace capacity (kB).
MCMX : 元空间最大空间大小(KB)Maximum metaspace capacity (kB).
MC : 元空间当前空间大小(KB)Metaspace capacity (kB).
CCSMN : 压缩类空间最小空间大小(KB) Compressed class space minimum capacity (kB).
CCSMX : 压缩类空间最大空间大小(KB) Compressed class space maximum capacity (kB).
CCSC : 压缩类空间当前空间大小(KB)Compressed class space capacity (kB).
YGC : 新生代GC次数 Number of young generation GC events.
FGC : 老年代GC次数 Number of full GC events.
FGCT: 老年代GC耗费时间 Full garbage collection time.
GCT : GC总耗费时间 Total garbage collection time.
jstat -gcutil : 垃圾回收统计 Summary of garbage collection statistics.
[root@root ~]# jstat -gcutil 1
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
6.68 0.00 39.54 66.79 96.66 94.62 1132 11.970 11 2.871 14.841
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 : 新生代GC次数 Number of young generation GC events.
YGCT :新生代GC总耗费时间 Young generation garbage collection time.
FGC : 老年代GC次数 Number of full GC events.
FGCT: 老年代GC耗费时间 Full garbage collection time.
GCT :GC总耗时 Total garbage collection time.
jstat -printcompilation : Hotspot方法编译统计情况 Java HotSpot VM compiler method statistics.
[root@root ~]# jstat -printcompilation 1
Compiled Size Type Method
31174 1055 1 sun/reflect/GeneratedMethodAccessor214 invoke
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.
其他示例
使用-h3
来每三行数据之后输出一次标题,每次数据数据时间间隔1秒:
[root@root ~]# jstat -gcnew -h3 1 1s
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
17472.0 17472.0 0.0 1359.4 15 15 8736.0 139776.0 51283.7 1133 11.980
17472.0 17472.0 0.0 1359.4 15 15 8736.0 139776.0 51283.8 1133 11.980
17472.0 17472.0 0.0 1359.4 15 15 8736.0 139776.0 51674.1 1133 11.980
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
17472.0 17472.0 0.0 1359.4 15 15 8736.0 139776.0 51816.1 1133 11.980
17472.0 17472.0 0.0 1359.4 15 15 8736.0 139776.0 51824.8 1133 11.980
17472.0 17472.0 0.0 1359.4 15 15 8736.0 139776.0 51828.9 1133 11.980
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
17472.0 17472.0 0.0 1359.4 15 15 8736.0 139776.0 52158.8 1133 11.980
17472.0 17472.0 0.0 1359.4 15 15 8736.0 139776.0 52312.8 1133 11.980
附
官方文档链接:https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html#BEHHGFAE