01: /*
02: * Copyright (C) 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 15. July 2006 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.tools.benchmark.reporters;
13:
14: import com.thoughtworks.xstream.tools.benchmark.Metric;
15: import com.thoughtworks.xstream.tools.benchmark.Product;
16: import com.thoughtworks.xstream.tools.benchmark.Reporter;
17: import com.thoughtworks.xstream.tools.benchmark.Target;
18:
19: import java.io.PrintWriter;
20: import java.io.Writer;
21:
22: /**
23: * Reports results of Harness in text form designed for human reading.
24: *
25: * @author Joe Walnes
26: * @see com.thoughtworks.xstream.tools.benchmark.Harness
27: * @see Reporter
28: */
29: public class TextReporter implements Reporter {
30:
31: private final PrintWriter out;
32: private Metric currentMetric;
33:
34: public TextReporter(PrintWriter out) {
35: this .out = out;
36: }
37:
38: public TextReporter(Writer out) {
39: this (new PrintWriter(out));
40: }
41:
42: /**
43: * Reports to System.out.
44: */
45: public TextReporter() {
46: this (new PrintWriter(System.out, true));
47: }
48:
49: public void startBenchmark() {
50: }
51:
52: public void startMetric(Metric metric) {
53: currentMetric = metric;
54: out
55: .println("======================================================================");
56: out.println(metric);
57: out
58: .println("======================================================================");
59: }
60:
61: public void startTarget(Target target) {
62: out.println("* " + target + "");
63: }
64:
65: public void metricRecorded(Product product, double result) {
66: out.println(" - " + pad(product.toString()) + " " + result
67: + " " + currentMetric.unit());
68: }
69:
70: public void metricFailed(Product product, Exception e) {
71: out.println(" - " + pad(product.toString()) + " FAILED (" + e
72: + ")");
73: }
74:
75: public void endTarget(Target target) {
76: }
77:
78: public void endMetric(Metric metric) {
79: out.println();
80: currentMetric = null;
81: }
82:
83: public void endBenchmark() {
84: out.flush();
85: }
86:
87: private String pad(String value) {
88: StringBuffer result = new StringBuffer();
89: result.append(value);
90: while (result.length() < 50) {
91: result.append('.');
92: }
93: return result.toString();
94: }
95: }
|