天天看點

JVM Learning Note 3 -- JVM Performance Monitor Tools

JDK Provided Tools

Command Line Tools

  • jps
  • jstat
  • jinfo
  • jmap

Visual Tools

  • JConsole
  • VisualVM with Plugins

jps - JVM Process Status

USAGE

jps -lvm

OPTIONS

The jps command supports a number of options that modify the output of the command. These options are subject to change or removal in the future.

-q

Suppress the output of the class name, JAR file name, and arguments passed to the main method, producing only a list of local VM identifiers.

-m

Output the arguments passed to the main method. The output may be null for embedded JVMs.

-l

Output the full package name for the application's main class or the full path name to the application's JAR file.

-v

Output the arguments passed to the JVM.

-V

Output the arguments passed to the JVM through the flags file (the .hotspotrc file or the file specified by the -XX:Flags=<filename> argument).

-Joption

Pass option to the java launcher called by jps. For example, -J-Xms48m sets the startup memory to 48 megabytes. It is a common convention for -J to pass options to the underlying VM executing applications written in Java.

HOST IDENTIFIER

The host identifier, or hostid is a string that indicates the target system. The syntax of the hostid string largely corresponds to the syntax of a URI:

[protocol:][[//]hostname][:port][/servername]

protocol

The communications protocol. If the protocol is omitted and a hostname is not specified, the default protocol is a platform specific, optimized, local protocol. If the protocol is omitted and a hostname is specified, then the default protocol is rmi.

hostname

A hostname or IP address indicating the target host. If hostname is omitted, then the target host is the local host.

port

The default port for communicating with the remote server. If the hostname is omitted or the protocol specifies an optimized, local protocol, then port is ignored. Otherwise, treatment of the port parameter is implementation specific. For the default rmi protocol the port indicates the port number for the rmiregistry on the remote host. If port is omitted, and protocol indicates rmi, then the default rmiregistry port (1099) is used.

servername

The treatment of this parameter depends on the implementation. For the optimized, local protocol, this field is ignored. For the rmi protocol, this parameter is a string representing the name of the RMI remote object on the remote host. See the -n option for the jstatd command.

OUTPUT FORMAT

The output of the jps command follows the following pattern:

lvmid [ [ classname | JARfilename | "Unknown"] [ arg* ] [ jvmarg* ] ]

Where all output tokens are separated by white space. An arg that includes embedded white space will introduce ambiguity when attempting to map arguments to their actual positional parameters.

jstat - Statistics Monitoring Tool

EXAMPLES

jstat -gcutil 21891 250 7

This example attaches to lvmid 21891 and takes 7 samples at 250 millisecond intervals and displays the output as specified by the -gcutil option.

jstat -gcnew -h3 21891 250

This example attaches to lvmid 21891 and takes samples at 250 millisecond intervals and displays the output as specified by -gcutil option. In addition, it uses the -h3 option to output the column header after every 3 lines of data.

OPTIONS

-statOption

Determines the statistics information that jstat displays. The following table lists the available options. Use the -options general option to display the list of options for a particular platform installation.

Option    Displays...

class    Statistics on the behavior of the class loader.

compiler    Statistics of the behavior of the HotSpot Just-in-Time compiler.

gc    Statistics of the behavior of the garbage collected heap.

gccapacity    Statistics of the capacities of the generations and their corresponding spaces.

gccause    Summary of garbage collection statistics (same as -gcutil), with the cause of the last and current (if applicable) garbage collection events.

gcnew    Statistics of the behavior of the new generation.

gcnewcapacity    Statistics of the sizes of the new generations and its corresponding spaces.

gcold    Statistics of the behavior of the old and permanent generations.

gcoldcapacity    Statistics of the sizes of the old generation.

gcpermcapacity    Statistics of the sizes of the permanent generation.

gcutil    Summary of garbage collection statistics.

printcompilation    HotSpot compilation method statistics.

-h n

Display a column header every n samples (output rows), where n is a positive integer. Default value is 0, which displays the column header above the first row of data.

-t

Display a timestamp column as the first column of output. The timestamp is the time since the start time of the target JVM.

-JjavaOption

Pass javaOption to the java application launcher. For example, -J-Xms48m sets the startup memory to 48 megabytes.

STATOPTIONS AND OUTPUT

The following tables summarize the columns that jstat outputs for each statOption.

-class Option

Column    Description

Loaded    Number of classes loaded.

Bytes    Number of Kbytes loaded.

Unloaded    Number of classes unloaded.

Bytes    Number of Kbytes unloaded.

Time    Time spent performing class load and unload operations.

-compiler Option

HotSpot Just-In-Time Compiler Statistics

Column    Description

Compiled    Number of compilation tasks performed.

Failed    Number of compilation tasks that failed.

Invalid    Number of compilation tasks that were invalidated.

Time    Time spent performing compilation tasks.

FailedType    Compile type of the last failed compilation.

FailedMethod    Class name and method for the last failed compilation.

-gc Option

Column    Description

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.

-gccapacity Option

Column    Description

NGCMN    Minimum new generation capacity (KB).

NGCMX    Maximum new generation capacity (KB).

NGC    Current new generation capacity (KB).

S0C    Current survivor space 0 capacity (KB).

S1C    Current survivor space 1 capacity (KB).

EC    Current eden space capacity (KB).

OGCMN    Minimum old generation capacity (KB).

OGCMX    Maximum old generation capacity (KB).

OGC    Current old generation capacity (KB).

OC    Current old space capacity (KB).

PGCMN    Minimum permanent generation capacity (KB).

PGCMX    Maximum Permanent generation capacity (KB).

PGC    Current Permanent generation capacity (KB).

PC    Current Permanent space capacity (KB).

YGC    Number of Young generation GC Events.

FGC    Number of Full GC Events.

-gccause Option

This option displays the same summary of garbage collection statistics as the -gcutil option, but includes the causes of the last garbage collection event and (if applicable) the current garbage collection event. In addition to the columns listed for -gcutil, this option adds the following columns:

Column    Description

LGCC    Cause of last Garbage Collection.

GCC    Cause of current Garbage Collection.

-gcnew Option

Column    Description

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).

TT    Tenuring threshold.

MTT    Maximum tenuring threshold.

DSS    Desired survivor size (KB).

EC    Current eden space capacity (KB).

EU    Eden space utilization (KB).

YGC    Number of young generation GC events.

YGCT    Young generation garbage collection time.

-gcnewcapacity Option

Column    Description

NGCMN     Minimum new generation capacity (KB).

NGCMX     Maximum new generation capacity (KB).

NGC     Current new generation capacity (KB).

S0CMX    Maximum survivor space 0 capacity (KB).

S0C    Current survivor space 0 capacity (KB).

S1CMX    Maximum survivor space 1 capacity (KB).

S1C    Current survivor space 1 capacity (KB).

ECMX    Maximum eden space capacity (KB).

EC    Current eden space capacity (KB).

YGC    Number of young generation GC events.

FGC    Number of Full GC Events.

-gcold Option

Column    Description

PC    Current permanent space capacity (KB).

PU    Permanent space utilization (KB).

OC    Current old space capacity (KB).

OU    old space utilization (KB).

YGC    Number of young generation GC events.

FGC    Number of full GC events.

FGCT    Full garbage collection time.

GCT    Total garbage collection time.

-gcoldcapacity Option

Column    Description

OGCMN    Minimum old generation capacity (KB).

OGCMX    Maximum old generation capacity (KB).

OGC    Current old generation capacity (KB).

OC    Current old space capacity (KB).

YGC    Number of young generation GC events.

FGC    Number of full GC events.

FGCT    Full garbage collection time.

GCT    Total garbage collection time.

-gcpermcapacity Option

Column    Description

PGCMN    Minimum permanent generation capacity (KB).

PGCMX    Maximum permanent generation capacity (KB).

PGC    Current permanent generation capacity (KB).

PC    Current permanent space capacity (KB).

YGC    Number of young generation GC events.

FGC    Number of full GC events.

FGCT    Full garbage collection time.

GCT    Total garbage collection time.

-gcutil Option

Column    Description

S0    Survivor space 0 utilization as a percentage of the space's current capacity.

S1    Survivor space 1 utilization as a percentage of the space's current capacity.

E    Eden space utilization as a percentage of the space's current capacity.

O    Old space utilization as a percentage of the space's current capacity.

P    Permanent space utilization as a percentage of the space's current capacity.

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.

-printcompilation Option

Column    Description

Compiled    Number of compilation tasks performed by the most recently compiled method.

Size    Number of bytes of bytecode of the most recently compiled method.

Type    Compilation type of the most recently compiled method.

Method    Class name and method name identifying the most recently compiled method. Class name uses "/" instead of "." as namespace separator. Method name is the method within the given class. The format for these two fields is consistent with the HotSpot - XX:+PrintComplation option.

jinfo - Configuration Info

USAGE

jinfo [ option ] pid

jinfo [ option ] executable core

jinfo [ option ] [server-id@]remote-hostname-or-IP

OPTIONS

<no option>

prints both command line flags as well as System properties name, value pairs.

-flag name

prints the name and value of the given command line flag.

-flag [+|-]name

enables or disables the given boolean command line flag.

-flag name=value

sets the given command line flag to the specified value.

-flags

prints command line flags passed to the JVM. pairs.

-sysprops

prints Java System properties as name, value pairs.

-h

prints a help message

-help

prints a help message

jmap - Memory Map

USAGE

jmap [ option ] pid

jmap [ option ] executable core

jmap [ option ] [server-id@]remote-hostname-or-IP

OPTIONS

<no option>

When no option is used jmap prints shared object mappings. For each shared object loaded in the target VM, start address, the size of the mapping, and the full path of the shared object file are printed. This is similar to the Solaris pmap utility.

-dump:[live,]format=b,file=<filename>

Dumps the Java heap in hprof binary format to filename. The live suboption is optional. If specified, only the live objects in the heap are dumped. To browse the heap dump, you can use jhat (Java Heap Analysis Tool) to read the generated file.

-finalizerinfo

Prints information on objects awaiting finalization.

-heap

Prints a heap summary. GC algorithm used, heap configuration and generation wise heap usage are printed.

-histo[:live]

Prints a histogram of the heap. For each Java class, number of objects, memory size in bytes, and fully qualified class names are printed. VM internal class names are printed with '*' prefix. If the live suboption is specified, only live objects are counted.

-permstat

Prints class loader wise statistics of permanent generation of Java heap. For each class loader, its name, liveness, address, parent class loader, and the number and size of classes it has loaded are printed. In addition, the number and size of interned Strings are printed.

-F

Force. Use with jmap -dump or jmap -histo option if the pid does not respond. The live suboption is not supported in this mode.

-h

Prints a help message.

-help

Prints a help message.

-J<flag>

Passes <flag> to the Java virtual machine on which jmap is run.