Java25 JFR 新增 Method Timing 和 Method Tracing 事件统计方法执行时间和堆栈
Java JFR About 1,436 words说明
We enhance default.jfc and profile.jfc with two new options, method-timing and method-trace, which control the filter settings for the MethodTiming and MethodTrace events.
method-timing
The method-timing option counts the number of invocations and calculates the average execution time of methods that match the filter
method-trace
the method-trace option records stack traces for methods that match the filter
MethodTiming
启动参数
java -XX:StartFlightRecording:method-timing=@org.springframework.web.bind.annotation.RestController,jdk.MethodTiming#period=5s -jar app.jar
查看信息
jcmd.exe <pid> JFR.view method-timing
MethodTrace
启动参数
java -XX:StartFlightRecording:method-trace=@org.springframework.web.bind.annotation.RestController -jar app.jar
查看信息
jcmd.exe <pid> JFR.view jdk.MethodTracing
过滤语法
可以指定注解、全路径类名、全路径方法名、通配方法名等。
可以指定多个过滤条件,以;分割
filter ::= target (";" target)*
target ::= class | class-method | method | annotation
class ::= identifier ("." identifier)*
class-method ::= class method
method ::= "::" method-name
method-name ::= identifier | "<clinit>" | "<init>"
annotation ::= "@" class
identifier ::= see JLS §3.8
示例:采集Spring Boot中的RestController注解标注的类中的所有方法,以及所有类的静态初始化方法。
java -XX:StartFlightRecording:method-trace=@org.springframework.web.bind.annotation.RestController;::<clinit> -jar app.jar
JEP 520
JDK25 更多 JFR 更新
https://egahlin.github.io/2025/05/31/whats-new-in-jdk-25.html
Views: 7 · Posted: 2026-01-02
———         Thanks for Reading         ———
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...