2

What I want to do is generate a call tree with CPU timing information for a Java application as it goes through a scripted task. The idea is to see how much time is spent in each part of the code, and how this changes when I change the code or the task, but to do so in a consistently repeatable way.

In Java VisualVM I can do this interactively by clicking to start and stop profiling, but I would like to automate the process so I can get more consistent results (and not get so bored). Can VisualVM do this, or is there another profiler that can?

Ben
  • 2,348
  • 2
  • 19
  • 28
  • YourKit allows you to start and stop profiling at specific lines of code. – Peter Lawrey Jul 02 '13 at 19:51
  • @PeterLawrey: the NetBeans profiler allows that as well. But I guess Ben doesn't want to run the application from within an IDE (or profiler) –  Jul 02 '13 at 20:35
  • Thanks. I'll investigate YourKit and NetBeans. (I normally use Eclipse as an IDE.) I don't mind too much how I run the application as long as I can get it to go through the same steps each time. – Ben Jul 03 '13 at 22:59

1 Answers1

-1

If I were a profiler vendor I would have to be concerned about providing people what they think they want, even if what they think they want does not solve the problem they have.

The thing is, only some problems can be found by knowing how long routines typically take, and if you ignore the ones you don't find that way, they will become the dominant part of how much time your program takes.

An example of what I mean is this recent example: A program spends 50% of its wall-clock time reading .dll files to look up string resources to get the names of files so that the strings can be displayed on a splash screen so the user can see that something is happening during application startup. That means, if there were some other way to provide eye-candy to the user, the app could start up twice as fast. During this process, the call stack is typically 15-20 functions deep, so it's really hard to tell what's going on just by having timing numbers for the functions.

What makes the problem difficult is that it is semantic. No particular routine is "hot" in a way that it could be speeded up. The only "hot" thing is the general description, overall, of what the program is doing, and no tool can isolate it for you. Only you can recognize it.

However, if you simply interrupted the program and examined the call stack during startup, the probability is 50% that you would see the entire explanation for the time being spent. If you do it several times, it's the basis of the random pausing technique that some programmers rely on because it will find every problem profilers can find, and more, and others look down on because it isn't a tool.

And do it interactively, either that or extract a small number of stack samples by using something analogous to pstack.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • Java VisualVM can use sampling, which is in effect (I think) the same as random pausing, but repeated many more times automatically. But whether sampling or profiling by instrumenting classes, I would like a way of quickly seeing the *difference* in the results when I change the code, rather than repeating a tedious manual procedure. Does that make sense? – Ben Jul 03 '13 at 23:06
  • @Ben: What makes it different is not in the taking of samples, but in the summarizing of them. The analysis is far more useful than the precision of timing. To see the effect of changes, simple timing suffices for me. For finding out what to fix, profilers don't work very well compared to pausing. Actual speedup results using them are very hard to find on-line, unlike pausing. [*Here's 43x.*](http://stackoverflow.com/a/927773/23771) As far as being tedious, I can show you a number of links like [*this one*](http://stackoverflow.com/a/2474118/23771). – Mike Dunlavey Jul 04 '13 at 00:59