1 /* Reattore HTTP Server
2
3 Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 $Id: PerfCap.java,v 1.4 2003/03/05 04:31:56 michaelh Exp $
20 */
21
22 package juju.reattore.perfcap;
23
24 import java.util.*;
25 import java.io.*;
26 import java.net.URL;
27
28 import org.apache.commons.digester.xmlrules.*;
29 import org.apache.commons.digester.*;
30 import org.apache.commons.logging.*;
31 import org.apache.commons.beanutils.BeanUtils;
32
33 import juju.reattore.perfcap.tester.*;
34 import juju.reattore.perfcap.tester.impl.*;
35 import juju.reattore.perfcap.reporter.impl.*;
36 import juju.reattore.perfcap.reporter.*;
37 import juju.reattore.perfcap.var.impl.*;
38 import juju.reattore.perfcap.var.*;
39
40 /*** An automated performance capture and reporting tool.
41
42 @tag perfcap
43 @group Top
44 @children Reporter Tester Variable
45 */
46 public class PerfCap {
47
48 private List reporters = new ArrayList();
49 private List variables = new ArrayList();
50 private List testers = new ArrayList();
51
52 private static Log log = LogFactory.getLog(PerfCap.class);
53
54 private static final String RULES = "juju/reattore/perfcap/rules.xml";
55
56 /*** Adds a reporter to call.
57
58 @param re The reporter.
59 */
60 public void addReporter(Reporter re) {
61 reporters.add(re);
62 }
63
64 /*** Adds an independant variable.
65
66 @param var The variable.
67 */
68 public void addVariable(Variable var) {
69 variables.add(var);
70 }
71
72 /*** Adds a tester to run.
73
74 @param tst The tester.
75 */
76 public void addTester(Tester tst) {
77 testers.add(tst);
78 }
79
80 private void iterate(List li, int idx)
81 throws Exception {
82
83 if (idx >= li.size()) {
84 /* At the node. Run all tests. */
85 for (Iterator tests = testers.iterator(); tests.hasNext();) {
86 Tester test = (Tester)tests.next();
87
88 /* Apply all of the variables */
89 for (Iterator vars = variables.iterator(); vars.hasNext();) {
90 Variable var = (Variable)vars.next();
91
92 BeanUtils.setProperty(test, var.getName(), var.getValue());
93 }
94
95 Results res = test.go();
96
97 for (Iterator reps = reporters.iterator(); reps.hasNext();) {
98 Reporter rep = (Reporter)reps.next();
99
100 rep.add(variables, res);
101 }
102 }
103 }
104 else {
105 Variable var = (Variable)li.get(idx++);
106
107 var.begin();
108
109 while (var.hasNext()) {
110 var.next();
111
112 iterate(li, idx);
113 }
114
115 var.end();
116 }
117 }
118
119 private void go()
120 throws Exception {
121
122 iterate(variables, 0);
123
124 for (Iterator reps = reporters.iterator(); reps.hasNext();) {
125 Reporter rep = (Reporter)reps.next();
126
127 rep.end();
128 }
129 }
130
131 private static PerfCap load(String fname)
132 throws Exception {
133
134 URL rules = PerfCap.class.getClassLoader().getResource(RULES);
135
136 if (rules == null) {
137 throw new RuntimeException("Unable to locate " + RULES);
138 }
139
140 Digester dig = DigesterLoader.createDigester(rules);
141 return (PerfCap)dig.parse(new File(fname));
142 }
143
144 /*** Entry point.
145
146 @param args First - optional config file name.
147 @throws Exception passed up from lower levels.
148 */
149 public static void main(String[] args)
150 throws Exception {
151
152 String config = args.length > 0 ? args[0] : "etc/perfcap-config.xml";
153
154 log.info("Loading configuration from " + config);
155
156 PerfCap perf = load(config);
157
158 log.info("Running tests");
159 perf.go();
160
161 /* Unfortunatly JFreeChart spawns Swing, which can only be closed
162 using exit() */
163 System.exit(0);
164 }
165 }
This page was automatically generated by Maven