设为首页收藏本站

数码鹭岛论坛

 找回密码
 注-册

QQ登录

只需一步,快速开始

搜索
查看: 2279|回复: 6
打印 上一主题 下一主题

JDK自带VM分析工具jps,jstat,jmap,jconsole

[复制链接]
跳转到指定楼层
1#
发表于 2014-10-30 20:50:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
一、概述  

    SUN 的JDK中的几个工具,非常好用。秉承着有免费,不用商用的原则。以下简单介绍一下这几种工具。(注:本文章下的所有工具都存在JDK5.0以上版本的工具集里,同javac一样,不须特意安装)  。
     
    我一共找到以下四个工具:重点看看jconsole和jmap。

    jps  
    :与unix上的ps类似,用来显示本地的java进程,可以查看本地运行着几个java程序,并显示他们的进程号。   
      
    jstat  
    :一个极强的监视VM内存工具。可以用来监视VM内存内的各种堆和非堆的大小及其内存使用量。   
      
    jmap  
    :打印出某个java进程(使用pid)内存内的,所有‘对象’的情况(如:产生那些对象,及其数量)。   
      
    jconsole  
    :一个java GUI监视工具,可以以图表化的形式显示各种数据。并可通过远程连接监视远程的服务器VM。  



二、 使用介绍:
     
    1、jps:我想很多人都是用过unix系统里的ps命令,这个命令主要是用来显示当前系统的进程情况,有哪些进程,及其 id。 jps 也是一样,它的作用是显示当前系统的java进程情况,及其id号。我们可以通过它来查看我们到底启动了几个java进程(因为每一个java程序都会独占一个java虚拟机实例),和他们的进程号(为下面几个程序做准备),并可通过opt来查看这些进程的详细启动参数。
    使用方法:在当前命令行下打 jps(需要JAVA_HOME,没有的话,到改程序的目录下打) 。

可惜没有linux下的ps好用,名称不好用。但是在第四个工具jconsole的界面里面会有具体JAR包的名称。
     
    2、jstat :对VM内存使用量进行监控。
    jstat工具特别强大,有众多的可选项,详细查看堆内各个部分的使用量,以及加载类的数量。使用时,需加上查看进程的进程id,和所选参数。以下详细介绍各个参数的意义。
    jstat -class pid:显示加载class的数量,及所占空间等信息。
    jstat -compiler pid:显示VM实时编译的数量等信息。
    jstat -gc pid:可以显示gc的信息,查看gc的次数,及时间。其中最后五项,分别是young gc的次数,young gc的时间,full gc的次数,full gc的时间,gc的总时间。
    jstat -gccapacity:可以显示,VM内存中三代(young,old,perm)对象的使用和占用大小,如:PGCMN显示的是最小perm的内存使用量,PGCMX显示的是perm的内存最大使用量,PGC是当前新生成的perm内存占用量,PC是但前perm内存占用量。其他的可以根据这个类推, OC是old内纯的占用量。
    jstat -gcnew pid:new对象的信息。
    jstat -gcnewcapacity pid:new对象的信息及其占用量。
    jstat -gcold pidld对象的信息。
    jstat -gcoldcapacity pidld对象的信息及其占用量。
    jstat -gcpermcapacity pid: perm对象的信息及其占用量。
    jstat -util pid:统计gc信息统计。
    jstat -printcompilation pid:当前VM执行的信息。
    除了以上一个参数外,还可以同时加上 两个数字,如:jstat -printcompilation 3024 250 6是每250毫秒打印一次,一共打印6次,还可以加上-h3每三行显示一下标题。
     
   3、jmap 是一个可以输出所有内存中对象的工具,甚至可以将VM 中的heap,以二进制输出成文本。使用方法 jmap -histo pid。如果连用 SHELL jmap -histo pid>a.log可以将其保存到文本中去(windows下也可以使用),在一段时间后,使用文本对比工具,可以对比出GC回收了哪些对象。jmap -dump:format=b,file=f1 3024可以将3024进程的内存heap输出出来到f1文件里。
     
    4、jconsole 是一个用java写的GUI程序,用来监控VM,并可监控远程的VM,非常易用,而且功能非常强。由于是GUI程序,这里就不详细介绍了,不会的地方可以参考SUN的官方文档。
    使用方法:命令行里打 jconsole,选则进程就可以了。
     
    友好提示:windows查看进程号,由于任务管理器默认的情况下是不显示进程id号的,所以可以通过如下方法加上。ctrl+alt+del打开任务管理器,选择‘进程’选项卡,点‘查看’->''选择列''->加上''PID'',就可以了。当然还有其他很好的选项。



三、参考资料:

    article:http://elf8848.iteye.com/blog/442806


    jps:http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html


    jstat:http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jstat.html


    jmap:http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jmap.html


    jconsole:http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html   
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
2#
 楼主| 发表于 2014-10-30 20:50:42 | 只看该作者

jps - Java Virtual Machine Process Status Tool

jps - Java Virtual Machine Process Status Tool

SYNOPSIS

jps [ options ] [ hostid ]

options
    Command-line options.
hostid
    The host identifier of the host for which the process report should be generated. The hostid may include optional components that indicate the communications protocol, port number, and other implementation specific data.

DESCRIPTION

The jps tool lists the instrumented HotSpot Java Virtual Machines (JVMs) on the target system. The tool is limited to reporting information on JVMs for which it has the access permissions.

If jps is run without specifying a hostid, it will look for instrumented JVMs on the local host. If started with a hostid, it will look for JVMs on the indicated host, using the specified protocol and port. A jstatd process is assumed to be running on the target host.

The jps command will report the local VM identifier, or lvmid, for each instrumented JVM found on the target system. The lvmid is typically, but not necessarily, the operating system's process identifier for the JVM process. With no options, jps will list each Java application's lvmid followed by the short form of the application's class name or jar file name. The short form of the class name or JAR file name omits the class's package information or the JAR files path information.

