001: package org.apache.lucene.benchmark;
002:
003: import java.io.File;
004: import java.io.FileReader;
005: import java.io.IOException;
006:
007: import org.apache.commons.digester.Digester;
008: import org.apache.lucene.benchmark.standard.StandardBenchmarker;
009: import org.apache.lucene.benchmark.stats.TestData;
010: import org.xml.sax.InputSource;
011: import org.xml.sax.SAXException;
012:
013: /**
014: * Copyright 2005 The Apache Software Foundation
015: *
016: * Licensed under the Apache License, Version 2.0 (the "License");
017: * you may not use this file except in compliance with the License.
018: * You may obtain a copy of the License at
019: *
020: * http://www.apache.org/licenses/LICENSE-2.0
021: *
022: * Unless required by applicable law or agreed to in writing, software
023: * distributed under the License is distributed on an "AS IS" BASIS,
024: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
025: * See the License for the specific language governing permissions and
026: * limitations under the License.
027: */
028:
029: /**
030: * Sets up the benchmark driver.
031: *
032: **/
033: public class Driver {
034: private File workingDir;
035: private Benchmarker benchmarker;
036: private BenchmarkOptions options;
037:
038: public Driver() {
039: }
040:
041: public Driver(Benchmarker benchmarker, BenchmarkOptions options) {
042: this .benchmarker = benchmarker;
043: this .options = options;
044: }
045:
046: /**
047: * Creates a Driver using Digester
048: * @param inputSource
049: */
050: public Driver(File workingDir, InputSource inputSource)
051: throws IOException, SAXException {
052: Digester digester = new Digester();
053: digester.setValidating(false);
054: digester.addObjectCreate("benchmark/benchmarker", "class",
055: StandardBenchmarker.class);
056: digester.addSetProperties("benchmark/benchmarker");
057: digester.addSetNext("benchmark/benchmarker", "setBenchmarker");
058: digester.addObjectCreate("benchmark/options", "class",
059: BenchmarkOptions.class);
060: digester.addSetProperties("benchmark/options");
061: digester.addSetNext("benchmark/options", "setOptions");
062: digester.push(this );
063: digester.parse(inputSource);
064: this .workingDir = workingDir;
065: }
066:
067: private void run() throws Exception {
068: TestData[] data = benchmarker.benchmark(workingDir, options);
069: //Print out summary:
070: /*System.out.println("Test Data:");
071: for (int i = 0; i < data.length; i++)
072: {
073: TestData testData = data[i];
074: System.out.println("---------------");
075: System.out.println(testData.showRunData(testData.getId()));
076: System.out.println("---------------");
077: }*/
078:
079: }
080:
081: public Benchmarker getBenchmarker() {
082: return benchmarker;
083: }
084:
085: public void setBenchmarker(Benchmarker benchmarker) {
086: this .benchmarker = benchmarker;
087: }
088:
089: public BenchmarkOptions getOptions() {
090: return options;
091: }
092:
093: public void setOptions(BenchmarkOptions options) {
094: this .options = options;
095: }
096:
097: public File getWorkingDir() {
098: return workingDir;
099: }
100:
101: public void setWorkingDir(File workingDir) {
102: this .workingDir = workingDir;
103: }
104:
105: public static void main(String[] args) {
106:
107: if (args.length != 2) {
108: printHelp(args);
109: System.exit(0);
110: }
111: File workingDir = new File(args[0]);
112: File configFile = new File(args[1]);
113: if (configFile.exists()) {
114: //Setup
115: try {
116: Driver driver = new Driver(workingDir, new InputSource(
117: new FileReader(configFile)));
118: driver.run();
119: } catch (Exception e) {
120: e.printStackTrace(System.err);
121: }
122: }
123:
124: }
125:
126: private static void printHelp(String[] args) {
127: System.out.println("Usage: java -cp [...] "
128: + Driver.class.getName()
129: + "<working dir> <config-file>");
130: }
131: }
|