001 package jp.osdl.jbento2.analyzer;
002
003 import java.io.File;
004 import java.io.FileInputStream;
005 import java.io.IOException;
006 import java.io.InputStreamReader;
007 import java.io.Reader;
008 import java.text.SimpleDateFormat;
009
010 import org.apache.commons.io.FileUtils;
011 import org.apache.commons.io.IOUtils;
012
013 public class GCAnalyzer {
014
015 public static void main(String[] args) throws Exception {
016 GCAnalyzer analyzer = new GCAnalyzer();
017 analyzer.analyze();
018 }
019
020 private String src = "gc.log";
021
022 private String dest = "gc.csv";
023
024 private String startTime = null;
025
026 private long rampUpMillis = 0;
027
028 private long durationMillis = 0;
029
030 public void analyze() throws Exception {
031 Reader r = null;
032
033 try {
034 GCParser gp = GCParserFactory.create(null);
035 r = createReader();
036 GCList allGCs = gp.parse(r);
037
038 GCBuilder gcb = new GCBuilder(allGCs);
039 if (startTime != null) {
040 SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
041 gcb.setStartMillis(formatter.parse(startTime).getTime());
042 }
043 gcb.setRampUpMillis(rampUpMillis);
044 gcb.setDurationMillis(durationMillis);
045 gcb.setLastModified(getLastModified());
046 FileUtils.writeStringToFile(new File(dest), gcb.build(), "UTF-8");
047
048 } finally {
049 IOUtils.closeQuietly(r);
050 }
051 }
052
053 protected Reader createReader() throws IOException {
054 File srcFile = new File(getSrc());
055 if (!srcFile.exists()) {
056 throw new AnalyzerException("File not found. src=" + getSrc());
057 }
058 return new InputStreamReader(new FileInputStream(srcFile));
059 }
060
061 protected long getLastModified() {
062 File srcFile = new File(getSrc());
063 return srcFile.lastModified();
064 }
065
066 public String getSrc() {
067 return src;
068 }
069
070 public void setSrc(String src) {
071 this.src = src;
072 }
073
074 public String getDest() {
075 return dest;
076 }
077
078 public void setDest(String dest) {
079 this.dest = dest;
080 }
081
082 public String getStartTime() {
083 return startTime;
084 }
085
086 public void setStartTime(String startTime) {
087 this.startTime = startTime;
088 }
089
090 public long getDurationMillis() {
091 return durationMillis;
092 }
093
094 public void setDurationMillis(long durationMillis) {
095 this.durationMillis = durationMillis;
096 }
097
098 public long getRampUpMillis() {
099 return rampUpMillis;
100 }
101
102 public void setRampUpMillis(long rampUpMillis) {
103 this.rampUpMillis = rampUpMillis;
104 }
105
106 }