The jps command uses the java launcher to find the class name and arguments passed to the main method. If the target JVM is started with a custom launcher, the class name (or JAR file name) and the arguments to the main method will not be available. In this case, the jps command will output the string Unknown for the class name or JAR file name and for the arguments to the main method.

The list of JVMs produced by the jps command may be limited by the permissions granted to the principal running the command. The command will only list the JVMs for which the principle has access rights as determined by operating system specific access control mechanisms.

NOTE: This utility is unsupported and may not be available in future versions of the JDK. It is not currently available on Windows 98 and Windows ME platforms.
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 javac. 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.

NOTE: You are advised not to write scripts to parse jps output since the format may change in future releases. If you choose to write scripts that parse jps output, expect to modify them for future releases of this tool.
EXAMPLES

This section provides examples of the jps command.

Listing the instrumented JVMs on the local host:

jps
18027 Java2Demo.JAR
18032 jps
18005 jstat

Listing the instrumented JVMs on a remote host:

This example assumes that the jstat server and either the its internal RMI registry or a separate external rmiregistry process are running on the remote host on the default port (port 1099). It also assumes that the local host has appropriate permissions to access the remote host. This example also includes the -l option to output the long form of the class names or JAR file names.

jps -l remote.domain
3002 /opt/j2sdk1.5.0/demo/jfc/Java2D/Java2Demo.JAR
2857 sun.tools.jstatd.jstatd

Listing the instrumented JVMs on a remote host with a non-default port for the RMI registry

This example assumes that the jstatd server, with an internal RMI registry bound to port 2002, is running on the remote host. This example also uses the -m option to include the arguments passed to the main method of each of the listed Java applications.

jps -m remote.domain:2002
3002 /opt/j2sdk1.5.0/demo/jfc/Java2D/Java2Demo.JAR
3102 sun.tools.jstatd.jstatd -p 2002
3#
 楼主| 发表于 2014-10-30 20:52:24 | 只看该作者

jstat - Java Virtual Machine Statistics Monitoring Tool

jstat - Java Virtual Machine Statistics Monitoring Tool

SYNOPSIS

jstat [ generalOption | outputOptions vmid [interval[s|ms] [count]] ]

generalOption
    A single general command-line option (-help, -options, or -version)
outputOptions
    One or more output options, consisting of a single statOption, plus any of the -t, -h, and -J options.
vmid
    Virtual machine identifier, a string indicating the target Java virtual machine (JVM). The general syntax is

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

    The syntax of the vmid string largely corresponds to the syntax of a URI. The vmid can vary from a simple integer representing a local JVM to a more complex construction specifying a communications protocol, port number, and other implementation-specific values. See Virtual Machine Identifier for details.
interval[s|ms]
    Sampling interval in the specified units, seconds (s) or milliseconds (ms). Default units are milliseconds.  Must be a positive integer.  If specified, jstat will produce its output at each interval.
count
    Number of samples to display. Default value is infinity; that is, jstat displays statistics until the target JVM terminates or the jstat command is terminated.  Must be a positive integer.

DESCRIPTION

The jstat tool displays performance statistics for an instrumented HotSpot Java virtual machine (JVM). The target JVM is identified by its virtual machine identifier, or vmid option described below.

NOTE: This utility is unsupported and may not be available in future versions of the J2SE SDK. It is not currently available on Windows 98 and Windows ME platforms.
VIRTUAL MACHINE IDENTIFIER

The syntax of the vmid string largely corresponds to the syntax of a URI:

