Detailed explanation of jcmd, JVM performance tuning tool 2 (covering the most comprehensive jcmd commands and documentation on the entire network)

In the previous article "Detailed Explanation of Commonly Used JVM Performance Tuning Tools 1" We have explored monitoring tools such as jps, jstat, and jinfo , jmap, jstack, jhat and other troubleshooting tools. Here I will take out a separate article to introduce jcmd in particular. (Because jcmd has too many details, it took several hours to sort out the document...)

jcmd

The full name of jcmd is JVM Command, which is used to send diagnostic command requests to the running Java virtual machine. It is available starting from JDK 7.

Instructions for use

The command is as follows:
Insert image description here

-f				从文件读取并执行命令
-l				列出本机上的所有JVM进程

Let’s take a look at the simplest one firstjcmd -l
You can view all the JVM processes currently running, which is somewhat similar to jps
Insert image description here
jcmd -h You can view the help of jcmd document.

Take another lookjcmd <pid | main class> <command ...| PerfCounter.print | -f file>
this command

Parameter Description:

  • pid: The process ID that accepts diagnostic command requests.
  • main class: The main class of the process that accepts diagnostic command requests. jcmd will send diagnostic command requests to all Java processes of the specified main class.
  • command: command must be a valid jcmd command. You can use the jcmd pid help command to view the list of available commands. If pid is 0, then the command will be sent to all Java processes. The main class will be used for matching (partial matching or full matching). If no options are specified, it will list the running Java process identifier and the main class and command parameters used to start the process (equivalent to using the -l parameter)
  • PerfCounter.print: Prints the performance counters available on the specified Java process.
  • -f filename: Read commands from the specified file and execute them. In file, each command must be written on a separate line. Lines starting with "#" are ignored. When the commands in all lines have been called, or a command containing the stop keyword is read, the processing of the file will be terminated.
  • -l: View all JVM processes. jcmd does not use parameters and has the same effect as jcmd -l.

Let’s play with PerfCounter.print first:Insert image description here

In this way we can see the performance counter of the process 12735.

Let’s change the way of playing
First use jps -l to get the startup class.
Insert image description here
Then use jcmd to keep up with the startup class:
Insert image description here
You can find and get the results normally.
Of course, the most important thing is another complicated gameplay, which is the form of following commands.
So what are the commands of jcmd?

Below I have summarized the most complete jcmd commands and usage instructions on the entire network . It took the author a lot of effort to compile this command note, which can be said to be unparalleled in the entire network. It is recommended that friends save it for subsequent review.

Supported commands

1.help [options] [arguments]
  • Function: View help information for the specified command
  • arguments: the command for which you want to see help (STRING, no default value)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -all: (optional) View help information for all commands (BOOLEAN, false)

Usage example:

# 获得指定进程可用的命令列表
jcmd <pid> help
# 获取指定进程、指定命令的帮助信息,如果参数包含空格,需要用 ' 或者 " 引起来
jcmd <pid> help <command>
2.Compiler.codecache
  • Function: Print the layout and boundaries of the code cache
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(monitor)
3.Complier.codelist
  • Function: Print the compiled methods running by everyone in the code cache
  • Impact: Medium
  • Required permission: java.lang.management.ManagementPermission(monitor)
4.Compiler.queue
  • Function: Print methods queued for compilation
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(monitor)
5.Compiler.directives_add filename arguments
  • Function: Add compiler instructions from file
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(monitor)
  • filename: name of the command file (STRING, no default value)
6.Compiler.directives_clear
  • Function: Remove all compiler directives
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(monitor)
7.Compiler.directives_print
  • Function: Print all active compiler instructions
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(monitor)
8.Compiler.directives_remove
  • Function: Delete the latest added compiler directive.
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(monitor)
9.GC.class_histogram [options]
  • Role: Provide statistical information about Java heap usage
  • Impact: High (depends on Java heap size and contents)
  • Required permission: java.lang.management.ManagementPermission(monitor)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -all: (optional) Check all objects, including unreachable objects (BOOLEAN, false)
