2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package dstm2.benchmark;
7 import java.io.BufferedReader;
8 import java.io.BufferedWriter;
9 import java.io.FileReader;
10 import java.io.FileWriter;
11 import java.io.IOException;
12 import java.util.logging.Level;
14 import dstm2.Defaults;
25 * @param args the command line arguments
26 * The first args is the name of the output file args[0]
27 * The second args is the name of the randomwords input file args[1]
28 * The third args is the name of the sequential words input file args[2]
30 public static void main(String[] args) {
32 // Code For Inserting Words From Random File to The Binary Tree
34 int numThreads = 20;//THREADS;
35 int numMillis = Defaults.TIME;
36 int experiment = Defaults.EXPERIMENT;
37 String managerClassName = Defaults.MANAGER;
38 Class managerClass = null;
39 String benchmarkClassName = null;
40 Class benchmarkClass = null;
41 double ii = (double)new File("/home/navid/iliad.text").length() / (double)20;
43 System.out.println(Math.ceil(ii));
44 String adapterClassName = Defaults.ADAPTER;
46 // discard statistics from previous runs
48 // Parse and check the args
51 while (argc < args.length) {
52 String option = args[argc++];
53 if (option.equals("-m"))
54 managerClassName = args[argc];
55 else if (option.equals("-b"))
56 benchmarkClassName = args[argc];
57 else if (option.equals("-t"))
58 numThreads = Integer.parseInt(args[argc]);
59 else if (option.equals("-n"))
60 numMillis = Integer.parseInt(args[argc]);
61 else if (option.equals("-e"))
62 experiment = Integer.parseInt(args[argc]);
63 else if (option.equals("-a"))
64 adapterClassName = args[argc];
66 reportUsageErrorAndDie();
69 } catch (NumberFormatException e) {
70 System.out.println("Expected a number: " + args[argc]);
72 } catch (Exception e) {
73 reportUsageErrorAndDie();
76 // Initialize contention manager.
78 managerClass = Class.forName(Defaults.MANAGER);
79 Thread.setContentionManagerClass(managerClass);
80 } catch (ClassNotFoundException ex) {
81 reportUsageErrorAndDie();
84 // Initialize adapter class
85 Thread.setAdapterClass(adapterClassName);
87 // initialize benchmark
88 Benchmark benchmark = null;
90 benchmarkClass = Class.forName(benchmarkClassName);
91 benchmark = (Benchmark) benchmarkClass.newInstance();
93 } catch (InstantiationException e) {
94 System.out.format("%s does not implement dstm.benchmark.Benchmark: %s\n", benchmarkClass, e);
96 } catch (ClassCastException e) {
97 System.out.format("Exception when creating class %s: %s\n", benchmarkClass, e);
99 } catch (Exception e) {
100 e.printStackTrace(System.out);
104 // Set up the benchmark
107 Thread[] thread = new Thread[numThreads];
108 System.out.println("Benchmark: " + benchmarkClass);
109 System.out.println("Adapter: " + adapterClassName);
110 System.out.println("Contention manager: " + managerClassName);
111 System.out.println("Threads: " + numThreads);
112 System.out.println("Mix: " + experiment + "% updates");
115 TransactionalIO.benchmarks.benchmark.init();
117 // System.out.println((char)97);
120 for (int i = 0; i < numThreads; i++){
122 //thread[i] = benchmark.createThread(experiment, (char)j);
123 thread[i] = benchmark.createThread(experiment, (char)j);
127 startTime = System.currentTimeMillis();
128 for (int i = 0; i < numThreads; i++)
130 // Thread.sleep(numMillis);
131 // Thread.stop = true; // notify threads to stop
132 for (int i = 0; i < numThreads; i++) {
135 } catch (Exception e) {
136 e.printStackTrace(System.out);
139 long stopTime = System.currentTimeMillis();
141 double elapsed = (double)(stopTime - startTime) / 1000.0;
143 // Run the sanity check for this benchmark
145 benchmark.sanityCheck();
146 } catch (Exception e) {
147 e.printStackTrace(System.out);
150 long committed = Thread.totalCommitted;
151 long total = Thread.totalTotal;
153 System.out.printf("Committed: %d\nTotal: %d\nPercent committed: (%d%%)\n",
156 (100 * committed) / total);
158 System.out.println("No transactions executed!");
161 System.out.println("Elapsed time: " + elapsed + " seconds.");
162 System.out.println("------------------------------------------");
168 private static void reportUsageErrorAndDie() {
169 System.out.println("usage: dstm2.Main -b <benchmarkclass> [-m <managerclass>] [-t <#threads>] [-n <#time-in-ms>] [-e <experiment#>] [-a <adapter>]");