Java Monitoring Tools之jcmd

Java Monitoring Tools之jcmd

jcmd

Prints basic class, thread, and VM informationfor a Java process. This is suitable  for use in scripts; it is executed like this:

% jcmd  process_idcommand optional_arguments

Supplying the command help willlist all possible commands, and supplying help
<command> will give the syntax for a particular command.

例如:我本机开启了一个jmeter程序。
找出jmeter进程ID:

$ jps -mlvV
11328 ApacheJMeter.jar -XX:+HeapDumpOnOutOfMemoryError -Xms512m -Xmx512m -XX:NewSize=128m -XX:MaxNewSize=128m -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=50 -XX:MaxTenuringThreshold=2 -XX:+CMSClassUnloadingEnabled
9948 sun.tools.jps.Jps -mlvV -Denv.class.path=.;C:\Java\jdk1.8.0_65\lib;C:\Java\jdk1.8.0_65\lib\tools.jar -Dapplication.home=C:\Java\jdk1.8.0_65 -Xms8m

jmeter的pid 为11328

$ jcmd 11328 help






$ jcmd 11328 help VM.flags

Java Monitoring Tools之jcmd_第1张图片


Basic VM Information

JVM tools can provide basic information about a running JVM process: how long it has been up, what JVM flags are in use, JVM system properties, and so on.

Uptime

The length of time the JVM has been up can be found via this command:
% jcmd process_id VM.uptime

System properties

The set of items in System.getProperties() can be displayed with either of these commands:
% jcmd process_id VM.system_properties
or
% jinfo -sysprops process_id
This includes all properties set on the command line with a -D option, any properties
dynamically added by the application
, and the set of default properties for the JVM.

JVM version

The version of the JVM is obtained like this:
% jcmd process_id VM.version

JVM command line

The command line can be displayed in the VM summary tab of jconsole, or via jcmd:
% jcmd process_id VM.command_line

JVM tuning flags

The tuning flags in effect for an application can be obtained like this:
% jcmd process_id VM.flags [-all]

Working with tuning flags

There are a lot of tuning flags that can be given to a JVM, and many of those flags are a major focus of this book. Keeping track of those flags and their default values can be a little daunting; those last two examples of jcmd are quite useful in that regard. The command_line command shows which flags were specified directly on the command line. The flags command shows which flags were set on the command line, plus some flags that were set directly by the JVM (because their value was determined ergonomically). Including the -all option lists every flag within the JVM. There are hundreds of JVM tuning flags, and most of them are very obscure; it is recommended that most of them never be changed (see“Too Much Information?” on page
49). Figuring out which flags are in effect is a frequent task when diagnosing performance issues, and the jcmd commands can do that for a running JVM. Often, what you’d rather figure out is whatthe platform-specific defaults for a particular JVM are, in which case using the-XX:+PrintFlagsFinal option on the command line is more useful.

A useful way to determine what the flags are set to on a particular platform is to execute this command:
% java other_options -XX:+PrintFlagsFinal -version
...Hundreds of lines of output, including...
uintx InitialHeapSize := 4169431040 {product}
intx InlineSmallCode = 2000 {pd product}

You should include all other options on the command line because some options affect others, particularly when setting GC-related flags. This will print out the entire list of JVM flags and their values (the same as is printed via the VM.flags -all option to jcmd for a live JVM).
Flag data from these commands is printed in one of the two ways shown. The colon in
the first line of included output indicates that a nondefault value is in use for the flag in
question. This can happen for the following reasons:



1. The flag’s value was specified directly on the command line.
2. Some other option indirectly changed that option.
3. The JVM calculated the default value ergonomically.
The second line (without a colon) indicates that value is the default value for this version
of the JVM. Default values for some flags may be different on different platforms, which
is shown in the final column of this output. product means that the default setting of
the flag is uniform across all platforms; pd product indicates that the default setting of
the flag is platform-dependent.

Quick Summary

1. jcmd can be used to find the basic JVM information—including the value of all the tuning flags—for a running application.
2. Default flag values can be found by including -XX:+PrintFlags Final on a command line. This is useful for determining the
default ergonomic settings of flags on a particular platform.
3. jinfo is useful for inspecting (and in some cases changing) individual flags.


读书笔记:

Java Performance: The Definitive Guide 
by  Scott Oaks (O’Reilly). Copyright 2014 Scott Oaks, 978-1-449-35845-7



你可能感兴趣的:(Java Monitoring Tools之jcmd)