Java 如何使用visualvm分析应用程序启动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4434860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to profile application startup with visualvm
提问by pstanton
As far as i can tell, you can only profile a running application using VisualVM.
据我所知,您只能使用 VisualVM 分析正在运行的应用程序。
Does anyone know of a way to profile the launch and startup of a java application using VisualVM?
有谁知道使用 VisualVM 来分析 Java 应用程序的启动和启动的方法吗?
I'm convinced there must be a way, otherwise it would be a major oversight.
我相信一定有办法,否则这将是一个重大的疏忽。
Hoping I've just misread the documentation.
希望我只是误读了文档。
Thanks, p.
谢谢,第。
采纳答案by skaffman
Are you setting up the profiling using the `-Xrunjdwp" command-line option? If so, that option has a "suspend" parameterfor just this purpose:
您是否使用`-Xrunjdwp”命令行选项设置分析?如果是这样,该选项有一个“挂起”参数用于此目的:
True if the target VM is to be suspended immediately before the main class is loaded; false otherwise.
如果在加载主类之前立即挂起目标 VM,则为真;否则为假。
Example from my own config:
来自我自己的配置示例:
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
I use this with the YourKit profiler, but I think the principle is the same.
我将它与 YourKit 分析器一起使用,但我认为原理是相同的。
回答by Robert
Both common Java development environments (NetBeans/Eclipse) support application execution directly with attached VisualVM. In case of Eclipse you have to install a plugin. In case of NetBeans the support is AFAIK already integrated.
Even if do not have the sources you can still run the JAR file(s) via both environments and therefore start your app connected with VisualVM.
两种常见的 Java 开发环境 (NetBeans/Eclipse) 都支持通过附加的 VisualVM 直接执行应用程序。在 Eclipse 的情况下,您必须安装插件。对于 NetBeans,已集成 AFAIK 支持。
即使没有源,您仍然可以通过两种环境运行 JAR 文件,从而启动与 VisualVM 连接的应用程序。
回答by KarlP
Use the eclipse launcher, and set a breakpoint at an appropriate place in the main method.
使用 eclipse 启动器,并在 main 方法中的适当位置设置断点。
Then, start in debug mode, enable profiling in visualVM, and then resume using eclipse.
然后,以调试模式启动,在visualVM 中启用分析,然后继续使用eclipse。
That won't profile class loading and stuff, but it's good enough for me.
这不会分析类加载和内容,但对我来说已经足够了。
回答by Haim Raman
I found Startup Profilerhelpful:
我发现Startup Profiler很有帮助:
Startup Profiler plugin for VisualVM 1.3.6 enables instrumented profiling of local Java 5+ applications from their startup. It is also helpful when profiling short-running processes.
VisualVM 1.3.6 的 Startup Profiler 插件支持从本地 Java 5+ 应用程序启动时对其进行检测分析。在分析短期运行的进程时也很有帮助。