Usage of jstat

The usage of jstat is used


to judge whether there is a memory problem in the JVM? How to judge whether JVM garbage collection is normal? The general top command basically cannot meet this requirement, because it mainly monitors the overall system resources, and it is difficult to locate the java application.

Jstat is a lightweight gadget that comes with the JDK. The full name is "Java Virtual Machine statistics monitoring tool", which is located in the bin directory of java. It mainly uses the built-in instructions of the JVM to monitor the resources and performance of Java applications in real-time on the command line, including Heap size and garbage collection status. monitoring. It can be seen that Jstat is a lightweight, JVM-specific tool that is very suitable. Due to the large JVM memory setting, the percentage change in the graph is less obvious.

An extremely powerful tool for monitoring VM memory. Can be used to monitor various heap and non-heap sizes and their memory usage within VM memory.

The jstat tool is particularly powerful, with numerous options to view the usage of various parts of the heap in detail, as well as the number of loaded classes. When using, you need to add the process id of the viewing process and the selected parameters.

Execution: Execute jstat in cd $JAVA_HOME/bin, pay attention to the parameters after jstat.


Syntax structure:

Usage: jstat -help|-options

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

Parameter explanation:

Options — options, we generally use -gcutil View gc situation

vmid — VM process ID, that is, the currently running java process ID

interval– Interval time, in seconds or milliseconds

count — the number of times to print, if the default is to print an infinite number



of times Percentage of space O — Percentage of used space in the Old space area on the Heap P — Percentage of used space in the Perm space area YGC — The number of Young GCs that occurred from application startup to sampling YGCT – Young GC from application startup to sampling Time spent on GC (in seconds) FGC - The number of Full GCs from application startup to sampling FGCT - Time from application startup to sampling for Full GC (in seconds) GCT - From application startup to sampling Total time in garbage collection (in seconds) instance usage 1: [root@localhost bin]# jstat -gcutil 25444   S0 S1 E O P YGC YGCT FGC FGCT GCT 11.63 0.00 56.46 66.92 98.49 162 0.248 6 0.331 0.579 instance usage 2: (25444 yes The process ID of java, ps -ef | grep java)






















[the root @ localhost bin] # jstat--gcutil 25444 1000. 5

  S0 Sl E O P YGC YGCT FGC FGCT GCT

73.54 0.00 99.04 67.52 98.49 166 0.252. 6 0.331 0.583

73.54 0.00 99.04 67.52 98.49 166 0.252. 6 0.331 0.583

73.54 0.00 99.04 67.52 98.49 166 0.252. 6 0.331 0.583

73.54 0.00 99.04 67.52 98.49 166 0.252 6 0.331 0.583

73.54 0.00 99.04 67.52 98.49 166 0.252 6 0.331 0.583

We can see that after 5 times the garbage memory is put into the Eden space (Eld space) from the Old space ), and caused a percentage change, causing the percentage used by Survivor space to drop from 73.54% (S0) to 0% (S1). Effectively freed up memory space. In the green box, we can see that after a full gc, the memory in the Old space area (O) is reclaimed, dropping from 99.05% to 67.52%.

In the figure, the total number of times and the total time of young gc and full gc are printed at the same time. However, the time consumed by each young gc can be obtained by subtracting the two lines of YGCT at intervals. The time consumed by each full gc can be obtained by subtracting the two separate lines of FGCT. For example, a young gc occurs between the first row and the second row indicated in the red box, and the time consumed is 0.252-0.252=0.0 seconds.

The usage rate of the resident memory area (P) is always around 98.49%, indicating that the resident memory has no mutation, which is relatively normal.

If young gc and full gc can occur normally, and can effectively reclaim memory, and the resident memory area does not change significantly, it means that java memory release is normal, garbage collection is timely, and the probability of java memory leakage will be greatly reduced. But it does not mean that there must be no memory leaks.

GCT is the time sum of YGCT and FGCT.

Above, the function of Jstat to view the gc situation by percentage is introduced. In fact, it also has functions, such as loading class information statistics function, memory pool information statistics function, etc. Those are printed out in the form of absolute values, which are seldom used, and will not be introduced here.

