I’ve recently found that a program I’ve written is surprisingly slow, and in an attempt to fix it I would like to profile it. My tools of choice so far have been Yourkit and hprof, yet I haven’t been able to find the functionality I seek in either.
Ideally, I would like a MATLAB Profiler style heat-map for all my source files, with stronger colors indicating more time was spent in that line. I realize this is a lot to ask, so if it doesn’t exist I won’t be surprised.
If the above isn’t possible, what I would like is to be able to perform hprof cpu=samples style profiling, but instead of spitting out a list of ALL methods of all classes executed in the project, I would like to be able to exclude namespaces (eg: java., scala.collection.) and have any time attributed to those methods to be reattributed to the lowest level in the stack where a method was called NOT in the excluded namespace. For example, if I have something like the following
def sillyMethod: Unit = {
0.until(1000000).map{ i =>
(0 until 1000).toSeq + 1) == ( 0 until 1000).toSeq + 2 )
}
}
I would much rather know that all my time is spent in sillyMethod, not in Seq.equals. Is this possible with any available profiler?
EDIT: I am currently using sbt to execute my commands and IntelliJ IDEA for actual editing.
I haven’t looked at yourkit in a very long time, but I would be surprised if its profiler wasn’t able to exclude packages or restrict profiled packages. The JVM actually ships with a profiler that isn’t so bad. visualvm is included with the jdk. Notice the second screenshot on the profiling page has a section at the bottom for “profile only classes” so if you put only your package in there you won’t profile anything else, or you can go deeper to only profile specific packages or classes.