You have to start the Tomcat server with the profiling options you want to be used. I believe that the JAVA_OPTIONS environment variable can be used to pass them into the catalina startup script.
To actually get a snapshot taken, you fire a signal to the Tomcat server. In Linux, this can be done using the "kill" command. If you send the right signal "kill" won't actually kill the app, it simply triggers a JVM snapshot. You can do this as many times as you like (they will be appended).
I'd be more specific, but I'd have to go back and RTFM. I've forgotten the exact details.
An IDE is no substitute for an Intelligent Developer.
Joined: Feb 19, 2008
Thanks for the advice Tim. I noticed that you cant use this for java 1.6. I had to do a little messing around, but I finally managed to get the memory dumps I needed. I've put together a rough HowTo for those that are interested;
For java 1.5 use:
1) Find the following line of code in your catalina.sh file;
Specifically the command -XX:+HeapDumpOnCtrlBreak will generate the heap dump file.
3) Start up tomcat as usual
4) After a few minutes get the process id of the tomcat process
ps ux | grep apache
look for anything in the line that says tomcat_version….
5) Use this process id to send a signal to the process with the following code
kill -3 <pid>
6) This will create a new file in the bin directory of you tomcat root installation directory with the .hprof.date.time extension. Remove the date.time extension and you can use this file with memory monitoring applications like eclipse based memory analyser
For java 1.6 use: jmap or jconsole -both of these are tools that come bundled with package. They located in JAVA_HOME/bin.
3) Open jconsole (just type jconsole)
4) Go to the mbeans tab
5) In the left hand tree structure look for the following folder; com.sun.management. Expand and click on HotSpotDiagnostic
6) In the right hand window click on operations. There should be an option to dump the heap memory in the tomcatHome/bin directory