Java Heap memory usage using jmap and jstat command

heap-usage

 

  • Login to your Linux/Unix Server
  • Enter the below command to get the JAVA PID running on the server.

                          ps –ef|grep –i java

From the output take the application JAVA PID.

  • Using jstat command with gc option to find out the JVM Heap Memory Usage.

<JAVA_HOME>/bin/jstat –gc <JAVA PID>

heap-jstat

S0C – Current survivor space 0 capacity (KB).
S1C  –  Current survivor space 1 capacity (KB).
S0U – Survivor space 0 utilization (KB).
S1U  – Survivor space 1 utilization (KB).
EC    – Current eden space capacity (KB).
EU    – Eden space utilization (KB).
OC    – Current old space capacity (KB).
OU    – Old space utilization (KB).
PC     – Current permanent space capacity (KB).
PU     – Permanent space utilization (KB).
YGC   – Number of young generation GC Events.
YGCT – Young generation garbage collection time.
FGC   – Number of full GC events.
FGCT – Full garbage collection time.
GCT   – Total garbage collection time.

When you add all the ‘utilizations’ i.e OU + EU + S0U + S1U  you get the total Heap utilization.

Use Below command if you lazy enough to calculate the above and to get Heap utilisation in one command.

heap-total

Heap Utilization using jmap 

  • Enter the below command to get the JAVA PID running on the server.

                          ps –ef|grep –i java

From the output take the application JAVA PID.

  • Using jstat command with gc option to find out the JVM Heap Memory Usage.

<JAVA_HOME>/bin/jmap –heap <JAVA PID>

heap-jmap

jmap-heap-usage

 

Calculate the Heap Utilisation  by adding the used value of

New Generation (Eden + 1 Survivor Space):
+
concurrent mark-sweep generation:

 

There are other tools like visualvm, APM tools to get the heap memory usage. If this article found useful please comment and let me know how can i improve.

To understand better about Grabage collection please refer below post.

https://javaperformance.wordpress.com/2017/07/05/garbage-collection-in-java/

To know more about JSTAT tool. Please refer to my below post.

https://javaperformance.wordpress.com/2017/07/05/jstat-jvm-performance-monitoringtool/

Advertisements

5 thoughts on “Java Heap memory usage using jmap and jstat command

  1. Pingback: JSTAT – JVM Performance Monitoring Tool | Java Tech Support

  2. Hi,

    I use below command to get heap usage

    jstat -gc 15924 | tail -n 1 | awk ‘{split($0,a,” “); sum=a[3]+a[4]+a[6]+a[8] ; print sum}’

    But i get output(scientific number) as below

    1.12586e+06

    How can i get proper output in KB.

    Please let me know.

    Like

  3. Hi,
    I use below command to get heap usage
    jstat -gc 15924 | tail -n 1 | awk ‘{split($0,a,” “); sum=a[3]+a[4]+a[6]+a[8] ; print sum}’
    But i get output(scientific number) as below
    1.12586e+06
    How can i get proper output in KB.
    Please let me know.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s