JVM command line monitoring tool jstat (JVM Statistics Monitoring Tool)

Introduction to jstat

jstat (JVM Statistics Monitoring Tool): A command-line tool for monitoring various running status information of virtual machines. It can display running data such as class loading, memory, garbage collection, JIT compilation, etc. in the local or remote virtual machine process.

The option parameters are as follows:

Types of content illustrate
Class loading related -class Display the relevant information of ClassLoader: the number of loaded and unloaded classes, the total space, the time consumed by class loading, etc.
Garbage Collection Related -gc Displays heap information related to GC. Including information such as the capacity of the Eden area, the two Survivor areas, the old generation, the permanent generation, etc., the used space, and the total GC time.
-gccapacity- The display content is basically the same as -gc, but the output mainly focuses on the maximum and minimum space used by each area of ​​the Java heap
-gcutil The display is basically the same as -gc, but the output focuses on the used space as a percentage of the total space
-gccause Same as -gcutil, but additionally outputs the cause of the last or currently occurring GC
-gcnew Display the new generation GC status
-gcnewcapacity The display content is basically the same as -gcnew, and the output mainly focuses on the maximum and minimum space used
-gcold Display old age GC status
-gcoldcapacity The display content is basically the same as -gcold, and the output mainly focuses on the maximum and minimum space used
-gcpermcapacity Display the maximum and minimum space used by the permanent generation
JIT related -compiler Displays information such as methods compiled by the JIT compiler and time-consuming
-printcompilation Output methods that have been JIT compiled

jstat use

1) Statistical class loading information

insert image description here

[root@bogon ~]# jps -l
781 sun.tools.jps.Jps
25887 org.apache.catalina.startup.Bootstrap
[root@bogon ~]# jstat -class 25887
Loaded  Bytes  Unloaded  Bytes     Time   
  3377  6492.3       37    53.6      30.34
content illustrate
Loaded The number of classes loaded
Bytes The size of the space occupied by the loaded class
Unloaded Number of classes not loaded
Bytes Unloaded class footprint size
Time Class loading takes time

Print 5 times at 1s interval

insert image description here

output program execution time

insert image description here

jstat -class -t 25887 1000 5

Print the header every 3 times

insert image description here

jstat -class -h 3 -t 25887 1000

2) View JIT compilation statistics

insert image description here

[root@bogon ~]# jps -l
8264 sun.tools.jps.Jps
7706 ParamTest.jar
25887 org.apache.catalina.startup.Bootstrap
[root@bogon ~]# jstat -compiler 7706
Compiled Failed Invalid   Time   FailedType FailedMethod
      10      0       0     0.00          0   
content illustrate
Compiled Number of classes compiled by JIT
Failed Number of JIT compilation failures
Invalid Unavailable quantity
Time time
FailedType failure type
FailedMethod fail method

insert image description here
insert image description here

jstat -printcompilation 7706

3) Garbage collection statistics

A brief introduction to garbage statistics

insert image description here

[root@bogon ~]# jstat -gc 25887
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
2880.0 2880.0  0.0   548.0  23552.0   8410.8   58488.0    41320.5   21632.0 20846.0 2432.0 2221.7    215    1.416   3      0.247    1.663
content illustrate
S0C Size of the first Survivor area (KB)
S1C Size of the second Survivor area (KB)
S0U The used size of the first Survivor area (KB)
S1U The used size of the second Survivor area (KB)
EC Size of Eden area (KB)
I Use size of Eden area (KB)
OC Size of the old area (KB)
WHERE The used size of the old area (KB)
MC Method area size (KB)
MU Use size of method area (KB)
CCSC Compressed class space size (KB)
CCSU Compressed class space usage size (KB)
YGC Young generation garbage collections
YGCT Young generation garbage collection takes time
FGC Number of old age garbage collections
FGCT Old age garbage collection takes time
GCT Total garbage collection time
oracle官方文档:https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gc-ergonomics.html

default heap size

insert image description here
When the heap memory size is not specified, the default heap memory is 1/64 of the physical memory, and the maximum heap memory is 1/4 or 1G of the physical machine memory.
Note about the meta space: the meta space will automatically expand and is not limited by default.
insert image description here

[root@bogon ~]# jstat -gc 6619
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT   
1024.0 1024.0  0.0    0.0    8192.0   672.0    20480.0      0.0     4480.0 774.5  384.0   75.9       0    0.000   0      0.000    0.000
[root@bogon ~]# jinfo -flag InitialHeapSize 6619 
-XX:InitialHeapSize=31457280

Percentage shows GC usage information

insert image description here
insert image description here

How to judge possible OOM?

We can compare the startup time of the Java process and the total GC time (GCT column), or the time between two measurements and the delta of the total GC time, to get the GC time as a proportion of the running time.
If the ratio exceeds 20%, it means that the current heap pressure is high;
if the ratio exceeds 90%, it means that there is almost no free space in the heap, and an OOM exception may be thrown at any time.
insert image description here

How to judge possible memory leaks?

Step 1: In a long-running Java program, we can run the jstat command to obtain multiple rows of performance data continuously, and take the minimum value of the OU column (that is, the occupied old memory) in these rows of data.
Step 2: Then, we repeat the above operation at long intervals to obtain multiple sets of OU minimum values. If these values ​​show an upward trend, it means that the old-age memory usage of the Java program is increasing, which means that the number of objects that cannot be reclaimed is increasing, so there is a high possibility of a memory leak.

Guess you like

Origin blog.csdn.net/fengsheng5210/article/details/123659743