java虚拟机的监控统计工具-jstat根据进程id查看Java项目的年轻代、年老代gc等情况

作者: admin 分类: JVM 发布时间: 2019-05-10 23:42  阅读: 45 views

作为一个java程序猿,随着工龄的增加去了解jvm的运行情况与原理是不得不去学习的。编写业务代码还是比较简单的,出现了性能问题如果不懂得jvm回收原理及调优,可能就像丈二的和尚——摸不到脑袋一样。jdk本身提供一个工具jvisualvm,提供可视化的界面。mac或windows系统查看比较方便,在linux中,选取 jstat是个不错的选择。

查看jstat的帮助说明

chenhailongdeMacBook-Pro:bin chenhailong$ 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.

options选项及说明

Option
Displays…
class
Statistics on the behavior of the class loader.【class加载器的行为统计】
compiler
Statistics of the behavior of the HotSpot Just-in-Time compiler.【即时编译器的行为统计】
gc
Statistics of the behavior of the garbage collected heap.【gc回收的行为统计】
gccapacity
Statistics of the capacities of the generations and their corresponding spaces.【不同年代空间的能力统计】
gccause
Summary of garbage collection statistics (same as -gcutil), with the cause of the last and current (if applicable) garbage collection events.【垃圾回收统计信息摘要,与gcutil相同,包含当前和最后一个回收时间的原因】
gcnew
Statistics of the behavior of the new generation.【新生代的行为统计】
gcnewcapacity
Statistics of the sizes of the new generations and its corresponding spaces.【新生代及空间大小信息统计】
gcold
Statistics of the behavior of the old and permanent generations.【老年代和永久代的行为统计】
gcoldcapacity
Statistics of the sizes of the old generation.【老年代的大小信息统计】
gcpermcapacity
Statistics of the sizes of the permanent generation.【永久代的大小统计】
gcutil
Summary of garbage collection statistics.【垃圾回收统计信息摘要】
printcompilation
HotSpot compilation method statistics.【编译方法统计】

 

jstat -class 2718 1000 5 【每1000ms输出一次,共5次】

chenhailongdeMacBook-Pro:bin chenhailong$ jstat -class 12718 1000 10
Loaded  Bytes  Unloaded  Bytes     Time   
 16864 29322.7        0     0.0      11.85
 16864 29322.7        0     0.0      11.85
 16864 29322.7        0     0.0      11.85
 16864 29322.7        0     0.0      11.85
 16864 29322.7        0     0.0      11.85
Column
Description
Loaded
Number of classes loaded.
Bytes
Number of Kbytes loaded.
Unloaded
Number of classes unloaded.
Bytes
Number of Kbytes unloaded.
Time
Time spent performing class load and unload operations.

jstat -compiler 12718 1000 10

chenhailongdeMacBook-Pro:bin chenhailong$ jstat -compiler 12718 1000 10
Compiled Failed Invalid   Time   FailedType FailedMethod
   21653      0       0   119.31          0             
   21653      0       0   119.31          0             
   21653      0       0   119.31          0             
   21653      0       0   119.31          0             
   21653      0       0   119.31          0    
Column
Description
Compiled
Number of compilation tasks performed.
Failed
Number of compilation tasks that 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 for the last failed compilation.

jstat -gc  2934 1000 5

jstat -gc 2934 1000 50
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
 0.0   131072.0  0.0   131072.0 970752.0 281600.0  646144.0   566657.0  156120.0 141392.4 21064.0 16994.0     20    2.785   0      0.000    2.785
 0.0   131072.0  0.0   131072.0 970752.0 282624.0  646144.0   566657.0  156120.0 141392.4 21064.0 16994.0     20    2.785   0      0.000    2.785
 0.0   131072.0  0.0   131072.0 970752.0 282624.0  646144.0   566657.0  156120.0 141392.4 21064.0 16994.0     20    2.785   0      0.000    2.785
 0.0   131072.0  0.0   131072.0 970752.0 282624.0  646144.0   566657.0  156120.0 141392.4 21064.0 16994.0     20    2.785   0      0.000    2.785
