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的更多相关文章

  1. Java7的新特性

    原文出处:xixicat 序 本文主要讲Java7的新特性,相对于Java6而言,Java7增加了一些重要的特性,比如NIO2,不像Java6那么鸡肋,也算是一个重要的版本. 特性列表 suppres ...

  2. java性能监控工具jcmd-windows

    jcmd Sends diagnostic command requests to a running Java Virtual Machine (JVM). Synopsis jcmd [-l|-h ...

  3. java 历年版本特征(简化)

     无论是学习任何新知识,我都是从历史的角度着手,这让我对这些新知识是如何孕育出来的,有一个很好的理解 只从java 5-8,之后我也开始转nodejs了,感谢java伴随的这几年 Java5的新特性 ...

  4. ASP.NET Aries JSAPI 文档说明:AR.Utility

    AR.Utility 文档 1:方法: 名称 说明 queryString function (key) *模拟.NET的Request对象 stringFormat function (str, a ...

  5. UNITY自带的PACKAGE的UTILITY 里面有一个自带的FPS COUNTER

    UNITY自带的PACKAGE的UTILITY 里面有一个自带的FPS COUNTER 可用,但是脚本是保密的?

  6. Top 15 Java Utility Classes

    In Java, a utility class is a class that defines a set of methods that perform common functions. Thi ...

  7. nginx负载均衡基于ip_hash的session粘帖

    nginx负载均衡基于ip_hash的session粘帖 nginx可以根据客户端IP进行负载均衡,在upstream里设置ip_hash,就可以针对同一个C类地址段中的客户端选择同一个后端服务器,除 ...

  8. [转帖]网络协议封封封之Panabit配置文档

    原帖地址:http://myhat.blog.51cto.com/391263/322378

  9. [转帖]零投入用panabit享受万元流控设备——搭建篇

    原帖地址:http://net.it168.com/a2009/0505/274/000000274918.shtml 你想合理高效的管理内网流量吗?你想针对各个非法网络应用与服务进行合理限制吗?你是 ...

  10. 3d数学总结帖

    3d数学总结帖,以下是对3d学习过程中数学知识的简单总结 角度值和弧度制的互转 Deg2Rad 角度A1转弧度A2 => A2=A1*PI/180 Rad2Deg 弧度A2转换角度A1 => ...

随机推荐

  1. 华为云 UCS GitOps:轻松交付多集群云原生应用

    摘要:使用华为云 UCS GitOps 配置管理来交付您的多云应用. 本文分享自华为云社区<华为云 UCS GitOps:轻松交付多集群云原生应用>,作者:华为云云原生团队. 随着业务的全 ...

  2. 云图说|云数据库GaussDB如何做到卓越性能

    摘要:对于数据库来说,性能一直被视为最关键的部分.GaussDB作为华为自主创新研发的分布式关系型数据库,那么华为云数据库GaussDB在提升数据库性能方面都有哪些黑科技呢? 本文分享自华为云社区&l ...

  3. 二进制SCA指纹提取黑科技:Go语言逆向技术

    摘要:SCA(Software Composition Analysis)软件成分分析,指通过对软件源码.二进制软件包等的静态分析,挖掘其所存在的开源合规.已知漏洞等安全合规风险,是一种业界常见的安全 ...

  4. “pip不是内部或外部命令,也不是可运行的程序或批处理文件” 到底有多么神秘

    摘要:pip不是内部或外部命令,也不是可运行的程序或批处理文件到底有多么神秘? 本文分享自华为云社区<揭开「pip不是内部或外部命令,也不是可运行的程序或批处理文件」的神秘面纱>,作者:A ...

  5. Intellij IDEA、 Pycharm 格式化换行,竖线修改 最大 分隔 线

    Intellij IDEA. Pycharm 等开发工具,超过 竖线,Ctrl + L 格式化时,就会换行 格式化后,现在的显示器分辨率高,这样右边一大片空白,看起来很不舒服 File -> S ...

  6. pytest+request+allure生成测试报告

    基本流程 模拟数据 url,paras,method,except http://www.baidu.com, {k=12}, get, 200 请求url (接口文档) 参数 请求方法 预期返回响应 ...

  7. django中间件需要了解的方法 importlib模块 csrf校验策略 csrf相关装饰器

    目录 django中间件三个需要了解的方法 process_view process_exception process_template_response 基于django中间件实现功能的插拔式设计 ...

  8. Codeforces Round #738 (Div. 2) (A~E)

    比赛链接:Here 1559A. Mocha and Math 题意: 给定一个区间,选择区间内的值执行 & 操作使得区间最大值最小化 观察样例发现:令 x = (1 << 30) ...

  9. AtCoder Beginner Contest 188 题解

    AtCoder Beginner Contest 188 A,B很简单就不多说 C - ABC Tournament 找出前一半的最大值和后一半的最大值,二者中较小的那一个对应的序号就是最后的答案. ...

  10. 制作PE工具箱

    事前准备: 能上网的电脑 x1 台 大于8G的U盘 x一个(如果需要储存安装镜像的话,如果不需要的话大于1G即可) 一.下载PE工具箱 推荐使用WEPE工具箱,无广告无推广.不推荐老X桃,大X菜,大X ...