mchr
mchr

Reputation: 6251

Detailed Java GC logs

The sun JVM outputs detailed GC logs to StdOut when the following args are used.

 -verbose:gc
 -XX:+PrintGCTimeStamps
 -XX:+PrintGCDetails

However, I don't want the output in StdOut and I dont really need the detail for every single GC. Is it possible to access the data used for these logs programatically? I would like to be able to log to my own log file the amount of memory allocated/collected and ideally the average object size over time.

Upvotes: 5

Views: 5957

Answers (2)

eckes
eckes

Reputation: 10423

You can use the JMX Beans for Memory Pools and GC instead. They have the advantage that you get counters wich you can query on a free schedule. The disadvantage is, that they differ for various VM vendors, versions and GC settings.

For example

java.lang:type=GarbageCollector,name=Copy
  CollectionCount, ColletionTime, LastGCInfo[1].duration,memoryUSageBefore/After
java.lang:type=GarbageCollector,name=MarkSweepCompact
  CollectionCount, CollectionTime, LastGCInfo[1].duration,memoryUSageBefore/After
java.lang:type=Memory
  HeapMemoryUsage[1].commited,init,max,used

Upvotes: 0

fvu
fvu

Reputation: 32953

You need to add

-Xloggc:log_file_name

This file gets reinitialized every time the JVM starts, so dont forget to move it to safe location if you want to keep it for analysis.

A complete list of the many command line options Java understands can be found here for Java 6.

Upvotes: 4

Related Questions