参考官方文档(jdk11)
https://docs.oracle.com/en/java/javase/11/tools/troubleshooting-tools-and-commands.html#GUID-CB44BFBA-E5F9-4D80-8EE8-28E9F16BC451
1. 监控工具(jps, jstat, jstatd)
jps
-q
Suppresses the output of the class name, JAR file name, and arguments passed to the main method, producing a list of only local JVM identifiers.
-mlvV
-m displays the arguments passed to the main method. The output may be null for embedded JVMs.-l displays the full package name for the application's main class or the full path name to the application's JAR file.-v displays the arguments passed to the JVM.-V suppresses the output of the class name, JAR file name, and arguments passed to the main method, producing a list of only local JVM identifiers.
jstat
(base) PS C:\Users\zishi> jstat -h
Usage: jstat --help|-optionsjstat -<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 targetJava virtual machine, typically a process id; <hostname> isthe name of the host running the target Java virtual machine;and <port> is the port number for the rmiregistry on thetarget host. See the jvmstat documentation for a more completedescription 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 asmilliseconds("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.-? -h --help Prints this help message.-help Prints this help message.
说明:
option:参数选项
-t:可以在打印的列加上Timestamp列,用于显示系统运行的时间
-h:可以在周期性数据输出的时候,指定输出多少行以后输出一次表头
vmid:Virtual Machine ID( 进程的 pid)
interval:执行每次的间隔时间,单位为毫秒
count:用于指定输出多少次记录,缺省则会一直打印
示例:
(base) PS C:\Users\zishi> jstat -gcutil -t -h5 24392 1000 20
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT2587.6 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122588.6 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122589.6 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122590.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122591.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.212
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT2592.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122593.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122594.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122595.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122596.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.212
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT2597.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122598.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122599.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122600.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122601.7 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.212
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT2602.8 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122603.8 0.00 100.00 14.61 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122604.8 0.00 100.00 15.17 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122605.8 0.00 100.00 15.17 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.2122606.8 0.00 100.00 15.17 11.16 97.36 91.49 12 0.202 0 0.000 6 0.010 0.212
-options说明
(base) PS C:\Users\zishi> jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation
class: Displays statistics about the behavior of the class loader.
(base) PS C:\Users\zishi> jstat -class 24392
Loaded Bytes Unloaded Bytes Time13370 25776.4 0 0.0 6.23
说明:
Loaded:加载class的数量
Bytes:所占用空间大小
Unloaded:未加载数量
Bytes:未加载占用空间
Time:时间
compiler: Displays statistics about the behavior of the Java HotSpot VM Just-in-Time compiler.
(base) PS C:\Users\zishi> jstat -compiler 24392
Compiled Failed Invalid Time FailedType FailedMethod9892 1 0 52.28 1 org/springframework/cglib/core/MethodWrapper$MethodWrapperKey$$KeyFactoryByCGLIB$$552be97a hashCode
说明:
Compiled:编译数量。
Failed:失败数量
Invalid:不可用数量
Time:时间
FailedType:失败类型
FailedMethod:失败的方法
gc: Displays statistics about the behavior of the garbage collected heap.
(base) PS C:\Users\zishi> jstat -gc 24392S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT CGC CGCT GCT0.0 36864.0 0.0 36864.0 358400.0 309248.0 231424.0 14005.6 73932.0 72017.7 8704.0 7939.9 11 0.185 0 0.000 6 0.010 0.195
说明:
S0C:第一个幸存区的大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
EC:eden区的大小
EU:eden区的使用大小
OC:老年代大小
OU:老年代使用大小
MC:方法区大小
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
gccapacity: Displays statistics about the capacities of the generations and their corresponding spaces.
(base) PS C:\Users\zishi> jstat -gccapacity 24392NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC CGC0.0 8325120.0 395264.0 0.0 36864.0 358400.0 0.0 8325120.0 231424.0 231424.0 0.0 1114112.0 73932.0 0.0 1048576.0 8704.0 11 0 6
NGCMN:新生代最小容量
NGCMX:新生代最大容量
NGC:当前新生代容量
S0C:第一个幸存区大小
S1C:第二个幸存区的大小
EC:伊甸园区的大小
OGCMN:老年代最小容量
OGCMX:老年代最大容量
OGC:当前老年代大小
OC:当前老年代大小
MCMN:最小元数据容量
MCMX:最大元数据容量
MC:当前元数据空间大小
CCSMN:最小压缩类空间大小
CCSMX:最大压缩类空间大小
CCSC:当前压缩类空间大小
YGC:年轻代gc次数
FGC:老年代GC次数
gccause: Displays a summary about garbage collection statistics (same as -gcutil), with the cause of the last and current (when applicable) garbage collection events.
(base) PS C:\Users\zishi> jstat -gccause 24392S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT LGCC GCC0.00 100.00 89.14 6.05 97.41 91.22 11 0.185 0 0.000 6 0.010 0.195 G1 Evacuation Pause No GC
说明:
这里是引用
gcnew: Displays statistics about the behavior of the new generation.
(base) PS C:\Users\zishi> jstat -gcnew 24392S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT0.0 36864.0 0.0 36864.0 7 15 23552.0 358400.0 323584.0 11 0.185
说明:
S0C:第一个幸存区大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
TT:对象在新生代存活的次数
MTT:对象在新生代存活的最大次数
DSS:期望的幸存区大小
EC:伊甸园区的大小
EU:伊甸园区的使用大小
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间
gcnewcapacity: Displays statistics about the sizes of the new generations and their corresponding spaces.
(base) PS C:\Users\zishi> jstat -gcnewcapacity 24392NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC CGC0.0 8325120.0 395264.0 0.0 0.0 8325120.0 36864.0 8325120.0 358400.0 11 0 6
说明:
NGCMN:新生代最小容量
NGCMX:新生代最大容量
NGC:当前新生代容量
S0CMX:最大幸存1区大小
S0C:当前幸存1区大小
S1CMX:最大幸存2区大小
S1C:当前幸存2区大小
ECMX:最大伊甸园区大小
EC:当前伊甸园区大小
YGC:年轻代垃圾回收次数
FGC:老年代回收次数
gcold: Displays statistics about the behavior of the old generation and metaspace statistics.
(base) PS C:\Users\zishi> jstat -gcold 24392MC MU CCSC CCSU OC OU YGC FGC FGCT CGC CGCT GCT73932.0 72017.7 8704.0 7939.9 231424.0 14005.6 11 0 0.000 6 0.010 0.195
说明:
MC:方法区大小
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
OC:老年代大小
OU:老年代使用大小
YGC:年轻代垃圾回收次数
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
gcoldcapacity: Displays statistics about the sizes of the old generation.
(base) PS C:\Users\zishi> jstat -gcoldcapacity 24392OGCMN OGCMX OGC OC YGC FGC FGCT CGC CGCT GCT0.0 8325120.0 231424.0 231424.0 11 0 0.000 6 0.010 0.195
说明:
OGCMN:老年代最小容量
OGCMX:老年代最大容量
OGC:当前老年代大小
OC:老年代大小
YGC:年轻代垃圾回收次数
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
gcmetacapacity: Displays statistics about the sizes of the metaspace.
(base) PS C:\Users\zishi> jstat -gcmetacapacity 24392MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT CGC CGCT GCT0.0 1114112.0 73932.0 0.0 1048576.0 8704.0 11 0 0.000 6 0.010 0.195
说明:
MCMN:最小元数据容量
MCMX:最大元数据容量
MC:当前元数据空间大小
CCSMN:最小压缩类空间大小
CCSMX:最大压缩类空间大小
CCSC:当前压缩类空间大小
YGC:年轻代垃圾回收次数
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
gcutil: Displays a summary about garbage collection statistics.
(base) PS C:\Users\zishi> jstat -gcutil 24392S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT0.00 100.00 92.57 6.05 97.41 91.22 11 0.185 0 0.000 6 0.010 0.195
说明:
S0:幸存1区当前使用比例
S1:幸存2区当前使用比例
E:伊甸园区使用比例
O:老年代使用比例
M:元数据区使用比例
CCS:压缩使用比例
YGC:年轻代垃圾回收次数
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间
printcompilation: Displays Java HotSpot VM compilation method statistics.
(base) PS C:\Users\zishi> jstat -printcompilation 24392
Compiled Size Type Method10271 246 1 java/util/AbstractCollection toString
说明:
Compiled:最近编译方法的数量
Size:最近编译方法的字节码数量
Type:最近编译方法的编译类型。
Method:方法名标识。
参考:
https://docs.oracle.com/en/java/javase/11/tools/jstat.html#GUID-5F72A7F9-5D5A-4486-8201-E1D1BA8ACCB5
jstatd
待完善
https://docs.oracle.com/en/java/javase/11/tools/jstatd.html#GUID-FA737806-75CD-4EE7-A087-1CC4A5441870