[转帖]2.6 The jcmd Utility

the,jcmd,utility · 浏览次数 : 0

小编点评

**jcmd Utility for Java Application Troubleshooting** **Overview:** The `jcmd` utility is a command-line tool for troubleshooting and monitoring Java applications. It allows users to send diagnostic commands to the Java Virtual Machine (JVM), providing insights into the application's performance, memory usage, and other aspects. **Key Features:** * Send diagnostic commands to the JVM. * Provides various options for troubleshooting and diagnostics. * Offers commands for starting, stopping, checking, and creating heap dumps. * Displays system properties and flags for a VM. **Usage:** To start a recording, use the `JFR.start` command: ``` jcmd 7060 JFR.start name=MyRecording settings=profile delay=20s duration=2m filename=C:\\TEMP\\myrecording.jfr ``` To check the status of a recording, use the `JFR.check` command: ``` jcmd 7060 JFR.check ``` To stop a recording, use the `JFR.stop` command: ``` jcmd 7060 JFR.stop ``` To create a heap dump, use the `GC.class_histogram` command: ``` jcmd GC.class_histogram filename=Myheaphistogram ``` **Additional Options:** * `-l`: Prints information about java.util.concurrent locks. * `-h`: Displays hot spot VM details. * `-f`: Displays heap dump information. * `-v`: Verbose output. * `-i`: Informative output. **Benefits:** * Provides deep insights into JVM performance and memory usage. * Helps identify bottlenecks and performance issues. * Facilitates troubleshooting and debugging. * Allows for capturing and analyzing heap dumps for further analysis. **Note:** The `jcmd` utility requires the `management-permission` to be set for the user running the command.

正文

https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html#BABEJDGE

 

The jcmd utility is used to send diagnostic command requests to the JVM, where these requests are useful for controlling Java Flight Recordings, troubleshoot, and diagnose JVM and Java Applications. It must be used on the same machine where the JVM is running, and have the same effective user and group identifiers that were used to launch the JVM.

For more details on jcmd syntax and other usage details, see the jcmd command man page.

A special command jcmd <process id/main class> PerfCounter.print prints all performance counters in the process.

The command jcmd <process id/main class> <command> [options] sends the actual command to the JVM.

Example 2-1 shows diagnostic command requests to JVM using jcmd utility.

Example 2-1 Diagnostic Command Requests with jcmd Utility

> jcmd
5485 sun.tools.jcmd.JCmd
2125 MyProgram
 
> jcmd MyProgram help (or "jcmd 2125 help")
2125:
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
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
 
> jcmd MyProgram help Thread.print
2125:
Thread.print
Print all threads with stacktraces.
 
Impact: Medium: Depends on the number of threads.
 
Permission: java.lang.management.ManagementPermission(monitor)
 
Syntax : Thread.print [options]
 
Options: (options must be specified using the <key> or <key>=<value> syntax)
        -l : [optional] print java.util.concurrent locks (BOOLEAN, false)
 
> jcmd MyProgram Thread.print
2125:
2014-07-04 15:58:56
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.0-b69 mixed mode):
...

The following sections describe some useful commands and troubleshooting techniques with jcmd utility.

2.6.1 Useful Commands for jcmd Utility

The available diagnostic command may be different in different versions of HotSpot VM; therefore, using jcmd <process id/main class> help is the best way to see all available options. The following are some of the most useful commands that were in the tool since JDK 8. Remember you can always use jcmd <process id/main class> help <command> to get any additional options to these commands.

  • Print full HotSpot and JDK version ID

    jcmd <process id/main class> VM.version

  • Print all the system properties set for a VM

    There can be several hundred lines of information displayed.

    jcmd <process id/main class> VM.system_properties

  • Print all the flags used for a VM

    Even if you have provided no flags, some of the default values will be printed, for example initial and maximum heap size.

    jcmd <process id/main class> VM.flags

  • Print the uptime in seconds

    jcmd <process id/main class> VM.uptime

  • Create a class histogram

    The results can be rather verbose, so you can redirect the output to a file. Both internal and application specific classes are included in the list. Classes taking the most memory are listed at the top, and classes are listed in a descending order.

    jcmd <process id/main class> GC.class_histogram

  • Create a heap dump (hprof dump)

    jcmd GC.heap_dump filename=Myheapdump

    This is the same as using jmap -dump:file=<file> <pid>, but jcmd is the recommended tool to use.

  • Create a heap histogram

    jcmd <process id/main class> GC.class_histogram filename=Myheaphistogram

    This is the same as using jmap -histo <pid>, but jcmd is the recommended tool to use.

  • Print all threads with stack traces

    jcmd <process id/main class> Thread.print

