JVisualVM 如何启动和停止 CPU 分析?
How does JVisualVM start and stop CPU profiling?
我想在我的应用程序中添加一个选项,最终用户可以在其中开始 CPU 分析、重现性能问题、停止 CPU 分析,然后将分析信息发送给我们的支持团队作为电子邮件的附件。我希望我可以使用 JVisualVM 用来停止和启动分析以及 return 结果的相同机制。
有人知道 JVisualVM 是如何做到这一点的吗?它不需要在命令行上设置 -agentlib:hprof 选项 - 它使用 hprof 还是其他机制?
该工具使用动态检测。
When the CPU button in Profiler tab is pressed, the profiler attaches to the application and starts profiling its performance. At the beginning the profiler needs to instrument some methods of the application, the actual number of instrumented methods is displayed in the Status area. Since the profiler uses dynamic instrumentation, the number of instrumented methods may change during the profiling session. After the profiler is attached and starts collecting the data...
https://blogs.oracle.com/nbprofiler/entry/profiling_with_visualvm_part_1
JVisualVM 通过使用 JMX 命令动态添加代理来检测代码。这实现起来并不容易。您可能会发现 JVisualVM 有一个 API,如果是这样我会使用它而不是尝试自己实现它。如果它没有 public API 而我怀疑它没有,我建议尝试一些更简单的方法。
我想在我的应用程序中添加一个选项,最终用户可以在其中开始 CPU 分析、重现性能问题、停止 CPU 分析,然后将分析信息发送给我们的支持团队作为电子邮件的附件。我希望我可以使用 JVisualVM 用来停止和启动分析以及 return 结果的相同机制。
有人知道 JVisualVM 是如何做到这一点的吗?它不需要在命令行上设置 -agentlib:hprof 选项 - 它使用 hprof 还是其他机制?
该工具使用动态检测。
When the CPU button in Profiler tab is pressed, the profiler attaches to the application and starts profiling its performance. At the beginning the profiler needs to instrument some methods of the application, the actual number of instrumented methods is displayed in the Status area. Since the profiler uses dynamic instrumentation, the number of instrumented methods may change during the profiling session. After the profiler is attached and starts collecting the data...
https://blogs.oracle.com/nbprofiler/entry/profiling_with_visualvm_part_1
JVisualVM 通过使用 JMX 命令动态添加代理来检测代码。这实现起来并不容易。您可能会发现 JVisualVM 有一个 API,如果是这样我会使用它而不是尝试自己实现它。如果它没有 public API 而我怀疑它没有,我建议尝试一些更简单的方法。