一个有用的命令jcmd

提要

jcmd 在安装 jdk 时已经安装,用于向本地jvm进程发送诊断命令

帮助

[root@p-finsettle03 apps]# 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

查看正在运行的 Java 进程ID、名称和 main 函数参数

ps:28384 进程是jcmd本身。执行完jcmd后,该进程已经结束了。

[root@p-finsettle03 apps]# jcmd
28384 sun.tools.jcmd.JCmd
1010 /apps/financial-management-datacentre-0.0.1-SNAPSHOT.jar --spring.profiles.active=prd
27716 ./financial-management-admin-0.0.1-SNAPSHOT.jar --spring.profiles.active=prd

查看某个进程支持的命令

ps:在jcmd 后加上进程 ID,然后加上 help 。

[root@p-finsettle03 apps]# jcmd 1010 help
1010:
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
VM.classloader_stats
GC.rotate_log
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.finalizer_info
GC.heap_info
GC.run_finalization
GC.run
VM.uptime
VM.dynlibs
VM.flags
VM.system_properties
VM.command_line
VM.version
help

For more information about a specific command use 'help <command>'.

当然jcmd 后也可以跟上进程名,但是比较麻烦,我反正不喜欢

查看某个进程的 JVM 版本

jcmd 1010 VM.version

查看 JVM 进程信息

jcmd 1010 VM.info

建议进程进行垃圾回收

jcmd 1010 GC.run

获取类的统计信息

ps:可以看到类名、对象数量、占用空间等。

jcmd 1010 GC.class_histogram | more

获取启动参数

jcmd 1010 VM.flags

获取进程到现在运行了多长时间

jcmd 1010 VM.uptime

查看线程信息

jcmd 1010 Thread.print

获取性能相关数据

jcmd 1010 PerfCounter.print

导出堆快照到当前目录

jcmd 1010 GC.heap_dump $PWD/heap.dump

参考地址

猜你喜欢

转载自blog.csdn.net/qq_35868811/article/details/112845570
今日推荐