English 中文(简体)
Java: Comparing memory heap dumps in Netbeans
原标题:

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.

最佳回答

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.
问题回答

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签