背景
IntelliJ IDEA
与以下分析工具集成:
Async Profiler
:适用于 Linux 和 macOS 的 CPU 和内存分析工具。Java Flight Recorder
:Oracle 提供的 CPU 工具,可在 Linux、macOS 和 Windows 上使用。
使用简介
public class Demo {
public static void main(String[] args) {
for (int i = 0; i < 10000000; i++) {
System.out.println(produceString());
}
}
private static String produceString() {
return "Hello World";
}
}
选择 【Run 'xxx' with 'Java Flight Recorder'
】
Run 'xxx' with 'Java Flight Recorder'
会出现如下错误:
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Error: To use 'FlightRecorder', first unlock using -XX:+UnlockCommercialFeatures.
在 VM options 中添加 -XX:+UnlockCommercialFeatures
参数。
以上配置完之后,再执行代码。然后在【Profiler】窗口点击【Stop Profiling and Show Results】
然后就可以看到结果。
Profiler 展示图表
1. Flame Graph(火焰图)
Flame Graph
2. Call Tree(调用树)
Call Tree
3. Method List(方法列表)
Method List
F4
调转到源码: