|
|
Auth |
2004-03-5 : I was having problems with one of my Java apps at work which I suspected was GC (garbage collection) related. Conveniently, Java has a switch you can use to turn on GC logging. The resulting log files look something like this:
4.238: [GC 28543K->27563K(33188K), 0.0225530 secs] 4.329: [GC 29675K->28726K(33188K), 0.0204620 secs] 4.424: [GC 30838K->29889K(33188K), 0.0192290 secs] 4.521: [GC 32001K->31050K(33188K), 0.0188990 secs] 4.587: [GC 33162K->32155K(34340K), 0.0237150 secs] 4.611: [Full GC 32155K->29298K(34340K), 0.5322610 secs] 5.262: [GC 32690K->31518K(52608K), 0.0375240 secs] 5.410: [GC 34910K->33477K(52608K), 0.0406830 secs] 5.576: [GC 36869K->35343K(52608K), 0.0326430 secs] 5.737: [GC 38735K->37160K(52608K), 0.0351080 secs] 5.854: [GC 40552K->38886K(52608K), 0.0404190 secs]While this has useful information, it's hard to visualize the performance over a long period or find the one interesting line out of thousands.
After getting a log from my problem app, the first thing I did was load it into Excel. After
a couple passes of Text to columns..., I was able to "parse" out all the fields and
then with some more work I was able to get a graph. It was easy to see what was happening with the
graph, but it was a lot of steps to go through every time I wanted to see the GC behavior.
My first idea was to write a script to parse the log and convert it into a CSV file that Excel could read directly. This I did without too much trouble (and the final script still has this capability). However, I quickly realized that creating the graph also took a bunch of steps, and I'd rather just go straight to the graph.
I knew that MS Office has an ActiveX charting control, basically a version of Excel's charts that you can display in a web page. I decided to have the script produce an HTML file containing a graph of the log.
Here (536K) is an example web page containing a GC graph. Here (22K) is a small screenshot of the results if the web page doesn't work for you.
In the graph, the time runs along the bottom X-axis and is marked off in hours. The VM size, start size, and end size are plotted against the left Y-axis in KB. The duration of the GC event is plotted against the right Y-axis in seconds. GC events are marked with diamonds to make it easy to find the long-running full GC's. As you can see in the example, the longest full GC took over six seconds. This is a problem for my app, since incoming data can only be buffered for about four seconds.
I started out using the API to access the charting control, and managed to produce almost exactly what I wanted. However, I couldn't figure out how to get a dual Y-axis graph, even though I was able to produce one with Excel's export to web page feature. After banging my head on it for quite a while, I decided that the only way to do so was through the XML interface. I changed the script to produce an XML description of the graph and load that into the charting control, and now everything works great!
Usage:
Usage: cscript translateGcLog.js -file {gc.log} {-csv|-html} [-startTime 0h0m0.0s] > gc.html
You can get the source via anonymous CVS at
cvs -d :pserver:anon@www.latenighthacking.com:/code-cvsroot co 2004/translateGcLog
Due to popular demand, you can download the script as a zip file: translateGcLog.zip
cscript translateGcLog.js -file gc.log -html > output.html
<object id="ChartSpace" Stye="margin:0px;" classid="CLSID:0002E500-0000-0000-C000-000000000046"
style="width:100%;height:100%"></object>
<object id=ChartSpace classid=CLSID:0002E556-0000-0000-C000-000000000046
style="width:100%;height:350"></object>
| Louis K. Thomas <louisth@hotmail.com> | Auth | 2006-08-29 (825 days ago) |