GC monitoring in Java with Jstat

By dave | June 30, 2012

Recently I had a few performance problems with an application that required JVM GC monitoring. It had been so long since the last time I'd had to perform any CG analysis that I had to remind myself of what to do!

Using jps and jstat to get JVM GC statistics

First, ensure that an appropriate JDK is on your path

[dave@titan ~]$ java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (fedora- u45-b15)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

Next, issue the command jps which shows a list of all running Java processes that can be interrogated.

[dave@titan ~]$ jps
2472 RemoteMavenServer
3189 Jps
2364 Main

Once you have identified the PID issue the following command:

jstat -gcutil [PID] [Frequency ms] [Iterations]
  • [PID]: the ID listed in the previous call to jps
  • [Frequency]: number of milliseconds between each sample
  • [Iterations] optional, number of times to repeat, if it is not specified, then jstat loops until it gets a signal.
``` [dave@titan ~]$ jstat -gcutil 2472 5000 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 12.60 2.42 40.12 2 0.012 1 0.037 0.050 0.00 0.00 12.60 2.42 40.12 2 0.012 1 0.037 0.050 ```

Fields available in jstat gcutil output

Basically, the first set of columns (S0, S1, E, O, P) describes the utilisation of the various memory heaps (Survivor heaps, Eden - young generation, Old generation and Permanent heap space).

Next, (YGC and YGCT) show the number of young (Eden) space collections and total time taken so far doing these collections.

Columns (FCG, FGCT) show the number and time taken doing old space collections.

Lastly, GCT shows the total time taken performing garbage collection so far.

This guide only breaks the surface of what output you can get from jstat; the Oracle website provides complete documentation for jstat. Also, I'm assuming that you are using the default garbage collector - if not the columns output may vary.

comments powered by Disqus
We use cookies to analyse traffic and to personalise content and adverts. Our social buttons may also use cookies.