每天学习一个linux命令:jstat查看Java应用的资源和性能

6 篇文章 0 订阅

命令环境:ubuntu1~16.04.5
JDK :java version “1.8.0_152”

一、序言

jstat 命令是JDK自带的一个轻量级小工具。全称“Java Virtual Machine statistics monitoring tool”,位于java的bin目录下,主要利用JVM内建的指令对Java应用程序的资源和性能进行实时命令行的监控,可以查看堆内存各部分的使用量,以及加载类的数量,包括了对Heap size和垃圾回收状况的监控。

二、命令介绍

jstat的主要命令是:

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

我们查看这些命令选项的英文解释:

bingsanlang@ubuntu:~$ 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.

一项项来看各项参数

2.1 -<option>

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
options 有如下选项:

bingsanlang@ubuntu:~$ jstat -options
-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.
-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  //Displays Java HotSpot VM compilation method statistics.

2.1.1 -class 是显示ClassLoad的相关信息,查看类的加载情况。

bingsanlang@ubuntu:~$ jstat -class 16723
Loaded  Bytes  Unloaded  Bytes     Time   
  7698 15838.2       19    23.3      12.13
指标名称解释英文解释
Loaded加载的class类个数Number of classes loaded.
Bytes加载的类占用的空间Number of Kbytes loaded.
Unloaded卸载的class类个数Number of classes unloaded.
Bytes卸载的类占用的空间Number of Kbytes unloaded.
Time加载和卸载class类花费的时间Time spent performing class load and unload operations.

2.1.2 -compiler 是显示JIT编译器的编译行为

bingsanlang@ubuntu:~$ jstat -compiler 16723 
Compiled Failed Invalid   Time   FailedType FailedMethod
    5130      0       0    47.31 
指标名称解释英文解释
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.

2.1.3 -gc 垃圾收集器的堆统计

bingsanlang@ubuntu:~$ jstat -gc 16723 
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
2368.0 2368.0  0.0    50.7  19392.0  10961.6   48124.0    31522.2   48512.0 47661.6 5760.0 5499.1    327    9.003   4      1.545   10.547
指标名称解释英文解释
S0C幸存区1的容量大小Current survivor space 0 capacity (kB).
S1C幸存区2的容量大小Current survivor space 1 capacity (kB).
S0U幸存区1的使用大小Survivor space 0 utilization (kB).
S1U幸存区2的使用大小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.

2.1.4 -gccapacity 内存分代情况和空间容量

Memory pool generation and space capacities.

bingsanlang@ubuntu:~$ jstat -gccapacity  16723 
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC 
  6144.0  96256.0  24128.0 2368.0 2368.0  19392.0    12288.0   192512.0    48124.0    48124.0      0.0 1091584.0  48512.0      0.0 1048576.0   5760.0    327     4
指标名称解释英文解释
NGCMN新生代的最小容量Minimum new generation capacity (kB).
NGCMX新生代的最大容量Maximum new generation capacity (kB).
NGC当前新生代的容量Current new generation capacity (kB).
S0C幸存区1的当前容量Current survivor space 0 capacity (kB).
S1C幸存区2的当前容量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次数Number of full GC events.

2.1.5 -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.

bingsanlang@ubuntu:~$ jstat -gccause  16723 
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC                 
  0.00   2.14  82.26  65.50  98.25  95.47    327    9.003     4    1.545   10.547 Allocation Failure   No GC
指标名称解释英文解释
S0幸存区1的大小
S1幸存区2的大小
E伊甸园区的大小
O老年代的大小
M元空间的大小
CCS压缩类的大小
YGC新生代的GC次数
YGCT新生代的GC时间
FGC老年代的GC次数
FGCT老年的GC时间
GCTGC的总耗时
LGCC最近一次GC的原因Cause of last garbage collection
GCC当前GC的原因Cause of current garbage collection

2.1.6 -gcmetacapacity 元数据的空间统计情况

Metaspace size statistics.

bingsanlang@ubuntu:~$ jstat -gcmetacapacity  16723 
   MCMN       MCMX        MC       CCSMN      CCSMX       CCSC     YGC   FGC    FGCT     GCT   
       0.0  1091584.0    48512.0        0.0  1048576.0     5760.0   327     4    1.545   10.547
指标名称解释英文解释
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新生代的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.

2.1.7 -gcnew 新生代的情况

New generation statistics.

bingsanlang@ubuntu:~$ jstat -gcnew  16723 
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT  
2368.0 2368.0    0.0   50.7 15  15 1184.0  19392.0  19113.4    327    9.003
指标名称解释英文解释
S0C当前幸存区1的容量大小Current survivor space 0 capacity (kB).
S1C当前幸存区2的容量大小Current survivor space 1 capacity (kB).
S0U当前幸存区1的使用大小Survivor space 0 utilization (kB).
S1U当前幸存区2的使用大小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新生代的GC次数Number of young generation GC events.
YGCT新生代的GC时间Young generation garbage collection time.

2.1.8 -gcnewcapacity 新生代的空间大小统计情况

New generation space size statistics.

wanghanbing@ubuntu:~$ jstat -gcnewcapacity  16723 
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC 
    6144.0    96256.0    24128.0   9600.0   2368.0   9600.0   2368.0    77056.0    19392.0   328     4
指标名称解释英文解释
NGCMN新生代的最小容量大小Minimum new generation capacity (kB).
NGCMX新生代的最大容量大小Maximum new generation capacity (kB).
NGC当前新生代的大小Current new generation capacity (kB).
S0CMX幸存区1的最大容量Maximum survivor space 0 capacity (kB).
S0C当前幸存区1的容量Current survivor space 0 capacity (kB).
S1CMX幸存区2的最大容量Maximum survivor space 1 capacity (kB).
S1C当前幸存区1的容量Current survivor space 1 capacity (kB).
ECMX伊甸园的最大容量大小Maximum eden space capacity (kB).
EC当前伊甸园的容量大小Current eden space capacity (kB).
YGC新生代的GC次数Number of young generation GC events.
FGC老年代的GC次数Number of full GC events.

2.1.9 -gcold 老年代统计情况

Old generation and metaspace behavior statistics.

bingsanlang@ubuntu:~$ jstat -gcold  16723 
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT   
 48512.0  47661.6   5760.0   5499.1     48124.0     31522.2    328     4    1.545   10.550
指标名称解释英文解释
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新生代的GC次数Number of young generation GC events.
FGC老年代的GC次数Number of full GC events.
FGCT老年代GC的时间Full garbage collection time.
GCTGC的总时间Total garbage collection time.

2.1.10 -gcoldcapacity 老年代的空间统计情况

Old generation size statistics.

bingsanlang@ubuntu:~$ jstat -gcoldcapacity  16723 
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT   
    12288.0    192512.0     48124.0     48124.0   328     4    1.545   10.550
指标名称解释英文解释
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新生代的GC次数Number of young generation GC events.
FGC老年代的GC次数Number of full GC events.
FGCT老年代的GC时间Full garbage collection time.
GCTGC的总时间Total garbage collection time.

2.1.11 -gcutil 垃圾回收的整体概况

Summary of garbage collection statistics.

bingsanlang@ubuntu:~$ jstat -gcutil  16723 
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
  1.59   0.00  48.46  65.50  98.25  95.47    328    9.005     4    1.545   10.550
指标名称解释英文解释
S0幸存区1的大小
S1幸存区2的大小
E伊甸园区的大小
O老年代的大小
M元空间的大小
CCS压缩类的大小
YGC新生代的GC次数
YGCT新生代的GC时间
FGC老年代的GC次数
FGCT老年的GC时间
GCTGC的总耗时

2.1.12 -printcompilation 虚拟机编译方法统计

Java HotSpot VM compiler method statistics.

bingsanlang@ubuntu:~$ jstat -printcompilation  16723 
Compiled  Size  Type Method
    5130    105    1 java/util/Formatter$FormatSpecifier justify
指标名称解释英文解释
CompiledNumber of compilation tasks performed by the most recently compiled method.
SizeNumber of bytes of byte code of the most recently compiled method.
TypeCompilation type of the most recently compiled method.
MethodClass 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.

2.2 [-t]

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Displays a timestamp column as the first column of output. The time stamp is the time since the start time of the target JVM.
在输出的第一列增加一列时间戳,这个时间戳是自从JVM启动的时间开始计算的。

bingsanlang@ubuntu:~$ jstat -class -t 16723 
Timestamp       Loaded  Bytes  Unloaded  Bytes     Time   
      1219513.8   7698 15838.2       19    23.3      12.13

2.3 [-h]

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Displays a column header every n samples (output rows), where n is a positive integer. Default value is 0, which displays the column header the first row of data.

bingsanlang@ubuntu:~$ jstat -printcompilation -h3 16723 2000 
Compiled  Size  Type Method
    5130    105    1 java/util/Formatter$FormatSpecifier justify
    5130    105    1 java/util/Formatter$FormatSpecifier justify
    5130    105    1 java/util/Formatter$FormatSpecifier justify
Compiled  Size  Type Method
    5130    105    1 java/util/Formatter$FormatSpecifier justify
    5130    105    1 java/util/Formatter$FormatSpecifier justify

这个参数是每输出多少行数据,就打印titile。

2.4 <vmid>

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Virtual machine identifier, which is a string that indicates the target JVM. The general syntax is the following:
[protocol:][//]lvmid[@hostname[:port]/servername]
The syntax of the vmid string corresponds to the syntax of a URI. The vmid string can vary from a simple integer that represents a local JVM to a more complex construction that specifies a communications protocol, port number, and other implementation-specific values. See Virtual Machine Identifier.

2.5 interval [s|ms]

Sampling interval in the specified units, seconds (s) or milliseconds (ms). Default units are milliseconds. Must be a positive integer. When specified, the jstat command produces its output at each interval.

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

2.6 count

Number of samples to display. The default value is infinity which causes the jstat command to display statistics until the target JVM terminates or the jstat command is terminated. This value must be a positive integer.

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

参考:

https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html#BEHHGFAE

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值