JFR文件导出

一.通过端口找到java程序对应的pid

netstat -anlp|grep 8081

二.查看jcmd可用的指令

[root@bes01 ~]# jcmd 2169858 help
2169858:
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
VM.class_hierarchy
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.finalizer_info
GC.heap_info
GC.run_finalization
GC.run
VM.info
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>'.

三.解锁JVM商业特性,使其可以使用JFR这样的高级诊断工具

[root@bes01 ~]# jcmd 2169858 VM.unlock_commercial_features
2169858:
Commercial Features now unlocked.

四.接下来有两种采集方式,

一种是开着采,采集一段时间后,手动从dump中导出jfr报告,并关闭采集(记录)

1.启动采集

[root@bes01 ~]# jcmd 2169858 JFR.start
2169858:
Started recording 3. No limit (duration/maxsize/maxage) in use.
Use JFR.dump recording=3 filename=FILEPATH to copy recording data to file.
####告诉你现在开始将记录数据写到dump文件中,并且记录的ID为3####

2.将dump文件转成jfr文件

[root@bes01 ~]# jcmd 2169858 JFR.dump recording=3 filename=/home/bes/yhadmin-20250523-1427.jfr
2169858:
Dumped recording 3, 11.3 MB written to:
/home/bes/yhadmin-20250523-1427.jfr
####如果忘记有没有在采集数据,可以用命令行查一下
[root@bes01 ~]# jcmd 2169858 JFR.check
2169858:
Recording: recording=3 name="Recording 3" (running)

3.关闭采集(切记,避免生产磁盘打爆掉)

[root@bes01 ~]# jcmd 2169858 JFR.stop recording=3
2169858:
Stopped recording 3.

一种是采集一段时间,自动生成报告

[root@bes01 ~]# jcmd 2169858 JFR.start duration=20s filename=/home/bes/yhadmin-20250523-1446.jfr
2169858:
Started recording 13. The result will be written to:
/home/bes/yhadmin-20250523-1446.jfr
[root@bes01 ~]# ls /home/bes/
yhadmin-20250523-1446.jfr
posted @ 2025-05-23 14:50  海yo  阅读(59)  评论(0)    收藏  举报