#include #include #include #include "Jeep/JTimekeeper.hh" #include "JSystem/JTime.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * Example program to test JEEP::JTimekeeper class. * \author mdejong */ int main(int argc, char* argv[]) { using namespace std; int intervalTime_ms; int totalTime_s; int debug; try { JParser<> zap; zap['t'] = make_field(intervalTime_ms) = 100; zap['s'] = make_field(totalTime_s) = 2; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; if (intervalTime_ms <= 0) { FATAL("interval time [ms] " << intervalTime_ms << " < 0." << endl); } if (totalTime_s <= 0) { FATAL("total time [s] " << totalTime_s << " < 0." << endl); } JFileDescriptorMask mask; cout << "hit to interrupt" << endl; JTimekeeper clock; clock.setInterval(intervalTime_ms * 1000); clock.reset(); const long long int t0 = getLocalTime(); string buffer; int numberOfInterrupts = 0; for (int i = 0; i < 1000 * totalTime_s / intervalTime_ms; ) { DEBUG(setw(5) << i << rewind); mask.set(STDIN_FILENO); // hit to interrupt wait(..) if (clock.wait(mask)) { getline(cin, buffer); // flush input ++numberOfInterrupts; } else { ++i; } } NOTICE(endl); const long long int t1 = getLocalTime(); NOTICE("Number of interrupts " << setw(8) << right << numberOfInterrupts << endl); NOTICE("Total delay [ms] " << setw(8) << right << clock.getDelay() / 1000 << endl); NOTICE("Elapsed time [ms] " << setw(8) << right << (t1 - t0) / 1000 << endl); if (numberOfInterrupts != 0) { NOTICE("Time per interrupt [us] " << setw(8) << right << (t1 - t0 - clock.getDelay()) / numberOfInterrupts << endl); } }