以编程方式即时启动 Java HPROF 分析器
我试图在满足某些运行时条件时有选择地监视/分析 Java 应用程序。我已经能够使用 HotSpotDiagnosticMXBean,这非常有用。
我现在正在尝试对 CPU 分析进行类似的操作,希望更有效地针对特定的代码路径。我对命令行有一些经验HPROF 接口 和 NetBeans 分析器,但两者都需要事先启动。
有没有办法从正在运行的应用程序中以编程方式激活 HPROF 分析器?最好是允许我随意启动和停止分析过程的东西?
I am trying to selectively monitor/profile a Java application when certain runtime conditions are met. I am already able to dump the heap on-the-fly using the HotSpotDiagnosticMXBean, which has been quite useful.
I am now trying to do something similar with CPU profiling, hoping to more effectively target specific code paths. I have some experience with the command-line HPROF interface and the NetBeans profiler, but both need to be started beforehand.
Is there a way to activate the HPROF profiler programatically from within a running application? Preferably something that would allow me to start and stop the profiling process at will?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 JVMTI 文档,本机像 hprof 这样的代理库必须在 JVM 初始化期间、在执行任何字节码之前加载。所以不,不可能即时执行此操作。
另一种方法是在主函数中使用修改后的 JVM 参数重新启动 java 进程,尽管这并不简单。
According to the JVMTI documentation, native agent libraries like hprof must be loaded very early during the JVM initialization, before any bytecode is executed. So no, it is not possible to do this on-the-fly.
An alternative could be to re-launch the java process with modified JVM parameters within the main function, although this is not trivial.