17

I have a few larger methods I'm trying to optimize in Java. I have been using jVisualVM to do most of my profiling as it gives method call hot spots and is a great starting point.

What I am looking for is a line-by-line hot spot profiler which can help me narrow down whats taking so long. The ovbious work around which I have used in the past is just strategically placed System.currentTimeMillis() prints and in more extreme cases using Java CPUTime (done via JNI). There are a few profilers like Intel Parallel Amplifier which works with C & Visual Studio, but is there anything like this for Java?

Both of those options are a bit tedious, so is there anything (Eclipse plug-in or otherwise) which can do line-by-line hot spot analysis?

NightWolf
  • 7,694
  • 9
  • 74
  • 121

2 Answers2

3

JProfiler has line number resolution. It's not enabled by default, but if you edit the profiling settings, there's a check box named "Record line numbers and show them in the call tree" on the "Method call recording" tab:

enter image description here

Disclaimer: My company develops JProfiler.

Ingo Kegel
  • 46,523
  • 10
  • 71
  • 102
  • 4
    You're lying. Well, at least partially. The line numbers are only for the call site, not the actual method's contents. – Dexter Apr 18 '14 at 18:03
  • I'm certainly not "lying". Of course the line numbers are recorded for call sites, because that's the only thing that is measurable. In a call tree view, the "method content" of interest is that of the method where the call site is located, not that of the method that is being called. Your problem may be that you're looking for a different view where you could see the method source with annotated timing information. As of 8.0, that is not a feature offered by JProfiler. – Ingo Kegel Apr 25 '14 at 13:03
0

In dynaTrace you can do something similar by instrumenting all invoked methods, however it is a commercial tool. Alternatively, you could write your own instrumenting tool using for example ASM (but it is extremely tedious :( )

s106mo
  • 1,243
  • 2
  • 14
  • 20