我正在尝试分析经常在数据库和休息调用中阻塞的情况。该代码不受 cpu 限制。以下示例 junit 方法应该可以说明该问题:
@RepeatedTest(10)
void fast() throws InterruptedException {
Thread.sleep(100);
}
@RepeatedTest(10)
void slow() throws InterruptedException {
// imagine a slow database or rest call or any other blocking code
Thread.sleep(1000);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 IntelliJ 和 Java Flight Recorder。我预计该方法fast将使用大约 10% 的执行时间,而该方法slow将使用大约 90% 的执行时间。但它们根本没有被报告,因为它们不占用 CPU 时间。
如何分析实际执行时间(包括阻塞代码中的等待时间而不仅仅是 CPU 时间)?