Disabled sniper, added logging to report sim progress.
This commit is contained in:
1 parent
3be5afc08b
commit
bcf4a04409
2 files changed
+40
-6
No files matched your search
@@ -13,7 +13,7 @@ namespace bts::spartan::mdp3 {
|
||||
struct ExchangeSim::RunState {
|
||||
RunState(protos::SimRunOptions const &o)
|
||||
: simulator(), options(o), timer(), gateways(), algos(),
|
||||
last_time_log(Timer::now()),last_sim_time(0) {}
|
||||
last_time_log(Timer::now()), last_sim_time(0) {}
|
||||
|
||||
sim::Simulator simulator;
|
||||
protos::SimRunOptions options;
|
||||
@@ -24,7 +24,10 @@ struct ExchangeSim::RunState {
|
||||
std::vector<AlgoAgent> algos;
|
||||
|
||||
bts::TimeStamp last_time_log;
|
||||
bts::TimeStamp run_start;
|
||||
sim::TimeStamp last_sim_time;
|
||||
size_t last_completed_count;
|
||||
size_t starting_event_count;
|
||||
};
|
||||
|
||||
struct ExchangeSim::PImpl {
|
||||
@@ -92,7 +95,11 @@ void ExchangeSim::prepare_run(std::vector<IAlgoModel *> const &algos,
|
||||
for (auto &rev : i->transactions)
|
||||
me->run_state->simulator.emit_event<ExchangeTransactionEvent>(
|
||||
rev.transact_time.value(), rev);
|
||||
bts_assert(me->run_state->simulator.pending_events_count());
|
||||
me->run_state->starting_event_count =
|
||||
me->run_state->simulator.pending_events_count();
|
||||
bts_assert(me->run_state->starting_event_count);
|
||||
me->run_state->run_start = bts::Timer::now();
|
||||
me->run_state->last_completed_count = 0;
|
||||
|
||||
// Inject a single timer event so that the timer can get started
|
||||
auto first_ev_ts = me->run_state->simulator.pending_event_time();
|
||||
@@ -122,13 +129,38 @@ void ExchangeSim::do_work() {
|
||||
me->run_state->simulator.run_once();
|
||||
auto now = Timer::now();
|
||||
const auto log_period_s = 1;
|
||||
if (ms_diff(now,me->run_state->last_time_log) > 1000*log_period_s) {
|
||||
if (ms_diff(now, me->run_state->last_time_log) > 1000 * log_period_s) {
|
||||
|
||||
auto sim_time = me->run_state->simulator.simulation_time();
|
||||
auto sim_elapsed = sim_time - me->run_state->last_sim_time;
|
||||
|
||||
size_t total_events = me->run_state->starting_event_count;
|
||||
|
||||
size_t remaining_events = me->run_state->simulator.pending_events_count();
|
||||
|
||||
size_t completed_events = total_events > remaining_events
|
||||
? total_events - remaining_events
|
||||
: total_events;
|
||||
|
||||
size_t p_complete = (double)completed_events / total_events * 100;
|
||||
|
||||
size_t completed_this_cycle =
|
||||
completed_events - me->run_state->last_completed_count;
|
||||
|
||||
size_t elapsed_secs = sec_diff(now, me->run_state->run_start);
|
||||
int eta_min = (remaining_events * elapsed_secs / completed_events) / 60;
|
||||
|
||||
auto TPS = completed_this_cycle / log_period_s;
|
||||
|
||||
me->run_state->last_time_log = now;
|
||||
me->run_state->last_sim_time = sim_time;
|
||||
LOG(Spartan,Info,"Simulation time: {} ({}x)",to_time_string(MDP3TimeStamp{sim_time}),
|
||||
(int) ((sim_elapsed / 1e9) / log_period_s));
|
||||
me->run_state->last_completed_count = completed_events;
|
||||
|
||||
LOG(Spartan, Info,
|
||||
"Simulation Status -> Time: {} TPS: {} Complete: {}% ETA: {} min",
|
||||
to_time_string(MDP3TimeStamp{sim_time}),
|
||||
TPS,
|
||||
p_complete,
|
||||
eta_min);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ void AlgoAgent::init() {
|
||||
}
|
||||
|
||||
void AlgoAgent::handle(sim::Event const &ev) {
|
||||
return;
|
||||
|
||||
if (dynamic_cast<TimerEvent const *>(&ev)) {
|
||||
me->algo.on_time(MDP3TimeStamp{time()});
|
||||
} else if (auto n = dynamic_cast<AlgoNotificationEvent const *>(&ev); n) {
|
||||
|
||||
Reference in new issue
Block a user