1 /* -*- mode: java; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  *  vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
3  *
4  *  Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License, version 2.0,
8  *  as published by the Free Software Foundation.
9  *
10  *  This program is also distributed with certain software (including
11  *  but not limited to OpenSSL) that is licensed under separate terms,
12  *  as designated in a particular file or component or in included license
13  *  documentation.  The authors of MySQL hereby grant you an additional
14  *  permission to link the program and your derivative works with the
15  *  separately licensed software that they have included with MySQL.
16  *
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License, version 2.0, for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25  */
26 
27 #ifndef Driver_hpp
28 #define Driver_hpp
29 
30 #include <iostream>
31 #include <sstream>
32 #include <fstream>
33 #include <string>
34 #include <vector>
35 
36 #include "Properties.hpp"
37 #include "hrt_utils.h"
38 
39 using std::ofstream;
40 using std::ostringstream;
41 using std::string;
42 using std::vector;
43 
44 using utils::Properties;
45 
46 class Driver {
47 public:
48 
49     /**
50      * Parses the benchmark's command-line arguments.
51      */
52     static void parseArguments(int argc, const char* argv[]);
53 
54     /**
55      * Creates an instance.
56      */
Driver()57     Driver() {}
58 
59     /**
60      * Deletes an instance.
61      */
~Driver()62     virtual ~Driver() {}
63 
64     /**
65      * Runs the benchmark.
66      */
67     void run();
68 
69 protected:
70 
71     // command-line arguments
72     static vector< string > propFileNames;
73     static string logFileName;
74 
75     static void exitUsage();
76 
77     // driver settings
78     Properties props;
79     bool logRealTime;
80     bool logCpuTime;
81     int nRuns;
82 
83     // driver resources
84     ofstream log;
85     string descr;
86     bool logHeader;
87     ostringstream header;
88     ostringstream rtimes;
89     ostringstream ctimes;
90     int s0, s1;
91     hrt_tstamp t0, t1;
92     long rta, cta;
93 
94     // driver intializers/finalizers
95     virtual void init();
96     virtual void close();
97     virtual void loadProperties();
98     virtual void initProperties();
99     virtual void printProperties();
100     virtual void openLogFile();
101     virtual void closeLogFile();
102 
103     // benchmark operations
104     virtual void runTests() = 0;
105     virtual void begin(const string& name);
106     virtual void commit(const string& name);
107 };
108 
109 #endif // Driver_hpp
110