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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 22:24:20

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.

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

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)

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,

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