[protocol:][//]lvmid[@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.
lvmid
    The local virtual machine identifier for the target JVM. The lvmid is a platform-specific value that uniquely identifies a JVM on a system. The lvmid is the only required component of a virtual machine identifier. The lvmid is typically, but not necessarily, the operating system's process identifier for the target JVM process. You can use the jps command to determine the lvmid. Also, you can determine lvmid on Unix platforms with the ps command, and on Windows with the Windows Task Manager.
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 implementation. For the optimized local protocol, this field is ignored. For the rmi protocol, it represents the name of the RMI remote object on the remote host.

OPTIONS

The jstat command supports two types of options, general options and output options. General options cause jstat to display simple usage and version information. Output options determine the content and format of the statistical output.

NOTE: All options, and their functionality are subject to change or removal in future releases.

GENERAL OPTIONS

If you specify one of the general options, you cannot specify any other option or parameter.

-help
    Display help message.
-version
    Display version information.
-options
    Display list of statistics options. See the Output Options section below.

OUTPUT OPTIONS

If you do not specify a general option, then you can specify output options. Output options determine the content and format of jstat's output, and consist of a single statOption, plus any of the other output options (-h, -t, and -J).  The statOption must come first.

Output is formatted as a table, with columns are separated by spaces. A header row with titles describes the columns.  Use the -h option to set the frequency at which the header is displayed.  Column header names are generally consistent between the different options. In general, if two options provide a column with the same name, then the data source for the two columns are the same.

Use the -t option to display a time stamp column, labeled Timestamp as the first column of output. The Timestamp column contains the elapsed time, in seconds, since startup of the target JVM. The resolution of the time stamp is dependent on various factors and is subject to variation due to delayed thread scheduling on heavily loaded systems.

Use the interval and count parameters to determine how frequently and how many times, respectively, jstat displays its output.

NOTE: You are advised not to write scripts to parse jstat's output since the format may change in future releases. If you choose to write scripts that parse jstat output, expect to modify them for future releases of this tool.

-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 n
    Display a timestamp column as the first column of output. The timestamp is the 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. For a complete list of options, see the following documents:

        java - the Java application launcher (Solaris)
        java - the Java application launcher (Linux)
        java - the Java application launcher (Windows)

STATOPTIONS AND OUTPUT

The following tables summarize the columns that jstat outputs for each statOption.
-class Option
Class Loader Statistics 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
Garbage-collected heap statistics 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
Memory Pool Generation and Space Capacities 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:
Garbage Collection Statistics, Including GC Events Column         Description
LGCC        Cause of last Garbage Collection.
GCC        Cause of current Garbage Collection.
-gcnew Option
New Generation Statistics 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
New Generation Space Size Statistics 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
Old and Permanent Generation Statistics 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
Old Generation Statistics 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
Permanent Generation Statistics 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
Summary of Garbage Collection Statistics 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
HotSpot Compiler Method Statistics Column         Description
Compiled         Number of compilation tasks performed.
Size         Number of bytes of bytecode for the method.
Type         Compilation type.
Method         Class name and method name identifying the 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.
EXAMPLES

This section presents some examples of monitoring a local JVM with a lvmid of 21891.
Using the gcutil option

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 -gcutil 21891 250 7
  S0     S1     E      O      P     YGC    YGCT    FGC    FGCT     GCT
12.44   0.00  27.20   9.49  96.70    78    0.176     5    0.495    0.672
12.44   0.00  62.16   9.49  96.70    78    0.176     5    0.495    0.672
12.44   0.00  83.97   9.49  96.70    78    0.176     5    0.495    0.672
  0.00   7.74   0.00   9.51  96.70    79    0.177     5    0.495    0.673
  0.00   7.74  23.37   9.51  96.70    79    0.177     5    0.495    0.673
  0.00   7.74  43.82   9.51  96.70    79    0.177     5    0.495    0.673
  0.00   7.74  58.11   9.51  96.71    79    0.177     5    0.495    0.673

The output of this example shows that a young generation collection occurred between the 3rd and 4th sample. The collection took 0.001 seconds and promoted objects from the eden space (E) to the old space (O), resulting in an increase of old space utilization from 9.49% to 9.51%. Before the collection, the survivor space was 12.44% utilized, but after this collection it is only 7.74% utilized.
Repeating the column header string

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.

jstat -gcnew -h3 21891 250
S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
  64.0   64.0    0.0   31.7 31  31   32.0    512.0    178.6    249    0.203
  64.0   64.0    0.0   31.7 31  31   32.0    512.0    355.5    249    0.203
  64.0   64.0   35.4    0.0  2  31   32.0    512.0     21.9    250    0.204
S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
  64.0   64.0   35.4    0.0  2  31   32.0    512.0    245.9    250    0.204
  64.0   64.0   35.4    0.0  2  31   32.0    512.0    421.1    250    0.204
  64.0   64.0    0.0   19.0 31  31   32.0    512.0     84.4    251    0.204
S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
  64.0   64.0    0.0   19.0 31  31   32.0    512.0    306.7    251    0.204

In addition to showing the repeating header string, this example shows that between the 2nd and 3rd samples, a young GC occurred. Its duration was 0.001 seconds. The collection found enough live data that the survivor space 0 utilization (S0U) would would have exceeded the desired survivor Size (DSS). As a result, objects were promoted to the old generation (not visible in this output), and the tenuring threshold (TT) was lowered from 31 to 2.

Another collection occurs between the 5th and 6th samples. This collection found very few survivors and returned the tenuring threshold to 31.
Including a time stamp for each sample

This example attaches to lvmid 21891 and takes 3 samples at 250 millisecond intervals. The -t option is used to generate a time stamp for each sample in the first column.

jstat -gcoldcapacity -t 21891 250 3
Timestamp          OGCMN        OGCMX         OGC           OC       YGC   FGC    FGCT    GCT
          150.1       1408.0      60544.0      11696.0      11696.0   194    80    2.874   3.799
          150.4       1408.0      60544.0      13820.0      13820.0   194    81    2.938   3.863
          150.7       1408.0      60544.0      13820.0      13820.0   194    81    2.938   3.863

The Timestamp column reports the elapsed time in seconds since the start of the target JVM. In addition, the -gcoldcapacity output shows the old generation capacity (OGC) and the old space capacity (OC) increasing as the heap expands to meet allocation and/or promotion demands. The old generation capacity (OGC) has grown to from 11696 KB to 13820 KB after the 81st Full GC (FGC). The maximum capacity of the generation (and space) is 60544 KB (OGCMX), so it still has room to expand.
Monitor instrumentation for a remote JVM

This example attaches to lvmid 40496 on the system named remote.domain using the -gcutil option, with samples taken every second indefinitely.

jstat -gcutil 40496@remote.domain 1000
... output omitted

The lvmid is combined with the name of the remote host to construct a vmid of 40496@remote.domain. This vmid results in the use of the rmi protocol to communicate to the default jstatd server on the remote host. The jstatd server is located using the rmiregistry on remote.domain that is bound to the default rmiregistry port (port 1099).
SEE ALSO

    java - the Java Application Launcher
    jps - the Java Process Status Application
    jstatd - the jvmstat daemon
    rmiregistry - the Java Remote Object Registry

Copyright &copy; 2004, 2010 Oracle and/or its affiliates. All rights reserved.
        Sun
4#
 楼主| 发表于 2014-10-30 20:54:25 | 只看该作者

jmap - Memory Map

jmap - Memory Map

SYNOPSIS

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

PARAMETERS

    option
        Options are mutually exclusive. Option, if used, should follow immediately after the command name.

    pid
        process id for which the memory map is to be printed. The process must be a Java process. To get a list of Java processes running on a machine, jps may be used.
    executable
        Java executable from which the core dump was produced.
    core
        core file for which the memory map is to be printed.
    remote-hostname-or-IP
        remote debug server's (see jsadebugd) hostname or IP address.
    server-id
        optional unique id, if multiple debug servers are running on the same remote host.

DESCRIPTION

    jmap prints shared object memory maps or heap memory details of a given process or core file or a remote debug server.

    NOTE - This utility is unsupported and may or may not be available in future versions of the J2SE SDK.
    jmap is not currently available on Windows platforms or on the Linux Itanium platform.

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.
    -heap
        Prints a heap summary. GC algorithm used, heap configuration and generation wise heap usage are printed.
    -histo
        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.
    -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.
    -h
        Prints a help message.

    -help
        Prints a help message.
5#
 楼主| 发表于 2014-10-30 21:01:09 | 只看该作者

RE: JDK自带VM分析工具jps,jstat,jmap,jconsole

jps工具
简洁:jps(Java Virtual Machine Process Status Tool)是JDK1.5提供的一个显示当前所有java进行的pid命令,非常适合在Linux/Unix平台上简单查看当前java进程的一些简单情况。可以通过它来查看到底启动了几个java进程(因为每一个java程序都会独占一个java虚拟机实例)
jps命令:

jps -q(只显示pid,不显示class名称,jar文件名和传递给main方法的参数)

jps -m输出传递给main方法的参数,在嵌入式jvm上可能是null

jps -l输出应用程序main class的完整package名 或者 应用程序的jar文件完整路径名

jps -v输出传递给JVM的参数

注:jsp命令有个地方不好,似乎只能显示当前用户的java进程,要显示其他用户的还是只能用unix/linux的ps命令
选项作用
-q只能输出LVMID,省略主类的名称
-m输出虚拟机进程启动时传递给主类main()函数的参数
-l输出主类的全名,如果进程执行的是Jar包,输出Jar路径
-v输出虚拟机进程启动时JVM参数
---------------------------------------------------------------------------------------------------------------------------

jstat

       (JVM Statistics Monitorning Tool)是用于监视虚拟机各种运行状态信息的状态信息的命令行工具。它可以显示本地或远程虚拟机进程中的类装载、内存、垃圾收集、JIT编译等运行数据,在没有GUI图形界面,只提供了纯文本控制台环境的服务器上,它将是运行期定位虚拟机性能问题的首选工具:

1. jstat -gc pid  可以显示gc的信息,查看gc的次数,及时间。此外还可以用jstat -gc pid 时间段(毫秒值) 查询次数

            其中最后五项,分别是young gc的次数,young gc的时间,full gc的次数,full gc的时间,gc的总时间。

2.jstat -gccapacity pid,监视内容与-gc基本相同,但输出主要关注Java堆各个区域使用到的最大和最小空间可以显示,VM内存中三代(young,old,perm)对象的使用和占用大小,

            如:PGCMN显示的是最小perm的内存使用量,PGCMX显示的是perm的内存最大使用量,

            PGC是当前新生成的perm内存占用量,PC是但前perm内存占用量。

            其他的可以根据这个类推, OC是old内纯的占用量。

经计算PGCMN的值为128m,PGCMX的值为256m,这些就是在虚拟机中配置的参数值。

3.jstat -gcutil pid:监视内容与-gc基本相同,但输出主要关注Java堆各个区域使用到的最大和最小空间

  

说明永生带使用了的内存量为88.03%

4.jstat -gcnew pid:监视新生代GC的状况

5.jstat -gcnewcapacity pid:监视内容与-gcnew基本相同,输出主要关注使用到的最大和最小空间

6.jstat -gcold pid:监视老年代的状况

7.stat -gcoldcapacity pid:监视内容与-gcold基本相同,输出主要关注使用到的最大和最小空间。

8.jstat -gcpermcapacity pid:输出永生代使用到的最大和最小空间

9.jstat -class pid:监视类装载、卸载数量、总空间及类装载所耗费的时间

显示加载class的数量,及所占空间等信息。


10.jstat -compiler pid:输出JIT编辑器编译过的方法、耗时等信息

11.stat -printcompilation pid:输出已经被JIT编译的方法

当前VM执行的信息。

        一些术语的中文解释:

         S0C:年轻代中第一个survivor(幸存区)的容量 (字节)
         S1C:年轻代中第二个survivor(幸存区)的容量 (字节)
         S0U:年轻代中第一个survivor(幸存区)目前已使用空间 (字节)
         S1U:年轻代中第二个survivor(幸存区)目前已使用空间 (字节)
         EC:年轻代中Eden(伊甸园)的容量 (字节)
         EU:年轻代中Eden(伊甸园)目前已使用空间 (字节)
         OC:Old代的容量 (字节)
         OU:Old代目前已使用空间 (字节)
         PC:Perm(持久代)的容量 (字节)
         PU:Perm(持久代)目前已使用空间 (字节)
         YGC:从应用程序启动到采样时年轻代中gc次数
         YGCT:从应用程序启动到采样时年轻代中gc所用时间(s)
         FGC:从应用程序启动到采样时old代(全gc)gc次数
         FGCT:从应用程序启动到采样时old代(全gc)gc所用时间(s)
         GCT:从应用程序启动到采样时gc用的总时间(s)

         NGCMN:年轻代(young)中初始化(最小)的大小 (字节)

         NGCMX:年轻代(young)的最大容量 (字节)

         NGC:年轻代(young)中当前的容量 (字节)

         OGCMN:old代中初始化(最小)的大小 (字节)

         OGCMX:old代的最大容量 (字节)

         OGC:old代当前新生成的容量 (字节)

         PGCMN:perm代中初始化(最小)的大小 (字节)

         PGCMX:perm代的最大容量 (字节)   

         PGC:perm代当前新生成的容量 (字节)

         S0:年轻代中第一个survivor(幸存区)已使用的占当前容量百分比

         S1:年轻代中第二个survivor(幸存区)已使用的占当前容量百分比

         E:年轻代中Eden(伊甸园)已使用的占当前容量百分比

         O:old代已使用的占当前容量百分比

         P:perm代已使用的占当前容量百分比

         S0CMX:年轻代中第一个survivor(幸存区)的最大容量 (字节)

         S1CMX :年轻代中第二个survivor(幸存区)的最大容量 (字节)

         ECMX:年轻代中Eden(伊甸园)的最大容量 (字节)

         DSS:当前需要survivor(幸存区)的容量 (字节)(Eden区已满)

         TT: 持有次数限制

         MTT : 最大持有次数限制

--------------------------------------------------------------------------------------------------------------------------------------------------------------
jinfo:实时地查看和调整虚拟机的各项参数。
通过java -XX:+PrintFlagsFinal查看参数默认值

---------------------------------------------------------------------------------------------------------------------------------------------------------------
jmap命令:jmap的用途是为了展示java进程的内存映射信息,或者堆内存详情
jmap(Memory Map for Java)命令用于生成堆转储快照(一般称为heapdump或dump文件)。如果不使用jmap命令,要想获取Java堆转储快照还有一些比较“暴力”的手段:譬如在第2章中用过的-XX:+HeapDumpOnOutOfMemoryError参数,可以让虚拟机在OOM异常出现之后自动生成 dump文件,通过-XX:+HeapDumpOnCtrlBreak参数则可以使用【Ctrl】+【Break】键让虚拟机生成dump文件,又或者在 Linux系统下通过Kill -3命令发送进程退出信号“恐吓”一下虚拟机,也能拿到dump文件。
jmap的作用并不仅仅是为了获取dump文件,它还可以查询finalize执行队列,Java堆和永久代的详细信息,如空间使用率、当前用的是哪种收集器等。

histo
jmap -histo pid 展示class的内存情况,可以采用jmap -histo pid >a.log(再如:jamp -histo:live 2464 >testjmap.txt)将其保存到文件中,在一段时间后使用文本对比工具,可以对必出GC回收了哪些对象。jmap -dump:format=b,file=outfile 5446可以将5446进程内存heap输出出来到outfile文件里,在配合MAT(内存分析工具)。
展示的信息为编号,实例数,字节,类名



heap
jmap -heap pid 展示pid的整体堆信息

[root@localhost ~]# jmap -heap 5446
Attaching to process ID 5446, please wait...
Debugger attached successfully.Server compiler detected.JVM version is 24.45-b08
using thread-local object allocation.Parallel GC with 10 thread(s)                    #10个gc线程
Heap Configuration:                              #堆内存初始化配置   
MinHeapFreeRatio = 40                         #-XX:MinHeapFreeRatio设置JVM堆最小空闲比率   
MaxHeapFreeRatio = 70                         #-XX:MaxHeapFreeRatio设置JVM堆最大空闲比率      
MaxHeapSize      = 3722444800 (3550.0MB)      #-XX:MaxHeapSize=设置JVM堆的最大大小   
NewSize          = 1310720 (1.25MB)           #-XX:NewSize=设置JVM堆的‘新生代’的默认大小   
MaxNewSize       = 17592186044415 MB          #-XX:MaxNewSize=设置JVM堆的‘新生代’的最大大小   
OldSize          = 5439488 (5.1875MB)         #-XX:OldSize=设置JVM堆的‘老生代’的大小   
NewRatio         = 2                          #-XX:NewRatio=:‘新生代’和‘老生代’的大小比率   
SurvivorRatio    = 8                          #-XX:SurvivorRatio=设置年轻代中Eden区与Survivor区的大小比值   
PermSize         = 134217728 (128.0MB)        #-XXermSize=<value>:设置JVM堆的‘永生代’的初始大小   
MaxPermSize      = 268435456 (256.0MB)        #-XX:MaxPermSize=<value>:设置JVM堆的‘永生代’的最大大小   
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:                                      #Eden区内存分布   
   capacity = 651165696 (621.0MB)   
   used     = 29038624 (27.693389892578125MB)   
   free     = 622127072 (593.3066101074219MB)
   4.459483074489231% used

From Space:                                      #其中一个Survivor区的内存分布
   capacity = 1572864 (1.5MB)
   used     = 0 (0.0MB)
   free     = 1572864 (1.5MB)   0.0% used

To Space:                                        #另一个Survivor区的内存分布
   capacity = 296747008 (283.0MB)
   used     = 0 (0.0MB)
   free     = 296747008 (283.0MB)   0.0% used

PS Old Generation                                #当前的Old区内存分布
   capacity = 2481979392 (2367.0MB)
   used     = 120759968 (115.16567993164062MB)
   free     = 2361219424 (2251.8343200683594MB)
   4.865470212574594% used

PS Perm Generation                              #当前的 “永生代” 内存分布
  capacity = 268435456 (256.0MB)
   used     = 139659040 (133.18923950195312MB)
   free     = 128776416 (122.81076049804688MB)
   52.02704668045044% used

dump
导出的文件可以供分析用,比如jhat或者mat,以便查找内存溢出原因
假如指定live选项,那么只输出活的对象到文件.
jmap –dump:live,[format=b,]file=/usr/java/dump.log 5446

-finalizerinfo 打印正等候回收的对象的信息
jmap -finalizerinfo 5446

64位机上使用需要使用如下方式:
-permstat 打印classload和jvm heap长久层的信息. 包含每个classloader的名字,活泼性,地址,父classloader和加载的class数量. 另外,内部String的数量和占用内存数也会打印出来
$jmap -permstat 5446
&Oslash;  -F 强迫.在pid没有相应的时候使用-dump或者-histo参数. 在这个模式下,live子参数无效.
&Oslash;  -h | -help 打印辅助信息
&Oslash;  -J 传递参数给jmap启动的jvm.
-----------------------------------------------------------------------------------------------------------------------------
jhat命令
用途:是用来分析java堆的命令,可以将堆中的对象一html的形式显示出来,包括对象的数组,大小等等,并支持对象查询语言
第一步:导出堆
jmap -dump:live,file=dump.txt 5446
第二步:分析堆文件
jhat dump.txt

第三步:查看html(再输入:http://访问机器的ip地址:7000后:)
注意:在访问的html下方有各种条件的查询:

(2)从根集能引用到的对象

(3)显示平台包括的所有类的实例数量

(4)堆实例的分布表

(5)执行对象查询语句

windows下按[Ctrl+C]停止

-------------------------------------------------------------------------------------------------------------------------------------------------------

jstack:java堆栈跟踪工具
jstack(Stack Trace for Java)命令用于生成虚拟机当前时刻的线程快照(一般称为threaddump或javadoc文件)。线程快照就是当前虚拟机内每一条线程正在执行的方法堆栈的集合,生成线程快照的主要目的是定位线程出现长时间停顿的原因,如线程间死锁、死循环、请求外部资源导致的长时间等待等都是导致线程长时间停顿的常见原因。线程出现停顿的时候通过jstack来查看各个线程的调用堆栈,就可以知道没有响应的线程到底在后台做些什么事情,或者等待着什么资源。

jstack命令
该命令打印java线程的堆栈跟踪,可以得知哪些线程被阻塞或正等待,以便于查找如线程死锁的原因
用法:
jstack [ option ] pid
-F:强制产生一个线程dump
-m:打印java和native frames
-l:打印关于锁的附加信息
jstack [-l] 5446


6#
 楼主| 发表于 2014-11-14 20:55:38 | 只看该作者

jstat分析VM内存

Jstat 是JDK自带的一个轻量级小工具。全称“Java Virtual Machine statistics monitoring tool”,它位于java的bin目录下,主要利用JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括了对Heap size和垃圾回收状况的监控。可见,Jstat是轻量级的、专门针对JVM的工具,非常适用。由于JVM内存设置较大,图中百分比变化不太明显

一个极强的监视VM内存工具。可以用来监视VM内存内的各种堆和非堆的大小及其内存使用量。

jstat工具特别强大,有众多的可选项,详细查看堆内各个部分的使用量,以及加载类的数量。使用时,需加上查看进程的进程id,和所选参数。

执行:cd $JAVA_HOME/bin中执行jstat,注意jstat后一定要跟参数。


语法结构:

Usage: jstat -help|-options

       jstat -<option> [-t] [-h<lines>] <vmid> [<interva[s|ms]> [<count>]]

参数解释:

Options — 选项,我们一般使用 -gcutil 查看gc情况

vmid      — VM的进程号,即当前运行的java进程号

interval[s|ms]  ——  间隔时间,单位为秒或者毫秒,默认为ms。必须是正整型。

count     — 打印次数,如果缺省则打印无数次

输出参数:

-hn 每个n行输出一次列表头。默认为0,仅输出一次。

-tn 在第一列输出时间戳。该时间戳从jvm启动开始。

-JjavaOption

具体参数:

-class: 统计class loader 行为信息

-compiler: 统计编译行为信息

-gc:统计jdk gc时heap信息

-gccapacity:统计不同的generations(新生代、老生代、永久代)相应的heap容量信息

-gccause:统计gc的情况,以及引起gc的事情。同-gcutil

-gcnew:统计新生代的gc情况

-gcnewcapacity:统计新生代gc时heap的容量信息

-gcold:统计老生代的gc情况

-gcoldcapacity:统计老生代gc时heap容量信息

-gcpermcapacity:统计永久代gc时的容量信息

-gcutil:统计heap的gc情况

-printcompilation:没用过

jstat -gcutil :

结果信息:

S0  — Heap上的 Survivor space 0 区已使用空间的百分比
S1  — Heap上的 Survivor space 1 区已使用空间的百分比
E   — Heap上的 Eden space 区已使用空间的百分比
O   — Heap上的 Old space 区已使用空间的百分比
P   — Perm space 区已使用空间的百分比
YGC — 从应用程序启动到采样时发生 Young GC 的次数
YGCT– 从应用程序启动到采样时 Young GC 所用的时间(单位秒)
FGC — 从应用程序启动到采样时发生 Full GC 的次数
FGCT– 从应用程序启动到采样时 Full GC 所用的时间(单位秒)
GCT — 从应用程序启动到采样时用于垃圾回收的总时间(单位秒)

jstat -gcutil 21891 250 7



21891 进程号; 250ms 采样interval; 7 count
S0     S1     E      O      P     YGC    YGCT    FGC    FGCT     GCT
12.44   0.00  27.20   9.49  96.70    78    0.176     5    0.495    0.672
12.44   0.00  62.16   9.49  96.70    78    0.176     5    0.495    0.672
12.44   0.00  83.97   9.49  96.70    78    0.176     5    0.495    0.672
0.00    7.74   0.00   9.51  96.70    79    0.177     5    0.495    0.673
0.00    7.74  23.37   9.51  96.70    79    0.177     5    0.495    0.673
0.00    7.74  43.82   9.51  96.70    79    0.177     5    0.495    0.673
0.00    7.74  58.11   9.51  96.71    79    0.177     5    0.495    0.673


以上输出表明:
1. 在第三行与第四行,发生一次新生代gc。 本次gc耗时0.001秒,且有对象从Eden区提升到老生代,老生代使用率从9.49% 上升到9.51%。
2. gc之前,survivor space 使用率12.44%, gc后,降为7.74%。

jstat -gcnew -h3 21891 250
      
-h3:每隔三行输出一次列表头; 21891:进程号; 250: interval采样间隔,ms; count不设置,表示打印无数次

S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
64.0   64.0    0.0   31.7   31  31   32.0    512.0    178.6    249    0.203

64.0   64.0    0.0   31.7   31  31   32.0    512.0    355.5    249    0.203
64.0   64.0   35.4    0.0   2    31   32.0    512.0     21.9    250    0.204
S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
64.0   64.0   35.4    0.0   2    31   32.0    512.0    245.9    250    0.204
64.0   64.0   35.4    0.0   2    31   32.0    512.0    421.1    250    0.204
64.0   64.0    0.0   19.0   31  31   32.0    512.0     84.4    251    0.204
S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT
64.0   64.0    0.0   19.0   31  31   32.0    512.0    306.7    251    0.204

以上输出表明:
1.  S0U: survivor space 0 utilization
     DSS: desired survivor Size
     TT: tenuring threshold 阀值, 用于控制对象在新生代存活的最大次数
2. 第二行和第三行之间,发生一次新生代gc。 耗时为0.001秒。
    本次gc发现较多的存活对象,且S0U超过了DSS,因此,将存活对象提升到老生代(这里没有显示)。并将
     TT从31降到2.
3.  另一次gc发生在第5行和第6行,本次gc发现较少的幸存对象,并将阀值变更为31。


jstat -gcoldcapacity -t 21891 250 3


-t:在第一列输出时间戳; 21891:进程号; 250: 采样间隔ms;3 采样次Timestamp    OGCMN   OGCMX       OGC       OC      YGC   FGC    FGCT    GCT
150.1      1408.0    60544.0   11696.0    11696.0   194    80    2.874   3.799
150.4     1408.0    60544.0   13820.0    13820.0   194    81    2.938   3.863
150.7      1408.0    60544.0    13820.0   13820.0   194    81    2.938   3.863


以上输出表明:
1. OGC: old generation capacity 老生代空间大小
   OGCMN:最小OGC
   OGCMX: 最大OGC
   OC: old space capacity
   FGC: Full  GC
   OGC: old generation capacity
2. Timestamp从jvm启动的时间开始。
3. 第二行和第三行,经过81次full gc, OGC从11696 KB 上升到13820 KB 。
4. 老生代最大空间大小OGCMX为 60544 KB, 因此还有上升空间。


jstat -gcutil



[root@localhost bin]# jstat -gcutil 25444 1000 5

  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT

73.54   0.00  99.04  67.52  98.49    166    0.252     6    0.331    0.583

73.54   0.00  99.04  67.52  98.49    166    0.252     6    0.331    0.583

73.54   0.00  99.04  67.52  98.49    166    0.252     6    0.331    0.583

73.54   0.00  99.04  67.52  98.49    166    0.252     6    0.331    0.583

73.54   0.00  99.04  67.52  98.49    166    0.252     6    0.331    0.583

可以看到,5次young gc之后,垃圾内存被从Eden space区(E)放入了Old space区(O),并引起了百分比的变化,导致Survivor space使用的百分比从73.54%(S0)降到0%(S1)。有效释放了内存空间。绿框中,我们可以看到,一次full gc之后,Old space区(O)的内存被回收,从99.05%降到67.52%。

图中同时打印了young gc和full gc的总次数、总耗时。而,每次young gc消耗的时间,可以用相间隔的两行YGCT相减得到。每次full gc消耗的时间,可以用相隔的两行FGCT相减得到。例如红框中表示的第一行、第二行之间发生了1次young gc,消耗的时间为0.252-0.252=0.0秒。

常驻内存区(P)的使用率,始终停留在98.49%左右,说明常驻内存没有突变,比较正常。

如果young gc和full gc能够正常发生,而且都能有效回收内存,常驻内存区变化不明显,则说明java内存释放情况正常,垃圾回收及时,java内存泄露的几率就会大大降低。但也不能说明一定没有内存泄露。

GCT 是YGCT 和FGCT的时间总和。

以上,介绍了Jstat按百分比查看gc情况的功能。其实,它还有功能,例如加载类信息统计功能、内存池信息统计功能等,那些是以绝对值的形式打印出来的,比较少用,在此就不做介绍。

jstat -class pid

显示加载class的数量,及所占空间等信息。

[root@localhost bin]# jstat -class 25917

Loaded  Bytes  Unloaded  Bytes     Time

2629    2916.8       29   24.6     0.90



jstat -compiler pid

显示VM实时编译的数量等信息。

[root@localhost bin]# jstat -compiler 25917

Compiled Failed Invalid   Time   FailedType FailedMethod

768      0       0   0.70            0



jstat –gccapacity

可以显示,VM内存中三代(young,old,perm)对象的使用和占用大小,如:PGCMN显示的是最小perm的内存使用量,PGCMX显示的 是perm的内存最大使用量,PGC是当前新生成的perm内存占用量,PC是但前perm内存占用量。其他的可以根据这个类推, OC是old内纯的占用量。



[root@localhost bin]# jstat -gccapacity 25917

NGCMN       640.0

NGCMX       4992.0

NGC         832.0

S0C         64.0

S1C         64.0

EC          704.0

OGCMN       1408.0

OGCMX       60544.0

OGC         9504.0

OC          9504.0                  OC是old内纯的占用量

PGCMN       8192.0                  PGCMN显示的是最小perm的内存使用量

PGCMX       65536.0                 PGCMX显示的是perm的内存最大使用量

PGC         12800.0                 PGC是当前新生成的perm内存占用量

PC          12800.0                 PC是但前perm内存占用量

YGC         164

FGC         6



jstat -gcnew pid

new对象的信息

[root@localhost bin]# jstat -gcnew 25917

S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT

64.0   64.0   47.4   0.0   2  15   32.0    704.0    145.7    168    0.254



jstat -gcnewcapacity pid: new对象的信息及其占用量

[root@localhost bin]# jstat -gcnewcapacity 25917

NGCMN  NGCMX   NGC   S0CMX  S0C   S1CMX  S1C   ECMX    EC      YGC   FGC

640.0  4992.0  832.0 64.0   448.0 448.0  64.0   4096.0  704.0  168     6



jstat -gcold pid: old对象的信息。

[root@localhost bin]# jstat -gcold 25917

   PC       PU        OC          OU       YGC    FGC    FGCT     GCT

12800.0  12617.6     9504.0      6561.3   169     6    0.335    0.591



jstat -gcoldcapacity pidld对象的信息及其占用量。

[root@localhost bin]# jstat -gcoldcapacity 25917

OGCMN      OGCMX        OGC         OC       YGC   FGC    FGCT     GCT

1408.0     60544.0      9504.0      9504.0   169     6    0.335    0.591



jstat -gcpermcapacity pid: perm对象的信息及其占用量。

[root@localhost bin]# jstat -gcpermcapacity 25917

PGCMN      PGCMX       PGC         PC      YGC   FGC    FGCT     GCT

8192.0    65536.0    12800.0    12800.0   169     6    0.335    0.591



jstat -printcompilation pid: 当前VM执行的信息。

[root@localhost bin]# jstat -printcompilation -h3  25917 1000 5

每1000毫秒打印一次,一共打印5次,还可以加上-h3每三行显示一下标题。

Compiled  Size  Type Method

     788     73    1 java/io/File <init>

     788     73    1 java/io/File <init>

     788     73    1 java/io/File <init>

Compiled  Size  Type Method

     788     73    1 java/io/File <init>

     788     73    1 java/io/File <init>
7#
 楼主| 发表于 2014-11-14 20:58:43 | 只看该作者

jstat命令 -- Java虚拟机监控统计工具

jstat命令 -- Java虚拟机监控统计工具

语法:
jstat [generalOption | outputOptions vmid [interval[s|ms] [count]]]

选项:
1.generalOption
-help 帮助
-options 打印选项

2.outputOptions
输出选项
-h n 每n个样本,显示header一次
-t n 在第一列显示时间戳列,时间戳时从jvm启动开始计算
-Jjvmoption 传递jvm选项
-statOption 决定统计什么信息
(1)class:统计classloader的行为
Column
Description
Loaded被读入类的数量
Bytes被读入的字节数(K)
Unloaded被卸载类的数量
Bytes被卸载的字节数(K)
Time花费在load和unload类的时间

(2)compiler:统计hotspot just-in-time编译器的行为
Column
Description
Compiled被执行的编译任务的数量
Failed失败的编译任务的数量
Invalid无效的编译任务的数量
Time花费在执行编译任务的时间.
FailedType最近失败编译的编译类弄.
FailedMethod最近失败编译的类名和方法名

(3)gc:统计gc行为
Column
Description
S0C 当前S0的容量 (KB).
S1C 当前S1的容量 (KB).
S0U S0的使用 (KB).
S1U S1的使用 (KB).
EC 当前eden的容量(KB).
EU eden的使用 (KB).
OC 当前old的容量(KB).
OU old的使用 (KB).
PC 当前perm的容量 (KB).
PU perm的使用 (KB).
YGC young代gc的次数
YGCT young代gc花费的时间
FGC full gc的次数
FGCT full gc的时间
GCT 垃圾收集收集的总时间

(4)gccapacity:统计堆中代的容量、空间
Column
Description
NGCMN年轻代的最小容量 (KB).
NGCMX 年轻代的最大容量 (KB).
NGC 当前年轻代的容量 (KB).
S0C当前S0的空间 (KB).
S1C 当前S1的空间 (KB).
EC 当前eden的空间 (KB).
OGCMN年老代的最小容量 (KB).
OGCMX 年老代的最大容量 (KB).
OGC 当前年老代的容量 (KB).
OC 当前年老代的空间 (KB).
PGCMN永久代的最小容量 (KB).
PGCMX 永久代的最大容量 (KB).
PGC 当前永久代的容量 (KB).
PC 当前永久代的空间 (KB).
YGC年轻代gc的次数
FGC full gc的次数

(5)gccause:垃圾收集统计,包括最近引用垃圾收集的事件,基本同gcutil,比gcutil多了两列
Column
Description
LGCC最近垃圾回收的原因.
GCC当前垃圾回收的原因.

(6)gcnew:统计新生代的行为
Column
Description
S0C当前S0空间 (KB).
S1C当前S1空间 (KB).
S0US0空间使用 (KB).
S1US1空间使用 (KB).
TTTenuring threshold.
MTT 最大的tenuring threshold.
DSS希望的Survivor大小 (KB).
EC当前eden空间 (KB).
EUeden空间使用 (KB).
YGC年轻代gc次数
YGCT年轻代垃圾收集时间

(7)gcnewcapacity:统计新生代的大小和空间
Column
Description
NGCMN           
最小的年轻代的容量 (KB).
NGCMX     最大的年轻代的容量 (KB).
NGC     当前年轻代的容量 (KB).
S0CMX最大的S0空间 (KB).
S0C当前S0空间 (KB).
S1CMX最大的S1空间 (KB).
S1C当前S1空间 (KB).
ECMX最大eden空间 (KB).
EC当前eden空间 (KB).
YGC年轻代gc数量
FGCfull gc数量

(8)gcold:统计旧生代的行为
Column
Description
PC当前perm空间 (KB).
PUperm空间使用 (KB).
OC当前old空间 (KB).
OUold空间使用 (KB).
YGC年轻代gc次数
FGCfull gc次数
FGCTfull gc时间
GCT垃圾收集总时间

(9)gcoldcapacity:统计旧生代的大小和空间
Column
Description
OGCMN最小年老代容量 (KB).
OGCMX最大年老代容量 (KB).
OGC当前年老代容量 (KB).
OC当前年老代空间 (KB).
YGC年轻代gc次数
FGCfull gc次数
FGCTfull gc时间
GCT垃圾收集总时间

(10)gcpermcapacity:统计永久代的大小和空间
Column
Description
PGCMN永久代最小容量 (KB).
PGCMX永久代最大容量 (KB).
PGC当前永久代的容量 (KB).
PC当前永久代的空间 (KB).
YGC年轻代gc次数
FGCfull gc次数
FGCTfull gc时间
GCT垃圾收集总时间

(11)gcutil:垃圾收集统计
Column
Description
S0S0使用百分比
S1S1使用百分比
Eeden使用百分比
Oold使用百分比
Pperm使用百分比
YGC年轻代gc次数
YGCT年轻代gc时间
FGCfull gc次数
FGCTfull gc时间
GCT垃圾收集总时间

(12)printcompilation:hotspot编译方法统计
Column
Description
Compiled被执行的编译任务的数量.
Size方法字节码的字节数
Type 编译类型
Method 编译方法的类名和方法名。类名使用"/" 代替 "." 作为空间分隔符. 方法名是给出类的方法名. 格式是一致于HotSpot - XX:+PrintComplation 选项.

3.vmid 虚拟机标识符,格式为:[protocol :][//]lvmid [@hostname [:port ]/servername ]
4.interval 是显示间隔
5.count 是显示次数

举例:

(1)每隔5秒显示在127.0.0.1机器上的18668jvm的classloader相关信息,一共显示100次,并且每5次显示一个列头,显示时间戳

(2)每隔5秒显示在127.0.0.1机器上的18668jvm的gc统计相关信息,一共显示100次,并且每5次显示一个列头,显示时间戳


更多具体的信息,请参见:
http://download.oracle.com/javase/1.5.0/docs/tooldocs/share/jstat.html

您需要登录后才可以回帖 登录 | 注-册

本版积分规则

小黑屋|手机版|Archiver|数码鹭岛 ( 闽ICP备20006246号 )  

counter

GMT+8, 2025-12-3 18:05 , Processed in 0.087679 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表