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-2.4.3.0.fc19-x86_64 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.

Other pages within this category

comments powered by Disqus

This site uses cookies to analyse traffic, and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.

Send a message
X

Please use the forum for help with UI & libraries.

This message will be securely transmitted to our servers.