25

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?

wilbeibi
  • 3,403
  • 4
  • 25
  • 44

3 Answers3

58

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. Finally, click on CPU and you got it. There you can see the time each function takes.

lfvv
  • 1,509
  • 15
  • 17
2

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)

Michal Borek
  • 4,584
  • 2
  • 30
  • 40
0

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,

Madan Madan
  • 674
  • 1
  • 11
  • 28