Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a2d91ab06ef04cc47f7e76ebdb5a7f54d5aec328 (plain) (blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.tests.ccvs.ui.old;


import java.io.PrintStream;

public class PrintTextSummaryVisitor implements ILogEntryVisitor {
	private PrintStream os;
	private String indent;
	private int totalAverageTime;
	
	/**
	 * Creates a visitor to print a summary of all entries contained in a log.
	 * @param os the output stream
	 */
	public PrintTextSummaryVisitor(PrintStream os) {
		this.os = os;
		this.indent = "";
		this.totalAverageTime = 0;
	}
	
	protected void visitContainer(LogEntryContainer container) {
		int oldTotalAverageTime = totalAverageTime;
		indent += "  ";
		container.acceptChildren(this);
		int averageTime = totalAverageTime - oldTotalAverageTime;
		StringBuffer line = new StringBuffer(indent);
		line.append("* total: ");
		line.append(Integer.toString(averageTime));
		line.append(" ms");
		os.println(line);
		indent = indent.substring(2);
	}

	/**
	 * Prints the root entry information.
	 */
	public void visitRootEntry(RootEntry entry) {
		entry.acceptChildren(this);
	}
	
	/**
	 * Prints the total average time spent by all subgroups and subtasks.
	 */
	public void visitCaseEntry(CaseEntry entry) {
		StringBuffer line = new StringBuffer(indent);
		line.append("%%% ");
		line.append(entry.getName());
		line.append(", class=");
		line.append(entry.getClassName());
		line.append(':');
		os.println(line);
		visitContainer(entry);
		os.println();
	}

	/**
	 * Prints the total average time spent by all subtasks.
	 */
	public void visitGroupEntry(GroupEntry entry) {		
		StringBuffer line = new StringBuffer(indent);
		line.append("+ ");
		line.append(entry.getName());
		line.append(':');
		os.println(line);
		visitContainer(entry);
	}
	
	/**
	 * Prints the average amount of time spent by a task.
	 */
	public void visitTaskEntry(TaskEntry task) {
		StringBuffer line = new StringBuffer(indent);
		line.append("- ");
		line.append(task.getName());
		line.append(": ");
		if (task.getTotalRuns() != 0) {
			int averageTime = task.getAverageMillis();
			totalAverageTime += averageTime;
			line.append(Integer.toString(averageTime));
			line.append(" ms");
			if (task.getTotalRuns() > 1) {
				line.append(" avg. over ");
				line.append(Integer.toString(task.getTotalRuns()));
				line.append(" runs");
				if (averageTime != 0) {
					int confidence = task.getConfidenceInterval();
					line.append(" (95% C.I. +/- ");
					line.append(Integer.toString(confidence));
					line.append(" ms = ");
					line.append(Util.formatPercentageRatio(confidence, averageTime));
					line.append(")");
				}
			}
		} else {
			line.append("skipped!");
		}
		os.println(line);
	}
}

Back to the top