Don't tick the MessageBridge*Status classes when disabled
When you have a log file where a node was booted *far* in the future, we
schedule a wakeup every 0.1 seconds to do nothing. Instead of using
just a bool to disable the statistics, also disable the timer.
Change-Id: I43a7c107d3984ece7e573d0e071b331dfc3eb0da
diff --git a/aos/network/message_bridge_client_status.cc b/aos/network/message_bridge_client_status.cc
index ba6ae80..e8520cf 100644
--- a/aos/network/message_bridge_client_status.cc
+++ b/aos/network/message_bridge_client_status.cc
@@ -61,9 +61,11 @@
statistics_timer_ = event_loop_->AddTimer([this]() { SendStatistics(); });
statistics_timer_->set_name("statistics");
event_loop_->OnRun([this]() {
- statistics_timer_->Setup(
- event_loop_->monotonic_now() + chrono::milliseconds(100),
- chrono::milliseconds(100));
+ if (send_) {
+ statistics_timer_->Setup(
+ event_loop_->monotonic_now() + chrono::milliseconds(100),
+ chrono::milliseconds(100));
+ }
});
}
@@ -163,7 +165,11 @@
filter->Sample(monotonic_delivered_time, offset);
}
-void MessageBridgeClientStatus::DisableStatistics() { send_ = false; }
+void MessageBridgeClientStatus::DisableStatistics() {
+ statistics_timer_->Disable();
+ // TODO(austin): Re-arm when re-enabled.
+ send_ = false;
+}
} // namespace message_bridge
} // namespace aos
diff --git a/aos/network/message_bridge_server_status.cc b/aos/network/message_bridge_server_status.cc
index dd7865b..6e32a95 100644
--- a/aos/network/message_bridge_server_status.cc
+++ b/aos/network/message_bridge_server_status.cc
@@ -123,8 +123,10 @@
statistics_timer_ = event_loop_->AddTimer([this]() { Tick(); });
event_loop_->OnRun([this]() {
- statistics_timer_->Setup(event_loop_->monotonic_now() + kPingPeriod,
- kPingPeriod);
+ if (send_) {
+ statistics_timer_->Setup(event_loop_->monotonic_now() + kPingPeriod,
+ kPingPeriod);
+ }
});
}
@@ -358,6 +360,7 @@
void MessageBridgeServerStatus::DisableStatistics() {
send_ = false;
+ statistics_timer_->Disable();
}
} // namespace message_bridge