如何将详细垃圾收集输出重定向到文件?

发布于 2024-07-27 16:57:07 字数 62 浏览 4 评论 0 原文

如何将详细垃圾收集输出重定向到文件? Sun 的网站显示了 Unix 的示例,但它不适用于 Windows。

How do I redirect verbose garbage collection output to a file? Sun’s website shows an example for Unix but it doesn't work for Windows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请叫√我孤独 2024-08-03 16:57:07

java -X 的输出:

    -Xloggc:<file>    log GC status to a file with time stamps

记录 此处

-Xloggc:文件名

设置应将详细 GC 事件信息重定向到的文件以进行日志记录。 写入此文件的信息类似于 -verbose:gc 的输出,其中包含自每个记录事件之前的第一个 GC 事件以来经过的时间。 如果使用相同的 java 命令指定 -Xloggc 选项,则 -Xloggc 选项将覆盖 -verbose:gc

示例:

 -Xloggc:garbage-collection.log

所以输出看起来像这样:

0.590: [GC 896K->278K(5056K), 0.0096650 secs]
0.906: [GC 1174K->774K(5056K), 0.0106856 secs]
1.320: [GC 1670K->1009K(5056K), 0.0101132 secs]
1.459: [GC 1902K->1055K(5056K), 0.0030196 secs]
1.600: [GC 1951K->1161K(5056K), 0.0032375 secs]
1.686: [GC 1805K->1238K(5056K), 0.0034732 secs]
1.690: [Full GC 1238K->1238K(5056K), 0.0631661 secs]
1.874: [GC 62133K->61257K(65060K), 0.0014464 secs]

From the output of java -X:

    -Xloggc:<file>    log GC status to a file with time stamps

Documented here:

-Xloggc:filename

Sets the file to which verbose GC events information should be redirected for logging. The information written to this file is similar to the output of -verbose:gc with the time elapsed since the first GC event preceding each logged event. The -Xloggc option overrides -verbose:gc if both are given with the same java command.

Example:

    -Xloggc:garbage-collection.log

So the output looks something like this:

0.590: [GC 896K->278K(5056K), 0.0096650 secs]
0.906: [GC 1174K->774K(5056K), 0.0106856 secs]
1.320: [GC 1670K->1009K(5056K), 0.0101132 secs]
1.459: [GC 1902K->1055K(5056K), 0.0030196 secs]
1.600: [GC 1951K->1161K(5056K), 0.0032375 secs]
1.686: [GC 1805K->1238K(5056K), 0.0034732 secs]
1.690: [Full GC 1238K->1238K(5056K), 0.0631661 secs]
1.874: [GC 62133K->61257K(65060K), 0.0014464 secs]
如歌彻婉言 2024-08-03 16:57:07

此外,如果您想将输出通过管道传输到单独的文件,您可以执行以下操作:

Sun JVM 上:

-Xloggc:C:\whereever\jvm.log -verbose:gc -XX:+PrintGCDateStamps

IBM JVM 上:

-Xverbosegclog:C:\whereever\jvm.log 

If in addition you want to pipe the output to a separate file, you can do:

On a Sun JVM:

-Xloggc:C:\whereever\jvm.log -verbose:gc -XX:+PrintGCDateStamps

ON an IBM JVM:

-Xverbosegclog:C:\whereever\jvm.log 
剧终人散尽 2024-08-03 16:57:07

Java 9 和 统一 JVM 日志

JEP 158 为 JVM 的所有组件引入了一个通用日志系统,该系统将发生变化(并且IMO 简化)日志记录如何与 GC 配合使用。 JEP 158 添加了一个新的命令行选项来控制 JVM 所有组件的日志记录:

-Xlog

例如,以下选项:

-Xlog:gc

将使用 info 级别记录标记有 gc 标签的消息到标准输出。 或者这个:

-Xlog:gc=debug:file=gc.txt:none

将使用 debug 级别将带有 gc 标记的消息记录到名为 gc.txt 的文件中,不带修饰。 有关更详细的讨论,您可以查看 JEP 页面中的示例。

Java 9 & Unified JVM Logging

JEP 158 introduces a common logging system for all components of the JVM which will change (and IMO simplify) how logging works with GC. JEP 158 added a new command-line option to control logging from all components of the JVM:

-Xlog

For example, the following option:

-Xlog:gc

will log messages tagged with gc tag using info level to stdout. Or this one:

-Xlog:gc=debug:file=gc.txt:none

would log messages tagged with gc tag using debug level to a file called gc.txt with no decorations. For more detailed discussion, you can checkout the examples in the JEP page.

长途伴 2024-08-03 16:57:07

要添加上述答案,有一篇很好的文章: 有用的 JVM 标志 – 第 8 部分(GC 日志记录),作者:Patrick Peschlow。

简短摘录:

标志 -XX:+PrintGC (或别名 -verbose:gc)激活“简单”GC 日志记录

模式默认情况下,GC 日志写入 stdout。 使用 -Xloggc: 我们可以指定一个输出文件。 请注意,此标志还隐式设置 -XX:+PrintGC-XX:+PrintGCTimeStamps

如果我们使用-XX:+PrintGCDetails而不是-XX:+PrintGC,我们会激活“详细”GC记录模式,该模式根据不同的情况而有所不同使用的 GC 算法。

使用 -XX:+PrintGCTimeStamps ,反映自 JVM 启动以来经过的实时时间(以秒为单位)的时间戳被添加到每一行。

如果我们指定 -XX:+PrintGCDateStamps 每行都以绝对日期和时间开头。

To add to the above answers, there's a good article: Useful JVM Flags – Part 8 (GC Logging) by Patrick Peschlow.

A brief excerpt:

The flag -XX:+PrintGC (or the alias -verbose:gc) activates the “simple” GC logging mode

By default the GC log is written to stdout. With -Xloggc:<file> we may instead specify an output file. Note that this flag implicitly sets -XX:+PrintGC and -XX:+PrintGCTimeStamps as well.

If we use -XX:+PrintGCDetails instead of -XX:+PrintGC, we activate the “detailed” GC logging mode which differs depending on the GC algorithm used.

With -XX:+PrintGCTimeStamps a timestamp reflecting the real time passed in seconds since JVM start is added to every line.

If we specify -XX:+PrintGCDateStamps each line starts with the absolute date and time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文