001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: OO1BenchmarkApp.java,v 1.2 2002/07/13 12:09:44 per_nyfelt Exp $
008:
009: package org.ozoneDB.tools;
010:
011: import java.awt.*;
012: import java.awt.event.*;
013: import java.applet.*;
014: import java.io.*;
015: import java.util.*;
016:
017: /** */
018: class BenchmarkThread extends Thread {
019: /** */
020: public String benchmarkClassName;
021: private int benchmarkId = 1;
022: private int size = 1000;
023: private String objectName = "cattell";
024: private String serverHost = "localhost";
025: private BenchmarkProgressLog log = new BenchmarkProgressLog();
026:
027: /** */
028: public BenchmarkThread(String className) {
029: benchmarkClassName = className;
030: }
031:
032: /** */
033: public void setProgressLog(BenchmarkProgressLog blog) {
034: log = blog;
035: }
036:
037: /** */
038: public String[] filterAndApplyArgs(String[] args) {
039: Vector remainingArgs = new Vector();
040:
041: for (int i = 0; i < args.length; i++) {
042: if (args[i].startsWith("-benchmark=")) {
043: benchmarkId = new Integer(args[i].substring(11))
044: .intValue();
045: } else if (args[i].startsWith("-size=")) {
046: size = new Integer(args[i].substring(6)).intValue();
047: } else if (args[i].startsWith("-name=")) {
048: objectName = args[i].substring(6);
049: } else if (args[i].startsWith("-host=")) {
050: serverHost = args[i].substring(6);
051: log.logMessage("serverHost=" + serverHost);
052: } else {
053: remainingArgs.addElement(args[i]);
054: }
055: }
056:
057: String[] result = new String[remainingArgs.size()];
058: for (int i = 0; i < result.length; i++) {
059: result[i] = (String) remainingArgs.elementAt(i);
060: }
061:
062: return result;
063: }
064:
065: /** */
066: public static String availableArgs() {
067: return "-benchmark=<test> -size=<size> [-name=<name>] [-host=<host[:port]>]";
068: }
069:
070: /** */
071: public static String helpText() {
072: return " -benchmark= : 1: create database; size: 100..(10000)\n"
073: + " 2: lookup; size 1..\n"
074: + " 3: traversal; size: 1..7\n"
075: + " 4: insert and delete; size: 1..\n"
076: + " 5: insert; size: 1..\n"
077: + " 6: insert size*1000 objects\n"
078: + " 7: traversal on the first size cattell objects\n"
079: + " 8: insert on the first size cattell objects\n"
080: + " -size : the size of the test\n"
081: + " -name : optional name of the benchmark object\n"
082: + " -host : optional name of the server host\n";
083: }
084:
085: /** */
086: public void run() {
087: try {
088: Class benchmarkClass = Class.forName(benchmarkClassName);
089: OO1Benchmark benchmark = (OO1Benchmark) benchmarkClass
090: .newInstance();
091: benchmark.setProgressLog(log);
092: switch (benchmarkId) {
093: case 1:
094: benchmark.create(size, objectName, serverHost);
095: break;
096: case 2:
097: benchmark.lookup(size, objectName, serverHost);
098: break;
099: case 3:
100: benchmark.traversal(size, objectName, serverHost);
101: break;
102: case 4:
103: benchmark.insertAndDelete(size, objectName, serverHost);
104: break;
105: case 5:
106: benchmark.insert(size, objectName, serverHost);
107: break;
108: case 55:
109: benchmark.delete(size, objectName, serverHost);
110: break;
111: case 6:
112: benchmark.createObjects(size, objectName, serverHost);
113: break;
114: case 7:
115: benchmark
116: .traversalObjects(size, objectName, serverHost);
117: break;
118: case 8:
119: benchmark.insertObjects(size, objectName, serverHost);
120: break;
121: }
122: } catch (Exception e) {
123: e.printStackTrace();
124: }
125: }
126: }
127:
128: /** */
129: public class OO1BenchmarkApp extends Applet implements ActionListener,
130: ItemListener {
131:
132: /** */
133: public class AppletProgressLog extends BenchmarkProgressLog {
134:
135: /** */
136: public AppletProgressLog() {
137: }
138:
139: /** */
140: public void logMessage(String msg) {
141: if (outText != null) {
142: outText.append(msg + "\n");
143: }
144: }
145:
146: /** */
147: public void logTime(long time) {
148: if (outText != null) {
149: outText.append("time: " + time + "msec\n");
150: }
151: if (chart != null) {
152: chart.appendTime(time);
153: }
154: }
155: }
156:
157: /** */
158: protected Button startButton;
159: protected Choice testChoice;
160: protected TextField sizeText;
161: protected TextField nameText;
162: protected TextField serverText;
163: protected TextField portText;
164: protected TextArea outText;
165: protected Label statusLabel;
166: protected ChartCanvas chart;
167: protected BenchmarkThread benchmarkThread;
168:
169: /** */
170: public OO1BenchmarkApp() {
171: }
172:
173: /** */
174: public void init() {
175: init(false, new BenchmarkThread("CattellImpl"));
176: }
177:
178: /** */
179: public void init(boolean chartOnly, BenchmarkThread bmt) {
180: benchmarkThread = bmt;
181: setLayout(new BorderLayout());
182:
183: if (!chartOnly) {
184: Panel panel = new Panel();
185: panel.setLayout(new FlowLayout(FlowLayout.LEFT));
186:
187: startButton = new Button(" Start ");
188: startButton.setFont(new Font("Monospaced", Font.BOLD, 14));
189: startButton.addActionListener(this );
190: panel.add(startButton);
191:
192: testChoice = new Choice();
193: testChoice.add("Help");
194: testChoice.add("1 Create");
195: testChoice.add("2 Lookup");
196: testChoice.add("3 Traversal");
197: testChoice.add("4 Ins & del");
198: testChoice.add("5 Insert");
199: testChoice.add("6 Ins*1000");
200: testChoice.add("7 Traversal");
201: testChoice.add("8 Insert");
202: testChoice.addItemListener(this );
203: panel.add(testChoice);
204:
205: sizeText = new TextField("1000", 5);
206: sizeText.setFont(new Font("Monospaced", Font.PLAIN, 12));
207: sizeText.addActionListener(this );
208: panel.add(sizeText);
209:
210: nameText = new TextField("cattell", 9);
211: nameText.setFont(new Font("Monospaced", Font.PLAIN, 12));
212: nameText.addActionListener(this );
213: panel.add(nameText);
214:
215: serverText = new TextField("localhost", 9);
216: serverText.setFont(new Font("Monospaced", Font.PLAIN, 12));
217: serverText.addActionListener(this );
218: panel.add(serverText);
219:
220: portText = new TextField("3333", 9);
221: portText.setFont(new Font("Monospaced", Font.PLAIN, 12));
222: portText.addActionListener(this );
223: panel.add(portText);
224:
225: add("North", panel);
226:
227: panel = new Panel();
228: panel.setLayout(new BorderLayout());
229:
230: outText = new TextArea();
231: panel.add(outText, "North");
232:
233: chart = new ChartCanvas();
234: panel.add(chart, "Center");
235:
236: add("Center", panel);
237:
238: statusLabel = new Label(
239: "Test:Build - Size:1000 - Name:cattell ");
240: add("South", statusLabel);
241: } else {
242: chart = new ChartCanvas();
243: add("Center", chart);
244: }
245:
246: benchmarkThread.setProgressLog(new AppletProgressLog());
247: }
248:
249: /** */
250: public void itemStateChanged(ItemEvent e) {
251: String[] defaults = { "0", "1000", "100", "7", "100", "100",
252: "10", "10", "10" };
253: if (testChoice.getSelectedIndex() > -1) {
254: sizeText.setText(defaults[testChoice.getSelectedIndex()]);
255: }
256: }
257:
258: /** */
259: public void actionPerformed(ActionEvent e) {
260: if (startButton.getLabel().equals(" Start ")) {
261: int test = testChoice.getSelectedIndex();
262: int size = Integer.valueOf(sizeText.getText()).intValue();
263: String name = nameText.getText();
264: String server = serverText.getText();
265: String port = portText.getText();
266: statusLabel.setText("Test: " + test + " Size: " + size
267: + " Name: " + name + " Host: " + server + ":"
268: + port);
269:
270: String[] args = { "-benchmark=" + test, "-size=" + size,
271: "-name=" + name, "-host=" + server + ":" + port };
272: benchmarkThread.filterAndApplyArgs(args);
273: startButton.setLabel(" Stop ");
274: benchmarkThread.start();
275: } else {
276: benchmarkThread.stop();
277: benchmarkThread = new BenchmarkThread(
278: benchmarkThread.benchmarkClassName);
279: benchmarkThread.setProgressLog(new AppletProgressLog());
280: startButton.setLabel(" Start ");
281: }
282: }
283:
284: /** */
285: public static void createFrame(boolean chartOnly,
286: BenchmarkThread thread) {
287: Frame f = new Frame("Cattell Benchmark");
288: OO1BenchmarkApp applet = new OO1BenchmarkApp();
289:
290: applet.init(chartOnly, thread);
291: applet.start();
292:
293: f.add("Center", applet);
294: f.pack();
295: f.setSize(chartOnly ? 300 : 550, chartOnly ? 120 : 400);
296: f.show();
297: f.addWindowListener(new WindowAdapter() {
298:
299: public void windowClosing(WindowEvent e) {
300: System.exit(0);
301: }
302: });
303:
304: if (chartOnly) {
305: thread.run();
306: }
307: }
308:
309: /** */
310: public static void main(String[] args) {
311: boolean chartOnly = false;
312: boolean noGui = false;
313: String benchmarkClass = "CattellImpl";
314:
315: for (int i = 0; i < args.length; i++) {
316: if (args[i].startsWith("-chartOnly")) {
317: chartOnly = true;
318: } else if (args[i].startsWith("-noGui")) {
319: noGui = true;
320: } else if (args[i].startsWith("-class=")) {
321: benchmarkClass = args[i].substring(7);
322: } else {
323: if (args[i].startsWith("-help")
324: || args[i].startsWith("-?")) {
325: System.out
326: .println("usage: java OO1BenchmarkApp "
327: + BenchmarkThread.availableArgs()
328: + " "
329: + ChartCanvas.availableArgs()
330: + " "
331: + "[-chartOnly] [-noGui] [-class=<classname>] [-help|-h|-?]\n"
332: + "Details:\n"
333: + BenchmarkThread.helpText()
334: + ChartCanvas.helpText()
335: + " -chartOnly : show only the chart panel and perform the given test\n"
336: + " -noGui : show no GUI at all and perform the given test\n"
337: + " -class= : the benchmark class, default is CattellImpl\n"
338: + " -help|-h|-? : shows this help");
339: return;
340: }
341: }
342: }
343:
344: BenchmarkThread thread = new BenchmarkThread(benchmarkClass);
345: thread.filterAndApplyArgs(args);
346: if (noGui) {
347: thread.run();
348: } else {
349: createFrame(chartOnly, thread);
350: }
351: }
352: }
|