Reputation: 1961
Are there any good tools available to track memory usage In a tomcat java webapp? I'm looking for something that can give a breakdown by class or package.
Thanks, J
Upvotes: 4
Views: 7207
Reputation: 7069
Try the Memory Leak Detector that comes with JRockit Mission Control. It can show you which type of classes that are the most common on the heap and how much they are growing.
(source: oracle.com)
You can also get statistics from the command line by running the jrmcd command that is available in the JROCKIT_HOME\bin directory. For instance,
jrcmd <pid> print_object_summary
will give you
31.8% 3198k 41907 -137k [C
11.9% 1196k 300 +0k [B
11.4% 1151k 49118 +6k java/lang/String
6.1% 612k 5604 +0k java/lang/Class
4.3% 431k 2388 +0k [I
3.5% 353k 15097 +0k java/util/HashMap$Entry
...
It's free to use for development and evaluation.
Upvotes: 3
Reputation: 12700
I use the Netbeans IDE and it is able to profile any type of Java project including webapps. Once you have the project setup in Netbeans you just click Profile and answer a few easy questions.
It is very easy to create a new project and import your existing code into it.
You can see screenshots of this here: http://profiler.netbeans.org/
You can download Netbeans from here: http://www.netbeans.org/
VisualVM may also work for you. There are also a number of plugins available for it. VisualVM has been shipping with the JDK since JDK 6 update 7. You can check it out here: https://visualvm.dev.java.net/
Upvotes: 5
Reputation: 6802
jconsole can give you summary statistics. I've used it in the past while load testing to infer the size of loaded classes (by noting the before and after usage when loading LOTS of objects.) Note that the usage keeps going UP until a garbage collection is triggered, so you will need to account for transient objects in your calculations.
Upvotes: 3