Tuesday, October 30, 2018

jcmd command line utility tool to debug and diagnostic java application

In this blog post, We are going to learn JCMD command line utility with examples.
jcmd  command line utility tool  to debug and diagnostic java application

jcmd command utility 

JCMD is command line utility tool to diagnose the java process. This will be useful in Java applications to debug the following use cases.
  • When Java application is crashed
  • To know the Application Heap Memory and Garbage collection 
  • troubleshoot and diagnose JVM applications
This tool is available as part of Java JDK installation.
This sends a diagnostic signal to retrieve JVM debugging information process id and class

This single tool answers most of the below questions
  • How to find a list of java running process using jcmd without options 
  • How to generate a thread dump for a java process using Thread.print 
  • how to enable garbage collection run from command line using GC.run
  • How to manage remote management agent  using ManagementAgent.stop/start/start_local
  • Native memory usage of application using native_memory
  • list out system properties using VM.system_properties
  • Get a report of all properties of a JVM
  • display HotSpot and JDK version using VM.version
  • get all the flags printed using VM.flags
  • uptime of JVM application using VM.uptime
  • class memory usage histogram display using GC.class_histogram
  • how to retrieve Heap dump of  java application using GC.heap_dump

Syntax

jcmd 
The options are -l and -h When there are no potions provided, It prints list of java process -f option This option allows to read the commands from the file -l option Displays list of java process information -h help option

B:\Workspace\modifysf>jcmd -l
4656 org.codehaus.plexus.classworlds.launcher.Launcher
5412 sun.tools.jcmd.JCmd -l
10444 com.kiran.MainApp
The above command gives process id and process name running in JVM. Next is to get detailed diagnostic information with each process, we need to run one more command to get the list of commands
B:\Workspace\modifysf>jcmd org.codehaus.plexus.classworlds.launcher.Launcher help
6604:
The following commands are available:
JFR.stop
JFR.start
JFR.dump
JFR.check
VM.native_memory
VM.check_commercial_features
VM.unlock_commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
GC.rotate_log
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help

For more information about a specific command use 'help '.

java flight recorder stop/start/dump/check options 

java flight recorder analyses the recordings and allows to get micro details about applications and JVM. This feature is available in java commercial license. To make use of this recordings, First, we need to enable it in the application
java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder
JFR.stop - stop the recording
JFR.start - This option allows to start the recordings
JFR.dump - This dumps all the data JFR.
check - This returns the status of recording of a process

Native memory summary details 

native memory usage will not be tracked. The application can be enabled by starting the application with -XX:NativeMemoryTracking=detail Here is the command for native memory for the specific process
jcmd org.codehaus.plexus.classworlds.launcher.Launcher VM.native_memory

Related article

1 comments so far

This comment has been removed by a blog administrator.


EmoticonEmoticon