Java Flight Recorder (JFR) 是一种监视工具,可在应用程序执行期间收集有关 Java 虚拟机中特定时刻的事件(数据片段)的信息。
以下 JDK 版本本身支持 Java Flight Recorder:
-
Oracle JDK 8-10:前提
UnlockCommercialFeatures
是启用了VM 选项 -
Oracle JDK 11 及更高版本
-
OpenJDK 11 及更高版本
为 Oracle JDK 8 或更高版本启用 JFR
-
从主菜单中,选择运行 | 编辑配置并从左侧的列表中选择要使用 JFR 分析的运行配置。
-
在VM 选项字段中,添加以下行:
-XX:+UnlockCommercialFeatures
.该标志解锁了 Oracle Java SE Advanced 或 Oracle Java SE Suite 产品的商业特性。在启用它们之前,请仔细阅读JAVA SE 平台产品的 Oracle 二进制代码许可协议。
-
应用更改并关闭对话框。如下图:
JFR configurations
There are two pre-installed configurations: Default and Profile. The Default configuration has low overhead (about 1%). That's why it works well for continuous profiling. The Profile configuration has overhead about 2% and can be used for more detailed application profiling.
These configurations cover most use cases. You can select the most suitable configuration in Settings/Preferences | Build, Execution, Deployment | Java Profiler | Java Flight Recorder.
If the pre-defined configurations don't meet your needs, you can create and upload your own settings by means of Java Mission Control.
点击分析WordDao的main方法,如下图
默认分析结果会dump到home目录里面
不过这时候我们查看下面的Profiler窗口已经有结果了: