Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure sum of collected memory of Young Generation?

I'd like to measure memory allocation data from my java application, i.e. the sum of the size of all objects that were allocated. Since object allocation is done in young generation this seems to be the right place.

I know jconsole and I know the JMX beans but I just can't find the right variable... Right at the moment we are parsing the gc log output file but that's quite hard. Ideally we'd like to measure it via JMX...

How can I get this value?

Additional info after comment of Chadwick:

I want to know how much memory my application is using. It's quite a big software running in a JBoss Appserver. Every 4 weeks there is a new release of the software and we need to compare the memory consumption between old and new version. It's not enough to compare the current value of the old generation at a specific time. It's very useful to know how much more / or less memory gets allocated. Since many objects are getting collected in the young generation I need to measure it there.

In the meantime I have an estimate for this. I will post it as an answer.

Thanks, Marcel

like image 252
Marcel Avatar asked Jun 01 '10 09:06

Marcel


2 Answers

You can monitor the Young Generation using the MemoryPool MBeans, and more specifically

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/management/MemoryPoolMXBean.html

See the code examples at http://www.javadocexamples.com/java_source/com/sun/enterprise/admin/mbeans/jvm/MemoryReporter.java.html and http://www.java2s.com/Code/Java/Development-Class/ThisVerboseGCclassdemonstratesthecapabilitytogetthegarbagecollectionstatisticsandmemoryusageremotely.htm

like image 116
JoseK Avatar answered Oct 13 '22 14:10

JoseK


If you are using the Sun JDK, you can simply enable GC logging with -verbose:gc -Xloggc:gc.log and analyze the file. Or, if you need the total amount only occasionally, get the GCViewer by Tagtraum, which computes the number you are looking for.

like image 35
Roland Illig Avatar answered Oct 13 '22 15:10

Roland Illig