Column
Description
S0C
Current survivor space 0 capacity (KB).
S1C
Current survivor space 1 capacity (KB).
S0U
Survivor space 0 utilization (KB).
S1U
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).
PC
Current permanent space capacity (KB).
PU
Permanent space utilization (KB).
YGC
Number of young generation GC Events.
YGCT
Young generation garbage collection time.
FGC
Number of full GC events.
FGCT
Full garbage collection time.
GCT
Total garbage collection time.

jstat -gccapacity 12718 1000 10

chenhailongdeMacBook-Pro:bin chenhailong$ jstat -gccapacity 12718 1000 10
 NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC 
340736.0 340736.0 340736.0 34048.0 34048.0 272640.0   707840.0   707840.0   707840.0   707840.0      0.0 1128448.0  91968.0      0.0 1048576.0  13252.0    123     4
340736.0 340736.0 340736.0 34048.0 34048.0 272640.0   707840.0   707840.0   707840.0   707840.0      0.0 1128448.0  91968.0      0.0 1048576.0  13252.0    123     4
340736.0 340736.0 340736.0 34048.0 34048.0 272640.0   707840.0   707840.0   707840.0   707840.0      0.0 1128448.0  91968.0      0.0 1048576.0  13252.0    123     4
Column
Description
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).
PGCMN
Minimum permanent generation capacity (KB).
PGCMX
Maximum Permanent generation capacity (KB).
PGC
Current Permanent generation capacity (KB).
PC
Current Permanent space capacity (KB).
YGC
Number of Young generation GC Events.
FGC
Number of Full GC Events.

jstat -gccaus 12718 1000 10

CchenhailongdeMacBook-Pro:bin chenhailong$ jstat -gccause 12718 1000 10
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC                 
  0.00   0.88  82.58  37.06  91.70  83.03    123    6.012     4    0.087    6.099 Allocation Failure   No GC               
  0.00   0.88  82.59  37.06  91.70  83.03    123    6.012     4    0.087    6.099 Allocation Failure   No GC               
  0.00   0.88  82.74  37.06  91.70  83.03    123    6.012     4    0.087    6.099 Allocation Failure   No GC               
  0.00   0.88  82.74  37.06  91.70  83.03    123    6.012     4    0.087    6.099 Allocation Failure   No GC 
Column
Description
LGCC
Cause of last Garbage Collection.
GCC
Cause of current Garbage Collection.

jstat -gcnew 12718 1000 10

chenhailongdeMacBook-Pro:bin chenhailong$ jstat -gcnew 12718 1000 10
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT  
34048.0 34048.0    0.0  298.3  6   6 17024.0 272640.0 234504.1    123    6.012
34048.0 34048.0    0.0  298.3  6   6 17024.0 272640.0 234504.1    123    6.012
34048.0 34048.0    0.0  298.3  6   6 17024.0 272640.0 234504.1    123    6.012
34048.0 34048.0    0.0  298.3  6   6 17024.0 272640.0 234504.1    123    6.012
Column
Description
S0C
Current survivor space 0 capacity (KB).
S1C
Current survivor space 1 capacity (KB).
S0U
Survivor space 0 utilization (KB).
S1U
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
Number of young generation GC events.
YGCT
Young generation garbage collection time.

jstat -gcnewcapacity 12718 1000 10

chenhailongdeMacBook-Pro:bin chenhailong$ jstat -gcnewcapacity 12718 1000 10
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC      YGC   FGC 
  340736.0   340736.0   340736.0  34048.0  34048.0  34048.0  34048.0   272640.0   272640.0   123     4
  340736.0   340736.0   340736.0  34048.0  34048.0  34048.0  34048.0   272640.0   272640.0   123     4
  340736.0   340736.0   340736.0  34048.0  34048.0  34048.0  34048.0   272640.0   272640.0   123     4
  340736.0   340736.0   340736.0  34048.0  34048.0  34048.0  34048.0   272640.0   272640.0   123     4
