blob: 0d50fb92b5acca8b2eb4b559a0d7ca2d6d6b07b1 [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
35using ReplayChannels =
36 std::vector<std::pair<std::string_view, std::string_view>>;
37// Vector of channel indices
38using ReplayChannelIndicies = std::vector<size_t>;
39
Austin Schuh6f3babe2020-01-26 20:34:50 -080040// We end up with one of the following 3 log file types.
41//
42// Single node logged as the source node.
43// -> Replayed just on the source node.
44//
45// Forwarding timestamps only logged from the perspective of the destination
46// node.
47// -> Matched with data on source node and logged.
48//
49// Forwarding timestamps with data logged as the destination node.
50// -> Replayed just as the destination
51// -> Replayed as the source (Much harder, ordering is not defined)
52//
53// Duplicate data logged. -> CHECK that it matches and explode otherwise.
54//
55// This can be boiled down to a set of constraints and tools.
56//
57// 1) Forwarding timestamps and data need to be logged separately.
58// 2) Any forwarded data logged on the destination node needs to be logged
59// separately such that it can be sorted.
60//
61// 1) Log reader needs to be able to sort a list of log files.
62// 2) Log reader needs to be able to merge sorted lists of log files.
63// 3) Log reader needs to be able to match timestamps with messages.
64//
65// We also need to be able to generate multiple views of a log file depending on
66// the target.
67
Austin Schuhe309d2a2019-11-29 13:25:21 -080068// Replays all the channels in the logfile to the event loop.
69class LogReader {
70 public:
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -080071 // If you want to supply a new configuration that will be used for replay
72 // (e.g., to change message rates, or to populate an updated schema), then
73 // pass it in here. It must provide all the channels that the original logged
74 // config did.
Austin Schuh6f3babe2020-01-26 20:34:50 -080075 //
Eric Schmiedebergb38477e2022-12-02 16:08:04 -070076 // If certain messages should not be replayed, the replay_channels param can
77 // be used as an inclusive list of channels for messages to be replayed.
78 //
Austin Schuh287d43d2020-12-04 20:19:33 -080079 // The single file constructor calls SortParts internally.
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -080080 LogReader(std::string_view filename,
Eric Schmiedebergb38477e2022-12-02 16:08:04 -070081 const Configuration *replay_configuration = nullptr,
82 const ReplayChannels *replay_channels = nullptr);
Austin Schuh287d43d2020-12-04 20:19:33 -080083 LogReader(std::vector<LogFile> log_files,
Eric Schmiedebergb38477e2022-12-02 16:08:04 -070084 const Configuration *replay_configuration = nullptr,
85 const ReplayChannels *replay_channels = nullptr);
James Kuszmaul7daef362019-12-31 18:28:17 -080086 ~LogReader();
Austin Schuhe309d2a2019-11-29 13:25:21 -080087
Austin Schuh6331ef92020-01-07 18:28:09 -080088 // Registers all the callbacks to send the log file data out on an event loop
89 // created in event_loop_factory. This also updates time to be at the start
90 // of the log file by running until the log file starts.
91 // Note: the configuration used in the factory should be configuration()
92 // below, but can be anything as long as the locations needed to send
93 // everything are available.
James Kuszmaul84ff3e52020-01-03 19:48:53 -080094 void Register(SimulatedEventLoopFactory *event_loop_factory);
Austin Schuhe33c08d2022-02-03 18:15:21 -080095
Austin Schuh58646e22021-08-23 23:51:46 -070096 // Registers all the callbacks to send the log file data out to an event loop
97 // factory. This does not start replaying or change the current distributed
98 // time of the factory. It does change the monotonic clocks to be right.
99 void RegisterWithoutStarting(SimulatedEventLoopFactory *event_loop_factory);
Austin Schuhe33c08d2022-02-03 18:15:21 -0800100 // Runs the log until the last start time. Register above is defined as:
101 // Register(...) {
102 // RegisterWithoutStarting
103 // StartAfterRegister
104 // }
105 // This should generally be considered as a stepping stone to convert from
106 // Register() to RegisterWithoutStarting() incrementally.
107 void StartAfterRegister(SimulatedEventLoopFactory *event_loop_factory);
108
Austin Schuh6331ef92020-01-07 18:28:09 -0800109 // Creates an SimulatedEventLoopFactory accessible via event_loop_factory(),
110 // and then calls Register.
111 void Register();
James Kuszmaul09632422022-05-25 15:56:19 -0700112
Austin Schuh6331ef92020-01-07 18:28:09 -0800113 // Registers callbacks for all the events after the log file starts. This is
114 // only useful when replaying live.
Austin Schuhe309d2a2019-11-29 13:25:21 -0800115 void Register(EventLoop *event_loop);
Austin Schuh6331ef92020-01-07 18:28:09 -0800116
James Kuszmaula16a7912022-06-17 10:58:12 -0700117 // Sets a sender that should be used for tracking timing statistics. If not
118 // set, no statistics will be recorded.
119 void set_timing_accuracy_sender(
120 const Node *node, aos::Sender<timing::ReplayTiming> timing_sender) {
121 states_[configuration::GetNodeIndex(configuration(), node)]
122 ->set_timing_accuracy_sender(std::move(timing_sender));
123 }
124
Austin Schuh58646e22021-08-23 23:51:46 -0700125 // Called whenever a log file starts for a node.
126 void OnStart(std::function<void()> fn);
127 void OnStart(const Node *node, std::function<void()> fn);
128 // Called whenever a log file ends for a node.
129 void OnEnd(std::function<void()> fn);
130 void OnEnd(const Node *node, std::function<void()> fn);
131
James Kuszmaul84ff3e52020-01-03 19:48:53 -0800132 // Unregisters the senders. You only need to call this if you separately
133 // supplied an event loop or event loop factory and the lifetimes are such
134 // that they need to be explicitly destroyed before the LogReader destructor
135 // gets called.
Austin Schuhe309d2a2019-11-29 13:25:21 -0800136 void Deregister();
137
Austin Schuh0c297012020-09-16 18:41:59 -0700138 // Returns the configuration being used for replay from the log file.
139 // Note that this may be different from the configuration actually used for
140 // handling events. You should generally only use this to create a
141 // SimulatedEventLoopFactory, and then get the configuration from there for
142 // everything else.
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800143 const Configuration *logged_configuration() const;
Austin Schuh11d43732020-09-21 17:28:30 -0700144 // Returns the configuration being used for replay from the log file.
145 // Note that this may be different from the configuration actually used for
146 // handling events. You should generally only use this to create a
147 // SimulatedEventLoopFactory, and then get the configuration from there for
148 // everything else.
Austin Schuh6f3babe2020-01-26 20:34:50 -0800149 // The pointer is invalidated whenever RemapLoggedChannel is called.
Austin Schuh15649d62019-12-28 16:36:38 -0800150 const Configuration *configuration() const;
151
Austin Schuh6f3babe2020-01-26 20:34:50 -0800152 // Returns the nodes that this log file was created on. This is a list of
Austin Schuh07676622021-01-21 18:59:17 -0800153 // pointers to a node in the nodes() list inside logged_configuration().
154 std::vector<const Node *> LoggedNodes() const;
Austin Schuhe309d2a2019-11-29 13:25:21 -0800155
156 // Returns the starting timestamp for the log file.
Austin Schuh11d43732020-09-21 17:28:30 -0700157 monotonic_clock::time_point monotonic_start_time(
158 const Node *node = nullptr) const;
159 realtime_clock::time_point realtime_start_time(
160 const Node *node = nullptr) const;
Austin Schuhe309d2a2019-11-29 13:25:21 -0800161
Austin Schuhe33c08d2022-02-03 18:15:21 -0800162 // Sets the start and end times to replay data until for all nodes. This
163 // overrides the --start_time and --end_time flags. The default is to replay
164 // all data.
165 void SetStartTime(std::string start_time);
166 void SetStartTime(realtime_clock::time_point start_time);
167 void SetEndTime(std::string end_time);
168 void SetEndTime(realtime_clock::time_point end_time);
169
James Kuszmaul53da7f32022-09-11 11:11:55 -0700170 // Enum to use for indicating how RemapLoggedChannel behaves when there is
171 // already a channel with the remapped name (e.g., as may happen when
172 // replaying a logfile that was itself generated from replay).
173 enum class RemapConflict {
174 // LOG(FATAL) on conflicts in remappings.
175 kDisallow,
176 // If we run into a conflict, attempt to remap the channel we would be
177 // overriding (and continue to do so if remapping *that* channel also
178 // generates a conflict).
179 // This will mean that if we repeatedly replay a log, we will end up
180 // stacking more and more /original's on the start of the oldest version
181 // of the channels.
182 kCascade
183 };
184
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800185 // Causes the logger to publish the provided channel on a different name so
186 // that replayed applications can publish on the proper channel name without
187 // interference. This operates on raw channel names, without any node or
188 // application specific mappings.
James Kuszmaul53da7f32022-09-11 11:11:55 -0700189 void RemapLoggedChannel(
190 std::string_view name, std::string_view type,
191 std::string_view add_prefix = "/original", std::string_view new_type = "",
192 RemapConflict conflict_handling = RemapConflict::kCascade);
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800193 template <typename T>
James Kuszmaul53da7f32022-09-11 11:11:55 -0700194 void RemapLoggedChannel(
195 std::string_view name, std::string_view add_prefix = "/original",
196 std::string_view new_type = "",
197 RemapConflict conflict_handling = RemapConflict::kCascade) {
198 RemapLoggedChannel(name, T::GetFullyQualifiedName(), add_prefix, new_type,
199 conflict_handling);
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800200 }
201
Austin Schuh01b4c352020-09-21 23:09:39 -0700202 // Remaps the provided channel, though this respects node mappings, and
203 // preserves them too. This makes it so if /aos -> /pi1/aos on one node,
204 // /original/aos -> /original/pi1/aos on the same node after renaming, just
Austin Schuh0de30f32020-12-06 12:44:28 -0800205 // like you would hope. If new_type is not empty, the new channel will use
206 // the provided type instead. This allows for renaming messages.
Austin Schuh01b4c352020-09-21 23:09:39 -0700207 //
208 // TODO(austin): If you have 2 nodes remapping something to the same channel,
209 // this doesn't handle that. No use cases exist yet for that, so it isn't
210 // being done yet.
James Kuszmaul53da7f32022-09-11 11:11:55 -0700211 void RemapLoggedChannel(
212 std::string_view name, std::string_view type, const Node *node,
213 std::string_view add_prefix = "/original", std::string_view new_type = "",
214 RemapConflict conflict_handling = RemapConflict::kCascade);
Brian Silvermande9f3ff2020-04-28 16:56:58 -0700215 template <typename T>
James Kuszmaul53da7f32022-09-11 11:11:55 -0700216 void RemapLoggedChannel(
217 std::string_view name, const Node *node,
218 std::string_view add_prefix = "/original", std::string_view new_type = "",
219 RemapConflict conflict_handling = RemapConflict::kCascade) {
Austin Schuh0de30f32020-12-06 12:44:28 -0800220 RemapLoggedChannel(name, T::GetFullyQualifiedName(), node, add_prefix,
James Kuszmaul53da7f32022-09-11 11:11:55 -0700221 new_type, conflict_handling);
Austin Schuh01b4c352020-09-21 23:09:39 -0700222 }
223
224 template <typename T>
225 bool HasChannel(std::string_view name, const Node *node = nullptr) {
Austin Schuh0ca51f32020-12-25 21:51:45 -0800226 return configuration::GetChannel(logged_configuration(), name,
Austin Schuh0de30f32020-12-06 12:44:28 -0800227 T::GetFullyQualifiedName(), "", node,
228 true) != nullptr;
Brian Silvermande9f3ff2020-04-28 16:56:58 -0700229 }
230
Austin Schuh82529062021-12-08 12:09:52 -0800231 template <typename T>
232 void MaybeRemapLoggedChannel(std::string_view name,
233 const Node *node = nullptr) {
234 if (HasChannel<T>(name, node)) {
235 RemapLoggedChannel<T>(name, node);
236 }
237 }
238
James Kuszmaul4f106fb2021-01-05 20:53:02 -0800239 // Returns true if the channel exists on the node and was logged.
240 template <typename T>
241 bool HasLoggedChannel(std::string_view name, const Node *node = nullptr) {
Austin Schuh5ee56872021-01-30 16:53:34 -0800242 const Channel *channel =
243 configuration::GetChannel(logged_configuration(), name,
244 T::GetFullyQualifiedName(), "", node, true);
James Kuszmaul4f106fb2021-01-05 20:53:02 -0800245 if (channel == nullptr) return false;
246 return channel->logger() != LoggerConfig::NOT_LOGGED;
247 }
248
Austin Schuh1c227352021-09-17 12:53:54 -0700249 // Returns a list of all the original channels from remapping.
250 std::vector<const Channel *> RemappedChannels() const;
251
James Kuszmaul84ff3e52020-01-03 19:48:53 -0800252 SimulatedEventLoopFactory *event_loop_factory() {
253 return event_loop_factory_;
254 }
255
Austin Schuh0ca51f32020-12-25 21:51:45 -0800256 std::string_view name() const { return log_files_[0].name; }
Austin Schuh0c297012020-09-16 18:41:59 -0700257
James Kuszmaul71a81932020-12-15 21:08:01 -0800258 // Set whether to exit the SimulatedEventLoopFactory when we finish reading
259 // the logfile.
260 void set_exit_on_finish(bool exit_on_finish) {
261 exit_on_finish_ = exit_on_finish;
262 }
263
James Kuszmaulb67409b2022-06-20 16:25:03 -0700264 // Sets the realtime replay rate. A value of 1.0 will cause the scheduler to
265 // try to play events in realtime. 0.5 will run at half speed. Use infinity
266 // (the default) to run as fast as possible. This can be changed during
267 // run-time.
268 // Only applies when running against a SimulatedEventLoopFactory.
269 void SetRealtimeReplayRate(double replay_rate);
270
Austin Schuhe309d2a2019-11-29 13:25:21 -0800271 private:
Austin Schuh58646e22021-08-23 23:51:46 -0700272 void Register(EventLoop *event_loop, const Node *node);
273
274 void RegisterDuringStartup(EventLoop *event_loop, const Node *node);
275
276 const Channel *RemapChannel(const EventLoop *event_loop, const Node *node,
Austin Schuh6f3babe2020-01-26 20:34:50 -0800277 const Channel *channel);
278
Austin Schuhe309d2a2019-11-29 13:25:21 -0800279 // Queues at least max_out_of_order_duration_ messages into channels_.
280 void QueueMessages();
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800281 // Handle constructing a configuration with all the additional remapped
282 // channels from calls to RemapLoggedChannel.
283 void MakeRemappedConfig();
Austin Schuhe309d2a2019-11-29 13:25:21 -0800284
Austin Schuh2f8fd752020-09-01 22:38:28 -0700285 // Returns the number of nodes.
286 size_t nodes_count() const {
287 return !configuration::MultiNode(logged_configuration())
288 ? 1u
289 : logged_configuration()->nodes()->size();
290 }
291
Austin Schuh287d43d2020-12-04 20:19:33 -0800292 const std::vector<LogFile> log_files_;
Austin Schuh6f3babe2020-01-26 20:34:50 -0800293
Austin Schuh969cd602021-01-03 00:09:45 -0800294 // Class to manage sending RemoteMessages on the provided node after the
295 // correct delay.
Austin Schuh5ee56872021-01-30 16:53:34 -0800296 class RemoteMessageSender {
Austin Schuh969cd602021-01-03 00:09:45 -0800297 public:
298 RemoteMessageSender(aos::Sender<message_bridge::RemoteMessage> sender,
299 EventLoop *event_loop);
300 RemoteMessageSender(RemoteMessageSender const &) = delete;
301 RemoteMessageSender &operator=(RemoteMessageSender const &) = delete;
302
303 // Sends the provided message. If monotonic_timestamp_time is min_time,
304 // send it immediately.
305 void Send(
306 FlatbufferDetachedBuffer<message_bridge::RemoteMessage> remote_message,
Austin Schuh58646e22021-08-23 23:51:46 -0700307 BootTimestamp monotonic_timestamp_time, size_t source_boot_count);
Austin Schuh969cd602021-01-03 00:09:45 -0800308
309 private:
310 // Handles actually sending the timestamp if we were delayed.
311 void SendTimestamp();
312 // Handles scheduling the timer to send at the correct time.
313 void ScheduleTimestamp();
314
315 EventLoop *event_loop_;
316 aos::Sender<message_bridge::RemoteMessage> sender_;
317 aos::TimerHandler *timer_;
318
319 // Time we are scheduled for, or min_time if we aren't scheduled.
320 monotonic_clock::time_point scheduled_time_ = monotonic_clock::min_time;
321
322 struct Timestamp {
323 Timestamp(FlatbufferDetachedBuffer<message_bridge::RemoteMessage>
324 new_remote_message,
325 monotonic_clock::time_point new_monotonic_timestamp_time)
326 : remote_message(std::move(new_remote_message)),
327 monotonic_timestamp_time(new_monotonic_timestamp_time) {}
328 FlatbufferDetachedBuffer<message_bridge::RemoteMessage> remote_message;
329 monotonic_clock::time_point monotonic_timestamp_time;
330 };
331
332 // List of messages to send. The timer works through them and then disables
333 // itself automatically.
334 std::deque<Timestamp> remote_timestamps_;
335 };
336
Austin Schuh6f3babe2020-01-26 20:34:50 -0800337 // State per node.
Austin Schuh858c9f32020-08-31 16:56:12 -0700338 class State {
339 public:
James Kuszmaula16a7912022-06-17 10:58:12 -0700340 // Whether we should spin up a separate thread for buffering up messages.
341 // Only allowed in realtime replay--see comments on threading_ member for
342 // details.
343 enum class ThreadedBuffering { kYes, kNo };
James Kuszmaul09632422022-05-25 15:56:19 -0700344 State(std::unique_ptr<TimestampMapper> timestamp_mapper,
345 message_bridge::MultiNodeNoncausalOffsetEstimator *multinode_filters,
Eric Schmiedebergb38477e2022-12-02 16:08:04 -0700346 const Node *node, ThreadedBuffering threading,
347 std::unique_ptr<const ReplayChannelIndicies> replay_channel_indicies);
Austin Schuh287d43d2020-12-04 20:19:33 -0800348
349 // Connects up the timestamp mappers.
350 void AddPeer(State *peer);
Austin Schuh6f3babe2020-01-26 20:34:50 -0800351
Austin Schuhe639ea12021-01-25 13:00:22 -0800352 TimestampMapper *timestamp_mapper() { return timestamp_mapper_.get(); }
353
Austin Schuhdda74ec2021-01-03 19:30:37 -0800354 // Returns the next sorted message with all the timestamps extracted and
355 // matched.
356 TimestampedMessage PopOldest();
Austin Schuh188eabe2020-12-29 23:41:13 -0800357
Austin Schuh858c9f32020-08-31 16:56:12 -0700358 // Returns the monotonic time of the oldest message.
James Kuszmaula16a7912022-06-17 10:58:12 -0700359 BootTimestamp SingleThreadedOldestMessageTime();
360 // Returns the monotonic time of the oldest message, handling querying the
361 // separate thread of ThreadedBuffering was set.
362 BootTimestamp MultiThreadedOldestMessageTime();
Austin Schuh58646e22021-08-23 23:51:46 -0700363
364 size_t boot_count() const {
365 // If we are replaying directly into an event loop, we can't reboot. So
366 // we will stay stuck on the 0th boot.
James Kuszmaul09632422022-05-25 15:56:19 -0700367 if (!node_event_loop_factory_) {
368 if (event_loop_ == nullptr) {
369 // If boot_count is being checked after startup for any of the
370 // non-primary nodes, then returning 0 may not be accurate (since
371 // remote nodes *can* reboot even if the EventLoop being played to
372 // can't).
373 CHECK(!started_);
374 CHECK(!stopped_);
375 }
376 return 0u;
377 }
Austin Schuh58646e22021-08-23 23:51:46 -0700378 return node_event_loop_factory_->boot_count();
379 }
Austin Schuh858c9f32020-08-31 16:56:12 -0700380
381 // Primes the queues inside State. Should be called before calling
382 // OldestMessageTime.
383 void SeedSortedMessages();
Austin Schuh8bd96322020-02-13 21:18:22 -0800384
Austin Schuh58646e22021-08-23 23:51:46 -0700385 void SetupStartupTimer() {
386 const monotonic_clock::time_point start_time =
387 monotonic_start_time(boot_count());
388 if (start_time == monotonic_clock::min_time) {
389 LOG(ERROR)
390 << "No start time, skipping, please figure out when this happens";
Austin Schuhe33c08d2022-02-03 18:15:21 -0800391 NotifyLogfileStart();
Austin Schuh58646e22021-08-23 23:51:46 -0700392 return;
393 }
James Kuszmaul09632422022-05-25 15:56:19 -0700394 if (node_event_loop_factory_) {
395 CHECK_GE(start_time + clock_offset(), event_loop_->monotonic_now());
396 }
397 startup_timer_->Setup(start_time + clock_offset());
Austin Schuh58646e22021-08-23 23:51:46 -0700398 }
399
400 void set_startup_timer(TimerHandler *timer_handler) {
401 startup_timer_ = timer_handler;
402 if (startup_timer_) {
403 if (event_loop_->node() != nullptr) {
404 startup_timer_->set_name(absl::StrCat(
405 event_loop_->node()->name()->string_view(), "_startup"));
406 } else {
407 startup_timer_->set_name("startup");
408 }
409 }
410 }
411
Austin Schuh858c9f32020-08-31 16:56:12 -0700412 // Returns the starting time for this node.
Austin Schuh2dc8c7d2021-07-01 17:41:28 -0700413 monotonic_clock::time_point monotonic_start_time(size_t boot_count) const {
414 return timestamp_mapper_
415 ? timestamp_mapper_->monotonic_start_time(boot_count)
416 : monotonic_clock::min_time;
Austin Schuh858c9f32020-08-31 16:56:12 -0700417 }
Austin Schuh2dc8c7d2021-07-01 17:41:28 -0700418 realtime_clock::time_point realtime_start_time(size_t boot_count) const {
419 return timestamp_mapper_
420 ? timestamp_mapper_->realtime_start_time(boot_count)
421 : realtime_clock::min_time;
Austin Schuh858c9f32020-08-31 16:56:12 -0700422 }
423
424 // Sets the node event loop factory for replaying into a
425 // SimulatedEventLoopFactory. Returns the EventLoop to use.
Austin Schuh60e77942022-05-16 17:48:24 -0700426 void SetNodeEventLoopFactory(NodeEventLoopFactory *node_event_loop_factory,
427 SimulatedEventLoopFactory *event_loop_factory);
Austin Schuh858c9f32020-08-31 16:56:12 -0700428
429 // Sets and gets the event loop to use.
430 void set_event_loop(EventLoop *event_loop) { event_loop_ = event_loop; }
431 EventLoop *event_loop() { return event_loop_; }
432
Austin Schuh58646e22021-08-23 23:51:46 -0700433 const Node *node() const { return node_; }
434
435 void Register(EventLoop *event_loop);
436
437 void OnStart(std::function<void()> fn);
438 void OnEnd(std::function<void()> fn);
439
Austin Schuh858c9f32020-08-31 16:56:12 -0700440 // Sets the current realtime offset from the monotonic clock for this node
441 // (if we are on a simulated event loop).
442 void SetRealtimeOffset(monotonic_clock::time_point monotonic_time,
443 realtime_clock::time_point realtime_time) {
444 if (node_event_loop_factory_ != nullptr) {
445 node_event_loop_factory_->SetRealtimeOffset(monotonic_time,
446 realtime_time);
447 }
448 }
449
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700450 // Returns the MessageHeader sender to log delivery timestamps to for the
451 // provided remote node.
Austin Schuh61e973f2021-02-21 21:43:56 -0800452 RemoteMessageSender *RemoteTimestampSender(const Channel *channel,
453 const Connection *connection);
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700454
Austin Schuh858c9f32020-08-31 16:56:12 -0700455 // Converts a timestamp from the monotonic clock on this node to the
456 // distributed clock.
457 distributed_clock::time_point ToDistributedClock(
458 monotonic_clock::time_point time) {
James Kuszmaul09632422022-05-25 15:56:19 -0700459 CHECK(node_event_loop_factory_);
Austin Schuh858c9f32020-08-31 16:56:12 -0700460 return node_event_loop_factory_->ToDistributedClock(time);
461 }
462
Austin Schuh858c9f32020-08-31 16:56:12 -0700463 // Returns the current time on the remote node which sends messages on
464 // channel_index.
Austin Schuh58646e22021-08-23 23:51:46 -0700465 BootTimestamp monotonic_remote_now(size_t channel_index) {
466 State *s = channel_source_state_[channel_index];
467 return BootTimestamp{
468 .boot = s->boot_count(),
469 .time = s->node_event_loop_factory_->monotonic_now()};
Austin Schuh858c9f32020-08-31 16:56:12 -0700470 }
471
Austin Schuh5ee56872021-01-30 16:53:34 -0800472 // Returns the start time of the remote for the provided channel.
473 monotonic_clock::time_point monotonic_remote_start_time(
Austin Schuh58646e22021-08-23 23:51:46 -0700474 size_t boot_count, size_t channel_index) {
Austin Schuh2dc8c7d2021-07-01 17:41:28 -0700475 return channel_source_state_[channel_index]->monotonic_start_time(
476 boot_count);
Austin Schuh5ee56872021-01-30 16:53:34 -0800477 }
478
Austin Schuh58646e22021-08-23 23:51:46 -0700479 void DestroyEventLoop() { event_loop_unique_ptr_.reset(); }
480
481 EventLoop *MakeEventLoop() {
482 CHECK(!event_loop_unique_ptr_);
James Kuszmaul890c2492022-04-06 14:59:31 -0700483 // TODO(james): Enable exclusive senders on LogReader to allow us to
484 // ensure we are remapping channels correctly.
485 event_loop_unique_ptr_ = node_event_loop_factory_->MakeEventLoop(
486 "log_reader", {NodeEventLoopFactory::CheckSentTooFast::kNo,
James Kuszmaul94ca5132022-07-19 09:11:08 -0700487 NodeEventLoopFactory::ExclusiveSenders::kYes,
488 NonExclusiveChannels()});
Austin Schuh58646e22021-08-23 23:51:46 -0700489 return event_loop_unique_ptr_.get();
490 }
491
Austin Schuh2f8fd752020-09-01 22:38:28 -0700492 distributed_clock::time_point RemoteToDistributedClock(
493 size_t channel_index, monotonic_clock::time_point time) {
James Kuszmaul09632422022-05-25 15:56:19 -0700494 CHECK(node_event_loop_factory_);
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700495 return channel_source_state_[channel_index]
496 ->node_event_loop_factory_->ToDistributedClock(time);
Austin Schuh2f8fd752020-09-01 22:38:28 -0700497 }
498
499 const Node *remote_node(size_t channel_index) {
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700500 return channel_source_state_[channel_index]
501 ->node_event_loop_factory_->node();
Austin Schuh2f8fd752020-09-01 22:38:28 -0700502 }
503
Stephan Pleines559fa6c2022-01-06 17:23:51 -0800504 monotonic_clock::time_point monotonic_now() const {
James Kuszmaul09632422022-05-25 15:56:19 -0700505 return event_loop_->monotonic_now();
Austin Schuh2f8fd752020-09-01 22:38:28 -0700506 }
507
Austin Schuh858c9f32020-08-31 16:56:12 -0700508 // Sets the number of channels.
509 void SetChannelCount(size_t count);
510
511 // Sets the sender, filter, and target factory for a channel.
Austin Schuh969cd602021-01-03 00:09:45 -0800512 void SetChannel(size_t logged_channel_index, size_t factory_channel_index,
513 std::unique_ptr<RawSender> sender,
514 message_bridge::NoncausalOffsetEstimator *filter,
Austin Schuh58646e22021-08-23 23:51:46 -0700515 bool is_forwarded, State *source_state);
516
517 void SetRemoteTimestampSender(size_t logged_channel_index,
518 RemoteMessageSender *remote_timestamp_sender);
519
520 void RunOnStart();
521 void RunOnEnd();
Austin Schuh858c9f32020-08-31 16:56:12 -0700522
Austin Schuhe33c08d2022-02-03 18:15:21 -0800523 // Handles a logfile start event to potentially call the OnStart callbacks.
524 void NotifyLogfileStart();
525 // Handles a start time flag start event to potentially call the OnStart
526 // callbacks.
527 void NotifyFlagStart();
528
529 // Handles a logfile end event to potentially call the OnEnd callbacks.
530 void NotifyLogfileEnd();
531 // Handles a end time flag start event to potentially call the OnEnd
532 // callbacks.
533 void NotifyFlagEnd();
534
Austin Schuh858c9f32020-08-31 16:56:12 -0700535 // Unregisters everything so we can destory the event loop.
Austin Schuh58646e22021-08-23 23:51:46 -0700536 // TODO(austin): Is this needed? OnShutdown should be able to serve this
537 // need.
Austin Schuh858c9f32020-08-31 16:56:12 -0700538 void Deregister();
539
540 // Sets the current TimerHandle for the replay callback.
541 void set_timer_handler(TimerHandler *timer_handler) {
542 timer_handler_ = timer_handler;
Austin Schuh58646e22021-08-23 23:51:46 -0700543 if (timer_handler_) {
544 if (event_loop_->node() != nullptr) {
545 timer_handler_->set_name(absl::StrCat(
546 event_loop_->node()->name()->string_view(), "_main"));
547 } else {
548 timer_handler_->set_name("main");
549 }
550 }
Austin Schuh858c9f32020-08-31 16:56:12 -0700551 }
552
Austin Schuhe33c08d2022-02-03 18:15:21 -0800553 // Creates and registers the --start_time and --end_time event callbacks.
554 void SetStartTimeFlag(realtime_clock::time_point start_time);
555 void SetEndTimeFlag(realtime_clock::time_point end_time);
556
557 // Notices the next message to update the start/end time callbacks.
558 void ObserveNextMessage(monotonic_clock::time_point monotonic_event,
559 realtime_clock::time_point realtime_event);
560
561 // Clears the start and end time flag handlers so we can delete the event
562 // loop.
563 void ClearTimeFlags();
564
Austin Schuh858c9f32020-08-31 16:56:12 -0700565 // Sets the next wakeup time on the replay callback.
566 void Setup(monotonic_clock::time_point next_time) {
James Kuszmaul8866e642022-06-10 16:00:36 -0700567 timer_handler_->Setup(
568 std::max(monotonic_now(), next_time + clock_offset()));
Austin Schuh858c9f32020-08-31 16:56:12 -0700569 }
570
571 // Sends a buffer on the provided channel index.
Austin Schuh287d43d2020-12-04 20:19:33 -0800572 bool Send(const TimestampedMessage &timestamped_message);
Austin Schuh858c9f32020-08-31 16:56:12 -0700573
James Kuszmaulc3f34d12022-08-15 15:57:55 -0700574 void MaybeSetClockOffset();
James Kuszmaul09632422022-05-25 15:56:19 -0700575 std::chrono::nanoseconds clock_offset() const { return clock_offset_; }
576
Austin Schuh858c9f32020-08-31 16:56:12 -0700577 // Returns a debug string for the channel merger.
Austin Schuh2f8fd752020-09-01 22:38:28 -0700578 std::string DebugString() const {
Austin Schuh287d43d2020-12-04 20:19:33 -0800579 if (!timestamp_mapper_) {
Austin Schuhe639ea12021-01-25 13:00:22 -0800580 return "";
Austin Schuh287d43d2020-12-04 20:19:33 -0800581 }
Austin Schuhe639ea12021-01-25 13:00:22 -0800582 return timestamp_mapper_->DebugString();
Austin Schuh2f8fd752020-09-01 22:38:28 -0700583 }
Austin Schuh858c9f32020-08-31 16:56:12 -0700584
Austin Schuh58646e22021-08-23 23:51:46 -0700585 void ClearRemoteTimestampSenders() {
586 channel_timestamp_loggers_.clear();
587 timestamp_loggers_.clear();
588 }
589
Austin Schuhbd5f74a2021-11-11 20:55:38 -0800590 void SetFoundLastMessage(bool val) {
591 found_last_message_ = val;
592 last_message_.resize(factory_channel_index_.size(), false);
593 }
594 bool found_last_message() const { return found_last_message_; }
595
596 void set_last_message(size_t channel_index) {
597 CHECK_LT(channel_index, last_message_.size());
598 last_message_[channel_index] = true;
599 }
600
601 bool last_message(size_t channel_index) {
602 CHECK_LT(channel_index, last_message_.size());
603 return last_message_[channel_index];
604 }
605
James Kuszmaula16a7912022-06-17 10:58:12 -0700606 void set_timing_accuracy_sender(
607 aos::Sender<timing::ReplayTiming> timing_sender) {
608 timing_statistics_sender_ = std::move(timing_sender);
609 OnEnd([this]() { SendMessageTimings(); });
610 }
611
612 // If running with ThreadedBuffering::kYes, will start the processing thread
613 // and queue up messages until the specified time. No-op of
614 // ThreadedBuffering::kNo is set. Should only be called once.
615 void QueueThreadUntil(BootTimestamp time);
616
Austin Schuh858c9f32020-08-31 16:56:12 -0700617 private:
James Kuszmaulc3f34d12022-08-15 15:57:55 -0700618 void TrackMessageSendTiming(const RawSender &sender,
619 monotonic_clock::time_point expected_send_time);
James Kuszmaula16a7912022-06-17 10:58:12 -0700620 void SendMessageTimings();
Austin Schuh858c9f32020-08-31 16:56:12 -0700621 // Log file.
Austin Schuh287d43d2020-12-04 20:19:33 -0800622 std::unique_ptr<TimestampMapper> timestamp_mapper_;
Austin Schuh858c9f32020-08-31 16:56:12 -0700623
Austin Schuh858c9f32020-08-31 16:56:12 -0700624 // Senders.
625 std::vector<std::unique_ptr<RawSender>> channels_;
Austin Schuh969cd602021-01-03 00:09:45 -0800626 std::vector<RemoteMessageSender *> remote_timestamp_senders_;
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700627 // The mapping from logged channel index to sent channel index. Needed for
628 // sending out MessageHeaders.
629 std::vector<int> factory_channel_index_;
630
Austin Schuh9942bae2021-01-07 22:06:44 -0800631 struct ContiguousSentTimestamp {
632 // Most timestamps make it through the network, so it saves a ton of
633 // memory and CPU to store the start and end, and search for valid ranges.
634 // For one of the logs I looked at, we had 2 ranges for 4 days.
635 //
636 // Save monotonic times as well to help if a queue index ever wraps. Odds
637 // are very low, but doesn't hurt.
638 //
639 // The starting time and matching queue index.
640 monotonic_clock::time_point starting_monotonic_event_time =
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700641 monotonic_clock::min_time;
Austin Schuh9942bae2021-01-07 22:06:44 -0800642 uint32_t starting_queue_index = 0xffffffff;
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700643
Austin Schuh9942bae2021-01-07 22:06:44 -0800644 // Ending time and queue index.
645 monotonic_clock::time_point ending_monotonic_event_time =
646 monotonic_clock::max_time;
647 uint32_t ending_queue_index = 0xffffffff;
648
649 // The queue index that the first message was *actually* sent with. The
650 // queue indices are assumed to be contiguous through this range.
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700651 uint32_t actual_queue_index = 0xffffffff;
652 };
653
James Kuszmaul94ca5132022-07-19 09:11:08 -0700654 // Returns a list of channels which LogReader will send on but which may
655 // *also* get sent on by other applications in replay.
656 std::vector<
657 std::pair<const aos::Channel *, NodeEventLoopFactory::ExclusiveSenders>>
658 NonExclusiveChannels();
659
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700660 // Stores all the timestamps that have been sent on this channel. This is
661 // only done for channels which are forwarded and on the node which
Austin Schuh9942bae2021-01-07 22:06:44 -0800662 // initially sends the message. Compress using ranges and offsets.
663 std::vector<std::unique_ptr<std::vector<ContiguousSentTimestamp>>>
664 queue_index_map_;
Austin Schuh858c9f32020-08-31 16:56:12 -0700665
666 // Factory (if we are in sim) that this loop was created on.
667 NodeEventLoopFactory *node_event_loop_factory_ = nullptr;
Austin Schuhe33c08d2022-02-03 18:15:21 -0800668 SimulatedEventLoopFactory *event_loop_factory_ = nullptr;
669
Austin Schuh858c9f32020-08-31 16:56:12 -0700670 std::unique_ptr<EventLoop> event_loop_unique_ptr_;
671 // Event loop.
Austin Schuh58646e22021-08-23 23:51:46 -0700672 const Node *node_ = nullptr;
Austin Schuh858c9f32020-08-31 16:56:12 -0700673 EventLoop *event_loop_ = nullptr;
674 // And timer used to send messages.
Austin Schuh58646e22021-08-23 23:51:46 -0700675 TimerHandler *timer_handler_ = nullptr;
676 TimerHandler *startup_timer_ = nullptr;
Austin Schuh858c9f32020-08-31 16:56:12 -0700677
Austin Schuhe33c08d2022-02-03 18:15:21 -0800678 std::unique_ptr<EventNotifier> start_event_notifier_;
679 std::unique_ptr<EventNotifier> end_event_notifier_;
680
Austin Schuh8bd96322020-02-13 21:18:22 -0800681 // Filters (or nullptr if it isn't a forwarded channel) for each channel.
682 // This corresponds to the object which is shared among all the channels
683 // going between 2 nodes. The second element in the tuple indicates if this
684 // is the primary direction or not.
Austin Schuh2f8fd752020-09-01 22:38:28 -0700685 std::vector<message_bridge::NoncausalOffsetEstimator *> filters_;
James Kuszmaul09632422022-05-25 15:56:19 -0700686 message_bridge::MultiNodeNoncausalOffsetEstimator *multinode_filters_;
Austin Schuh8bd96322020-02-13 21:18:22 -0800687
688 // List of NodeEventLoopFactorys (or nullptr if it isn't a forwarded
689 // channel) which correspond to the originating node.
Austin Schuh8d7e0bb2020-10-02 17:57:00 -0700690 std::vector<State *> channel_source_state_;
691
Austin Schuh61e973f2021-02-21 21:43:56 -0800692 // This is a cache for channel, connection mapping to the corresponding
693 // sender.
694 absl::btree_map<std::pair<const Channel *, const Connection *>,
695 std::shared_ptr<RemoteMessageSender>>
696 channel_timestamp_loggers_;
697
698 // Mapping from resolved RemoteMessage channel to RemoteMessage sender. This
699 // is the channel that timestamps are published to.
700 absl::btree_map<const Channel *, std::shared_ptr<RemoteMessageSender>>
701 timestamp_loggers_;
Austin Schuh58646e22021-08-23 23:51:46 -0700702
James Kuszmaul09632422022-05-25 15:56:19 -0700703 // Time offset between the log's monotonic clock and the current event
704 // loop's monotonic clock. Useful when replaying logs with non-simulated
705 // event loops.
706 std::chrono::nanoseconds clock_offset_{0};
707
Austin Schuh58646e22021-08-23 23:51:46 -0700708 std::vector<std::function<void()>> on_starts_;
709 std::vector<std::function<void()>> on_ends_;
710
James Kuszmaula16a7912022-06-17 10:58:12 -0700711 std::atomic<bool> stopped_ = false;
712 std::atomic<bool> started_ = false;
Austin Schuhbd5f74a2021-11-11 20:55:38 -0800713
714 bool found_last_message_ = false;
715 std::vector<bool> last_message_;
James Kuszmaula16a7912022-06-17 10:58:12 -0700716
717 std::vector<timing::MessageTimingT> send_timings_;
718 aos::Sender<timing::ReplayTiming> timing_statistics_sender_;
719
720 // Protects access to any internal state after Run() is called. Designed
721 // assuming that only one node is actually executing in replay.
722 // Threading design:
723 // * The worker passed to message_queuer_ has full ownership over all
724 // the log-reading code, timestamp filters, last_queued_message_, etc.
725 // * The main thread should only have exclusive access to the replay
726 // event loop and associated features (mainly senders).
727 // It will pop an item out of the queue (which does maintain a shared_ptr
728 // reference which may also be being used by the message_queuer_ thread,
729 // but having shared_ptr's accessing the same memory from
730 // separate threads is permissible).
731 // Enabling this in simulation is currently infeasible due to a lack of
732 // synchronization in the MultiNodeNoncausalOffsetEstimator. Essentially,
733 // when the message_queuer_ thread attempts to read/pop messages from the
734 // timestamp_mapper_, it will end up calling callbacks that update the
735 // internal state of the MultiNodeNoncausalOffsetEstimator. Simultaneously,
736 // the event scheduler that is running in the main thread to orchestrate the
737 // simulation will be querying the estimator to know what the clocks on the
738 // various nodes are at, leading to potential issues.
739 ThreadedBuffering threading_;
740 std::optional<BootTimestamp> last_queued_message_;
741 std::optional<util::ThreadedQueue<TimestampedMessage, BootTimestamp>>
742 message_queuer_;
Eric Schmiedebergb38477e2022-12-02 16:08:04 -0700743
744 // If a ReplayChannels was passed to LogReader, this will hold the
745 // indices of the channels to replay for the Node represented by
746 // the instance of LogReader::State.
747 std::unique_ptr<const ReplayChannelIndicies> replay_channel_indicies_;
Austin Schuh6f3babe2020-01-26 20:34:50 -0800748 };
749
Eric Schmiedebergb38477e2022-12-02 16:08:04 -0700750 // If a ReplayChannels was passed to LogReader then creates a
751 // ReplayChannelIndicies for the given node. Otherwise, returns a nullptr.
752 std::unique_ptr<const ReplayChannelIndicies> MaybeMakeReplayChannelIndicies(
753 const Node *node);
754
Austin Schuh8bd96322020-02-13 21:18:22 -0800755 // Node index -> State.
756 std::vector<std::unique_ptr<State>> states_;
757
758 // Creates the requested filter if it doesn't exist, regardless of whether
759 // these nodes can actually communicate directly. The second return value
760 // reports if this is the primary direction or not.
Austin Schuh2f8fd752020-09-01 22:38:28 -0700761 message_bridge::NoncausalOffsetEstimator *GetFilter(const Node *node_a,
762 const Node *node_b);
Austin Schuh8bd96322020-02-13 21:18:22 -0800763
Austin Schuh8bd96322020-02-13 21:18:22 -0800764 // List of filters for a connection. The pointer to the first node will be
765 // less than the second node.
Austin Schuh0ca1fd32020-12-18 22:53:05 -0800766 std::unique_ptr<message_bridge::MultiNodeNoncausalOffsetEstimator> filters_;
Austin Schuh8bd96322020-02-13 21:18:22 -0800767
James Kuszmaul84ff3e52020-01-03 19:48:53 -0800768 std::unique_ptr<FlatbufferDetachedBuffer<Configuration>>
769 remapped_configuration_buffer_;
770
James Kuszmaul84ff3e52020-01-03 19:48:53 -0800771 std::unique_ptr<SimulatedEventLoopFactory> event_loop_factory_unique_ptr_;
772 SimulatedEventLoopFactory *event_loop_factory_ = nullptr;
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800773
774 // Map of channel indices to new name. The channel index will be an index into
775 // logged_configuration(), and the string key will be the name of the channel
776 // to send on instead of the logged channel name.
Austin Schuh0de30f32020-12-06 12:44:28 -0800777 struct RemappedChannel {
778 std::string remapped_name;
779 std::string new_type;
780 };
781 std::map<size_t, RemappedChannel> remapped_channels_;
Austin Schuh01b4c352020-09-21 23:09:39 -0700782 std::vector<MapT> maps_;
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800783
Austin Schuh6f3babe2020-01-26 20:34:50 -0800784 // Number of nodes which still have data to send. This is used to figure out
785 // when to exit.
786 size_t live_nodes_ = 0;
787
James Kuszmaulc7bbb3e2020-01-03 20:01:00 -0800788 const Configuration *remapped_configuration_ = nullptr;
789 const Configuration *replay_configuration_ = nullptr;
Austin Schuhcde938c2020-02-02 17:30:07 -0800790
Eric Schmiedebergb38477e2022-12-02 16:08:04 -0700791 // If a ReplayChannels was passed to LogReader, this will hold the
792 // name and type of channels to replay which is used when creating States.
793 const ReplayChannels *replay_channels_ = nullptr;
794
Austin Schuhcde938c2020-02-02 17:30:07 -0800795 // If true, the replay timer will ignore any missing data. This is used
796 // during startup when we are bootstrapping everything and trying to get to
797 // the start of all the log files.
798 bool ignore_missing_data_ = false;
James Kuszmaul71a81932020-12-15 21:08:01 -0800799
800 // Whether to exit the SimulatedEventLoop when we finish reading the logs.
801 bool exit_on_finish_ = true;
Austin Schuhe33c08d2022-02-03 18:15:21 -0800802
803 realtime_clock::time_point start_time_ = realtime_clock::min_time;
804 realtime_clock::time_point end_time_ = realtime_clock::max_time;
Austin Schuhe309d2a2019-11-29 13:25:21 -0800805};
806
807} // namespace logger
808} // namespace aos
809
Austin Schuhb06f03b2021-02-17 22:00:37 -0800810#endif // AOS_EVENTS_LOGGING_LOG_READER_H_