jcmd是一款命令行工具,可以监控jvm虚拟机性能和诊断问题。
GC.class_stats
如果报错:
GC.class_stats command requires -XX:+UnlockDiagnosticVMOptions
在启动脚本中添加参数:
-XX:+UnlockDiagnosticVMOptions
内容太多了,只选前10换行吧
jcmd 25274 GC.class_stats | head
25274:
Index Super InstBytes KlassBytes annotations CpAll MethodCount Bytecodes MethodAll ROAll RWAll Total ClassName
1 -1 12764600 480 0 0 0 0 0 24 584 608 [C
2 10302 5398800 1112 0 5600 40 847 20904 4224 24072 28296 java.lang.reflect.Method
3 18 3961152 568 0 1376 8 223 1744 1032 2976 4008 java.util.concurrent.ConcurrentHashMap$Node
4 18 3175992 624 0 8784 94 4623 51968 12144 50312 62456 java.lang.String
5 18 2488704 632 0 2280 10 248 4760 1640 6400 8040 org.aspectj.weaver.reflect.ShadowMatchImpl
jcmd 25274 Thread.print
也来一段输出吧,根本看不懂。
"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007f4b2814b800 nid=0x62cc in Object.wait() [0x00007f4b08513000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
- locked <0x00000000c03a3948> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:212)
"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f4b28147000 nid=0x62cb in Object.wait() [0x00007f4b08614000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
- locked <0x00000000c03a2e88> (a java.lang.ref.Reference$Lock)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
"VM Thread" os_prio=0 tid=0x00007f4b2813f800 nid=0x62ca runnable
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f4b2801f800 nid=0x62c4 runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f4b28021000 nid=0x62c6 runnable
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f4b28023000 nid=0x62c8 runnable
"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00007f4b28025000 nid=0x62c9 runnable
jcmd 25274 GC.run
对25274进程手动进行垃圾回收。
这个倒是简单,一般都是返回成功。
jcmd 25274 GC.run
返回内容:
25274:
Command executed successfully
怎么感觉只有这个命令能用的上,其他的根本看不懂。
其他
文档(命令行)
这文档可够简洁的。
jcmd -h
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