JVM调优

JVM工具命令之jstat小结

2020-06-18  本文已影响0人  LittleMagic

jstat

今日六一八,事情多的很,正好适合写流水账总结。之前已经分别讲过了JVM提供的jstack、jmap工具的用法,今天简单说说jstat吧。

jstat命令的格式如下。

# jstat -help
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.

stat一词顾名思义是“统计”,也就是说jstat命令是打印JVM进程里某些统计信息的。通过jstat -options可以列出所有可用的统计项。

# jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation

下面逐个列举其用法。

类加载统计:-class

# jstat -class 32968
Loaded  Bytes  Unloaded  Bytes     Time   
 12734 25041.9        0     0.0       5.24

HotSpot JIT编译统计:-compiler

# jstat -compiler 32968
Compiled Failed Invalid   Time   FailedType FailedMethod
   18324      3       0    52.58          1 java/net/URLClassLoader$1 run

HotSpot编译方法统计:-printcompilation

# jstat -printcompilation 32968
Compiled  Size  Type Method
   18360     12    1 org/apache/flink/shaded/netty4/io/netty/buffer/WrappedByteBuf readBytes

堆和GC概况统计:-gc

以下用上了jstat的周期性打印参数,即每隔1000毫秒打印一次,共打印10条,并每隔5行输出一次表头(-h参数)。

# jstat -gc -h 5 32968 1000 10 
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
43456.0 43456.0  0.0   2397.5 347904.0 176826.0  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263
43456.0 43456.0  0.0   2397.5 347904.0 181654.1  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263
43456.0 43456.0  0.0   2397.5 347904.0 187518.6  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263
43456.0 43456.0  0.0   2397.5 347904.0 188852.0  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263
43456.0 43456.0  0.0   2397.5 347904.0 194509.4  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
43456.0 43456.0  0.0   2397.5 347904.0 199233.7  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263
43456.0 43456.0  0.0   2397.5 347904.0 201916.8  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263
43456.0 43456.0  0.0   2397.5 347904.0 206240.1  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263
43456.0 43456.0  0.0   2397.5 347904.0 211307.5  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263
43456.0 43456.0  0.0   2397.5 347904.0 216620.3  869760.0   117548.3  79836.0 77869.0 9840.0 9420.1   1009    4.212   6      0.051    4.263

放个图复习一下基础知识吧。

JDK 8+已不存在永久代,自动把图中永久代脑补成元空间即可,懒得重新画= =

堆分代容量统计:-gccapacity

# jstat -gccapacity 32968
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC 
434816.0 434816.0 434816.0 43456.0 43456.0 347904.0   869760.0   869760.0   869760.0   869760.0      0.0 1120256.0  79836.0      0.0 1048576.0   9840.0   1016     6

堆分代GC和容量详情:-gcnew(capacity)/-gcold(capacity)/-gcmetacapacity

分别用来查看新生代、老生代和元空间的详细数据。它们呈现的数据与上面-gc/-gccapacity选项有很多相同,以下仅用-gcnew(capacity)来举例。

# jstat -gcnew 32968
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT  
43456.0 43456.0    0.0 2633.4  6   6 21728.0 347904.0 104542.9   1041    4.338

# jstat -gcnewcapacity 32968
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC 
  434816.0   434816.0   434816.0  43456.0  43456.0  43456.0  43456.0   347904.0   347904.0  1041     6

以下三个需要特别注意:

GC汇总信息:-gcutil

(前面说了辣么多,这个选项其实才是最常用的_(:з」∠)_

# jstat -gcutil -h 5 32968 1000 10
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
  6.20   0.00  39.06  13.81  97.54  95.73   1050    4.373     6    0.051    4.424
  6.20   0.00  39.42  13.81  97.54  95.73   1050    4.373     6    0.051    4.424
  6.20   0.00  40.86  13.81  97.54  95.73   1050    4.373     6    0.051    4.424
  6.20   0.00  41.16  13.81  97.54  95.73   1050    4.373     6    0.051    4.424
  6.20   0.00  42.72  13.81  97.54  95.73   1050    4.373     6    0.051    4.424
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
  6.20   0.00  43.17  13.81  97.54  95.73   1050    4.373     6    0.051    4.424
  6.20   0.00  48.45  13.81  97.54  95.73   1050    4.373     6    0.051    4.424
  6.20   0.00  49.80  13.81  97.54  95.73   1050    4.373     6    0.051    4.424
  6.20   0.00  51.23  13.81  97.54  95.73   1050    4.373     6    0.051    4.424
  6.20   0.00  52.54  13.81  97.54  95.73   1050    4.373     6    0.051    4.424

GC原因:-gccause

# jstat -gccause 32968
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC                 
  0.00  11.77  84.45  13.80  97.54  95.73   1049    4.370     6    0.051    4.421 Allocation Failure   No GC               

The End

还有些事情要做,民那晚安晚安。

上一篇 下一篇

猜你喜欢

热点阅读