Profiling Java Apps Using Bundled Tools

Background

Lately I have found myself playing with a lot of Applications that are running inside Java’s JVM.

The responsible next step is to start profiling their consumption patterns.

 

Referenced Work

These days most of my work are begun from a Google Search.

This work started from Karun Subramanian’s well thought effort.

Here are his blog posts:

  1. 5 not so easy ways to monitor the Heap Usage of your Java Application
    Link

 

Constraints

The tools that we will be evaluating have the following constraints:

  1. They should be run under the same account as the Java Processes that will be monitored

 

Tools

In this exercise we will look at our tools from the prism of Interface; Command Line  Interface ( CLI ) or Graphical User Interface.

Outline

  1. Interface
    • Command Line Tools ( CLI )
      • jstat
      • jmap
    • GUI
      • visualvm
      • jconsole

Preparation

jps

Outline

jps is analogous to the ps command in Linux.

While ps list all processes; jps lists all running Java Processes.

 

Syntax


jps

 

Sample


jps | find /I /V "Jps"

 

Output

 

Explanation

  1. The first column is the LVMDID ( process ID)
  2. The second column is the Process Name

 

Command Line Interface ( CLI )

jstat

Artifacts

Upon installing Java’s JDK, jstat is available in the JDK’s HOME bin folder.

Code

syntax

jstat -gc [process-id]

Sample

jstat -gc 13800

Output

jstat_20180811_0913AM

Explanation
Column Meaning Sample
EC Eden Capacity (KB) 69952
EU Eden Space Utilization (KB) 19112.8
OU Old Space Utilization (KB) 120747.8
OC Old Space Capacity (KB) 174784.0

jmap

Artifacts

jmap is available in the JDK’s HOME bin folder.

Code

syntax

jmap -heap [process-id]

Sample

jmap -heap 13800

Output

es.20180811.0943AM

Explanation
Attribute Meaning Sample
MaxHeapSize Maximum Heap Size 256 MB
NewSize Eden Space Utilization 85 MB
MaxNewSize Eden Space Capacity 85 MB
OldSize Old Space Utilization 170 MB

jhsdb

Artifacts

From Java JDK v9, jhsdb is available in the JDK’s HOME bin folder.

Code

syntax

jhsdb jmap -heap --pid [process-id]

Sample

jhsdb jmap --heap --pid 1960

Output

Explanation
Attribute Meaning Sample
G1
Regions 2020
Capacity 2020 MB ( 2 GB )
Used 98 MB
Free 1921 MB ( 1.92 GB)
Used % 4.90%
G1 – Eden Space
Regions 62
Capacity 74 MB
Used 62 MB
Free 12 MB
Used % 83.78%
G1 – Survivor Space
Regions 4
Capacity 4 MB
Used 4 MB
Free 0
Used % 100 %
G1 Old Generation
Regions 34
Capacity 50 MB
Used 32 MB
Free 17 MB
Used % 65.79 %

 

Graphical User Interface ( GUI )

visualVM

Artifacts

Java Version
Java Version v1.8 and Before

Up to Java v1.8 Visual M was bundled with Java JDK.

Once Java’s JDK is installed, please access visualvm.exe from the JDK’s HOME bin folder.

Java Version  9 and Above

Please download VisualVM from here.

Extract the zip file and run visualvm.exe from the bin folder.

Visual

Tab – Overview
Image

es_Tab_Overview_20180811_1004AM.PNG

Textual
  1. JDK
    1. Bitness :- x64
    2. v1.8
  2. JVM Arguments
    • -XX:+UseConcMarkSweepGC
      • Garbage Collection Algorithm
      • Web Links
    • HeapDumpPath = data
    • ErrorFile :- logs/hs_err_pid%p.log
Tab – Monitor
Image

es_Tab_Monitor_20180811_1005AM.PNG

Textual
  1. Heap
    • Max :- 256 MB
    • In use :-  120 MB

 

Tab – Threads
Image

es_Tab_Threads_20180811_1004AM

 

jconsole

Artifacts

JDK is accessible from the bin folder of Java’s JDK HOME folder.

Visual

Tab – Overview
Image

jconsole_Tab_Overview_20180811_1121AM

Textual
  1. Heap Memory Usage :- 137 MB
  2. Live Threads :- 60
  3. Classes :- 16,000
Tab – Memory
Image

jconsole_Tab_Memory_20180811_1112AM

Textual
  1. Used :- 156 MB
  2. Committed :- 256 MB

 

Tab – Threads
Image

jconsole_Tab_Threads_20180811_1128AM

Textual
  1. Live Threads :- 60
  2. Peak :- 63

 

 

References

  • Oracle
    • Home / Java / Oracle JDK 9 Documentation
      • Java Platform, Standard Edition Tools Reference
    • Java
      • jps
        • jps – Java Virtual Machine Process Status Tool
          Link
  • Karun Subramanian
    • 5 not so easy ways to monitor the Heap Usage of your Java Application
      Link
  • Dustin Marx
    • Dzone
      • jhsdb: A New Tool for JDK 9
        Link

One thought on “Profiling Java Apps Using Bundled Tools

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s