views:

178

answers:

3

I need a memory snapshot at the peak of my application's memory usage - is there an easy way to achieve this?

thanks

A: 

Uh? Unless you can quantatively say when that peak occurs, how would you expect this to be implemented? If every single point in time could be the one state you want to save, and there's no way of knowing in advance, it would have to save a complete snapshot for all points. That sounds hard.

unwind
if (current peak > peak so far) overwrite snapshot //not hard is it?
MalcomTucker
@MalcolmTucker: So if you do a very costly operation (as I assume storing the full state of a VM is) every time that is true, and there's for instance a *growth* up to the max, it will trigger multiple times. And of course there can be local minima, too.
unwind
A: 

An alternative to JVisualVM would be to take your native_stderr.log and open it in IBM's Pattern Modeling and Analysis Tool for Java Garbage. You'd be able to quickly see the highest point at which your application is using heap space.

Greg
A: 

Monitor the application with VisualVM/JConsole. when you see the peak do a heap dump.

Another way would be (if you do not want to monitor) to reducte the Xmx to something you know for sure it is going to throw a Out of Memory Exception. And activate the flag -XX:+HeapDumpOnOutOfMemoryError

Mikel