blob: 6a0fcea23391fd7f5cadef4653b98acf0397a3fb [file] [log] [blame]
Austin Schuhb06f03b2021-02-17 22:00:37 -08001#ifndef AOS_EVENTS_LOGGING_LOG_READER_H_
2#define AOS_EVENTS_LOGGING_LOG_READER_H_
Austin Schuhe309d2a2019-11-29 13:25:21 -08003
Austin Schuh8bd96322020-02-13 21:18:22 -08004#include <chrono>
Austin Schuhe309d2a2019-11-29 13:25:21 -08005#include <deque>
James Kuszmaula16a7912022-06-17 10:58:12 -07006#include <queue>
James Kuszmaulc3f34d12022-08-15 15:57:55 -07007#include <string_view>
Austin Schuh2f8fd752020-09-01 22:38:28 -07008#include <tuple>
Austin Schuh6f3babe2020-01-26 20:34:50 -08009#include <vector>
Austin Schuhe309d2a2019-11-29 13:25:21 -080010
James Kuszmaulc3f34d12022-08-15 15:57:55 -070011#include "aos/condition.h"
Austin Schuhe309d2a2019-11-29 13:25:21 -080012#include "aos/events/event_loop.h"
Austin Schuhf6f9bf32020-10-11 14:37:43 -070013#include "aos/events/logging/logfile_sorting.h"
Austin Schuha36c8902019-12-30 18:07:15 -080014#include "aos/events/logging/logfile_utils.h"
James Kuszmaul38735e82019-12-07 16:42:06 -080015#include "aos/events/logging/logger_generated.h"
James Kuszmaula16a7912022-06-17 10:58:12 -070016#include "aos/events/logging/replay_timing_generated.h"
James Kuszmaul09632422022-05-25 15:56:19 -070017#include "aos/events/shm_event_loop.h"
Austin Schuh92547522019-12-28 14:33:43 -080018#include "aos/events/simulated_event_loop.h"
James Kuszmaulc3f34d12022-08-15 15:57:55 -070019#include "aos/mutex/mutex.h"
Austin Schuh2f8fd752020-09-01 22:38:28 -070020#include "aos/network/message_bridge_server_generated.h"
Austin Schuh0ca1fd32020-12-18 22:53:05 -080021#include "aos/network/multinode_timestamp_filter.h"
Austin Schuh0de30f32020-12-06 12:44:28 -080022#include "aos/network/remote_message_generated.h"
Austin Schuh8bd96322020-02-13 21:18:22 -080023#include "aos/network/timestamp_filter.h"
Austin Schuhe309d2a2019-11-29 13:25:21 -080024#include "aos/time/time.h"
James Kuszmaula16a7912022-06-17 10:58:12 -070025#include "aos/util/threaded_queue.h"
James Kuszmaulc3f34d12022-08-15 15:57:55 -070026#include "aos/uuid.h"
Austin Schuhe309d2a2019-11-29 13:25:21 -080027#include "flatbuffers/flatbuffers.h"
28
29namespace aos {
30namespace logger {
31
Austin Schuhe33c08d2022-02-03 18:15:21 -080032class EventNotifier;
33
Eric Schmiedebergb38477e2022-12-02 16:08:04 -070034// Vector of pair of name and type of the channel
Sanjay Narayanan5ec00232022-07-08 15:21:30 -070035using ReplayChannels = std::vector<std::pair<std::string, std::string>>;
Eric Schmiedebergb38477e2022-12-02 16:08:04 -070036// Vector of channel indices
Naman Guptacf6d4422023-03-01 11:41:00 -080037using ReplayChannelIndices = std::vector<size_t>;
Eric Schmiedebergb38477e2022-12-02 16:08:04 -070038
Austin Schuh6f3babe2020-01-26 20:34:50 -080039// We end up with one of the following 3 log file types.
40//
41// Single node logged as the source node.
42// -> Replayed just on the source node.
43//
44// Forwarding timestamps only logged from the perspective of the destination
45// node.
46// -> Matched with data on source node and logged.
47//
48// Forwarding timestamps with data logged as the destination node.
49// -> Replayed just as the destination
50// -> Replayed as the source (Much harder, ordering is not defined)
51//
52// Duplicate data logged. -> CHECK that it matches and explode otherwise.
53//
54// This can be boiled down to a set of constraints and tools.
55//
56// 1) Forwarding timestamps and data need to be logged separately.
57// 2) Any forwarded data logged on the destination node needs to be logged
58// separately such that it can be sorted.
59//
60// 1) Log reader needs to be able to sort a list of log files.
61// 2) Log reader needs to be able to merge sorted lists of log files.
62// 3) Log reader needs to be able to match timestamps with messages.
63//
64// We also need to be able to generate multiple views of a log file depending on
65// the target.
66
Austin Schuhe309d2a2019-11-29 13:25:21 -080067// Replays all the channels in the logfile to the event loop.
68class LogReader {
69 public:
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -080070 // If you want to supply a new configuration that will be used for replay
71 // (e.g., to change message rates, or to populate an updated schema), then
72 // pass it in here. It must provide all the channels that the original logged
73 // config did.
Austin Schuh6f3babe2020-01-26 20:34:50 -080074 //
Eric Schmiedebergb38477e2022-12-02 16:08:04 -070075 // If certain messages should not be replayed, the replay_channels param can
76 // be used as an inclusive list of channels for messages to be replayed.
77 //
Austin Schuh287d43d2020-12-04 20:19:33 -080078 // The single file constructor calls SortParts internally.
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -080079 LogReader(std::string_view filename,
Eric Schmiedebergb38477e2022-12-02 16:08:04 -070080 const Configuration *replay_configuration = nullptr,
81 const ReplayChannels *replay_channels = nullptr);
Austin Schuh287d43d2020-12-04 20:19:33 -080082 LogReader(std::vector<LogFile> log_files,
Eric Schmiedebergb38477e2022-12-02 16:08:04 -070083 const Configuration *replay_configuration = nullptr,
84 const ReplayChannels *replay_channels = nullptr);
James Kuszmaul7daef362019-12-31 18:28:17 -080085 ~LogReader();
Austin Schuhe309d2a2019-11-29 13:25:21 -080086
Austin Schuh6331ef92020-01-07 18:28:09 -080087 // Registers all the callbacks to send the log file data out on an event loop
88 // created in event_loop_factory. This also updates time to be at the start
89 // of the log file by running until the log file starts.
90 // Note: the configuration used in the factory should be configuration()
91 // below, but can be anything as long as the locations needed to send
92 // everything are available.
James Kuszmaul84ff3e52020-01-03 19:48:53 -080093 void Register(SimulatedEventLoopFactory *event_loop_factory);
Austin Schuhe33c08d2022-02-03 18:15:21 -080094
Austin Schuh58646e22021-08-23 23:51:46 -070095 // Registers all the callbacks to send the log file data out to an event loop
96 // factory. This does not start replaying or change the current distributed
97 // time of the factory. It does change the monotonic clocks to be right.
98 void RegisterWithoutStarting(SimulatedEventLoopFactory *event_loop_factory);
Austin Schuhe33c08d2022-02-03 18:15:21 -080099 // Runs the log until the last start time. Register above is defined as:
100 // Register(...) {
101 // RegisterWithoutStarting
102 // StartAfterRegister
103 // }
104 // This should generally be considered as a stepping stone to convert from
105 // Register() to RegisterWithoutStarting() incrementally.
106 void StartAfterRegister(SimulatedEventLoopFactory *event_loop_factory);
107
Austin Schuh6331ef92020-01-07 18:28:09 -0800108 // Creates an SimulatedEventLoopFactory accessible via event_loop_factory(),
109 // and then calls Register.
110 void Register();
James Kuszmaul09632422022-05-25 15:56:19 -0700111
Austin Schuh6331ef92020-01-07 18:28:09 -0800112 // Registers callbacks for all the events after the log file starts. This is
113 // only useful when replaying live.
Austin Schuhe309d2a2019-11-29 13:25:21 -0800114 void Register(EventLoop *event_loop);
Austin Schuh6331ef92020-01-07 18:28:09 -0800115
James Kuszmaula16a7912022-06-17 10:58:12 -0700116 // Sets a sender that should be used for tracking timing statistics. If not
117 // set, no statistics will be recorded.
118 void set_timing_accuracy_sender(
119 const Node *node, aos::Sender<timing::ReplayTiming> timing_sender) {
120 states_[configuration::GetNodeIndex(configuration(), node)]
121 ->set_timing_accuracy_sender(std::move(timing_sender));
122 }
123
Austin Schuh58646e22021-08-23 23:51:46 -0700124 // Called whenever a log file starts for a node.
125 void OnStart(std::function<void()> fn);
126 void OnStart(const Node *node, std::function<void()> fn);
127 // Called whenever a log file ends for a node.
128 void OnEnd(std::function<void()> fn);
129 void OnEnd(const Node *node, std::function<void()> fn);
130
James Kuszmaul84ff3e52020-01-03 19:48:53 -0800131 // Unregisters the senders. You only need to call this if you separately
132 // supplied an event loop or event loop factory and the lifetimes are such
133 // that they need to be explicitly destroyed before the LogReader destructor
134 // gets called.
Austin Schuhe309d2a2019-11-29 13:25:21 -0800135 void Deregister();
136
Austin Schuh0c297012020-09-16 18:41:59 -0700137 // Returns the configuration being used for replay from the log file.
138 // Note that this may be different from the configuration actually used for
139 // handling events. You should generally only use this to create a
140 // SimulatedEventLoopFactory, and then get the configuration from there for
141 // everything else.
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800142 const Configuration *logged_configuration() const;
Austin Schuh11d43732020-09-21 17:28:30 -0700143 // Returns the configuration being used for replay from the log file.
144 // Note that this may be different from the configuration actually used for
145 // handling events. You should generally only use this to create a
146 // SimulatedEventLoopFactory, and then get the configuration from there for
147 // everything else.
Austin Schuh6f3babe2020-01-26 20:34:50 -0800148 // The pointer is invalidated whenever RemapLoggedChannel is called.
Austin Schuh15649d62019-12-28 16:36:38 -0800149 const Configuration *configuration() const;
150
Austin Schuh6f3babe2020-01-26 20:34:50 -0800151 // Returns the nodes that this log file was created on. This is a list of
Austin Schuh07676622021-01-21 18:59:17 -0800152 // pointers to a node in the nodes() list inside logged_configuration().
153 std::vector<const Node *> LoggedNodes() const;
Austin Schuhe309d2a2019-11-29 13:25:21 -0800154
155 // Returns the starting timestamp for the log file.
Austin Schuh11d43732020-09-21 17:28:30 -0700156 monotonic_clock::time_point monotonic_start_time(
157 const Node *node = nullptr) const;
158 realtime_clock::time_point realtime_start_time(
159 const Node *node = nullptr) const;
Austin Schuhe309d2a2019-11-29 13:25:21 -0800160
Austin Schuhe33c08d2022-02-03 18:15:21 -0800161 // Sets the start and end times to replay data until for all nodes. This
162 // overrides the --start_time and --end_time flags. The default is to replay
163 // all data.
164 void SetStartTime(std::string start_time);
165 void SetStartTime(realtime_clock::time_point start_time);
166 void SetEndTime(std::string end_time);
167 void SetEndTime(realtime_clock::time_point end_time);
168
James Kuszmaul53da7f32022-09-11 11:11:55 -0700169 // Enum to use for indicating how RemapLoggedChannel behaves when there is
170 // already a channel with the remapped name (e.g., as may happen when
171 // replaying a logfile that was itself generated from replay).
172 enum class RemapConflict {
173 // LOG(FATAL) on conflicts in remappings.
174 kDisallow,
175 // If we run into a conflict, attempt to remap the channel we would be
176 // overriding (and continue to do so if remapping *that* channel also
177 // generates a conflict).
178 // This will mean that if we repeatedly replay a log, we will end up
179 // stacking more and more /original's on the start of the oldest version
180 // of the channels.
181 kCascade
182 };
183
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800184 // Causes the logger to publish the provided channel on a different name so
185 // that replayed applications can publish on the proper channel name without
186 // interference. This operates on raw channel names, without any node or
187 // application specific mappings.
James Kuszmaul53da7f32022-09-11 11:11:55 -0700188 void RemapLoggedChannel(
189 std::string_view name, std::string_view type,
190 std::string_view add_prefix = "/original", std::string_view new_type = "",
191 RemapConflict conflict_handling = RemapConflict::kCascade);
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800192 template <typename T>
James Kuszmaul53da7f32022-09-11 11:11:55 -0700193 void RemapLoggedChannel(
194 std::string_view name, std::string_view add_prefix = "/original",
195 std::string_view new_type = "",
196 RemapConflict conflict_handling = RemapConflict::kCascade) {
197 RemapLoggedChannel(name, T::GetFullyQualifiedName(), add_prefix, new_type,
198 conflict_handling);
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800199 }
Austin Schuh01b4c352020-09-21 23:09:39 -0700200 // Remaps the provided channel, though this respects node mappings, and
201 // preserves them too. This makes it so if /aos -> /pi1/aos on one node,
202 // /original/aos -> /original/pi1/aos on the same node after renaming, just
Austin Schuh0de30f32020-12-06 12:44:28 -0800203 // like you would hope. If new_type is not empty, the new channel will use
204 // the provided type instead. This allows for renaming messages.
Austin Schuh01b4c352020-09-21 23:09:39 -0700205 //
206 // TODO(austin): If you have 2 nodes remapping something to the same channel,
207 // this doesn't handle that. No use cases exist yet for that, so it isn't
208 // being done yet.
James Kuszmaul53da7f32022-09-11 11:11:55 -0700209 void RemapLoggedChannel(
210 std::string_view name, std::string_view type, const Node *node,
211 std::string_view add_prefix = "/original", std::string_view new_type = "",
212 RemapConflict conflict_handling = RemapConflict::kCascade);
Brian Silvermande9f3ff2020-04-28 16:56:58 -0700213 template <typename T>
James Kuszmaul53da7f32022-09-11 11:11:55 -0700214 void RemapLoggedChannel(
215 std::string_view name, const Node *node,
216 std::string_view add_prefix = "/original", std::string_view new_type = "",
217 RemapConflict conflict_handling = RemapConflict::kCascade) {
Austin Schuh0de30f32020-12-06 12:44:28 -0800218 RemapLoggedChannel(name, T::GetFullyQualifiedName(), node, add_prefix,
James Kuszmaul53da7f32022-09-11 11:11:55 -0700219 new_type, conflict_handling);
Austin Schuh01b4c352020-09-21 23:09:39 -0700220 }
221
Sanjay Narayanan5ec00232022-07-08 15:21:30 -0700222 // Similar to RemapLoggedChannel(), but lets you specify a name for the new
223 // channel without constraints. This is useful when an application has been
224 // updated to use new channels but you want to support replaying old logs. By
225 // default, this will not add any maps for the new channel. Use add_maps to
226 // specify any maps you'd like added.
227 void RenameLoggedChannel(std::string_view name, std::string_view type,
228 std::string_view new_name,
229 const std::vector<MapT> &add_maps = {});
230 template <typename T>
231 void RenameLoggedChannel(std::string_view name, std::string_view new_name,
232 const std::vector<MapT> &add_maps = {}) {
233 RenameLoggedChannel(name, T::GetFullyQualifiedName(), new_name, add_maps);
234 }
235 // The following overloads are more suitable for multi-node configurations,
236 // and let you rename a channel on a specific node.
237 void RenameLoggedChannel(std::string_view name, std::string_view type,
238 const Node *node, std::string_view new_name,
239 const std::vector<MapT> &add_maps = {});
240 template <typename T>
241 void RenameLoggedChannel(std::string_view name, const Node *node,
242 std::string_view new_name,
243 const std::vector<MapT> &add_maps = {}) {
244 RenameLoggedChannel(name, T::GetFullyQualifiedName(), node, new_name,
245 add_maps);
246 }
247
Austin Schuh01b4c352020-09-21 23:09:39 -0700248 template <typename T>
249 bool HasChannel(std::string_view name, const Node *node = nullptr) {
Sanjay Narayanan5ec00232022-07-08 15:21:30 -0700250 return HasChannel(name, T::GetFullyQualifiedName(), node);
251 }
252 bool HasChannel(std::string_view name, std::string_view type,
253 const Node *node) {
254 return configuration::GetChannel(logged_configuration(), name, type, "",
255 node, true) != nullptr;
Brian Silvermande9f3ff2020-04-28 16:56:58 -0700256 }
257
Austin Schuh82529062021-12-08 12:09:52 -0800258 template <typename T>
259 void MaybeRemapLoggedChannel(std::string_view name,
260 const Node *node = nullptr) {
261 if (HasChannel<T>(name, node)) {
262 RemapLoggedChannel<T>(name, node);
263 }
264 }
Sanjay Narayanan5ec00232022-07-08 15:21:30 -0700265 template <typename T>
266 void MaybeRenameLoggedChannel(std::string_view name, const Node *node,
267 std::string_view new_name,
268 const std::vector<MapT> &add_maps = {}) {
269 if (HasChannel<T>(name, node)) {
270 RenameLoggedChannel<T>(name, node, new_name, add_maps);
271 }
272 }
Austin Schuh82529062021-12-08 12:09:52 -0800273
James Kuszmaul4f106fb2021-01-05 20:53:02 -0800274 // Returns true if the channel exists on the node and was logged.
275 template <typename T>
276 bool HasLoggedChannel(std::string_view name, const Node *node = nullptr) {
Austin Schuh5ee56872021-01-30 16:53:34 -0800277 const Channel *channel =
278 configuration::GetChannel(logged_configuration(), name,
279 T::GetFullyQualifiedName(), "", node, true);
James Kuszmaul4f106fb2021-01-05 20:53:02 -0800280 if (channel == nullptr) return false;
281 return channel->logger() != LoggerConfig::NOT_LOGGED;
282 }
283
Austin Schuh1c227352021-09-17 12:53:54 -0700284 // Returns a list of all the original channels from remapping.
285 std::vector<const Channel *> RemappedChannels() const;
286
James Kuszmaul84ff3e52020-01-03 19:48:53 -0800287 SimulatedEventLoopFactory *event_loop_factory() {
288 return event_loop_factory_;
289 }
290
Austin Schuh0ca51f32020-12-25 21:51:45 -0800291 std::string_view name() const { return log_files_[0].name; }
Austin Schuh0c297012020-09-16 18:41:59 -0700292
James Kuszmaul71a81932020-12-15 21:08:01 -0800293 // Set whether to exit the SimulatedEventLoopFactory when we finish reading
294 // the logfile.
295 void set_exit_on_finish(bool exit_on_finish) {
296 exit_on_finish_ = exit_on_finish;
297 }
James Kuszmaulb11a1502022-07-01 16:02:25 -0700298 bool exit_on_finish() const { return exit_on_finish_; }
James Kuszmaul71a81932020-12-15 21:08:01 -0800299
James Kuszmaulb67409b2022-06-20 16:25:03 -0700300 // Sets the realtime replay rate. A value of 1.0 will cause the scheduler to
301 // try to play events in realtime. 0.5 will run at half speed. Use infinity
302 // (the default) to run as fast as possible. This can be changed during
303 // run-time.
304 // Only applies when running against a SimulatedEventLoopFactory.
305 void SetRealtimeReplayRate(double replay_rate);
306
Austin Schuhe309d2a2019-11-29 13:25:21 -0800307 private:
Austin Schuh58646e22021-08-23 23:51:46 -0700308 void Register(EventLoop *event_loop, const Node *node);
309
310 void RegisterDuringStartup(EventLoop *event_loop, const Node *node);
311
312 const Channel *RemapChannel(const EventLoop *event_loop, const Node *node,
Austin Schuh6f3babe2020-01-26 20:34:50 -0800313 const Channel *channel);
314
Austin Schuhe309d2a2019-11-29 13:25:21 -0800315 // Queues at least max_out_of_order_duration_ messages into channels_.
316 void QueueMessages();
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800317 // Handle constructing a configuration with all the additional remapped
318 // channels from calls to RemapLoggedChannel.
319 void MakeRemappedConfig();
Austin Schuhe309d2a2019-11-29 13:25:21 -0800320
Austin Schuh2f8fd752020-09-01 22:38:28 -0700321 // Returns the number of nodes.
322 size_t nodes_count() const {
323 return !configuration::MultiNode(logged_configuration())
324 ? 1u
325 : logged_configuration()->nodes()->size();
326 }
327
James Kuszmaulb11a1502022-07-01 16:02:25 -0700328 // Handles when an individual node hits the realtime end time, exitting the
329 // entire event loop once all nodes are stopped.
330 void NoticeRealtimeEnd();
331
Austin Schuh287d43d2020-12-04 20:19:33 -0800332 const std::vector<LogFile> log_files_;
Austin Schuh6f3babe2020-01-26 20:34:50 -0800333
Austin Schuh969cd602021-01-03 00:09:45 -0800334 // Class to manage sending RemoteMessages on the provided node after the
335 // correct delay.
Austin Schuh5ee56872021-01-30 16:53:34 -0800336 class RemoteMessageSender {
Austin Schuh969cd602021-01-03 00:09:45 -0800337 public:
338 RemoteMessageSender(aos::Sender<message_bridge::RemoteMessage> sender,
339 EventLoop *event_loop);
340 RemoteMessageSender(RemoteMessageSender const &) = delete;
341 RemoteMessageSender &operator=(RemoteMessageSender const &) = delete;
342
343 // Sends the provided message. If monotonic_timestamp_time is min_time,
344 // send it immediately.
345 void Send(
346 FlatbufferDetachedBuffer<message_bridge::RemoteMessage> remote_message,
Austin Schuh58646e22021-08-23 23:51:46 -0700347 BootTimestamp monotonic_timestamp_time, size_t source_boot_count);
Austin Schuh969cd602021-01-03 00:09:45 -0800348
349 private:
350 // Handles actually sending the timestamp if we were delayed.
351 void SendTimestamp();
352 // Handles scheduling the timer to send at the correct time.
353 void ScheduleTimestamp();
354
355 EventLoop *event_loop_;
356 aos::Sender<message_bridge::RemoteMessage> sender_;
357 aos::TimerHandler *timer_;
358
359 // Time we are scheduled for, or min_time if we aren't scheduled.
360 monotonic_clock::time_point scheduled_time_ = monotonic_clock::min_time;
361
362 struct Timestamp {
363 Timestamp(FlatbufferDetachedBuffer<message_bridge::RemoteMessage>
364 new_remote_message,
365 monotonic_clock::time_point new_monotonic_timestamp_time)
366 : remote_message(std::move(new_remote_message)),
367 monotonic_timestamp_time(new_monotonic_timestamp_time) {}
368 FlatbufferDetachedBuffer<message_bridge::RemoteMessage> remote_message;
369 monotonic_clock::time_point monotonic_timestamp_time;
370 };
371
372 // List of messages to send. The timer works through them and then disables
373 // itself automatically.
374 std::deque<Timestamp> remote_timestamps_;
375 };
376
Austin Schuh6f3babe2020-01-26 20:34:50 -0800377 // State per node.
Austin Schuh858c9f32020-08-31 16:56:12 -0700378 class State {
379 public:
James Kuszmaula16a7912022-06-17 10:58:12 -0700380 // Whether we should spin up a separate thread for buffering up messages.
381 // Only allowed in realtime replay--see comments on threading_ member for
382 // details.
383 enum class ThreadedBuffering { kYes, kNo };
James Kuszmaul09632422022-05-25 15:56:19 -0700384 State(std::unique_ptr<TimestampMapper> timestamp_mapper,
385 message_bridge::MultiNodeNoncausalOffsetEstimator *multinode_filters,
James Kuszmaulb11a1502022-07-01 16:02:25 -0700386 std::function<void()> notice_realtime_end, const Node *node,
387 ThreadedBuffering threading,
Naman Guptacf6d4422023-03-01 11:41:00 -0800388 std::unique_ptr<const ReplayChannelIndices> replay_channel_indices);
Austin Schuh287d43d2020-12-04 20:19:33 -0800389
390 // Connects up the timestamp mappers.
391 void AddPeer(State *peer);
Austin Schuh6f3babe2020-01-26 20:34:50 -0800392
Austin Schuhe639ea12021-01-25 13:00:22 -0800393 TimestampMapper *timestamp_mapper() { return timestamp_mapper_.get(); }
394
Austin Schuhdda74ec2021-01-03 19:30:37 -0800395 // Returns the next sorted message with all the timestamps extracted and
396 // matched.
397 TimestampedMessage PopOldest();
Austin Schuh188eabe2020-12-29 23:41:13 -0800398
Austin Schuh858c9f32020-08-31 16:56:12 -0700399 // Returns the monotonic time of the oldest message.
James Kuszmaula16a7912022-06-17 10:58:12 -0700400 BootTimestamp SingleThreadedOldestMessageTime();
401 // Returns the monotonic time of the oldest message, handling querying the
402 // separate thread of ThreadedBuffering was set.
403 BootTimestamp MultiThreadedOldestMessageTime();
Austin Schuh58646e22021-08-23 23:51:46 -0700404
405 size_t boot_count() const {
406 // If we are replaying directly into an event loop, we can't reboot. So
407 // we will stay stuck on the 0th boot.
James Kuszmaul09632422022-05-25 15:56:19 -0700408 if (!node_event_loop_factory_) {
409 if (event_loop_ == nullptr) {
410 // If boot_count is being checked after startup for any of the
411 // non-primary nodes, then returning 0 may not be accurate (since
412 // remote nodes *can* reboot even if the EventLoop being played to
413 // can't).
414 CHECK(!started_);
415 CHECK(!stopped_);
416 }
417 return 0u;
418 }
Austin Schuh58646e22021-08-23 23:51:46 -0700419 return node_event_loop_factory_->boot_count();
420 }
Austin Schuh858c9f32020-08-31 16:56:12 -0700421
422 // Primes the queues inside State. Should be called before calling
423 // OldestMessageTime.
424 void SeedSortedMessages();
Austin Schuh8bd96322020-02-13 21:18:22 -0800425
Austin Schuh58646e22021-08-23 23:51:46 -0700426 void SetupStartupTimer() {
427 const monotonic_clock::time_point start_time =
428 monotonic_start_time(boot_count());
429 if (start_time == monotonic_clock::min_time) {
430 LOG(ERROR)
431 << "No start time, skipping, please figure out when this happens";
Austin Schuhe33c08d2022-02-03 18:15:21 -0800432 NotifyLogfileStart();
Austin Schuh58646e22021-08-23 23:51:46 -0700433 return;
434 }
James Kuszmaul09632422022-05-25 15:56:19 -0700435 if (node_event_loop_factory_) {
436 CHECK_GE(start_time + clock_offset(), event_loop_->monotonic_now());
437 }
438 startup_timer_->Setup(start_time + clock_offset());
Austin Schuh58646e22021-08-23 23:51:46 -0700439 }
440
441 void set_startup_timer(TimerHandler *timer_handler) {
442 startup_timer_ = timer_handler;
443 if (startup_timer_) {
444 if (event_loop_->node() != nullptr) {
445 startup_timer_->set_name(absl::StrCat(
446 event_loop_->node()->name()->string_view(), "_startup"));
447 } else {
448 startup_timer_->set_name("startup");
449 }
450 }
451 }
452
Austin Schuh858c9f32020-08-31 16:56:12 -0700453 // Returns the starting time for this node.
Austin Schuh2dc8c7d2021-07-01 17:41:28 -0700454 monotonic_clock::time_point monotonic_start_time(size_t boot_count) const {
455 return timestamp_mapper_
456 ? timestamp_mapper_->monotonic_start_time(boot_count)
457 : monotonic_clock::min_time;
Austin Schuh858c9f32020-08-31 16:56:12 -0700458 }
Austin Schuh2dc8c7d2021-07-01 17:41:28 -0700459 realtime_clock::time_point realtime_start_time(size_t boot_count) const {
460 return timestamp_mapper_
461 ? timestamp_mapper_->realtime_start_time(boot_count)
462 : realtime_clock::min_time;
Austin Schuh858c9f32020-08-31 16:56:12 -0700463 }
464
465 // Sets the node event loop factory for replaying into a
466 // SimulatedEventLoopFactory. Returns the EventLoop to use.
Austin Schuh60e77942022-05-16 17:48:24 -0700467 void SetNodeEventLoopFactory(NodeEventLoopFactory *node_event_loop_factory,
468 SimulatedEventLoopFactory *event_loop_factory);
Austin Schuh858c9f32020-08-31 16:56:12 -0700469
470 // Sets and gets the event loop to use.
471 void set_event_loop(EventLoop *event_loop) { event_loop_ = event_loop; }
472 EventLoop *event_loop() { return event_loop_; }
473
Austin Schuh58646e22021-08-23 23:51:46 -0700474 const Node *node() const { return node_; }
475
476 void Register(EventLoop *event_loop);
477
478 void OnStart(std::function<void()> fn);
479 void OnEnd(std::function<void()> fn);
480
Austin Schuh858c9f32020-08-31 16:56:12 -0700481 // Sets the current realtime offset from the monotonic clock for this node
482 // (if we are on a simulated event loop).
483 void SetRealtimeOffset(monotonic_clock::time_point monotonic_time,
484 realtime_clock::time_point realtime_time) {
485 if (node_event_loop_factory_ != nullptr) {
486 node_event_loop_factory_->SetRealtimeOffset(monotonic_time,
487 realtime_time);
488 }
489 }
490
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700491 // Returns the MessageHeader sender to log delivery timestamps to for the
492 // provided remote node.
Austin Schuh61e973f2021-02-21 21:43:56 -0800493 RemoteMessageSender *RemoteTimestampSender(const Channel *channel,
494 const Connection *connection);
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700495
Austin Schuh858c9f32020-08-31 16:56:12 -0700496 // Converts a timestamp from the monotonic clock on this node to the
497 // distributed clock.
498 distributed_clock::time_point ToDistributedClock(
499 monotonic_clock::time_point time) {
James Kuszmaul09632422022-05-25 15:56:19 -0700500 CHECK(node_event_loop_factory_);
Austin Schuh858c9f32020-08-31 16:56:12 -0700501 return node_event_loop_factory_->ToDistributedClock(time);
502 }
503
Austin Schuh858c9f32020-08-31 16:56:12 -0700504 // Returns the current time on the remote node which sends messages on
505 // channel_index.
Austin Schuh58646e22021-08-23 23:51:46 -0700506 BootTimestamp monotonic_remote_now(size_t channel_index) {
507 State *s = channel_source_state_[channel_index];
508 return BootTimestamp{
509 .boot = s->boot_count(),
510 .time = s->node_event_loop_factory_->monotonic_now()};
Austin Schuh858c9f32020-08-31 16:56:12 -0700511 }
512
Austin Schuh5ee56872021-01-30 16:53:34 -0800513 // Returns the start time of the remote for the provided channel.
514 monotonic_clock::time_point monotonic_remote_start_time(
Austin Schuh58646e22021-08-23 23:51:46 -0700515 size_t boot_count, size_t channel_index) {
Austin Schuh2dc8c7d2021-07-01 17:41:28 -0700516 return channel_source_state_[channel_index]->monotonic_start_time(
517 boot_count);
Austin Schuh5ee56872021-01-30 16:53:34 -0800518 }
519
Austin Schuh58646e22021-08-23 23:51:46 -0700520 void DestroyEventLoop() { event_loop_unique_ptr_.reset(); }
521
522 EventLoop *MakeEventLoop() {
523 CHECK(!event_loop_unique_ptr_);
James Kuszmaul890c2492022-04-06 14:59:31 -0700524 // TODO(james): Enable exclusive senders on LogReader to allow us to
525 // ensure we are remapping channels correctly.
526 event_loop_unique_ptr_ = node_event_loop_factory_->MakeEventLoop(
527 "log_reader", {NodeEventLoopFactory::CheckSentTooFast::kNo,
James Kuszmaul94ca5132022-07-19 09:11:08 -0700528 NodeEventLoopFactory::ExclusiveSenders::kYes,
529 NonExclusiveChannels()});
Austin Schuh58646e22021-08-23 23:51:46 -0700530 return event_loop_unique_ptr_.get();
531 }
532
Austin Schuh2f8fd752020-09-01 22:38:28 -0700533 distributed_clock::time_point RemoteToDistributedClock(
534 size_t channel_index, monotonic_clock::time_point time) {
James Kuszmaul09632422022-05-25 15:56:19 -0700535 CHECK(node_event_loop_factory_);
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700536 return channel_source_state_[channel_index]
537 ->node_event_loop_factory_->ToDistributedClock(time);
Austin Schuh2f8fd752020-09-01 22:38:28 -0700538 }
539
540 const Node *remote_node(size_t channel_index) {
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700541 return channel_source_state_[channel_index]
542 ->node_event_loop_factory_->node();
Austin Schuh2f8fd752020-09-01 22:38:28 -0700543 }
544
Stephan Pleines559fa6c2022-01-06 17:23:51 -0800545 monotonic_clock::time_point monotonic_now() const {
James Kuszmaul09632422022-05-25 15:56:19 -0700546 return event_loop_->monotonic_now();
Austin Schuh2f8fd752020-09-01 22:38:28 -0700547 }
548
Austin Schuh858c9f32020-08-31 16:56:12 -0700549 // Sets the number of channels.
550 void SetChannelCount(size_t count);
551
552 // Sets the sender, filter, and target factory for a channel.
Austin Schuh969cd602021-01-03 00:09:45 -0800553 void SetChannel(size_t logged_channel_index, size_t factory_channel_index,
554 std::unique_ptr<RawSender> sender,
555 message_bridge::NoncausalOffsetEstimator *filter,
Austin Schuh58646e22021-08-23 23:51:46 -0700556 bool is_forwarded, State *source_state);
557
558 void SetRemoteTimestampSender(size_t logged_channel_index,
559 RemoteMessageSender *remote_timestamp_sender);
560
561 void RunOnStart();
562 void RunOnEnd();
Austin Schuh858c9f32020-08-31 16:56:12 -0700563
Austin Schuhe33c08d2022-02-03 18:15:21 -0800564 // Handles a logfile start event to potentially call the OnStart callbacks.
565 void NotifyLogfileStart();
566 // Handles a start time flag start event to potentially call the OnStart
567 // callbacks.
568 void NotifyFlagStart();
569
570 // Handles a logfile end event to potentially call the OnEnd callbacks.
571 void NotifyLogfileEnd();
572 // Handles a end time flag start event to potentially call the OnEnd
573 // callbacks.
574 void NotifyFlagEnd();
575
Austin Schuh858c9f32020-08-31 16:56:12 -0700576 // Unregisters everything so we can destory the event loop.
Austin Schuh58646e22021-08-23 23:51:46 -0700577 // TODO(austin): Is this needed? OnShutdown should be able to serve this
578 // need.
Austin Schuh858c9f32020-08-31 16:56:12 -0700579 void Deregister();
580
581 // Sets the current TimerHandle for the replay callback.
582 void set_timer_handler(TimerHandler *timer_handler) {
583 timer_handler_ = timer_handler;
Austin Schuh58646e22021-08-23 23:51:46 -0700584 if (timer_handler_) {
585 if (event_loop_->node() != nullptr) {
586 timer_handler_->set_name(absl::StrCat(
587 event_loop_->node()->name()->string_view(), "_main"));
588 } else {
589 timer_handler_->set_name("main");
590 }
591 }
Austin Schuh858c9f32020-08-31 16:56:12 -0700592 }
593
Austin Schuhe33c08d2022-02-03 18:15:21 -0800594 // Creates and registers the --start_time and --end_time event callbacks.
595 void SetStartTimeFlag(realtime_clock::time_point start_time);
596 void SetEndTimeFlag(realtime_clock::time_point end_time);
597
598 // Notices the next message to update the start/end time callbacks.
599 void ObserveNextMessage(monotonic_clock::time_point monotonic_event,
600 realtime_clock::time_point realtime_event);
601
602 // Clears the start and end time flag handlers so we can delete the event
603 // loop.
604 void ClearTimeFlags();
605
Austin Schuh858c9f32020-08-31 16:56:12 -0700606 // Sets the next wakeup time on the replay callback.
607 void Setup(monotonic_clock::time_point next_time) {
James Kuszmaul8866e642022-06-10 16:00:36 -0700608 timer_handler_->Setup(
609 std::max(monotonic_now(), next_time + clock_offset()));
Austin Schuh858c9f32020-08-31 16:56:12 -0700610 }
611
612 // Sends a buffer on the provided channel index.
Austin Schuh287d43d2020-12-04 20:19:33 -0800613 bool Send(const TimestampedMessage &timestamped_message);
Austin Schuh858c9f32020-08-31 16:56:12 -0700614
James Kuszmaulc3f34d12022-08-15 15:57:55 -0700615 void MaybeSetClockOffset();
James Kuszmaul09632422022-05-25 15:56:19 -0700616 std::chrono::nanoseconds clock_offset() const { return clock_offset_; }
617
Austin Schuh858c9f32020-08-31 16:56:12 -0700618 // Returns a debug string for the channel merger.
Austin Schuh2f8fd752020-09-01 22:38:28 -0700619 std::string DebugString() const {
Austin Schuh287d43d2020-12-04 20:19:33 -0800620 if (!timestamp_mapper_) {
Austin Schuhe639ea12021-01-25 13:00:22 -0800621 return "";
Austin Schuh287d43d2020-12-04 20:19:33 -0800622 }
Austin Schuhe639ea12021-01-25 13:00:22 -0800623 return timestamp_mapper_->DebugString();
Austin Schuh2f8fd752020-09-01 22:38:28 -0700624 }
Austin Schuh858c9f32020-08-31 16:56:12 -0700625
Austin Schuh58646e22021-08-23 23:51:46 -0700626 void ClearRemoteTimestampSenders() {
627 channel_timestamp_loggers_.clear();
628 timestamp_loggers_.clear();
629 }
630
Austin Schuhbd5f74a2021-11-11 20:55:38 -0800631 void SetFoundLastMessage(bool val) {
632 found_last_message_ = val;
633 last_message_.resize(factory_channel_index_.size(), false);
634 }
635 bool found_last_message() const { return found_last_message_; }
636
637 void set_last_message(size_t channel_index) {
638 CHECK_LT(channel_index, last_message_.size());
639 last_message_[channel_index] = true;
640 }
641
642 bool last_message(size_t channel_index) {
643 CHECK_LT(channel_index, last_message_.size());
644 return last_message_[channel_index];
645 }
646
James Kuszmaula16a7912022-06-17 10:58:12 -0700647 void set_timing_accuracy_sender(
648 aos::Sender<timing::ReplayTiming> timing_sender) {
649 timing_statistics_sender_ = std::move(timing_sender);
650 OnEnd([this]() { SendMessageTimings(); });
651 }
652
653 // If running with ThreadedBuffering::kYes, will start the processing thread
654 // and queue up messages until the specified time. No-op of
655 // ThreadedBuffering::kNo is set. Should only be called once.
656 void QueueThreadUntil(BootTimestamp time);
657
Austin Schuh858c9f32020-08-31 16:56:12 -0700658 private:
James Kuszmaulc3f34d12022-08-15 15:57:55 -0700659 void TrackMessageSendTiming(const RawSender &sender,
660 monotonic_clock::time_point expected_send_time);
James Kuszmaula16a7912022-06-17 10:58:12 -0700661 void SendMessageTimings();
Austin Schuh858c9f32020-08-31 16:56:12 -0700662 // Log file.
Austin Schuh287d43d2020-12-04 20:19:33 -0800663 std::unique_ptr<TimestampMapper> timestamp_mapper_;
Austin Schuh858c9f32020-08-31 16:56:12 -0700664
Austin Schuh858c9f32020-08-31 16:56:12 -0700665 // Senders.
666 std::vector<std::unique_ptr<RawSender>> channels_;
Austin Schuh969cd602021-01-03 00:09:45 -0800667 std::vector<RemoteMessageSender *> remote_timestamp_senders_;
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700668 // The mapping from logged channel index to sent channel index. Needed for
669 // sending out MessageHeaders.
670 std::vector<int> factory_channel_index_;
671
Austin Schuh9942bae2021-01-07 22:06:44 -0800672 struct ContiguousSentTimestamp {
673 // Most timestamps make it through the network, so it saves a ton of
674 // memory and CPU to store the start and end, and search for valid ranges.
675 // For one of the logs I looked at, we had 2 ranges for 4 days.
676 //
677 // Save monotonic times as well to help if a queue index ever wraps. Odds
678 // are very low, but doesn't hurt.
679 //
680 // The starting time and matching queue index.
681 monotonic_clock::time_point starting_monotonic_event_time =
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700682 monotonic_clock::min_time;
Austin Schuh9942bae2021-01-07 22:06:44 -0800683 uint32_t starting_queue_index = 0xffffffff;
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700684
Austin Schuh9942bae2021-01-07 22:06:44 -0800685 // Ending time and queue index.
686 monotonic_clock::time_point ending_monotonic_event_time =
687 monotonic_clock::max_time;
688 uint32_t ending_queue_index = 0xffffffff;
689
690 // The queue index that the first message was *actually* sent with. The
691 // queue indices are assumed to be contiguous through this range.
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700692 uint32_t actual_queue_index = 0xffffffff;
693 };
694
James Kuszmaul94ca5132022-07-19 09:11:08 -0700695 // Returns a list of channels which LogReader will send on but which may
696 // *also* get sent on by other applications in replay.
697 std::vector<
698 std::pair<const aos::Channel *, NodeEventLoopFactory::ExclusiveSenders>>
699 NonExclusiveChannels();
700
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700701 // Stores all the timestamps that have been sent on this channel. This is
702 // only done for channels which are forwarded and on the node which
Austin Schuh9942bae2021-01-07 22:06:44 -0800703 // initially sends the message. Compress using ranges and offsets.
704 std::vector<std::unique_ptr<std::vector<ContiguousSentTimestamp>>>
705 queue_index_map_;
Austin Schuh858c9f32020-08-31 16:56:12 -0700706
707 // Factory (if we are in sim) that this loop was created on.
708 NodeEventLoopFactory *node_event_loop_factory_ = nullptr;
Austin Schuhe33c08d2022-02-03 18:15:21 -0800709 SimulatedEventLoopFactory *event_loop_factory_ = nullptr;
710
James Kuszmaulb11a1502022-07-01 16:02:25 -0700711 // Callback for when this node hits its realtime end time.
712 std::function<void()> notice_realtime_end_;
713
Austin Schuh858c9f32020-08-31 16:56:12 -0700714 std::unique_ptr<EventLoop> event_loop_unique_ptr_;
715 // Event loop.
Austin Schuh58646e22021-08-23 23:51:46 -0700716 const Node *node_ = nullptr;
Austin Schuh858c9f32020-08-31 16:56:12 -0700717 EventLoop *event_loop_ = nullptr;
718 // And timer used to send messages.
Austin Schuh58646e22021-08-23 23:51:46 -0700719 TimerHandler *timer_handler_ = nullptr;
720 TimerHandler *startup_timer_ = nullptr;
Austin Schuh858c9f32020-08-31 16:56:12 -0700721
Austin Schuhe33c08d2022-02-03 18:15:21 -0800722 std::unique_ptr<EventNotifier> start_event_notifier_;
723 std::unique_ptr<EventNotifier> end_event_notifier_;
724
Austin Schuh8bd96322020-02-13 21:18:22 -0800725 // Filters (or nullptr if it isn't a forwarded channel) for each channel.
726 // This corresponds to the object which is shared among all the channels
727 // going between 2 nodes. The second element in the tuple indicates if this
728 // is the primary direction or not.
Austin Schuh2f8fd752020-09-01 22:38:28 -0700729 std::vector<message_bridge::NoncausalOffsetEstimator *> filters_;
James Kuszmaul09632422022-05-25 15:56:19 -0700730 message_bridge::MultiNodeNoncausalOffsetEstimator *multinode_filters_;
Austin Schuh8bd96322020-02-13 21:18:22 -0800731
732 // List of NodeEventLoopFactorys (or nullptr if it isn't a forwarded
733 // channel) which correspond to the originating node.
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700734 std::vector<State *> channel_source_state_;
735
Austin Schuh61e973f2021-02-21 21:43:56 -0800736 // This is a cache for channel, connection mapping to the corresponding
737 // sender.
738 absl::btree_map<std::pair<const Channel *, const Connection *>,
739 std::shared_ptr<RemoteMessageSender>>
740 channel_timestamp_loggers_;
741
742 // Mapping from resolved RemoteMessage channel to RemoteMessage sender. This
743 // is the channel that timestamps are published to.
744 absl::btree_map<const Channel *, std::shared_ptr<RemoteMessageSender>>
745 timestamp_loggers_;
Austin Schuh58646e22021-08-23 23:51:46 -0700746
James Kuszmaul09632422022-05-25 15:56:19 -0700747 // Time offset between the log's monotonic clock and the current event
748 // loop's monotonic clock. Useful when replaying logs with non-simulated
749 // event loops.
750 std::chrono::nanoseconds clock_offset_{0};
751
Austin Schuh58646e22021-08-23 23:51:46 -0700752 std::vector<std::function<void()>> on_starts_;
753 std::vector<std::function<void()>> on_ends_;
754
James Kuszmaula16a7912022-06-17 10:58:12 -0700755 std::atomic<bool> stopped_ = false;
756 std::atomic<bool> started_ = false;
Austin Schuhbd5f74a2021-11-11 20:55:38 -0800757
758 bool found_last_message_ = false;
759 std::vector<bool> last_message_;
James Kuszmaula16a7912022-06-17 10:58:12 -0700760
761 std::vector<timing::MessageTimingT> send_timings_;
762 aos::Sender<timing::ReplayTiming> timing_statistics_sender_;
763
764 // Protects access to any internal state after Run() is called. Designed
765 // assuming that only one node is actually executing in replay.
766 // Threading design:
767 // * The worker passed to message_queuer_ has full ownership over all
768 // the log-reading code, timestamp filters, last_queued_message_, etc.
769 // * The main thread should only have exclusive access to the replay
770 // event loop and associated features (mainly senders).
771 // It will pop an item out of the queue (which does maintain a shared_ptr
772 // reference which may also be being used by the message_queuer_ thread,
773 // but having shared_ptr's accessing the same memory from
774 // separate threads is permissible).
775 // Enabling this in simulation is currently infeasible due to a lack of
776 // synchronization in the MultiNodeNoncausalOffsetEstimator. Essentially,
777 // when the message_queuer_ thread attempts to read/pop messages from the
778 // timestamp_mapper_, it will end up calling callbacks that update the
779 // internal state of the MultiNodeNoncausalOffsetEstimator. Simultaneously,
780 // the event scheduler that is running in the main thread to orchestrate the
781 // simulation will be querying the estimator to know what the clocks on the
782 // various nodes are at, leading to potential issues.
783 ThreadedBuffering threading_;
784 std::optional<BootTimestamp> last_queued_message_;
785 std::optional<util::ThreadedQueue<TimestampedMessage, BootTimestamp>>
786 message_queuer_;
Eric Schmiedebergb38477e2022-12-02 16:08:04 -0700787
788 // If a ReplayChannels was passed to LogReader, this will hold the
789 // indices of the channels to replay for the Node represented by
790 // the instance of LogReader::State.
Naman Guptacf6d4422023-03-01 11:41:00 -0800791 std::unique_ptr<const ReplayChannelIndices> replay_channel_indices_;
Austin Schuh6f3babe2020-01-26 20:34:50 -0800792 };
793
Eric Schmiedebergb38477e2022-12-02 16:08:04 -0700794 // If a ReplayChannels was passed to LogReader then creates a
Naman Guptacf6d4422023-03-01 11:41:00 -0800795 // ReplayChannelIndices for the given node. Otherwise, returns a nullptr.
796 std::unique_ptr<const ReplayChannelIndices> MaybeMakeReplayChannelIndices(
Eric Schmiedebergb38477e2022-12-02 16:08:04 -0700797 const Node *node);
798
Austin Schuh8bd96322020-02-13 21:18:22 -0800799 // Node index -> State.
800 std::vector<std::unique_ptr<State>> states_;
801
802 // Creates the requested filter if it doesn't exist, regardless of whether
803 // these nodes can actually communicate directly. The second return value
804 // reports if this is the primary direction or not.
Austin Schuh2f8fd752020-09-01 22:38:28 -0700805 message_bridge::NoncausalOffsetEstimator *GetFilter(const Node *node_a,
806 const Node *node_b);
Austin Schuh8bd96322020-02-13 21:18:22 -0800807
Austin Schuh8bd96322020-02-13 21:18:22 -0800808 // List of filters for a connection. The pointer to the first node will be
809 // less than the second node.
Austin Schuh0ca1fd32020-12-18 22:53:05 -0800810 std::unique_ptr<message_bridge::MultiNodeNoncausalOffsetEstimator> filters_;
Austin Schuh8bd96322020-02-13 21:18:22 -0800811
James Kuszmaul84ff3e52020-01-03 19:48:53 -0800812 std::unique_ptr<FlatbufferDetachedBuffer<Configuration>>
813 remapped_configuration_buffer_;
814
James Kuszmaul84ff3e52020-01-03 19:48:53 -0800815 std::unique_ptr<SimulatedEventLoopFactory> event_loop_factory_unique_ptr_;
816 SimulatedEventLoopFactory *event_loop_factory_ = nullptr;
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800817
818 // Map of channel indices to new name. The channel index will be an index into
819 // logged_configuration(), and the string key will be the name of the channel
820 // to send on instead of the logged channel name.
Austin Schuh0de30f32020-12-06 12:44:28 -0800821 struct RemappedChannel {
822 std::string remapped_name;
823 std::string new_type;
824 };
825 std::map<size_t, RemappedChannel> remapped_channels_;
Austin Schuh01b4c352020-09-21 23:09:39 -0700826 std::vector<MapT> maps_;
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800827
Austin Schuh6f3babe2020-01-26 20:34:50 -0800828 // Number of nodes which still have data to send. This is used to figure out
829 // when to exit.
830 size_t live_nodes_ = 0;
831
James Kuszmaulb11a1502022-07-01 16:02:25 -0700832 // Similar counter to live_nodes_, but for tracking which individual nodes are
833 // running and have yet to hit the realtime end time, if any.
834 size_t live_nodes_with_realtime_time_end_ = 0;
835
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800836 const Configuration *remapped_configuration_ = nullptr;
837 const Configuration *replay_configuration_ = nullptr;
Austin Schuhcde938c2020-02-02 17:30:07 -0800838
Eric Schmiedebergb38477e2022-12-02 16:08:04 -0700839 // If a ReplayChannels was passed to LogReader, this will hold the
840 // name and type of channels to replay which is used when creating States.
841 const ReplayChannels *replay_channels_ = nullptr;
842
Austin Schuhcde938c2020-02-02 17:30:07 -0800843 // If true, the replay timer will ignore any missing data. This is used
844 // during startup when we are bootstrapping everything and trying to get to
845 // the start of all the log files.
846 bool ignore_missing_data_ = false;
James Kuszmaul71a81932020-12-15 21:08:01 -0800847
848 // Whether to exit the SimulatedEventLoop when we finish reading the logs.
849 bool exit_on_finish_ = true;
Austin Schuhe33c08d2022-02-03 18:15:21 -0800850
851 realtime_clock::time_point start_time_ = realtime_clock::min_time;
852 realtime_clock::time_point end_time_ = realtime_clock::max_time;
Austin Schuhe309d2a2019-11-29 13:25:21 -0800853};
854
855} // namespace logger
856} // namespace aos
857
Austin Schuhb06f03b2021-02-17 22:00:37 -0800858#endif // AOS_EVENTS_LOGGING_LOG_READER_H_