diff options
author | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
commit | 420d2ef464d4a741028e132e662d5626806a41f5 (patch) | |
tree | 1aca6eb512e4ed0fb5f3c10c528cb998b6ffd695 /core/simulate.cpp |
Diffstat (limited to 'core/simulate.cpp')
-rw-r--r-- | core/simulate.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/core/simulate.cpp b/core/simulate.cpp new file mode 100644 index 0000000..7205308 --- /dev/null +++ b/core/simulate.cpp @@ -0,0 +1,77 @@ +#include <boost/mpl/list.hpp> +#include <boost/mpl/pair.hpp> +#include <iostream> + +#include "everything_else.hpp" +#include "perftools.hpp" +#include "signal_handler.hpp" +#include "sim_loop.hpp" + +#include "mempool.hpp" + +#include "model.hpp" + +using namespace std; + +int main(int argc, char **argv) { + // init sim env + const uint64_t eventsPerChunk = 100000; + uint64_t totalEventsProcessed(0); + installSigIntHandler(); + assertSimDir(); + + // parse command line args + assert(argc == 2); + Time until(atof(argv[1])); + + { + SimLoop<Lists::all> sim; + + Time startTime(sim.currentTime()), oldTime(startTime); + cout << "simulating from " << oldTime() + << " to " << until() << endl; + + // run for requested time + Timer timerAll; + while (oldTime < until && !terminationRequested) { + uint64_t eventsProcessed = eventsPerChunk - sim.run(until, eventsPerChunk); + totalEventsProcessed += eventsProcessed; + Time newTime(sim.currentTime()), + dt(newTime - oldTime); + cout << "\r\033[K" + << newTime() << "\t" + << eventsProcessed / dt() << " Hz(v)\t" + << totalEventsProcessed / timerAll.diff() << " Hz(p)\t" + << totalEventsProcessed << " events\t"; + if (newTime < until) + cout << "ETA " << ceil( (until() - newTime()) + / (newTime() - startTime()) + * timerAll.diff()); + cout << flush; + oldTime = newTime; + } + + if (terminationRequested) { + cout << " ... received SIGINT, terminating" << endl; + }else{ + cout << "\r\033[K"; + } + + // print summary + cout << "simulated " << totalEventsProcessed << " events " + << "in " << timerAll.diff() << " s " + << "(" << totalEventsProcessed / timerAll.diff() << " Hz(p))" + << endl; + + // sync to disk + cout << "syncing ... " << flush; + Timer timerSync; + sim.sync(); + cout << "done (" << timerSync.diff() << "s)" << endl; + + if (terminationRequested) + sigIntExit(); + } + + return 0; +} |