java 如何使用VisualVM获取每个函数花费的时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16441274/
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 use VisualVM to get the time each function costs
提问by wilbeibi
VisualVM is a nice but a little complicated tool for me.
VisualVM 对我来说是一个不错但有点复杂的工具。
I wrote a class with many functions (in Eclipse). How can I get the information of how many time each function calls and the time they cost when during execution?
我写了一个有很多功能的类(在 Eclipse 中)。如何获取每个函数调用多少次以及它们在执行期间花费的时间的信息?
采纳答案by Tomas Hurka
See Profiling With VisualVM, Part 1and Profiling With VisualVM, Part 2to get more information about profiling and how to set profiling roots and instrumentation filter.
请参阅使用 VisualVM 进行分析,第 1 部分和使用 VisualVM 进行分析,第 2 部分,以获取有关分析以及如何设置分析根和检测过滤器的更多信息。
回答by lfvv
It is actually simple. Run your program and it will automatically appear as a running process in the VisualVM Panel. Click on it, and go straight to the Sampler tab. Finnaly, click on CPU and bingo! There you can see the time each function takes! (awesome!)
其实很简单。运行您的程序,它将自动在 VisualVM 面板中显示为正在运行的进程。单击它,然后直接转到 Sampler 选项卡。最后,点击 CPU 和宾果游戏!在那里你可以看到每个函数所花费的时间!(惊人的!)
回答by Michal Borek
For exhaustive analysis need to use alternative tool, e.g. JProfiler.
对于详尽的分析,需要使用替代工具,例如 JProfiler。
According to what @TomasHurka says you can profile also with VisualVM (https://blogs.oracle.com/nbprofiler/entry/profiling_with_visualvm_part_1)
根据@TomasHurka 所说的,您也可以使用 VisualVM 进行分析(https://blogs.oracle.com/nbprofiler/entry/profiling_with_visualvm_part_1)
回答by Madan Madan
This might be a little helpful for you..
这可能对你有点帮助..
Use Time Difference to calculate the execution by making a method return something.
使用 Time Difference 通过使方法返回某些内容来计算执行。
long before = System.currentTimeMillis();
String responseFromMethod=methodCall(); // String value returned from method
long totalResponseTime=((System.currentTimeMillis() - before )/1000);
You can keep a counter value for how many times a function is called.
您可以为函数被调用的次数保留一个计数器值。
For VisualVM you can use Eclipse MAT to analyze heapdump . It will explain where does your program needs improvement.
对于 VisualVM,您可以使用 Eclipse MAT 来分析 heapdump 。它将解释您的程序哪里需要改进。
Thanks,
谢谢,