views:

439

answers:

3

How do I compare memory heap dumps in Netbeans?

What I have done is to configure my project to use profiling, then added several profiling points at chosen lines of code (similar to setting breakpoints). These profiling points trigger a "snapshot", which creates a memory dump.

As my application is running, the profiling tab lists each of the profiling points, and marks the number of hits it has encounteed, providing a link to open a report for that profiling point. In addition, the profiler control panel adds the new snapshots to a list.

If I open these reports and follow the links, or open the snapshots from the control panel, in both cases, Netbeans opens a snapshot tab with Summary, Classes, Instances and OQL subscreens.

If I select one of them from the Profiler control panel, and press save, the file gets saved in HPROF format.

If I select the menu Profile --> Compare Memory Snapshots, it only allows me to select NPS format files, of which I cannot obtain any.

I believe Compare Memory Snapshots sounds like it should be able to compare heap dumps, but I cannot figure out how to do it.

Questions

  • Where is Netbeans putting the NPS files (if it is indeed creating them)? If not how do I get Netbeans to create NPS files triggered from profiling points?

  • Is there a way to get Netbeans to compare HPROF files, since that is the memory heap dump after all?

  • Or am I simply completely overlooking something altogether?

Thanks!


Background

Using Netbeans 6.7.1.

I am doing memory profiling for a really large & complex application that has a memory leak problem. I have managed to solve large chunks of the leaks using a combination of Netbeans' profiler & JHAT (command line util that comes with JDK). It's the remaining stragglers that I need a more powerful heap analysis capabilities for - the hypothesis-first approach that worked previously is becoming decreasingly effective.

This question's really specific, for more background see a question I have asked previously.

A: 

I would suggest using eclipse's memory analyzer: http://www.eclipse.org/mat/

I know that you are a netbeans user but mat is actually a standalone application (rcp based) and is capable of loading and comparing hprof files.

I found that it was the best heap analyzer around, particularly with larger heap dumps.

Dave Jefferson
Same comment as the Yourkit fanboy: how does this answer the question??? The OP isn't asking for another tool...
Pascal Thivent
A: 

YourKit Java Profiler http://www.yourkit.com can compare memory and CPU snapshots. It also has "Generation" feature which allows to separate objects by generation within single snapshot.

--serge

Serge
Yourkit is a nice piece of software but first, it isn't free and second, how does this answer the question???
Pascal Thivent
+1  A: 

Unfortunately, I was not asking for recommendations on other tools which can do this.

I have since found that Netbeans does indeed support comparison of memory heap dumps, but only indirectly. Edit the profiling points such that the "Snapshot" is selected over "heap". This means that Netbeans will produce a .nps file instead of a .hprof file.

The .nps file is Netbean's own proprietary file format, whereas .hprof is the "universal" heap dump format, understood by almost all profiling tools, including JHAT, MAT & Netbeans.

However, the limitation with Netbeans is that it can look at .hprof files, and analyse them, but it cannot compare them to another .hprof file. It can, though, compare one .nps file to another .nps file. However the level of analysis available is limited with .nps files, so that's the trade-off.


So, to answer my own questions:

Where is Netbeans putting the NPS files (if it is indeed creating them)? If not how do I get Netbeans to create NPS files triggered from profiling points?

  • It is one or the other, you can only choose one per profiling point.

Is there a way to get Netbeans to compare HPROF files, since that is the memory heap dump after all?

  • No. You cannot compare to HPROF's. The only way to compare the memory at two different points in time appears to be to compare two NPS'es.
bguiz
Thanks for that feedback.
Pascal Thivent