JFR 查看命令 - Sip of Java
Billy Korando 于 2023 年 9 月 26 日
Java 21 中添加了新的 JFR view
命令,提供了一种无需下载记录并在 JDK Mission Control 等工具中打开记录即可从命令行分析 JFR 记录的方法。我们来看看如何使用新的 JFR 查看命令。
使用 JFR 查看命令
可以通过 jfr
命令行工具和 jcmd
工具访问 JFR 查看。
JFR 工具
JFR 查看可以使用 jfr
工具,其模式如下
$ jfr view [view] [recording file]
JCMD 工具
JFR 查看可以使用 jcmd
工具,其模式如下
$ jcmd [pid] JFR.view [view]
查看选项
JFR 查看命令的初始版本提供了 70 多种不同的查看选项,未来这个数字可能会增加。每个视图都提供了从应用程序级别到 JVM 再到环境的堆栈的不同视角。
Java virtual machine views:
class-modifications gc-concurrent-phases longest-compilations
compiler-configuration gc-configuration native-memory-committed
compiler-phases gc-cpu-time native-memory-reserved
compiler-statistics gc-pause-phases safepoints
deoptimizations-by-reason gc-pauses tlabs
deoptimizations-by-site gc-references vm-operations
gc heap-configuration
Environment views:
active-recordings cpu-information jvm-flags
active-settings cpu-load native-libraries
container-configuration cpu-load-samples network-utilization
container-cpu-throttling cpu-tsc recording
container-cpu-usage environment-variables system-information
container-io-usage events-by-count system-processes
container-memory-usage events-by-name system-properties
Application views:
allocation-by-class exception-count native-methods
allocation-by-site file-reads-by-path object-statistics
allocation-by-thread file-writes-by-path pinned-threads
class-loaders finalizers socket-reads-by-host
contention-by-address hot-methods socket-writes-by-host
contention-by-class latencies-by-type thread-allocation
contention-by-site longest-class-loading thread-count
contention-by-thread memory-leaks-by-class thread-cpu-load
exception-by-message memory-leaks-by-site thread-start
exception-by-site modules
视图可以使用此示例
$ jfr view thread-count [recording-file]
修改视图输出
有几个选项可以修改从 JFR 查看返回的数据的格式
--width [number-of-columns]
--cell-height [number of rows]
--verbose
--truncate beginning
这些选项需要在视图之前提供,如下例所示
$ jfr view --width 40 thread-count recording.jfr
Output:
Java Thread Statistics
Time Acti... Daem... Accu... Peak...
------- ------- ------- ------- -------
21:4... 26 22 145 34
其他阅读材料
编码愉快!