24 #include "helpers.hpp" 
   25 #include "string_helpers.hpp" 
   37 using utils::toString;
 
   43 #define ABORT_GETTIMEOFDAY_ERROR()                                      \ 
   44     do { cout << "!!! error in " << __FILE__ << ", line: " << __LINE__  \ 
   45               << ", gettimeofday() returned an error code." << endl;    \ 
   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
 
   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()) {
 
   98         const char format[] = 
"%Y%m%d_%H%M%S";
 
   99         const int size = 
sizeof(
"yyyymmdd_HHMMSS");
 
  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";
 
  120     if (warmupRuns > 0) {
 
  122              << 
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl
 
  123              << 
"warmup runs ..." << endl
 
  124              << 
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
 
  126         for (
int i = 0; 
i < warmupRuns; 
i++) {
 
  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());
 
  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;
 
  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();
 
  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;
 
  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;