Add realtime replay support to SimulatedEventLoopFactory
"realtime" is heavily overloaded here, but this adds support
for making it so that you can play a SimulatedEventLoopFactory at
realtime speed (rather than just "as fast as possible"). This
can be useful in a variety of situations (e.g., debugging
tooling that will run in realtime on a robot).
Adds a demonstration of using this in an piece of AOS tooling for
plotting (this change also makes it so that that binary no longer spins
at 100% CPU indefinitely by consequence of better integrating
the EPoll object into the log replay).
Change-Id: Ia01ecd850a50c9b78dd72bfb0e8862672a716067
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/logging/log_reader.cc b/aos/events/logging/log_reader.cc
index bdee44f..1ad60c9 100644
--- a/aos/events/logging/log_reader.cc
+++ b/aos/events/logging/log_reader.cc
@@ -2208,5 +2208,12 @@
}
}
+void LogReader::SetRealtimeReplayRate(double replay_rate) {
+ CHECK(event_loop_factory_ != nullptr)
+ << ": Can't set replay rate without an event loop factory (have you "
+ "called Register()?).";
+ event_loop_factory_->SetRealtimeReplayRate(replay_rate);
+}
+
} // namespace logger
} // namespace aos
diff --git a/aos/events/logging/log_reader.h b/aos/events/logging/log_reader.h
index 6ea3193..157249c 100644
--- a/aos/events/logging/log_reader.h
+++ b/aos/events/logging/log_reader.h
@@ -231,6 +231,13 @@
exit_on_finish_ = exit_on_finish;
}
+ // Sets the realtime replay rate. A value of 1.0 will cause the scheduler to
+ // try to play events in realtime. 0.5 will run at half speed. Use infinity
+ // (the default) to run as fast as possible. This can be changed during
+ // run-time.
+ // Only applies when running against a SimulatedEventLoopFactory.
+ void SetRealtimeReplayRate(double replay_rate);
+
private:
void Register(EventLoop *event_loop, const Node *node);