Java 分析 Sun Hotspots、JVM 6 的 GC 日志

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1839599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:10:28  来源:igfitidea点击:

Analyze GC logs for Sun Hotspots, JVM 6

javagarbage-collectionloggingjstat

提问by ripper234

I'm trying to analyze GC behaviour for our application (running in Tomcat, under Sun's Hotspots, JVM 1.6).

我正在尝试分析我们的应用程序的 GC 行为(在Tomcat 中运行,在Sun 的 Hotspots 下JVM 1.6)。

So far I've Instructed the JVM to emit GC logs to a separate file using...

到目前为止,我已经指示 JVM 使用......

-Xloggc:gc.log 
-XX:+PrintGCApplicationStoppedTime 
-XX:+PrintGCApplicationConcurrentTime 
-XX:+PrintGC 
-XX:+PrintGCTimeStamps 
-XX:+PrintGCDetails

...and used jstat to output logs using...

...并使用 jstat 使用...输出日志

jstat -gc -t 29045 5s > jstat.gc

I am seeing interesting information, but haven't found a tool to help me analyze/visualize these logs. I was pointed to GCViewer by this question, but it only parses a few log lines from gc.log and then crashes with an exception. Is there a better or more up-to-date tool for parsing these specific logs, for the specific JVM I'm using?

我看到了有趣的信息,但还没有找到帮助我分析/可视化这些日志的工具。我被这个问题指向了 GCViewer ,但它只解析了 gc.log 中的几行日志,然后因异常而崩溃。对于我正在使用的特定 JVM,是否有更好或更先进的工具来解析这些特定日志?

回答by Helter Scelter

I personally use HP JMeterfor a lot of GC visualization. it works "ok" on SUN JRE's, and exceptionally well on HP's JRE (go figure).

我个人使用HP JMeter进行大量 GC 可视化。它在 SUN JRE 上“正常”运行,在 HP 的 JRE 上运行得非常好(请看图)。

With Sun HotSpot 1.6 (on non-HP platforms), I use these GC Options to produce the logs for analysis:

对于 Sun HotSpot 1.6(在非 HP 平台上),我使用这些 GC 选项来生成日志以进行分析:

-Xloggc:/path/to/vgc/log/location/logfile.vgc  --XX:+PrintHeapAtGC 

回答by Steve B.

Have you looked at jvisualvm? Comes with the latest JDK, and allows you to watch the JVM. Sample output (using the visualGCplugin). Sample output - alt text http://g4u0420c.houston.hp.com/en/5992-4687/img/visualgc_2.png

你看过 jvisualvm 吗?自带最新的JDK,让你看JVM。示例输出(使用visualGC插件)。示例输出 -替代文本 http://g4u0420c.houston.hp.com/en/5992-4687/img/visualgc_2.png

回答by Agnes

I tried to use Visual GC, but it seems to work with an id process (the jvm one ou jstatd one). I can't use it with a jstat.gc, I mean a file and not a stream Is it right?

我尝试使用 Visual GC,但它似乎适用于 id 进程(jvm one ou jstatd one)。我不能将它与 jstat.gc 一起使用,我的意思是文件而不是流,对吗?

回答by Venkat

Try using gchisto (gchisto.dev.java.net). It can understand the GC log output (I am not sure whether it has been updated to work with the G1 GC). You have to get the sources from CVS (you need a dev.java.net account for that) and build this yourself

尝试使用 gchisto (gchisto.dev.java.net)。它可以理解 GC 日志输出(我不确定它是否已更新为与 G1 GC 一起使用)。您必须从 CVS 获取源代码(为此您需要一个 dev.java.net 帐户)并自己构建它

回答by David J. Liszewski

Here is a $0.00 log scraper good for 1.5 CMS collector which gives you a high level view of GC pauses.

这是一个 0.00 美元的日志抓取工具,适用于 1.5 CMS 收集器,它为您提供了 GC 暂停的高级视图。

You may need to change positional parameter $7 argument to the timestamp function in order to match your log line syntax (my .out gets "enhanced" by Tanuki Wrapper).

您可能需要将位置参数 $7 参数更改为时间戳函数以匹配您的日志行语法(我的 .out 被 Tanuki Wrapper “增强”)。

#! /usr/bin/awk -f
# Awk script to parse .out logs and print total of
# stop-the-world GC pause times in ten minute intervals

BEGIN {print "t\timark\tmark\tremark\tfullgc"}

/CMS-initial-mark:/ {
  t=timestamp();
  imark[t] += $(NF-1);
}

/\[CMS-concurrent-mark:/ {
  t=timestamp();
  split($(NF-1), b, "/");
#  print t" NF="NF" val="b[1];
  mark[t] += b[1];
}

/CMS-remark/ {
  t=timestamp();
  remark[t] += $(NF-1);
}

/\[Full GC / {
  t=timestamp();
  level=0;
  for (i=1; i<=NF; i++) {
      if ($i ~ /\[/) {
        level++;
      } else if ($i ~ /\]/) {
        level--;
      }
  }
  while (level > 0) {
    getline;
    for (i=1; i<=NF; i++) {
      if ($i ~ /\[/) {
        level++;
      } else if ( $i ~ /\]/ ) {
        level-- ;
      }
    }
  }
  if ( $(NF) ~ /secs\]/ ) {
    full[t] += $(NF-1) ;
  }
}

function timestamp(str) {
  split(str, a, ":");
  return a[1]":"substr(a[2],0,length(a[2])-1)"0";
}

# print out UK+US trading hours

END {
  for (hour = 5; hour <= 16; hour++) {
    for (minute = 0; minute <= 59; minute+=10) {
      t = sprintf("%02d:%02d", hour, minute);
      printf "%s\t%d\t%d\t%d\t%d\n", t, imark[t], mark[t], remark[t], full[t];
    }
  }
}

回答by David J. Liszewski

gcviewerhasn't been updated in a number of years, so it's hit or miss - some gc files will work fine, others get exceptions.

gcviewer许多年没有更新,所以它是命中还是未命中 - 一些 gc 文件可以正常工作,其他的会出现异常。

IBM's gc log parser works acceptably, http://www.alphaworks.ibm.com/tech/pmat/faq

IBM 的 gc 日志解析器工作正常, http://www.alphaworks.ibm.com/tech/pmat/faq

Sun has something called GCPortal, but it requires:

Sun 有一个叫做 GCPortal 的东西,但它需要:

  • install into a web app server
  • install of awk and perl
  • install of a RDBMS with a JDBC driver and configuration
  • and the real killer, third-party graph/chart software that used to be free and now isn't. Amazing.
  • 安装到 Web 应用服务器
  • 安装 awk 和 perl
  • 安装带有 JDBC 驱动程序和配置的 RDBMS
  • 真正的杀手级第三方图形/图表软件曾经是免费的,现在却不是。惊人的。

gchistohas died, there's no longer anything in the project.

gchisto已经死了,项目中不再有任何东西。

HPJmeter doesn't understand IBM gc files.

HPJmeter 不理解 IBM gc 文件。

回答by Will

The tools available in the IBM Support Assistantdo a pretty good job.

IBM Support Assistant 中可用的工具做得非常好。