4 * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa
5 * Clara, California 95054, U.S.A. All rights reserved.
7 * Sun Microsystems, Inc. has intellectual property rights relating to
8 * technology embodied in the product that is described in this
9 * document. In particular, and without limitation, these
10 * intellectual property rights may include one or more of the
11 * U.S. patents listed at http://www.sun.com/patents and one or more
12 * additional patents or pending patent applications in the U.S. and
15 * U.S. Government Rights - Commercial software.
16 * Government users are subject to the Sun Microsystems, Inc. standard
17 * license agreement and applicable provisions of the FAR and its
18 * supplements. Use is subject to license terms. Sun, Sun
19 * Microsystems, the Sun logo and Java are trademarks or registered
20 * trademarks of Sun Microsystems, Inc. in the U.S. and other
23 * This product is covered and controlled by U.S. Export Control laws
24 * and may be subject to the export or import laws in other countries.
25 * Nuclear, missile, chemical biological weapons or nuclear maritime
26 * end uses or end users, whether direct or indirect, are strictly
27 * prohibited. Export or reexport to countries subject to
28 * U.S. embargo or to entities identified on U.S. export exclusion
29 * lists, including, but not limited to, the denied persons and
30 * specially designated nationals lists is strictly prohibited.
34 import static dstm2.Defaults.*;
35 import dstm2.benchmark.Benchmark;
36 import TransactionalIO.exceptions.PanicException;
37 import dstm2.factory.Factory;
42 * @param args the command line arguments
43 * usage: dstm.benchmark.Main -b <benchmarkclass> [-m <managerclass>] [-t <#threads>] [-n <#time-in-ms>] [-e <experiment#>] [-f <factory>"
45 public static void main(String args[]) {
46 int numThreads = 20;//THREADS;
48 int experiment = EXPERIMENT;
49 String managerClassName = MANAGER;
50 Class managerClass = null;
51 String benchmarkClassName = null;
52 Class benchmarkClass = null;
54 String adapterClassName = Defaults.ADAPTER;
56 // discard statistics from previous runs
58 // Parse and check the args
61 while (argc < args.length) {
62 String option = args[argc++];
63 if (option.equals("-m"))
64 managerClassName = args[argc];
65 else if (option.equals("-b"))
66 benchmarkClassName = args[argc];
67 else if (option.equals("-t"))
68 numThreads = Integer.parseInt(args[argc]);
69 else if (option.equals("-n"))
70 numMillis = Integer.parseInt(args[argc]);
71 else if (option.equals("-e"))
72 experiment = Integer.parseInt(args[argc]);
73 else if (option.equals("-a"))
74 adapterClassName = args[argc];
76 reportUsageErrorAndDie();
79 } catch (NumberFormatException e) {
80 System.out.println("Expected a number: " + args[argc]);
82 } catch (Exception e) {
83 reportUsageErrorAndDie();
86 // Initialize contention manager.
88 managerClass = Class.forName(MANAGER);
89 Thread.setContentionManagerClass(managerClass);
90 } catch (ClassNotFoundException ex) {
91 reportUsageErrorAndDie();
94 // Initialize adapter class
95 Thread.setAdapterClass(adapterClassName);
97 // initialize benchmark
98 Benchmark benchmark = null;
100 benchmarkClass = Class.forName(benchmarkClassName);
101 benchmark = (Benchmark) benchmarkClass.newInstance();
102 } catch (InstantiationException e) {
103 System.out.format("%s does not implement dstm.benchmark.Benchmark: %s\n", benchmarkClass, e);
105 } catch (ClassCastException e) {
106 System.out.format("Exception when creating class %s: %s\n", benchmarkClass, e);
108 } catch (Exception e) {
109 e.printStackTrace(System.out);
113 // Set up the benchmark
116 Thread[] thread = new Thread[numThreads];
117 System.out.println("Benchmark: " + benchmarkClass);
118 System.out.println("Adapter: " + adapterClassName);
119 System.out.println("Contention manager: " + managerClassName);
120 System.out.println("Threads: " + numThreads);
121 System.out.println("Mix: " + experiment + "% updates");
124 TransactionalIO.benchmarks.benchmark.init();
126 System.out.println((char)97);
129 for (int i = 0; i < numThreads; i++){
130 System.out.println((char)j);
131 thread[i] = benchmark.createThread(experiment, (char)j);
135 startTime = System.currentTimeMillis();
136 for (int i = 0; i < numThreads; i++)
138 Thread.sleep(numMillis);
139 Thread.stop = true; // notify threads to stop
140 for (int i = 0; i < numThreads; i++) {
143 } catch (Exception e) {
144 e.printStackTrace(System.out);
147 long stopTime = System.currentTimeMillis();
149 double elapsed = (double)(stopTime - startTime) / 1000.0;
151 // Run the sanity check for this benchmark
153 benchmark.sanityCheck();
154 } catch (Exception e) {
155 e.printStackTrace(System.out);
158 long committed = Thread.totalCommitted;
159 long total = Thread.totalTotal;
161 System.out.printf("Committed: %d\nTotal: %d\nPercent committed: (%d%%)\n",
164 (100 * committed) / total);
166 System.out.println("No transactions executed!");
169 System.out.println("Elapsed time: " + elapsed + " seconds.");
170 System.out.println("----------------------------------------");
173 private static void reportUsageErrorAndDie() {
174 System.out.println("usage: dstm2.Main -b <benchmarkclass> [-m <managerclass>] [-t <#threads>] [-n <#time-in-ms>] [-e <experiment#>] [-a <adapter>]");