1

VisualVM is showing me that a particular method is taking a long time to execute.

Are there any widely used strategies for looking at the performance (in regards to time) of a Java method?

My gut feeling is that the sluggish response time will come from a method that is somewhere down the call hierarchy from the one VisualVM is reporting but I think getting some hard numbers is better than fishing around in the code based on an assumption when it comes to performance.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
csilk
  • 188
  • 1
  • 15
  • VisualVM organizes times not by method, but by complete call stack, so you can always drill down to exactly the method call that makes its callers consume time. – Marko Topolnik Oct 23 '12 at 12:33

2 Answers2

2

VisualVM should be showing you the methods which use the most CPU. If the biggest user is your method, it means it not a method you are calling unless you are calling many methods which individually look small but in total are more.

I suggest you take the difference of the methods this method calls and your total. That is how much your method is adding which being profiled. Note: how much it adds when not profiled could be less as the profiler has an overhead.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Hi Peter. Thanks for the comment but I'm not entirely sure what you mean in regards to " methods which individually look small but in total are more" and "I suggest you take the difference of the methods this method calls and your total". – csilk Oct 23 '12 at 14:23
  • The time spent in a method can include all the methods its calls as well. If methodA calls methodB and methodC and these take 10 seconds, 2 seconds and 3 seconds, the methodA is adding 10 - 2 - 3 = 5 seconds. – Peter Lawrey Oct 23 '12 at 15:57
  • The sum of all the methods execution times is the metric I am using. – csilk Oct 24 '12 at 08:32
  • In that case, you are assuming only the method you call are using CPU. Can you optimise those methods or call them less? – Peter Lawrey Oct 24 '12 at 08:38
1

You need to use tools like JProfiler, Yourkit etc. You can profile you code in depth & you can exactly catch which method is taking much time. You can go as much in depth hierarchy as you want with these tools.

Ravi K
  • 976
  • 7
  • 9