| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
package org.perfidix.ouput; |
| 28 | |
|
| 29 | |
import java.io.PrintStream; |
| 30 | |
import java.lang.reflect.Method; |
| 31 | |
|
| 32 | |
import org.perfidix.exceptions.AbstractPerfidixMethodException; |
| 33 | |
import org.perfidix.exceptions.PerfidixMethodInvocationException; |
| 34 | |
import org.perfidix.meter.AbstractMeter; |
| 35 | |
import org.perfidix.ouput.asciitable.NiceTable; |
| 36 | |
import org.perfidix.ouput.asciitable.AbstractTabularComponent.Alignment; |
| 37 | |
import org.perfidix.result.AbstractResult; |
| 38 | |
import org.perfidix.result.BenchmarkResult; |
| 39 | |
import org.perfidix.result.ClassResult; |
| 40 | |
import org.perfidix.result.MethodResult; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public final class TabularSummaryOutput extends AbstractOutput { |
| 49 | |
|
| 50 | |
|
| 51 | |
private transient final PrintStream out; |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
public TabularSummaryOutput(final PrintStream paramOut) { |
| 60 | 25 | super(); |
| 61 | 25 | out = paramOut; |
| 62 | 25 | } |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
public TabularSummaryOutput() { |
| 68 | 25 | this(System.out); |
| 69 | 25 | } |
| 70 | |
|
| 71 | |
|
| 72 | |
@Override |
| 73 | |
public void visitBenchmark(final BenchmarkResult benchRes) { |
| 74 | 10 | final int numberOfColumns = 9; |
| 75 | 10 | NiceTable table = new NiceTable(numberOfColumns); |
| 76 | 10 | table = generateHeader(table); |
| 77 | 10 | for (final AbstractMeter meter : benchRes.getRegisteredMeters()) { |
| 78 | 15 | table.addHeader(meter.getName(), '=', Alignment.Center); |
| 79 | 15 | for (final ClassResult classRes : benchRes.getIncludedResults()) { |
| 80 | 25 | table.addHeader(classRes.getElementName(), '.', Alignment.Left); |
| 81 | 25 | for (final MethodResult methRes : classRes.getIncludedResults()) { |
| 82 | 75 | table = generateMeterResult(methRes.getElementName(), meter, methRes, table); |
| 83 | 75 | } |
| 84 | |
|
| 85 | 25 | table.addHeader(new StringBuilder("Summary for ").append(classRes.getElementName()) |
| 86 | |
.toString(), '_', Alignment.Left); |
| 87 | 25 | table = generateMeterResult("", meter, classRes, table); |
| 88 | 25 | table.addLine('-'); |
| 89 | |
|
| 90 | 25 | } |
| 91 | 15 | } |
| 92 | 10 | table.addHeader("Summary for the whole benchmark", '=', Alignment.Center); |
| 93 | |
|
| 94 | 10 | for (final AbstractMeter meter : benchRes.getRegisteredMeters()) { |
| 95 | 15 | table = generateMeterResult("", meter, benchRes, table); |
| 96 | 15 | } |
| 97 | |
|
| 98 | 10 | table.addHeader("Exceptions", '=', Alignment.Center); |
| 99 | 10 | for (final AbstractPerfidixMethodException exec : benchRes.getExceptions()) { |
| 100 | 26 | final StringBuilder execBuilder0 = new StringBuilder(); |
| 101 | 26 | execBuilder0.append("Related exception: ").append(exec.getExec().getClass().getSimpleName()); |
| 102 | 26 | table.addHeader(execBuilder0.toString(), ' ', Alignment.Left); |
| 103 | |
|
| 104 | 26 | final StringBuilder execBuilder1 = new StringBuilder(); |
| 105 | 26 | if (exec instanceof PerfidixMethodInvocationException) { |
| 106 | 26 | execBuilder1.append("Related place: method invocation"); |
| 107 | |
} else { |
| 108 | 0 | execBuilder1.append("Related place: method check"); |
| 109 | |
} |
| 110 | 26 | table.addHeader(execBuilder1.toString(), ' ', Alignment.Left); |
| 111 | 26 | if (exec.getMethod() != null) { |
| 112 | 26 | final StringBuilder execBuilder2 = new StringBuilder(); |
| 113 | 26 | execBuilder2.append("Related method: ").append(exec.getMethod().getName()); |
| 114 | 26 | table.addHeader(execBuilder2.toString(), ' ', Alignment.Left); |
| 115 | |
} |
| 116 | 26 | final StringBuilder execBuilder3 = new StringBuilder(); |
| 117 | 26 | execBuilder3.append("Related annotation: ").append(exec.getRelatedAnno().getSimpleName()); |
| 118 | 26 | table.addHeader(execBuilder3.toString(), ' ', Alignment.Left); |
| 119 | 26 | table.addLine('-'); |
| 120 | |
|
| 121 | 26 | } |
| 122 | 10 | table.addLine('='); |
| 123 | 10 | out.println(table.toString()); |
| 124 | 10 | } |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
private NiceTable generateMeterResult(final String columnDesc, final AbstractMeter meter, |
| 140 | |
final AbstractResult result, final NiceTable input) { |
| 141 | 115 | input.addRow(new String[] { |
| 142 | |
columnDesc, |
| 143 | |
meter.getUnit(), |
| 144 | |
AbstractOutput.format(result.sum(meter)), |
| 145 | |
AbstractOutput.format(result.min(meter)), |
| 146 | |
AbstractOutput.format(result.max(meter)), |
| 147 | |
AbstractOutput.format(result.mean(meter)), |
| 148 | |
AbstractOutput.format(result.getStandardDeviation(meter)), |
| 149 | |
new StringBuilder("[").append(AbstractOutput.format(result.getConf05(meter))).append("-").append( |
| 150 | |
AbstractOutput.format(result.getConf95(meter))).append("]").toString(), |
| 151 | |
AbstractOutput.format(result.getResultSet(meter).size()) |
| 152 | |
}); |
| 153 | 115 | return input; |
| 154 | |
} |
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
@Override |
| 160 | |
public boolean listenToResultSet(final Method meth, final AbstractMeter meter, final double data) { |
| 161 | 50 | final StringBuilder builder = new StringBuilder(); |
| 162 | 50 | builder.append("Class: ").append(meth.getDeclaringClass().getSimpleName()).append("#").append( |
| 163 | |
meth.getName()); |
| 164 | 50 | builder.append("\nMeter: ").append(meter.getName()); |
| 165 | 50 | builder.append("\nData: ").append(data).append("\n"); |
| 166 | 50 | out.println(builder.toString()); |
| 167 | 50 | return true; |
| 168 | |
} |
| 169 | |
|
| 170 | |
|
| 171 | |
@Override |
| 172 | |
public boolean listenToException(final AbstractPerfidixMethodException exec) { |
| 173 | 5 | final StringBuilder builder = new StringBuilder(); |
| 174 | 5 | if (exec.getMethod() != null) { |
| 175 | 5 | builder.append("Class: ").append(exec.getMethod().getDeclaringClass().getSimpleName()) |
| 176 | |
.append("#").append(exec.getMethod().getName()).append("\n"); |
| 177 | |
} |
| 178 | 5 | builder.append("Annotation: ").append(exec.getRelatedAnno().getSimpleName()); |
| 179 | 5 | builder.append("\nException: ").append(exec.getClass().getSimpleName()).append("/").append( |
| 180 | |
exec.getExec().toString()); |
| 181 | 5 | out.println(builder.toString()); |
| 182 | 5 | exec.getExec().printStackTrace(out); |
| 183 | 5 | return true; |
| 184 | |
|
| 185 | |
} |
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
private NiceTable generateHeader(final NiceTable table) { |
| 195 | 10 | table.addHeader("Benchmark"); |
| 196 | 10 | table.addRow(new String[] { |
| 197 | |
"-", "unit", "sum", "min", "max", "avg", "stddev", "conf95", "runs" |
| 198 | |
}); |
| 199 | 10 | return table; |
| 200 | |
} |
| 201 | |
|
| 202 | |
} |