JDK Command Performance Monitoring

Read the original

View Virtual Machine process: jps command

jps command lists all of the Java processes. If jps without any parameters, you can list the process ID Java programs as well as the short name of the Main function, as shown below.

$ jps
6540 Jps
64447 Main

In addition, the following parameters can also specify a custom output:

parameter meaning
-q Jps output only specified process ID
-m Output parameters passed to the Java process
-l The full path of the main function output
-v Display parameters passed to the Java Virtual Machine

Virtual Machine statistics: jstat command

jstat used to observe details of the Java heap information, the basic syntax bit:

jstat -<option> [-t] [-h<lines>] <vmid> [<interval>] [<count>]]

Option which may be composed of the following values.

parameter meaning
-class Monitoring class loading, unloading amount of total space, and the time it takes to load the class
-gc Monitor Java heap conditions, including Eden District, two Survivor areas, the old era, such as permanent-generation capacity, used space, GC total time information
-gccapacity Monitor the content and -gc basically the same, but the output is mainly concerned about the use of Java heap each region to the maximum, minimum space
-gcutil Monitor the content and -gc basically the same, but the output has been focused on the use of the percentage of total space
-gccause Like -gcutil function, but will cause additional output generated by the last GC
-gcnew GC monitors the status of the new generation
-gcnewcapacity Monitor the content and -gcnew basically the same, using the output of major concern to the maximum, minimum space
-gcold GC old's condition monitoring
-gcoldcapacity Monitor the content and -gcold basically the same, using the output of major concern to the maximum, minimum space
-gcpermcapacity Generation output permanently to use the maximum, minimum space
-compiler Output JIT compiler compiled method, time-consuming information
-printcompilation Output has been JIT compiled methods

-t parameter represents the output time stamps, -h parameter represents the output of a header after how many rows, vmid is a process virtual machine ID, interval and count represents the number of output and the output gap.

For example: We use a LVMID jstat command to monitor the JVM process 2365.

$ jstat -gcutil 2365 
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT   
  0.00   0.00  12.05   0.00  14.17      0    0.000     0    0.000    0.000

In which the meaning of each option are as follows:

parameter meaning
S0、S1 He represents Survivor0, Survivor1, not been used.
E Eden district represents 12.05% of the use of space.
O It represents years old yet use.
P Permanent represents 14.17% of the generation of the use of space
YUC, YGCT Since the program runs indicate the occurrence of a total of 0 times Minor GC (YGC, Young GC), took a total of 0 seconds.
FGC, FGCT Since the program represents a total of 0 times to run it occurred Full GC (FGC, Full GC), took a total of 0 seconds.

View virtual machine parameters: jinfo command

jinfo expansion parameter can be used to view a Java application running, even at run-time support, modify some parameters. Its basic syntax is:

jinfo <option> <pid>

Execution example, the query parameter values ​​CMSInitiatingOccupancyFraction

$ jinfo -flag CMSInitiatingOccupancyFraction 2618
-XX:CMSInitiatingOccupancyFraction=-1

Export heap to file: jmap command

jmap is a versatile command, you can generate Java program Dump files, you can also view the statistics within the heap object instance to view the information ClassLoader and finalizer queue.

jmap [option] vmid

Apply example, an example of using jmap generate a running Eclipse snapshot of the dump file. The example in 2618 was queried by jps name LVMID.

$ jmap -dump:format=b,file=Desktop/dump.bin 2618
Dumping heap to /Users/yurongchan/Desktop/dump.bin ... Heap dump file created

Heap analysis tool: jhat command

jhat command is used to analyze Java application snapshot memory. Sun JDK provides jhat command jmap with the use, to analyze the heap dump snapshot jmap generated. After jhat built a miniature of HTTP / HTML server, generate analysis results dump files can be viewed in a browser. Here we use to analyze jhat generated above dump.bin file:

$ jhat dump.bin 
Reading from dump.bin...
Dump file created Sun May 15 23:04:19 CST 2016 Snapshot read, resolving... Resolving 13822 objects... Chasing references, expect 2 dots.. Eliminating duplicate references.. Snapshot resolved. Started HTTP server on port 7000 Server is ready.

After you enter in the browser  http: // localhost: 7000  you can see the results, as shown below:

But do not generally jhat order to analyze the dump file, mainly for two reasons: First, analysis of the dump file on the server generally will not deploy the application because analysis is a hardware resource consumption and process time-consuming. Another reason is the analysis jhat is still relatively simple, compared to the introduction of tools such as VisualVM behind a lot worse.

View thread stacks: jstack command

jstack command is used to derive a Java application thread's stack. jstack command format:

jstack [option] vmid

The following examples use jstack see a thread of battle:

nobody $ jstack -l 2618
2016-05-15 23:39:04 Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode): "Attach Listener" daemon prio=5 tid=0x00007f83228e6000 nid=0x280b waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "DestroyJavaVM" prio=5 tid=0x00007f832387e800 nid=0x1303 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None

Remote host information collection: jstatd command

jstad command is used to gather information on the remote host.

Multi-function command line: jcmd command

jcmd command can execute a command for a given Java virtual machine.

Performance statistics tools: hprof

 

Read the original

View Virtual Machine process: jps command

jps command lists all of the Java processes. If jps without any parameters, you can list the process ID Java programs as well as the short name of the Main function, as shown below.

