1
/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
4
* Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
#include "helpers.hpp"
25
#include "string_helpers.hpp"
34
using utils::Properties;
37
using utils::toString;
39
// ---------------------------------------------------------------------------
40
// Helper Macros & Functions
41
// ---------------------------------------------------------------------------
43
#define ABORT_GETTIMEOFDAY_ERROR() \
44
do { cout << "!!! error in " << __FILE__ << ", line: " << __LINE__ \
45
<< ", gettimeofday() returned an error code." << endl; \
49
// ---------------------------------------------------------------------------
50
// Driver Implementation
51
// ---------------------------------------------------------------------------
53
vector< string > Driver::propFileNames;
54
string Driver::logFileName;
59
cout << "usage: [options]" << endl
60
<< " [-p <file name>]... properties file name" << endl
61
<< " [-l <file name>] log file name for data output" << endl
62
<< " [-h|--help] print usage message and exit" << endl
64
exit(1); // return an error code
68
Driver::parseArguments(int argc, const char* argv[])
70
for (int i = 1; i < argc; i++) {
71
const string arg = argv[i];
72
if (arg.compare("-p") == 0) {
76
propFileNames.push_back(argv[++i]);
77
} else if (arg.compare("-l") == 0) {
81
logFileName = argv[++i];
82
} else if (arg.compare("-h") == 0 || arg.compare("--help") == 0) {
85
cout << "unknown option: " << arg << endl;
90
if (propFileNames.size() == 0) {
91
propFileNames.push_back("run.properties");
94
if (logFileName.empty()) {
97
// format, destination strings (static size)
98
const char format[] = "%Y%m%d_%H%M%S";
99
const int size = sizeof("yyyymmdd_HHMMSS");
102
// get time, convert to timeinfo (statically allocated) then to string
103
const time_t now = time(0);
104
const int nchars = strftime(dest, size, format, localtime(&now));
105
assert(nchars == size-1);
109
logFileName += ".txt";
111
//cout << "logFileName='" << logFileName << "'" << endl;
114
// ----------------------------------------------------------------------
120
if (warmupRuns > 0) {
122
<< "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl
123
<< "warmup runs ..." << endl
124
<< "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
126
for (int i = 0; i < warmupRuns; i++) {
130
// truncate log file, reset log buffers
137
<< "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl
138
<< "hot runs ..." << endl
139
<< "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
143
<< "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
163
Driver::loadProperties() {
165
for (vector<string>::const_iterator i = propFileNames.begin();
166
i != propFileNames.end(); ++i) {
167
cout << "reading properties file: " << *i << endl;
168
props.load(i->c_str());
169
//cout << "props = {" << endl << props << "}" << endl;
174
Driver::initProperties() {
175
cout << "setting driver properties ..." << flush;
179
warmupRuns = toInt(props[L"warmupRuns"], 0, -1);
180
if (warmupRuns < 0) {
181
msg << "[ignored] warmupRuns: '"
182
<< toString(props[L"warmupRuns"]) << "'" << endl;
186
//if (msg.tellp() == 0) // netbeans reports amibuities
187
if (msg.str().empty()) {
188
cout << " [ok]" << endl;
190
cout << endl << msg.str() << endl;
195
Driver::printProperties() {
196
const ios_base::fmtflags f = cout.flags();
197
// no effect calling manipulator function, not sure why
198
//cout << ios_base::boolalpha;
199
cout.flags(ios_base::boolalpha);
201
cout << endl << "driver settings ..." << endl;
202
cout << "warmupRuns: " << warmupRuns << endl;
208
Driver::openLogFile() {
210
<< "opening results file:" << flush;
211
log.open(logFileName.c_str(), ios_base::out | ios_base::trunc);
213
cout << " [ok: " << logFileName << "]" << endl;
217
Driver::closeLogFile() {
219
<< "closing results file:" << flush;
221
cout << " [ok: " << logFileName << "]" << endl;
224
// ---------------------------------------------------------------------------
227
Driver::clearLogBuffers() {
229
header.rdbuf()->str("");
230
rtimes.rdbuf()->str("");
234
Driver::writeLogBuffers() {
235
log << descr << ", rtime[ms]"
236
<< header.rdbuf()->str() << endl
237
<< rtimes.rdbuf()->str() << endl;
241
Driver::begin(const string& name) {
243
cout << name << endl;
245
if (gettimeofday(&t0, NULL) != 0)
246
ABORT_GETTIMEOFDAY_ERROR();
250
Driver::finish(const string& name) {
251
if (gettimeofday(&t1, NULL) != 0)
252
ABORT_GETTIMEOFDAY_ERROR();
254
const long r_usec = (((t1.tv_sec - t0.tv_sec) * 1000000)
255
+ (t1.tv_usec - t0.tv_usec));
256
const long r_msec = r_usec / 1000;
258
cout << "tx real time: " << r_msec
260
rtimes << "\t" << r_msec;
264
header << "\t" << name;
267
//---------------------------------------------------------------------------