开发者

Detailed Java GC logs

开发者 https://www.devze.com 2023-04-02 18:05 出处:网络
The sun JVM outputs detailed GC logs to StdOut when the following args are used. -verbose:gc -X开发者_如何学运维X:+PrintGCTimeStamps

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

 -verbose:gc
 -X开发者_如何学运维X:+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.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号