28 #include "helpers.hpp"
29 #include "string_helpers.hpp"
38 using std::ostringstream;
46 using utils::toString;
50 vector< string > Driver::propFileNames;
51 string Driver::logFileName;
56 cout <<
"usage: [options]" << endl
57 <<
" [-p <file name>]... properties file name" << endl
58 <<
" [-l <file name>] log file name for data output" << endl
59 <<
" [-h|--help] print usage message and exit" << endl
67 for (
int i = 1;
i < argc;
i++) {
68 const string arg = argv[
i];
69 if (arg.compare(
"-p") == 0) {
73 propFileNames.push_back(argv[++
i]);
74 }
else if (arg.compare(
"-l") == 0) {
78 logFileName = argv[++
i];
79 }
else if (arg.compare(
"-h") == 0 || arg.compare(
"--help") == 0) {
82 cout <<
"unknown option: " << arg << endl;
87 if (propFileNames.size() == 0) {
88 propFileNames.push_back(
"run.properties");
91 if (logFileName.empty()) {
95 const char format[] =
"%Y%m%d_%H%M%S";
96 const int size =
sizeof(
"yyyymmdd_HHMMSS");
100 const time_t now = time(0);
101 const int nchars = strftime(dest, size, format, localtime(&now));
102 assert(nchars == size-1);
106 logFileName +=
".txt";
119 <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl
120 <<
"hot runs ..." << endl
121 <<
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
123 for (
int i = 0;
i < nRuns;
i++) {
129 log << descr <<
", rtime[ms]"
130 << header.rdbuf()->str() << endl
131 << rtimes.rdbuf()->str() << endl << endl << endl;
134 log << descr <<
", ctime[ms]"
135 << header.rdbuf()->str() << endl
136 << ctimes.rdbuf()->str() << endl << endl << endl;
152 header.rdbuf()->str(
"");
153 rtimes.rdbuf()->str(
"");
159 header.rdbuf()->str(
"");
160 rtimes.rdbuf()->str(
"");
166 Driver::loadProperties() {
168 for (vector<string>::const_iterator
i = propFileNames.begin();
169 i != propFileNames.end(); ++
i) {
170 cout <<
"reading properties file: " << *
i << endl;
171 props.load(
i->c_str());
177 Driver::initProperties() {
178 cout <<
"setting driver properties ..." << flush;
182 logRealTime = toBool(props[L
"logRealTime"],
true);
183 logCpuTime = toBool(props[L
"logCpuTime"],
false);
185 nRuns = toInt(props[L
"nRuns"], 1, -1);
187 msg <<
"[ignored] nRuns: '"
188 << toString(props[L
"nRuns"]) <<
"'" << endl;
193 if (msg.str().empty()) {
194 cout <<
" [ok]" << endl;
196 cout << endl << msg.str() << endl;
201 Driver::printProperties() {
202 const ios_base::fmtflags f = cout.flags();
205 cout.flags(ios_base::boolalpha);
207 cout << endl <<
"driver settings ..." << endl;
208 cout <<
"logRealTime: " << logRealTime << endl;
209 cout <<
"logCpuTime: " << logCpuTime << endl;
210 cout <<
"nRuns: " << nRuns << endl;
216 Driver::openLogFile() {
218 <<
"opening results file:" << flush;
219 log.open(logFileName.c_str(), ios_base::out | ios_base::trunc);
221 cout <<
" [ok: " << logFileName <<
"]" << endl;
225 Driver::closeLogFile() {
227 <<
"closing results file:" << flush;
229 cout <<
" [ok: " << logFileName <<
"]" << endl;
235 Driver::begin(
const string&
name) {
237 cout << name << endl;
239 if (logRealTime && logCpuTime) {
241 }
else if (logRealTime) {
242 s0 = hrt_rtnow(&t0.rtstamp);
243 }
else if (logCpuTime) {
244 s0 = hrt_ctnow(&t0.ctstamp);
249 Driver::commit(
const string& name) {
250 if (logRealTime && logCpuTime) {
252 }
else if (logRealTime) {
253 s1 = hrt_rtnow(&t1.rtstamp);
254 }
else if (logCpuTime) {
255 s1 = hrt_ctnow(&t1.ctstamp);
260 cout <<
"ERROR: failed to get the system's real time.";
263 long t = long(hrt_rtmicros(&t1.rtstamp, &t0.rtstamp)/1000);
264 cout <<
"tx real time: " << t
273 cout <<
"ERROR: failed to get this process's cpu time.";
276 long t = long(hrt_ctmicros(&t1.ctstamp, &t0.ctstamp)/1000);
277 cout <<
"tx cpu time: " << t
285 header <<
"\t" <<
name;