001 package jp.osdl.jbento2.analyzer; 002 003 import java.text.DateFormat; 004 import java.text.SimpleDateFormat; 005 import java.util.Date; 006 import java.util.Iterator; 007 008 public class ThroughputTimeLineBuilder { 009 010 private SampleList samples; 011 private DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); 012 013 public ThroughputTimeLineBuilder(SampleList samples) { 014 this.samples = samples; 015 } 016 017 public String build() { 018 long start = 019 SampleUtils.getMinEndTime(samples).getMillitime(); 020 long end = SampleUtils.getMaxEndTime(samples).getMillitime(); 021 022 int durationSeconds = (int) (end - start) / 1000 + 1; 023 024 int[] success = new int[durationSeconds]; 025 int[] error = new int[durationSeconds]; 026 027 Iterator ite = samples.iterator(); 028 while (ite.hasNext()) { 029 Sample sample = (Sample) ite.next(); 030 int index = (int) (sample.getEndTime().getMillitime() - start) / 1000; 031 if (sample.isError()) { 032 error[index]++; 033 } else { 034 success[index]++; 035 } 036 } 037 038 TextTable tt = new TextTable(3, TextTable.ALIGN_RIGHT, ","); 039 tt.setAlign(0, TextTable.ALIGN_LEFT); 040 tt.addRow(new String[] { 041 "Time", "success", "error" 042 }); 043 tt.addSeparator("-"); 044 045 for (int i = 0; i < durationSeconds; i++) { 046 tt.addRow(new String[] { 047 formatter.format(new Date(start + i * 1000)), 048 Integer.toString(success[i]), 049 Integer.toString(error[i])}); 050 } 051 return tt.toString(); 052 } 053 } 054