简体   繁体   English

使用VisualVM分析应用程序

[英]Profiling application with VisualVM

Imagine you have command-line application that takes input file and does something with it. 想象一下,你有一个命令行应用程序,它接受输入文件并用它做一些事情。 Now imagine you want to sample/profile this application. 现在假设您想要对此应用程序进行采样/配置。 If it were Visual Studio you would just select profiling method (sampling/instrumentation) and VS would run application for you and collect data while program completes. 如果它是Visual Studio,您只需选择分析方法(采样/检测),VS将为您运行应用程序并在程序完成时收集数据。 But as far as I can see there is no similar functionality in VisualVM. 但据我所知,VisualVM中没有类似的功能。 You have to run your application, then select it in VisualVM and then explicitly start sampling/profiling. 您必须运行您的应用程序,然后在VisualVM中选择它,然后显式开始采样/分析。 The problem is that sometimes execution of program with certain input data takes less time than it is required to setup VisualVM. 问题是,有时使用某些输入数据执行程序所需的时间比设置VisualVM所需的时间短。 Also with such an approach there is no possibility to batch profile application. 使用这种方法也不可能批量配置应用程序。 Someone has suggested to start application in debug mode from Eclipse and set breakpoint somewhere in the beginning of main() method. 有人建议从Eclipse开始以调试模式启动应用程序,并在main()方法的开头某处设置断点。 Then setup VisualVM and continue execution. 然后设置VisualVM并继续执行。 But I have suspicion that running in Debug vs Release mode has performance implications on its own. 但我怀疑在Debug vs Release模式下运行会对其自身产生性能影响。 Suggestions? 建议?

If the program does I/O, the Visual Studio sampler will not see the I/O because it is a "CPU Sampler" (even if nearly all of the time is spent waiting for I/O). 如果程序执行I / O,则Visual Studio采样器将看不到I / O,因为它是“CPU采样器”(即使几乎所有时间都花在等待I / O上)。

If you use Instrumentation, you won't see any line-level information because it only summarizes at the function level. 如果使用“检测”,则不会看到任何行级信息,因为它仅在功能级别进行汇总。

I use this technique . 我用这种技术

If the program runs too quickly to sample, just put a temporary outer loop around it of, say, 100 or 1000 iterations. 如果程序运行得太快而无法采样,只需在其周围放置一个临时外环,比如100或1000次迭代。

The difference between Debug and Release mode will be next to nothing unless you are spending a good fraction of time in tight loops, in your code , where the loops do not contain any function calls, OR if you are doing data structure operations that do a lot of validation in the libraries. 调试和发布模式之间的区别几乎没有,除非您在紧密循环中花费很长一段时间, 在代码中 ,循环不包含任何函数调用,或者如果您正在执行数据结构操作库中有很多验证。

If you are, then your samples will show that you are, and you will know that Release will make a speed difference. 如果你是,那么你的样品将证明你是,并且你会知道Release会产生速度差异。

As far as batch profiling is concerned, I don't. 就批量分析而言,我不这样做。 I just keep an eye on the program's overall throughput rate. 我只关注该计划的整体吞吐率。 If there is some input that seems to make it take too long, then I do the sampling procedure on the program with that input, see what the problem is, and fix it. 如果有一些输入似乎需要花费太长时间,那么我使用该输入对程序进行采样过程,查看问题所在并进行修复。

There is a new Startup Profiler plugin for VisualVM 1.3.6, which allows you to profile your application from its startup. VisualVM 1.3.6有一个新的Startup Profiler插件 ,允许您从启动时分析您的应用程序。 See this article for additional information. 有关其他信息,请参阅此文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM