Hi ,
Anybody got the source code for GCStats.java compatible with jdk1.2.2,I have an older version which works fine with jdk1.1.8.When i am trying to use this with WebsphereV3.5.4(jdk1.2.2) for analyzing verbosegc output in stderr.
Here is the source code i got
// GCStats.java
// This utility tabulates data generated from a verbose garbage collection trace.
// To run this utility type:
// java GCStats inputfile [total_time]
//
// Gennaro (Jerry) Cuomo - IBM Corp. 03/2000
// Carmine F. Greco 3/17/00 - JDK1.2.2 compatibility
//
import java.io.*;
import java.util.*;
public class GCStats {
static int total_time=-1; // total time of run in ms
static long total_gctime=0, total_gctime1=0; // total time spent in GCs
static long total_bytes=0, total_bytes1=0; // total bytes collected
static long total_free=0, total_free1=0; // total
static int total_gc=0; // total number of GCs
static boolean verbose=false; // debug trace on/off
public static void parseLine(String line) {
// parsing a string that looks like this...
// <GC(31): freed 16407744 bytes in 107 ms, 97% free (16417112/16777208)>
if (isGCStatsLine(line)) { // First test if line starts with "<GC..."<br /> if (verbose) System.out.println("GOT a GC - "+line);<br /> long temp=numberBefore(line, " bytes")/1024; // get total memory collected<br /> total_bytes+=temp; total_bytes1+=(temp*temp);<br /> temp=numberBefore(line, " ms"); // get time in GC<br /> total_gctime+=temp; total_gctime1+=(temp*temp);<br /> temp=numberBefore(line, "% free"); // get time % free<br /> total_free+=temp; total_free1+=(temp*temp);<br /> if (temp!=0) {<br /> total_gc++; // total number of GCs<br /> }<br /> }<br /> }<br /> public static int numberBefore( String line, String s) {<br /> int ret = 0;<br /> int idx = line.indexOf(s);<br /> int idx1= idx-1;<br /> if (idx>0) {
// the string was found, now walk backwards until we find the blank
while (idx1!=0 && line.charAt(idx1)!=' ') idx1--;
if (idx1>0) {
String temp=line.substring(idx1+1,idx);
if (temp!=null) {
ret=Integer.parseInt(temp); // convert from string to number
}
} else {
if (verbose) System.out.println("ERROR: numberBefore() - Parse Error looking for "+s);
}
}
return ret;
}
public static boolean isGCStatsLine(String line) {
return ( (line.indexOf("<GC") > -1) && (line.indexOf(" freed")>0) && (line.indexOf(" bytes")>0));
}
public static void main (String args[]) {
String filename=null;
BufferedReader foS=null;
boolean keepgoing=true;
if (args.length==0) {
System.out.println("GCStats - ");
System.out.println(" - ");
System.out.println(" - Syntax: GCStats filename [run_duration(ms)]");
System.out.println(" - filename = file containing -verbosegc data");
System.out.println(" - run_duration(ms) = duration of fixed work run in which GCs took place");
return;
}
if (args.length>0) {
filename=args[0];
}
if (args.length>1) {
total_time=Integer.parseInt(args[1]);
}
if (verbose) System.out.println("Filename="+filename);
try {
foS = new BufferedReader(new FileReader(filename));
} catch (Throwable e) {
System.out.println("Error opening file="+filename);
return;
}
while (keepgoing) {
String nextLine;
try {
nextLine=foS.readLine();
} catch (Throwable e) {
System.out.println("Cannot read file="+filename);
return;
}
if (nextLine!=null) {
parseLine(nextLine);
} else {
keepgoing=false;
}
}
try {
foS.close();
} catch (Throwable e) {
System.out.println("Cannot close file="+filename);
return;
}
System.out.println("-------------------------------------------------");
System.out.println("- GC Statistics for file - "+filename);
System.out.println("-------------------------------------------------");
System.out.println("-**** Totals ***");
System.out.println("- "+total_gc+" Total number of GCs");
System.out.println("- "+total_gctime+" ms. Total time in GCs");
System.out.println("- "+total_bytes+" Kbytes. Total memory collected during GCs");
System.out.println("- ");
System.out.println("-**** Averages ***");
double mean=total_gctime/total_gc,
stddev=Math.sqrt((total_gctime1-2*mean*total_gctime+total_gc*mean*mean)/total_gc);
int imean=new Double(mean).intValue(), istddev=new Double(stddev).intValue();
System.out.println("- "+imean+" ms. Average time per GC. (stddev="+istddev+" ms.)");
mean=total_bytes/total_gc; stddev=Math.sqrt((total_bytes1-2*mean*total_bytes+total_gc*mean*mean)/total_gc);
imean=new Double(mean).intValue(); istddev=new Double(stddev).intValue();
System.out.println("- "+imean+" Kbytes. Average memory collected per GC. (stddev="+istddev+" Kbytes)");
mean=total_free/total_gc; stddev=Math.sqrt((total_free1-2*mean*total_free+total_gc*mean*mean)/total_gc);
imean=new Double(mean).intValue(); istddev=new Double(stddev).intValue();
System.out.println("- "+imean+"%. Free memory after each GC. (stddev="+istddev+"%)");
if (total_time>0 && total_gctime>0) {
System.out.println("- "+((total_gctime*1.0)/(total_time*1.0))*100.0+"% of total time ("+total_time+"ms.) spentin GC.");
}
System.out.println("___________________________ "+new Date());
System.out.println("");
}
}
Thanks in Advance
Raj Varanasi