1

I have an application which runs a rather long analysis (lots of number crunching) so running the application once takes about 3-4 hours, fully utilizing all of the cores. Now I am pretty sure my code is not water-tight so I want to profile and look for potential weak points.

I have been reading quite a bit on jvisualvm, and played around with it a bit too. However it appears as one chooses either cpu or memory profiling, while this article from Javalobby has an interesting quote where the author says:

I realise that both the CPU and Memory Profiling could have been done simultaneously, but for the purpose of this article I wanted to keep them seperate.

Could anyone deny or confirm this? If this is possible it would very useful, so I don't start over and over to profile in different modes. If it's not possible, would it be possible to queue to different profiling analyses so I can run them overnight?

Thanks,

posdef
  • 6,498
  • 11
  • 46
  • 94

2 Answers2

2

It is not possible to do CPU and Memory profiling together, but you can switch between CPU and memory very easily especially when using 'Sampler' tab. For your case, I would start with just simple monitoring. Looking at the graphs, you should be able to tell, if you have memory problem or not. If you have memory problem, I would try to fix it first and that turn your attention to the CPU profiling.

Tomas Hurka
  • 6,723
  • 29
  • 38
  • Thanks Tomas. Do you think it would be possible to queue profiling events without too much headache? or is it asking too much? :) – posdef Apr 06 '11 at 07:22
  • I am not sure what do you mean by 'to queue profiling events'. What kind of events do you have in mind? – Tomas Hurka Apr 06 '11 at 12:06
  • I was thinking like X minutes CPU profiling, Y minutes memory profiling, Z min sampling etc. However on a second thought I realize that it's not really a smart way to go anyways.. – posdef Apr 06 '11 at 12:39
  • Right, start with monitoring first. After you collect some monitoring data, you can decide what to next. Switch to 'Sampler' tab and try Memory or CPU sampling, depending on the results from monitoring. – Tomas Hurka Apr 06 '11 at 14:23
0

I find that profilers tend to underestimate the cost of object allocation, so I usually enable memory profiling with cpu profiling, as I feel this gives a more realistic CPU profiling result. (Even if I don't look at the memory profiling report)

If in doubt I suggest you run the CPU profile, with and without memory profiling and you can get very different results. In my experience it is worth optimising for both results. ;)

BTW: I use YourKit, but I don't imagine VisualVM to be very different in this regard.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • thanks for a rapid reply Peter, though I think I might have been unclear in the question. Is it possible to run both profiling at the same time? If so, how? – posdef Apr 05 '11 at 08:44
  • I assume there is a seperate button for each. What happens when you click both? – Peter Lawrey Apr 05 '11 at 08:48
  • yes there is, it appears as the profiling switches from one type to the other. The application blocks for initialization of instruments, which takes a long time, so I haven't really tried to wait till the underlying application to finish execution, since as I mentioned, it eats up pretty much all processor power (designed to do so) and takes a long time to finish. I was hoping to learn from similar experiences others in the community might have had (perhaps with simpler cases) – posdef Apr 05 '11 at 09:01
  • Perhaps you could run a simpler/shorter test which will be easier to profile. I wouldn't wait until the program has finished, you should find one minute is enough for a busy process. – Peter Lawrey Apr 05 '11 at 09:18