$ jps
6540 Jps
64447 Main

In addition, the following parameters can also specify a custom output:

parameter meaning
-q Jps output only specified process ID
-m Output parameters passed to the Java process
-l The full path of the main function output
-v Display parameters passed to the Java Virtual Machine

Virtual Machine statistics: jstat command

jstat used to observe details of the Java heap information, the basic syntax bit:

jstat -<option> [-t] [-h<lines>] <vmid> [<interval>] [<count>]]

Option which may be composed of the following values.

parameter meaning
-class Monitoring class loading, unloading amount of total space, and the time it takes to load the class
-gc Monitor Java heap conditions, including Eden District, two Survivor areas, the old era, such as permanent-generation capacity, used space, GC total time information
-gccapacity 监视内容与-gc基本相同,但输出主要关注Java堆各个区域使用到的最大、最小空间
-gcutil 监视内容与-gc基本相同,但输出主要关注已使用空间占总空间的百分比
-gccause 与-gcutil功能一样,但是会额外输出导致上一次GC产生的原因
-gcnew 监视新生代GC状况
-gcnewcapacity 监视内容与-gcnew基本相同,输出主要关注使用到的最大、最小空间
-gcold 监视老年代GC状况
-gcoldcapacity 监视内容与-gcold基本相同,输出主要关注使用到的最大、最小空间
-gcpermcapacity 输出永久代使用到的最大、最小空间
-compiler 输出JIT编译器编译过的方法、耗时信息
-printcompilation 输出已经被JIT编译的方法

-t 参数表示输出时间戳、-h 参数表示在多少行后输出一个表头、vmid 则是虚拟机的进程ID、interval 和 count 表示输出间隔以及输出次数。

例如:我们用jstat命令来监视一个LVMID为2365的JVM进程。

$ jstat -gcutil 2365 
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT   
  0.00   0.00  12.05   0.00  14.17      0    0.000     0    0.000    0.000

其中每个选项的意义如下:

参数 含义
S0、S1 表示Survivor0、Survivor1,还未使用。
E 表示Eden区使用了12.05%的空间。
O 表示老年代还未使用。
P 表示永久代使用了14.17%的空间
YUC、YGCT 表示从程序运行以来一共发生了0次Minor GC(YGC,Young GC),总共耗时0秒。
FGC、FGCT 表示从程序运行以来一共发生了0次Full GC(FGC,Full GC),总共耗时0秒。

查看虚拟机参数:jinfo 命令

jinfo 可以用来查看正在运行的 Java 应用程序的扩展参数,甚至支持在运行时,修改部分参数。它的基本语法是:

jinfo <option> <pid>

执行例子,查询 CMSInitiatingOccupancyFraction 参数值

$ jinfo -flag CMSInitiatingOccupancyFraction 2618
-XX:CMSInitiatingOccupancyFraction=-1

导出堆到文件:jmap 命令

jmap 是一个多功能命令,可以生成 Java 程序的 Dump 文件,也可以查看堆内对象实例的统计信息、查看 ClassLoader 的信息以及 finalizer 队列。

jmap [option] vmid

执行样例,使用 jmap 生成一个正在运行的 Eclipse 的 dump 快照文件的例子。例子中的2618是通过jps名称查询到的LVMID。

$ jmap -dump:format=b,file=Desktop/dump.bin 2618
Dumping heap to /Users/yurongchan/Desktop/dump.bin ... Heap dump file created

堆分析工具:jhat 命令

jhat 命令用于分析 Java 应用的对快照内存。Sun JDK 提供了 jhat 命令与 jmap 搭配使用,来分析 jmap 生成的堆转储快照。jhat 内置了一个微型的 HTTP/HTML 服务器,生成 dump 文件的分析结果后,可以在浏览器中查看。下面我们用 jhat 来分析上面生成的 dump.bin 文件:

$ jhat dump.bin 
Reading from dump.bin...
Dump file created Sun May 15 23:04:19 CST 2016 Snapshot read, resolving... Resolving 13822 objects... Chasing references, expect 2 dots.. Eliminating duplicate references.. Snapshot resolved. Started HTTP server on port 7000 Server is ready.

之后在浏览器输入 http://localhost:7000 就可以看到分析结果,如下图所示:

不过一般情况下不用 jhat 命令来分析 dump 文件,主要有以下两个原因:一是一般不会再部署应用的服务器上分析 dump 文件,因为分析工作是一个耗时而且消耗硬件资源的过程。另一个原因是 jhat 的分析功能还比较简陋,比起后面介绍的 VisualVM 等工具还差得很多。

查看线程堆栈:jstack 命令

jstack 命令用于导出 Java 应用程序的线程堆栈。jstack命令格式:

jstack [option] vmid

下面使用jstack查看一个线程对战的例子:

nobody $ jstack -l 2618
2016-05-15 23:39:04 Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode): "Attach Listener" daemon prio=5 tid=0x00007f83228e6000 nid=0x280b waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None "DestroyJavaVM" prio=5 tid=0x00007f832387e800 nid=0x1303 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE Locked ownable synchronizers: - None

远程主机信息收集:jstatd 命令

jstad 命令用于收集远程主机信息。

多功能命令行:jcmd 命令

jcmd 命令可以针对给定的 Java 虚拟机执行一条命令。

性能统计工具:hprof

Guess you like

Origin www.cnblogs.com/276815076/p/11907068.html