10.GC.class_stats [options] [arguments]
  • Function: Display statistical information about Java class metadata
  • Impact: High (depends on Java heap size and contents)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -all: (optional) show all columns (BOOLEAN, false)
    • -csv: (optional) Print the spreadsheet in CSV format (BOOLEAN, false)
    • help: (optional) show the meaning of all columns (BOOLEAN, false)
  • arguments: parameters, optional parameters are as follows:
    • columns: (optional) Columns to display, separated by commas. If not specified, the following columns are displayed:
      • InstBytes
      • KlassBytes
      • CpAll
      • annotations
      • MethodCount
      • Bytecodes
      • MethodAll
      • ROAll
      • RWAll
      • Total

Usage example:

# 展示指定进程类的元数据的所有统计信息
jcmd 12737 GC.class_stats -all

# InstBytes、KlassBytes等列的含义
jcmd 12737 GC.class_stats -help

# 显示InstBytes,KlassBytes这两列,并生成csv
jcmd 12737 GC.class_stats -cvs InstBytes,KlassBytes > t.csv
11. GC.finalizer_info
  • Function: Display information about Java finalization queue
  • Impact: Medium
  • Required permission: java.lang.management.ManagementPermission(monitor)
12. GC.heap_dump [options][arguments]
  • Function: Generate Java heap Dump file (HPROF format)
  • Impact: High (depends on Java heap size and content. Will cause Full GC unless -all option is specified
  • Required permission: java.lang.management.ManagementPermission(monitor)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -all: (optional) Dump all objects, including unreachable objects (BOOLEAN, false)
  • arguments: parameters, available parameters are as follows:
    • filename: name of the Dump file (STRING, no default value)

Usage example:

jcmd 12737 GC.heap_dump -all 1.hprof
13. GC.heap_info
  • Function: Display Java heap information
  • Impact: Medium
  • Required permission: java.lang.management.ManagementPermission(monitor)
14. GC.run
  • Function: calljava.lang.System.gc()
  • Impact: Medium (depends on Java heap size and contents)
15.GC.run_finalization
  • effect:java.lang.System.runFianlization()
  • Impact: Medium (depends on Java content)
16.JFR.check [options]

Please refer to JFR.check in"Java Flight Recorder Command Reference"

17.JFR.configure [options]

Please refer to JFR.configure in"Java Flight Recorder Command Reference"

18.JFR.dump [options]

Please refer to JFR.dump in"Java Flight Recorder Command Reference"

19.JFR.start [options]

Please refer to JFR.start in"Java Flight Recorder Command Reference"

20.JFR.stop [options]

Please refer to JFR.stop in"Java Flight Recorder Command Reference"

21.JVMTI.agent_load [arguments]
  • Function: Load the JVMTI native agent.
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(control)
  • arguments:
    • library path: absolute path to the JVMTI agent to load (STRING, no default)
    • agent option: (optional) option string (STRING, no default) used to pass the agent
22. JVMMTI.data_dump
  • Function: Notify JVM heap JVMTI to perform data dump
  • Impact: High
  • Required permission: java.lang.management.ManagementPermission(monitor)
23. ManagentAgent.start [options]
  • Function: Start the remote management agent
  • Impact: low
  • option: option, which must be specified using the key or key=value syntax. The available options are as follows:
    • config.file: (optional) settings com.sun.management.config.file (STRING, no default)
    • jmxremote.host: (optional) settingscom.sun.management.jmxremote.host(STRING, no default)
    • jmxremote.port: (optional) settings com.sun.management.jmxremote.port (STRING, no default)
    • jmxremote.rmi.port: (optional) settings com.sun.management.jmxremote.rmi.port (STRING, no default)
    • jmxremote.ssl: (optional) settings com.sun.management.jmxremote.ssl (STRING, no default)
    • jmxremote.registry.ssl: (optional) settings com.sun.management.jmxremote.registry.ssl (STRING, no default)
    • jmxremote.authenticate: (optional) set com.sun.management.jmxremote.authenticate (STRING, no default)
    • jmxremote.password.file: (optional) setting com.sun.management.password.file (STRING, no default)
    • jmxremote.access.file: (optional) settings com.sun.management.jmxremote.access.file (STRING, no default)
    • jmxremote.login.config: (optional) settings com.sun.management.jmxremote.login.config (STRING, no default)
    • jmxremote.ssl.enabled.cipher.suites:(可选)集com.sun.management
    • jmxremote.ssl.enabled.cipher.suite: (STIRNG, no default)
    • jmxremote.ssl.enabled.protocols: (optional) settings com.sun.management.jmxremote.ssl.enabled.protocols (STRING, no default)
    • jmxremote.ssl.need.client.auth: (optional) setting com.sun.management.jmxremote.need.client.auth (STRING, no default)
    • jmxremote.ssl.config.file: (optional) settings com.sun.management.jmxremote.ssl_config_file (STRING, no default)
    • jmxremote.autodiscovery: (optional) Settings com.sun.management.jmxremote.autodiscoery (STRING, no default)
    • jdp.port: (optional) settings com.sun.management.jdp.port (INT, no default)
    • jdp.address: (optional) setting com.sun.management.jpdaddress (STRING, no default)
    • jdp.source_addr: (optional) setting com.sun.management.jdp.sourcce_addr (STRING, no default)
    • jdp.pause: Settings com.sun.management.jdp.pause (INT, no default)
    • jdp.name: (optional) setting com.sun.management.jdp.name (STRING, default)
24. ManagementAgent.start_local
  • Function: Start the local management agent
  • Impact: low
25.ManagementAgent.status
  • Function: Display the status of the management agent
  • Impact: low
  • Required permission: java.lang.mangement.ManagementPermission(monitor)
26.Management.Agent.stop
  • Function: Stop the remote management agent
  • Impact: low
27.Thread.print [options]
  • Function: Print all threads with stack traces
  • Impact: Medium (depends on number of threads)
  • Required permission: java.lang.management.ManagementPermission(monitor)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -l: (optional) print java.util.concurrent lock (BOLEAN, false)

Usage example:

jcmd 12737 Thread.print -l
28.VM.check_commercial_features
  • Function: Display the status of business features
  • Impact: low
29. VM.unlock_commercial_features
  • Function: Unlock business functions
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(control)
30. VM.classloader_stats
  • Function: Print the statistical information of all ClassLoaders.
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(monitor)
31. VM.class_hierarchy [options] [arguments]
  • Effect: Prints a list of all loaded files, indented to show the class hierarchy. The name of each class followed by its ClassLoader's ClassLoaderData*, or null if there is a bootstrap class loader loading
  • Impact: Medium (depends on the number of loaded classes)
  • Required permission: java.lang.management.ManagementPermission(monitor)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -i: (optional) print inherited interfaces (BOOLEAN, false)
    • -s: (optional) If a class name is specified, subclasses will be printed. Print superclass if no class name is specified (BOOLEAN, false)
  • arguments: Parameters, available options are as follows:
    • classname: (optional) Prints the hierarchy of the specified class, if not specified all class hierarchies will be printed (STRING, no default)

Usage example:

jcmd 12737 VM.class_hierarchy -i -s javax.servlet.GenericFilter
32.VM.command_line
  • Function: Print the command line used to start this VM instance
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(monitor)
33.VM.dynlibs
  • Function: Print the loaded dynamic library
  • Impact: low
  • Allow: java.lang.management.ManagementPermission(monitor)
34.VM.info
  • Function: Print information about the JVM environment and status
  • Impact: low
  • Allow: java.lang.management.ManagementPermission(monitor)
35.VM.log [options]
  • Function: List current log configuration, enable/disable/configure log output, or rotate all logs
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(control)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • output: (optional) The name or index of the output to configure. (STRING, no default)
    • output_options: (optional) Output options. (STRING, no default)
    • what: (optional) Configure the tag to be recorded. (STRING, no default)
    • disable: (Optional) Turn off all logging and clear the log configuration.
    • list: (optional) List the current log configuration. (BOOLEAN, no default)
    • rotate: (optional) Rotate all logs. (boolean, no default)

Usage example:

jcmd 12737 VM.log output what
36. VM.flags [options]
  • Function: Print the VM flag and its current value
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(monitor)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -all: (optional) Print all flags supported by the VM (BOOLEAN, false)
37.VM.native_memory [options]

This function is called "Native Memory Tracking (NMT)" and the following parameters must be turned on before it can be turned on.
-XX:NativeMemoryTracking=[off | summary | detail |
Turning on will cause 5~10% performance loss.
You can also use ```-XX:+UnlockDiagnosticVMOptions -XX:+PrintNMTStatistics`` to let the JVM print the NMT report when exiting.
Reference article: https://blog.csdn.net/varyall/article/details/86514888

  • Function: Print native memory usage.
  • Impact: Medium
  • Allow: java.lang.management.ManagementPermission(monitor)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • summary: (optional) Requests a runtime report on the current memory summary, including all reserved and committed memory and a per-subsystem memory usage summary (BOOLEAN, false)
    • detail: (optional) Request runtime reporting of memory allocations per callsite (callsite) >= 1K (BOOLEAN, false)
    • baseline: (optional) Requests the runtime to be baselined against current memory usage for later comparison (BOOLEAN, false)
    • summary.diff: (optional) Request runtime report memory summary comparison to previous benchmark (BOOLEAN, false)
    • detail.diff: (optional) Requests a runtime report to compare memory details to a previous benchmark showing memory allocation activity at different call sites (BOOLEAN, false)
    • shutdown: (optional) Requests the runtime to shut down itself and release the memory used by the runtime (BOOLEAN, false)
    • statistics: (optional) Print tracker statistics for adjustment (BOOLEAN, false)
    • scale: (optional) memory usage in MB, MB or GB (STRING, KB)
38. VM.print_touched_methods
  • Function: Print all methods that have been contacted during the JVM life cycle.
  • Impact: Medium (depends on Java content)
39. VM.set_flag [arguments]
  • Function: Set VM flag
  • Impact: low
  • Required permission: java.lang.management.ManagementPermission(control)
  • arguments:
    • Flag Name: The flag name you want to set (STRING, no default)
    • string value: (optional) value to set (STRING, no default)
VM.stringable [options]
  • Function: Dump string table (string table)
  • Impact: Medium (depends on Java content)
  • Required permission: java.lang.management.ManagementPermission(monitor)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -verbose: (optional) dump the contents of each string in the table (BOOLEAN, false)

Usage example:

jcmd 12737 VM.stringable -verbose
41. VM.symboltable [options]
  • Function: Dump symbol table
  • Impact: Medium (depends on Java content)
  • Required permission: java.lang.management.ManagementPermission(monitor)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -verbose: (optional) dump the contents of each symbol in the table (BOOLEAN, false)

Usage example:

jcmd 12737 VM.symboltable -verbose
42 VM.systemdictionary
  • Function: Print statistics of dictionary hash table size and bucket length
  • Impact: Medium
  • Required permission: java.lang.management.ManagementPermission(monitor)
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • verbose: (optional) Dump the contents of each dictionary entry for all class loaders (BOOLEAN, false)

Usage example:

jcmd 12737 VM.systemdictionary -verbose
43.VM.system_properties
  • Function: Print system properties
  • Impact: low
  • Required permissions: java.util.PropertyPermission(*, read)
44.VM.uptime [options]
  • Function: Print the running time of the virtual machine
  • Impact: low
  • options: Options must be specified using key or key=value syntax. The available options are as follows:
    • -date: (optional) add prefix with current date (BOOLEAN, false)
45. VM.version
  • Function: Print JVM version information
  • Impact: low
  • Required permissions: java.util.PropertyPermission(java.vm.version, read)

Guess you like

Origin blog.csdn.net/qq_45455361/article/details/120938015