Column
Description
NGCMN
Minimum new generation capacity (KB).
NGCMX
Maximum new generation capacity (KB).
NGC
Current new generation capacity (KB).
S0CMX
Maximum survivor space 0 capacity (KB).
S0C
Current survivor space 0 capacity (KB).
S1CMX
Maximum survivor space 1 capacity (KB).
S1C
Current survivor space 1 capacity (KB).
ECMX
Maximum eden space capacity (KB).
EC
Current eden space capacity (KB).
YGC
Number of young generation GC events.
FGC
Number of Full GC Events.

jstat -gcold 12718 1000 4

chenhailongdeMacBook-Pro:bin chenhailong$ jstat -gcold 12718 1000 4
   MC       MU      CCSC     CCSU       OC          OU       YGC    FGC    FGCT     GCT   
 91968.0  84332.6  13252.0  11003.6    707840.0    262359.9    123     4    0.087    6.099
 91968.0  84332.6  13252.0  11003.6    707840.0    262359.9    123     4    0.087    6.099
 91968.0  84332.6  13252.0  11003.6    707840.0    262359.9    123     4    0.087    6.099
 91968.0  84332.6  13252.0  11003.6    707840.0    262359.9    123     4    0.087    6.099
Column
Description
PC
Current permanent space capacity (KB).
PU
Permanent space utilization (KB).
OC
Current old space capacity (KB).
OU
old space utilization (KB).
YGC
Number of young generation GC events.
FGC
Number of full GC events.
FGCT
Full garbage collection time.
GCT
Total garbage collection time.

jstat -gcoldcapacity 12718 1000 4

chenhailongdeMacBook-Pro:bin chenhailong$ jstat -gcoldcapacity 12718 1000 4
   OGCMN       OGCMX        OGC         OC       YGC   FGC    FGCT     GCT   
   707840.0    707840.0    707840.0    707840.0   124     4    0.087    6.140
   707840.0    707840.0    707840.0    707840.0   124     4    0.087    6.140
   707840.0    707840.0    707840.0    707840.0   124     4    0.087    6.140
   707840.0    707840.0    707840.0    707840.0   124     4    0.087    6.140
Column
Description
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
Number of young generation GC events.
FGC
Number of full GC events.
FGCT
Full garbage collection time.
GCT
Total garbage collection time.

jstat -gcutil 12718 1000 4

chenhailongdeMacBook-Pro:bin chenhailong$ jstat -gcutil 12718 1000 4
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
  0.92   0.00  13.70  37.06  91.70  83.03    124    6.053     4    0.087    6.140
  0.92   0.00  13.72  37.06  91.70  83.03    124    6.053     4    0.087    6.140
  0.92   0.00  13.72  37.06  91.70  83.03    124    6.053     4    0.087    6.140
  0.92   0.00  13.74  37.06  91.70  83.03    124    6.053     4    0.087    6.140
Column
Description
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.
P
Permanent space utilization as a percentage of the space’s current capacity.
YGC
Number of young generation GC events.
YGCT
Young generation garbage collection time.
FGC
Number of full GC events.
FGCT
Full garbage collection time.
GCT
Total garbage collection time.

jstat –printcompilation 12718 1000 4

chenhailongdeMacBook-Pro:bin chenhailong$ jstat -printcompilation 12718 1000 4
Compiled  Size  Type Method
   21653   1657    1 org/elasticsearch/protocol/xpack/XPackInfoResponse toXContent
   21653   1657    1 org/elasticsearch/protocol/xpack/XPackInfoResponse toXContent
   21653   1657    1 org/elasticsearch/protocol/xpack/XPackInfoResponse toXContent
   21653   1657    1 org/elasticsearch/protocol/xpack/XPackInfoResponse toXContent
Column
Description
Compiled
Number of compilation tasks performed.
Size
Number of bytes of bytecode for the method.
Type
Compilation type.
Method
Class name and method name identifying the compiled method. Class name uses “/” instead of “.” as namespace separator. Method name is the method within the given class. The format for these two fields is consistent with the HotSpot – XX:+PrintComplation option.

 


   原创文章,转载请标明本文链接: java虚拟机的监控统计工具-jstat根据进程id查看Java项目的年轻代、年老代gc等情况

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注