How to use VisualVM to get the time each function costs [duplicate]

懵懂的女人 提交于 2019-12-05 09:30:01

问题


VisualVM is a nice but a little complicated tool for me.

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?


回答1:


See Profiling With VisualVM, Part 1 and Profiling With VisualVM, Part 2 to get more information about profiling and how to set profiling roots and instrumentation filter.




回答2:


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!)




回答3:


For exhaustive analysis need to use alternative tool, e.g. JProfiler.

According to what @TomasHurka says you can profile also with VisualVM (https://blogs.oracle.com/nbprofiler/entry/profiling_with_visualvm_part_1)




回答4:


This might be a little helpful for you..

Use Time Difference to calculate the execution by making a method return something.

  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.

Thanks,



来源:https://stackoverflow.com/questions/16441274/how-to-use-visualvm-to-get-the-time-each-function-costs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!