JVM在线分析-监控工具(jps, jstat, jstatd)

参考官方文档(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

bash 复制代码
-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

bash 复制代码
(base) PS C:\Users\zishi> jstat -h
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.
  -? -h --help  Prints this help message.
  -help         Prints this help message.

说明:

option:参数选项

-t:可以在打印的列加上Timestamp列,用于显示系统运行的时间

-h:可以在周期性数据输出的时候,指定输出多少行以后输出一次表头

vmid:Virtual Machine ID( 进程的 pid)

interval:执行每次的间隔时间,单位为毫秒

count:用于指定输出多少次记录,缺省则会一直打印

示例:

bash 复制代码
(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     GCT
         2587.6   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2588.6   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2589.6   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2590.7   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2591.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     GCT
         2592.7   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2593.7   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2594.7   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2595.7   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2596.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     GCT
         2597.7   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2598.7   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2599.7   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2600.7   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2601.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     GCT
         2602.8   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2603.8   0.00 100.00  14.61  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2604.8   0.00 100.00  15.17  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2605.8   0.00 100.00  15.17  11.16  97.36  91.49     12    0.202     0    0.000     6    0.010    0.212
         2606.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说明

bash 复制代码
(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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -class 24392
Loaded  Bytes  Unloaded  Bytes     Time
 13370 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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -compiler 24392
Compiled Failed Invalid   Time   FailedType FailedMethod
    9892      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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -gc 24392
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT    CGC    CGCT     GCT
 0.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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -gccapacity 24392
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC   CGC
   0.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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -gccause 24392
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT    CGC    CGCT     GCT    LGCC                 GCC
  0.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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -gcnew 24392
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
   0.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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -gcnewcapacity 24392
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC   CGC
       0.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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -gcold 24392
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT    CGC    CGCT     GCT
 73932.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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -gcoldcapacity 24392
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT    CGC    CGCT     GCT
        0.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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -gcmetacapacity 24392
   MCMN       MCMX        MC       CCSMN      CCSMX       CCSC     YGC   FGC    FGCT    CGC    CGCT     GCT
       0.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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -gcutil 24392
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT    CGC    CGCT     GCT
  0.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.

bash 复制代码
(base) PS C:\Users\zishi> jstat -printcompilation 24392
Compiled  Size  Type Method
   10271    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

相关推荐
情报员0073 分钟前
Java练习6
java·算法·排序算法
andrew_121912 分钟前
JVM的内存管理、垃圾回收、类加载和参数调优
java·jvm
百锦再14 分钟前
Python深度挖掘:openpyxl和pandas的使用详细
java·开发语言·python·框架·pandas·压力测试·idea
microhex18 分钟前
Glide 如何加载远程 Base64 图片
java·开发语言·glide
chilling heart27 分钟前
JAVA---集合ArrayList
java·开发语言
ss27327 分钟前
基于Springboot + vue实现的中医院问诊系统
java·spring boot·后端
wuqingshun31415943 分钟前
经典算法 最长单调递增子序列
java·c++·算法·蓝桥杯·机器人
IT技术员1 小时前
【Java学习】动态代理有哪些形式?
java·python·学习
2401_897930061 小时前
Maven 依赖范围(Scope)详解
java·maven
豆沙沙包?1 小时前
2025年- H13-Lc120-189.轮转数组(普通数组)---java版
java·算法·排序算法