How to get heap usage using jstat?
Asked Answered
T

1

15

I'm running jstat -gc (from OpenJDK):

# jstat -gc 1
 S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
287744.0 290304.0 88368.6  0.0   1469440.0 787186.5 2162176.0  1805969.7  945432.0 923880.4 136576.0 133284.0    268   32.797  21     30.089   62.886

How to read:

  1. used heap

  2. heap size

  3. max heap

from this output, just like shown by VisualVM?

Tonguing answered 2/5, 2017 at 10:45 Comment(6)
If you are insterested only in those three values, maybe jmap -heap <pid> would better fit your needs.Wellchosen
Nice. Max heap (3) is shown in MaxHeapSize. Used heap (1) is sum of "used" in Eden Space, From Space, To Space, and PS Old Generation. But how to get heap size (2)?Tonguing
Also, unfortunately jmap in OpenJDK doesn't have -heap param... Any alternatives?Tonguing
Which OpenJDK version are you using? I can see the option here (openjdk version "1.8.0_131").Wellchosen
openjdk8-8.111.14-r0 Alpine Linux package, javac -version shows javac 1.8.0_111-internalTonguing
I did a check. Updateing Alpine Linux to 3.5/3.6 doesn't bring you up to 131, as it's simply not yet available. see blogs.oracle.com/developers/…Wellchosen
S
15

See https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html for general reference.

Current heap size would be the sum of all the fields that end with "C" - S0C, S1C, EC, OC (except for metaspace which is the fields that start with "M")

Used heap would be the sum of all the fields that end with "U" - S0U, S1U, EU, OU (again, except metaspace).

Note that the "C" values (current) are greater than or equal to "U" values (actually used).

To get maximum values run jstat with the -gccapacity flag and add up all the fields that end with "MX" (NGCMX, OGCMX, ... except for MCMX which is metaspace).

Shotwell answered 21/5, 2017 at 10:12 Comment(4)
What about CCSC and CCSU columns?Tonguing
Can you provide a source that heap consists of these spaces?Tonguing
CCSC/CCSU are the Compressed Class Space and apparently not part of the heap. Perhaps the following link may help: java-latte.blogspot.co.il/2014/03/metaspace-in-java-8.htmlShotwell
is there any tool taht can show this data easily?Deerskin

© 2022 - 2024 — McMap. All rights reserved.