简体   繁体   English

详细的Java GC日志

[英]Detailed Java GC logs

The sun JVM outputs detailed GC logs to StdOut when the following args are used. 当使用以下args时,sun JVM将详细的GC日志输出到StdOut。

 -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. 但是,我不希望StdOut中的输出,我真的不需要每个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. 每次JVM启动时都会重新初始化此文件,因此如果要保留它以进行分析,请不要忘记将其移动到安全位置。

A complete list of the many command line options Java understands can be found here for Java 6. 的许多命令行选项的Java理解的完整列表,可以发现这里的Java 6。

You can use the JMX Beans for Memory Pools and GC instead. 您可以使用JMX Bean for Memory Pools和GC。 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. 缺点是,它们因各种VM供应商,版本和GC设置而不同。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM