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

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


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

1.用途

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

2.语法

Usage: jcmd <pid | main class> <command ...|PerfCounter.print|-f file>
   or: jcmd -l
   or: jcmd -h

  command must be a valid jcmd command for the selected jvm.
  Use the command "help" to see which commands are available.
  If the pid is 0, commands will be sent to all Java processes.
  The main class argument will be used to match (either partially
  or fully) the class used to start Java.
  If no options are given, lists Java processes (same as -p).

  PerfCounter.print display the counters exposed by this process
  -f  read and execute commands from the file
  -l  list JVM processes on the local machine
  -h  this help
  • h:帮助。
  • l:显示当前机器上的进程,包括进程id、主类全路径名、main方法参数,等同于jps -ml
  • f:从文件读取并执行命令。
  • PerfCounter.print:打印性能计数器信息。
  • help:显示当前JVM进程可用的命令。
C:\Users\hanchao>jcmd 7484 help
7484:
The following commands are available:
JFR.stop
JFR.start
JFR.dump
JFR.check
VM.native_memory
VM.check_commercial_features
VM.unlock_commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
GC.rotate_log
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help

3.常用命令示例

  • jcmd pid VM.uptime:VM启动时间
C:\Users\hanchao>jcmd 7484 VM.uptime
7484:
5783.212 s
  • jcmd pid VM.system_properties:VM系统属性
C:\Users\hanchao>jcmd 7484 VM.system_properties
7484:
#Tue May 08 23:22:22 CST 2018
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C\:\\Program Files\\Java\\jdk1.8.0_131\\jre\\bin
java.vm.version=25.131-b11
java.vm.vendor=Oracle Corporation
java.vendor.url=http\://java.oracle.com/
...
  • jcmd pid Thread.print打印线程信息
C:\Users\hanchao>jcmd 7484 Thread.print
7484:
2018-05-08 23:23:13
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode):

"DestroyJavaVM" #13 prio=5 os_prio=0 tid=0x00000000047a3800 nid=0x3a8 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Thread-1" #12 prio=5 os_prio=0 tid=0x000000001ab7b800 nid=0xe64 waiting on condition [0x000000001bd7f000]
   java.lang.Thread.State: TIMED_WAITING (sleeping)
        at java.lang.Thread.sleep(Native Method)
        at pers.hanchao.concurrent.eg04.ThreadWaitDemo$Restaurant.run(ThreadWaitDemo.java:105)
        - locked <0x00000000d63bfd00> (a java.util.LinkedList)
...
  • jcmd pid GC.class_histgram:类统计信息,包括类名、实例个数、内存大小等。
C:\Users\hanchao>jcmd 7484 GC.class_histogram
7484:

 num     #instances         #bytes  class name
----------------------------------------------
   1:          6510         558304  [C
   2:           716         458368  [B
   3:          6365         152760  java.lang.String
   4:           991         113016  java.lang.Class
   5:           810          56856  [Ljava.lang.Object;
   6:           835          33400  java.util.TreeMap$Entry
   7:           817          26144  java.util.HashMap$Node
  • jcmd pid VM.flgs:获取启动参数
C:\Users\hanchao>jcmd 7484 VM.flags
7484:
-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
  • jcmd pid GC.heap_dump dump.bin:将堆信息导入到项目根目录下的dump.bin文件中,以供其他分析工具进行分析。
C:\Users\hanchao>jcmd 7484 GC.heap_dump dump.bin
7484:
Heap dump file created
  • jcmd pid PerfCounter.print:获取性能相关参数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值