2.6.2 Troubleshoot with jcmd Utility

The jcmd utility provides the following troubleshooting options:

  • Start a recording

    For example, to start a 2-minute recording on the running Java process with the identifier 7060 and save it to myrecording.jfr in the current directory, use the following:

    jcmd 7060 JFR.start name=MyRecording settings=profile delay=20s duration=2m filename=C:\TEMP\myrecording.jfr

  • Check a recording

    The JFR.check diagnostic command checks a running recording. For example:

    jcmd 7060 JFR.check

  • Stop a recording

    The JFR.stop diagnostic command stops a running recording and has the option to discard the recording data. For example:

    jcmd 7060 JFR.stop

  • Dump a recording

    The JFR.dump diagnostic command stops a running recording and has the option to dump recordings to a file. For example:

    jcmd 7060 JFR.dump name=MyRecording filename=C:\TEMP\myrecording.jfr

  • Create a heap dump

    The preferred way to create a heap dump is

    jcmd <pid> GC.heap_dump filename=Myheapdump

  • Create a heap histogram

    The preferred way to create a heap histogram is

    jcmd <pid> GC.class_histogram filename=Myheaphistogram

与[转帖]2.6 The jcmd Utility相似的内容:

[转帖]2.6 The jcmd Utility

https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html#BABEJDGE The jcmd utility is used to send diagnostic command req

[转帖]MySQL Performance : 8.0 and UTF8 impact

http://dimitrik.free.fr/blog/posts/mysql-performance-80-and-utf8-impact.html 2018-04-26 00:58 | MySQL, Performance, UTF8 by Dimitri The world is movin

[转帖]Redis-6.2.x版本官方发行说明(附谷歌翻译)【持续更新】

https://www.yii666.com/blog/12891.html 一、前言 本文只是单纯地翻译Redis官方的6.2.x版本的发行说明,不会对发行说明内容做任何改动,读者如果觉得有异议,可自行去Redis官网相关网页查阅。翻译工具翻译出来的不一定百分百准确,英语好的人别喷,大家都是英语差

[转帖]2. 扩展插件概述

https://help.kingbase.com.cn/v8.6.7.12/development/sql-plsql/ref-extended-plug-in/plug-in.html KingbaseES开发了大量的扩展包。如:dbms_output,dbms_ddl,dbms_metadat

[转帖]【redis】redis各稳定版本特性(更新到6.0版本)

1.Redis2.6 Redis2.6在2012年正是发布,经历了17个版本,到2.6.17版本,相对于Redis2.4,主要特性如下: 1)服务端支持Lua脚本。 2)去掉虚拟内存相关功能。 3)放开对客户端连接数的硬编码限制。 4)键的过期时间支持毫秒。 5)从节点支持只读功能。 6)两个新的位

[转帖]redis惰性删除 lazy free 源码剖析,干货满满

目录 前言 数据删除场景 lazy free 概念 配置 源码剖析(版本 6.2.6) 场景一:客户端执行的显示删除/清除命令 场景二:某些指令带有的隐式删除命令 场景三:删除过期数据 场景四:内存淘汰数据删除 场景五:主从同步清空从库 小结 前言 都说 redis 是单线程的,其实并不是说 red

[转帖]Redis里使用Lua

http://me.52fhy.com/lua-book/chapter11.html 版本:自2.6.0起可用。 时间复杂度:取决于执行的脚本。 使用Lua脚本的好处: 减少网络开销。可以将多个请求通过脚本的形式一次发送,减少网络时延。 原子操作。redis会将整个脚本作为一个整体执行,中间不会被

[转帖]sar -Linux 上全面的系统性能分析工具(2)

https://zhuanlan.zhihu.com/p/554619823 sar -b[ <时间间隔> [ <次数> ] ] 示例: sar -b 1 3 Linux 2.6.32-696.13.2.el6.x86_64 (upfor163) 2018年04月25日 _x86_64_ (2 CP

[转帖]正则表达式及在Jmeter中的应用

目录 1.正则表达式 1.1 什么是正则表达式 1.2 为什么使用正则表达式 2.语法 2.1 普通字符 2.2 限定符 2.3 非打印字符 2.4 特殊字符 2.5 定位符 2.6 修饰符(标记) 2.7 选择 2.8 运算符优先级 3.常用正则表达式及在线工具 4.Jmeter之正则表达式提取器

[转帖]Oracle优化案例:vfs_cache_pressure和min_free_kbytes解决RMAN挂起问题

https://www.modb.pro/db/34028 环境: Oracle 11gr2 + dataguard 512GB内存 + 128核cpu + 高性能存储服务器 uname -an Linux dbhost 2.6.18-238.el5 #1 SMP Sun Dec 19 14:22: