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 009 import org.apache.commons.io.FileUtils; 010 011 public class Analyzer { 012 013 public static void main(String[] args) throws Exception { 014 Analyzer analyzer = new Analyzer(); 015 analyzer.analyze(); 016 } 017 018 private String src = "jbento.log"; 019 020 private String srcEncoding = null; 021 022 private String dest = "result"; 023 024 private String parser = "jbento"; 025 026 private long rampUpMillis = 0; 027 028 private long rampDownMillis = 0; 029 030 private long durationMillis = 0; 031 032 public void analyze() throws Exception { 033 SampleParser sp = SampleParserFactory.create(getParser()); 034 SampleList allSamples = sp.parse(createReader()); 035 036 SampleList samples = null; 037 038 if (getDurationMillis() > 0) { 039 samples = new RampUpDurationFilter(getRampUpMillis(), 040 getDurationMillis()).doFilter(allSamples); 041 } else { 042 samples = new RampUpDownFilter(getRampUpMillis(), 043 getRampDownMillis()).doFilter(allSamples); 044 } 045 046 File destFile = new File(dest); 047 destFile.mkdirs(); 048 SummaryBuilder sb = new SummaryBuilder(allSamples, samples); 049 FileUtils.writeStringToFile(new File(destFile, "summary.txt"), sb 050 .build(), "UTF-8"); 051 if (samples.isEmpty()) { 052 return; 053 } 054 ThroughputBuilder tb = new ThroughputBuilder(samples); 055 FileUtils.writeStringToFile(new File(destFile, "throughput.txt"), tb 056 .build(), "UTF-8"); 057 ResponseTimeBuilder rtb = new ResponseTimeBuilder(samples); 058 FileUtils.writeStringToFile(new File(destFile, "responseTime.txt"), rtb 059 .build(), "UTF-8"); 060 061 ThroughputTimeLineBuilder ttlb = new ThroughputTimeLineBuilder(samples); 062 FileUtils.writeStringToFile(new File(destFile, "throughputTimeLine.txt"), 063 ttlb.build(), "UTF-8"); 064 } 065 066 protected Reader createReader() throws IOException { 067 File srcFile = new File(getSrc()); 068 if (!srcFile.exists()) { 069 throw new AnalyzerException("File not found. src=" + getSrc()); 070 } 071 if (getSrcEncoding() == null) { 072 return new InputStreamReader(new FileInputStream(srcFile)); 073 } else { 074 return new InputStreamReader(new FileInputStream(srcFile), 075 getSrcEncoding()); 076 } 077 } 078 079 public String getSrc() { 080 return src; 081 } 082 083 public void setSrc(String src) { 084 this.src = src; 085 } 086 087 public String getSrcEncoding() { 088 return srcEncoding; 089 } 090 091 public void setSrcEncoding(String srcEncoding) { 092 this.srcEncoding = srcEncoding; 093 } 094 095 public String getDest() { 096 return dest; 097 } 098 099 public void setDest(String dest) { 100 this.dest = dest; 101 } 102 103 public String getParser() { 104 return parser; 105 } 106 107 public void setParser(String parser) { 108 this.parser = parser; 109 } 110 111 public long getRampUpMillis() { 112 return rampUpMillis; 113 } 114 115 public void setRampUpMillis(long rampUpMillis) { 116 this.rampUpMillis = rampUpMillis; 117 } 118 119 public long getRampDownMillis() { 120 return rampDownMillis; 121 } 122 123 public void setRampDownMillis(long rampDownMillis) { 124 this.rampDownMillis = rampDownMillis; 125 } 126 127 public long getDurationMillis() { 128 return durationMillis; 129 } 130 131 public void setDurationMillis(long durationMillis) { 132 this.durationMillis = durationMillis; 133 } 134 135 }