JVM性能调优工具04-jcmd-Java程序诊断工具

释放双眼,带上耳机,听听看~!

[超级链接:JVM性能调优工具学习记录-序章]


本章主要学习Java程序诊断工具jcmd。

1.用途

发送诊断命令至正在活动的JVM。

2.语法


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1Usage: jcmd <pid | main class> <command ...|PerfCounter.print|-f file>
2   or: jcmd -l
3   or: jcmd -h
4
5  command must be a valid jcmd command for the selected jvm.
6  Use the command "help" to see which commands are available.
7  If the pid is 0, commands will be sent to all Java processes.
8  The main class argument will be used to match (either partially
9  or fully) the class used to start Java.
10  If no options are given, lists Java processes (same as -p).
11
12  PerfCounter.print display the counters exposed by this process
13  -f  read and execute commands from the file
14  -l  list JVM processes on the local machine
15  -h  this help
16
  • h:帮助。

  • l:显示当前机器上的进程,包括进程id、主类全路径名、main方法参数,等同于jps -ml。

  • f:从文件读取并执行命令。

  • PerfCounter.print:打印性能计数器信息。

  • help:显示当前JVM进程可用的命令。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1C:\Users\hanchao>jcmd 7484 help
27484:
3The following commands are available:
4JFR.stop
5JFR.start
6JFR.dump
7JFR.check
8VM.native_memory
9VM.check_commercial_features
10VM.unlock_commercial_features
11ManagementAgent.stop
12ManagementAgent.start_local
13ManagementAgent.start
14GC.rotate_log
15Thread.print
16GC.class_stats
17GC.class_histogram
18GC.heap_dump
19GC.run_finalization
20GC.run
21VM.uptime
22VM.flags
23VM.system_properties
24VM.command_line
25VM.version
26help
27

3.常用命令示例

  • jcmd pid VM.uptime:VM启动时间


1
2
3
4
1C:\Users\hanchao>jcmd 7484 VM.uptime
27484:
35783.212 s
4
  • jcmd pid VM.system_properties:VM系统属性


1
2
3
4
5
6
7
8
9
10
1C:\Users\hanchao>jcmd 7484 VM.system_properties
27484:
3#Tue May 08 23:22:22 CST 2018
4java.runtime.name=Java(TM) SE Runtime Environment
5sun.boot.library.path=C\:\\Program Files\\Java\\jdk1.8.0_131\\jre\\bin
6java.vm.version=25.131-b11
7java.vm.vendor=Oracle Corporation
8java.vendor.url=http\://java.oracle.com/
9...
10
  • jcmd pid Thread.print打印线程信息


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1C:\Users\hanchao>jcmd 7484 Thread.print
27484:
32018-05-08 23:23:13
4Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode):
5
6"DestroyJavaVM" #13 prio=5 os_prio=0 tid=0x00000000047a3800 nid=0x3a8 waiting on condition [0x0000000000000000]
7   java.lang.Thread.State: RUNNABLE
8
9"Thread-1" #12 prio=5 os_prio=0 tid=0x000000001ab7b800 nid=0xe64 waiting on condition [0x000000001bd7f000]
10   java.lang.Thread.State: TIMED_WAITING (sleeping)
11        at java.lang.Thread.sleep(Native Method)
12        at pers.hanchao.concurrent.eg04.ThreadWaitDemo$Restaurant.run(ThreadWaitDemo.java:105)
13        - locked <0x00000000d63bfd00> (a java.util.LinkedList)
14...
15
  • jcmd pid GC.class_histgram:类统计信息,包括类名、实例个数、内存大小等。


1
2
3
4
5
6
7
8
9
10
11
12
13
1C:\Users\hanchao>jcmd 7484 GC.class_histogram
27484:
3
4 num     #instances         #bytes  class name
5----------------------------------------------
6   1:          6510         558304  [C
7   2:           716         458368  [B
8   3:          6365         152760  java.lang.String
9   4:           991         113016  java.lang.Class
10   5:           810          56856  [Ljava.lang.Object;
11   6:           835          33400  java.util.TreeMap$Entry
12   7:           817          26144  java.util.HashMap$Node
13
  • jcmd pid VM.flgs:获取启动参数


1
2
3
4
1C:\Users\hanchao>jcmd 7484 VM.flags
27484:
3-XX:CICompilerCount=3 -XX:InitialHeapSize=134217728 -XX:MaxHeapSize=2126512128 -XX:MaxNewSize=708837376 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=44564480 -XX:OldSize=89653248 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
4
  • jcmd pid GC.heap_dump dump.bin:将堆信息导入到项目根目录下的dump.bin文件中,以供其他分析工具进行分析。


1
2
3
4
1C:\Users\hanchao>jcmd 7484 GC.heap_dump dump.bin
27484:
3Heap dump file created
4
  • jcmd pid PerfCounter.print:获取性能相关参数。

给TA打赏
共{{data.count}}人
人已打赏
安全技术

用node.js做cluster,监听异常的邮件提醒服务

2021-12-21 16:36:11

安全技术

从零搭建自己的SpringBoot后台框架(二十三)

2022-1-12 12:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索