jstat command

Overview


Jstat is used to monitor the HotSpot-based JVM and perform real-time command-line statistics on its heap usage. Using jstat, we can monitor the specified JVM as follows:

- Class loading and unloading

- View the capacity and usage of the young generation, old generation and persistent generation

- View the garbage collection status of the young generation, old generation and persistent generation, including the number of garbage collections and the time taken for garbage collection

- Check the capacity and allocation of the Eden area and Survior area in the new generation


Common commands and output analysis

1. Summarize garbage collection statistics

$ jstat -gcutil 19148 1000 10

The GC status of java with process number 19148 is displayed every 1 second (only 10 times are printed), and the result is as follows:

How to tell if an application has memory problems:

1. Frequency, duration and effect of Full GC: If the frequency of Full GC is high, such as once every few seconds, then the program may have a problem at this time, because jvm does not respond to external requests during Full GC.

If the Full GC takes a long time, such as lasting several seconds, then the program may have a problem at this time, because the JVM does not respond to external requests during the Full GC.

If the old area memory is not significantly reduced after Full GC, then the program is likely to have a memory leak problem, and an outofmemory exception may occur in the near future.

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.

2. The frequency, duration and effect of GC: If the frequency of memory recycling by the JVM is very high, such as almost every few seconds, the time for each recycling is several seconds; and the memory released by each recycling is also found through the output. Very limited, most objects cannot be recycled. This phenomenon largely implies a memory leak. ( At this point you can use "jmap" to get a current memory image and see which objects are causing the problem to find out why )

If each GC takes a particularly long time, such as tens of seconds, then this phenomenon largely implies a memory leak. (There are too many objects in memory, resulting in too long traversal time, and sometimes a bad caching mechanism can cause such problems)

 

Complete grammar details

 

Official detailed documentation

jstat [Options] vmid [interval] [count]

Command parameter description:

Options, generally use -gcutil or -gc to view the gc situation

pid, the current running java process number

interval, the interval time, in seconds or milliseconds

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

PS: The options supported by different operating systems may be different. You can view the options supported by different operating systems through the -options option. ( The picture below shows the options supported by the company server )

Option

Displays...

class

Statistics for viewing class loading

compiler

Statistics for viewing just-in-time compiler compilations in HotSpot

gc

Statistics for viewing the garbage collection of the heap in the JVM

gccapacity

Used to view the storage capacity of the young generation, old generation and persistent generation

gccause

Used to view the statistics of garbage collection (this is the same as the -gcutil option), if there is a garbage collection, it will also display the reason for the last and current garbage collection.

gcnew

Used to view the situation of young generation garbage collection

gcnewcapacity

Used to view the storage capacity of the new generation

gcold

Used to view the GC occurrences in the old generation and persistent generation

gcoldcapacity

Used to view the capacity of the old generation

gcpermcapacity

Used to view persistent generation capacity

gcutil

Used to view the situation of young generation, old generation and holding generation garbage collection

printcompilation

Statistics of HotSpot Compilation Methods

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325360861&siteId=291194637