[root@localhost bin]# ps -ef | grep java

root 25917 1 2 23:23 pts/2 00:00:05 /usr/local/jdk1.5/bin/java -Djava.endorsed.dirs=/usr/local/jakarta-tomcat-5.0.30/common/endorsed -classpath /usr/local/jdk1.5/lib/tools.jar:/usr/local/jakarta-tomcat-5.0.30/bin/bootstrap.jar:/usr/local/jakarta-tomcat-5.0.30/bin /commons-logging-api.jar -Dcatalina.base=/usr/local/jakarta-tomcat-5.0.30 -Dcatalina.home=/usr/local/jakarta-tomcat-5.0.30 -Djava.io.tmpdir=/ usr/local/jakarta-tomcat-5.0.30/temp org.apache.catalina.startup.Bootstrap start

jstat -class pid: Displays information such as the number of loaded classes and the space they occupy.

Example use 3:

[root@localhost bin]# jstat -class 25917

Loaded Bytes Unloaded Bytes Time

2629 2916.8 29 24.6 0.90



jstat -compiler pid: Displays information such as the number of VM real-time compilations.

Example use 4:

[root@localhost bin]# jstat -compiler 25917

Compiled Failed Invalid Time FailedType FailedMethod

     768 0 0 0.70 0



jstat –gccapacity : It can display the usage and size of objects of three generations (young, old, perm) in VM memory, such as: PGCMN Displays the memory usage of the minimum perm, PGCMX displays the maximum memory usage of the perm, PGC is the memory usage of the newly generated perm, and PC is the memory usage of the previous perm. Others can be analogized according to this, OC is the pure occupancy in old.



[root@localhost bin]# jstat -gccapacity 25917

NGCMN 640.0

NGCMX 4992.0

NGC 832.0

S0C 64.0

S1C 64.0

EC 704.0

OGCMN 1408.0

OGCMX 60544.0

OGC 9504.0

OC 9504.0 OC is the pure occupancy of old

PGCMN 819 quantity

PGCMX 65536.0 PGCMX shows the maximum

memory usage of perm PGC 12800.0 PGC is the current newly generated perm memory usage

PC 12800.0 PC is but the former perm memory usage

YGC 164

FGC 6



jstat -gcnew pid: new object information

[root@ localhost bin]# jstat -gcnew 25917

S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT

64.0 64.0 47.4 0.0 2 15 32.0 704.0 145.7 168 0.254



jstat -gcnewcapacity pid: new object information and its occupancy

[root@localhost bin]# jstat -gcnewcapacity 25917

NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC

640.0 4992.0 832.0 64.0 448.0 448.0 64.0 4096.0 704.0 168 6



jstat -gcold pid: information about the old object.

[root@localhost bin]# jstat -gcold 25917

   PC PU OC OU YGC FGC FGCT GCT

12800.0 12617.6 9504.0 6561.3 169 6 0.335 0.591



jstat -gcoldcapacity pid:old object information and its occupancy.

[root@localhost bin]# jstat -gcoldcapacity 25917

OGCMN OGCMX OGC OC YGC FGC FGCT GCT

1408.0 60544.0 9504.0 9504.0 169 6 0.335 0.591



jstat -gcpermcapacity pid: Perm object information and its occupancy.

[root@localhost bin]# jstat -gcpermcapacity 25917

PGCMN PGCMX PGC PC YGC FGC FGCT GCT

8192.0 65536.0 12800.0 12800.0 169 6 0.335 0.591



jstat -printcompilation pid: Information about the current VM execution.

[root@localhost bin]# jstat -printcompilation -h3 25917 1000 5

Print every 1000 milliseconds, a total of 5 times, you can also add -h3 to display the title every three lines.

Compiled Size Type Method

     788 73 1 java/io/File <init>

     788 73 1 java/io/File <init>

     788 73 1 java/io/File <init>

Compiled Size Type Method

     788 73 1 java/io/File < init>

     788 73 1 java/io/File <init>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327079144&siteId=291194637