001 package jp.osdl.jbento2.analyzer;
002
003 import java.text.DecimalFormat;
004
005 public class ThroughputBuilder {
006
007 private SampleList samples;
008 private DecimalFormat format = new DecimalFormat("#0.00");
009
010 public ThroughputBuilder(SampleList samples) {
011 this.samples = samples;
012 }
013
014 public String build() {
015 TextTable tt = new TextTable(5, TextTable.ALIGN_RIGHT, ",");
016 tt.setAlign(0, TextTable.ALIGN_LEFT);
017 tt.addRow(new String[] {
018 "RequestType", "tps", "tpm", "success", "error"
019 });
020 tt.addSeparator("-");
021 long start =
022 SampleUtils.getMinEndTime(samples).getMillitime();
023
024 String[] requestTypes = SampleUtils.getRequestTypes(samples);
025 for (int i = 0; i < requestTypes.length; i++) {
026 buildRow(requestTypes[i],
027 SampleUtils.select(samples, requestTypes[i]), start, tt);
028 }
029 tt.addSeparator("-");
030 buildRow("TOTAL", samples, start, tt);
031 return tt.toString();
032 }
033
034 private void buildRow(String label, SampleList sampleList,
035 long start, TextTable tt) {
036 sampleList.sortByEndTime();
037 Stats stats = new Stats();
038 long termEnd = start + 1000;
039 int count = 0;
040 int successCount = 0;
041 int errorCount = 0;
042 for (int i = 0; i < sampleList.size(); i++) {
043 Sample sample =sampleList.get(i);
044 if (sample.getEndTime().getMillitime() >= termEnd) {
045 stats.add(count);
046 count = 0;
047 termEnd += 1000;
048 }
049 if (!sample.isError()) {
050 count++;
051 successCount++;
052 } else {
053 errorCount++;
054 }
055 }
056 tt.addRow(new String[] {
057 label,
058 format.format(stats.average()),
059 format.format(stats.average() * 60),
060 String.valueOf(successCount),
061 String.valueOf(errorCount)
062 });
063 }
064 }
065