Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 1 | #ifndef AOS_EVENTS_LOGGING_LOGFILE_UTILS_H_ |
| 2 | #define AOS_EVENTS_LOGGING_LOGFILE_UTILS_H_ |
| 3 | |
| 4 | #include <sys/uio.h> |
| 5 | |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 6 | #include <chrono> |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 7 | #include <deque> |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 8 | #include <limits> |
| 9 | #include <memory> |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 10 | #include <optional> |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 11 | #include <string> |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 12 | #include <string_view> |
Brian Silverman | 98360e2 | 2020-04-28 16:51:20 -0700 | [diff] [blame] | 13 | #include <tuple> |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 14 | #include <utility> |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Austin Schuh | 4b5c22a | 2020-11-30 22:58:43 -0800 | [diff] [blame] | 17 | #include "absl/container/btree_set.h" |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 18 | #include "absl/types/span.h" |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 19 | #include "aos/containers/resizeable_buffer.h" |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 20 | #include "aos/events/event_loop.h" |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 21 | #include "aos/events/logging/boot_timestamp.h" |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 22 | #include "aos/events/logging/buffer_encoder.h" |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 23 | #include "aos/events/logging/logfile_sorting.h" |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 24 | #include "aos/events/logging/logger_generated.h" |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 25 | #include "aos/flatbuffers.h" |
Austin Schuh | f2d0e68 | 2022-10-16 14:20:58 -0700 | [diff] [blame] | 26 | #include "aos/network/remote_message_generated.h" |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 27 | #include "flatbuffers/flatbuffers.h" |
| 28 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 29 | namespace aos::logger { |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 30 | |
| 31 | enum class LogType : uint8_t { |
| 32 | // The message originated on this node and should be logged here. |
| 33 | kLogMessage, |
| 34 | // The message originated on another node, but only the delivery times are |
| 35 | // logged here. |
| 36 | kLogDeliveryTimeOnly, |
| 37 | // The message originated on another node. Log it and the delivery times |
| 38 | // together. The message_gateway is responsible for logging any messages |
| 39 | // which didn't get delivered. |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 40 | kLogMessageAndDeliveryTime, |
| 41 | // The message originated on the other node and should be logged on this node. |
| 42 | kLogRemoteMessage |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 45 | // This class manages efficiently writing a sequence of detached buffers to a |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 46 | // file. It encodes them, queues them up, and batches the write operation. |
Austin Schuh | 4c3cdb7 | 2023-02-11 15:05:26 -0800 | [diff] [blame^] | 47 | // |
| 48 | // There are a couple over-arching constraints on writing to keep track of. |
| 49 | // 1) The kernel is both faster and more efficient at writing large, aligned |
| 50 | // chunks with O_DIRECT set on the file. The alignment needed is specified |
| 51 | // by kSector and is file system dependent. |
| 52 | // 2) Not all encoders support generating round multiples of kSector of data. |
| 53 | // Rather than burden the API for detecting when that is the case, we want |
| 54 | // DetachedBufferWriter to be as efficient as it can at writing what given. |
| 55 | // 3) Some files are small and not updated frequently. They need to be |
| 56 | // flushed or we will lose data on power off. It is most efficient to write |
| 57 | // as much as we can aligned by kSector and then fall back to the non direct |
| 58 | // method when it has been flushed. |
| 59 | // 4) Not all filesystems support O_DIRECT, and different sizes may be optimal |
| 60 | // for different machines. The defaults should work decently anywhere and |
| 61 | // be tuneable for faster systems. |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 62 | class DetachedBufferWriter { |
| 63 | public: |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 64 | // Marker struct for one of our constructor overloads. |
| 65 | struct already_out_of_space_t {}; |
| 66 | |
Austin Schuh | 4c3cdb7 | 2023-02-11 15:05:26 -0800 | [diff] [blame^] | 67 | // Size of an aligned sector used to detect when the data is aligned enough to |
| 68 | // use O_DIRECT instead. |
| 69 | static constexpr size_t kSector = 512u; |
| 70 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 71 | DetachedBufferWriter(std::string_view filename, |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 72 | std::unique_ptr<DataEncoder> encoder); |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 73 | // Creates a dummy instance which won't even open a file. It will act as if |
| 74 | // opening the file ran out of space immediately. |
| 75 | DetachedBufferWriter(already_out_of_space_t) : ran_out_of_space_(true) {} |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 76 | DetachedBufferWriter(DetachedBufferWriter &&other); |
| 77 | DetachedBufferWriter(const DetachedBufferWriter &) = delete; |
| 78 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 79 | ~DetachedBufferWriter(); |
| 80 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 81 | DetachedBufferWriter &operator=(DetachedBufferWriter &&other); |
Brian Silverman | 98360e2 | 2020-04-28 16:51:20 -0700 | [diff] [blame] | 82 | DetachedBufferWriter &operator=(const DetachedBufferWriter &) = delete; |
| 83 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 84 | std::string_view filename() const { return filename_; } |
| 85 | |
Brian Silverman | a9f2ec9 | 2020-10-06 18:00:53 -0700 | [diff] [blame] | 86 | // This will be true until Close() is called, unless the file couldn't be |
| 87 | // created due to running out of space. |
| 88 | bool is_open() const { return fd_ != -1; } |
| 89 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 90 | // Queues up a finished FlatBufferBuilder to be encoded and written. |
| 91 | // |
| 92 | // Triggers a flush if there's enough data queued up. |
| 93 | // |
| 94 | // Steals the detached buffer from it. |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 95 | void CopyMessage(DataEncoder::Copier *coppier, |
| 96 | aos::monotonic_clock::time_point now); |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 97 | |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 98 | // Indicates we got ENOSPC when trying to write. After this returns true, no |
| 99 | // further data is written. |
| 100 | bool ran_out_of_space() const { return ran_out_of_space_; } |
| 101 | |
| 102 | // To avoid silently failing to write logfiles, you must call this before |
| 103 | // destruction if ran_out_of_space() is true and the situation has been |
| 104 | // handled. |
| 105 | void acknowledge_out_of_space() { |
| 106 | CHECK(ran_out_of_space_); |
| 107 | acknowledge_ran_out_of_space_ = true; |
| 108 | } |
| 109 | |
| 110 | // Fully flushes and closes the underlying file now. No additional data may be |
| 111 | // enqueued after calling this. |
| 112 | // |
| 113 | // This will be performed in the destructor automatically. |
| 114 | // |
| 115 | // Note that this may set ran_out_of_space(). |
| 116 | void Close(); |
| 117 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 118 | // Returns the total number of bytes written and currently queued. |
Austin Schuh | a426f1f | 2021-03-31 22:27:41 -0700 | [diff] [blame] | 119 | size_t total_bytes() const { |
| 120 | if (!encoder_) { |
| 121 | return 0; |
| 122 | } |
| 123 | return encoder_->total_bytes(); |
| 124 | } |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 125 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 126 | // The maximum time for a single write call, or 0 if none have been performed. |
| 127 | std::chrono::nanoseconds max_write_time() const { return max_write_time_; } |
| 128 | // The number of bytes in the longest write call, or -1 if none have been |
| 129 | // performed. |
| 130 | int max_write_time_bytes() const { return max_write_time_bytes_; } |
| 131 | // The number of buffers in the longest write call, or -1 if none have been |
| 132 | // performed. |
| 133 | int max_write_time_messages() const { return max_write_time_messages_; } |
| 134 | // The total time spent in write calls. |
| 135 | std::chrono::nanoseconds total_write_time() const { |
| 136 | return total_write_time_; |
| 137 | } |
| 138 | // The total number of writes which have been performed. |
| 139 | int total_write_count() const { return total_write_count_; } |
| 140 | // The total number of messages which have been written. |
| 141 | int total_write_messages() const { return total_write_messages_; } |
| 142 | // The total number of bytes which have been written. |
| 143 | int total_write_bytes() const { return total_write_bytes_; } |
| 144 | void ResetStatistics() { |
| 145 | max_write_time_ = std::chrono::nanoseconds::zero(); |
| 146 | max_write_time_bytes_ = -1; |
| 147 | max_write_time_messages_ = -1; |
| 148 | total_write_time_ = std::chrono::nanoseconds::zero(); |
| 149 | total_write_count_ = 0; |
| 150 | total_write_messages_ = 0; |
| 151 | total_write_bytes_ = 0; |
| 152 | } |
Brian Silverman | 98360e2 | 2020-04-28 16:51:20 -0700 | [diff] [blame] | 153 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 154 | private: |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 155 | // Performs a single writev call with as much of the data we have queued up as |
Austin Schuh | 8bdfc49 | 2023-02-11 12:53:13 -0800 | [diff] [blame] | 156 | // possible. now is the time we flushed at, to be recorded in |
| 157 | // last_flush_time_. |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 158 | // |
| 159 | // This will normally take all of the data we have queued up, unless an |
| 160 | // encoder has spit out a big enough chunk all at once that we can't manage |
| 161 | // all of it. |
Austin Schuh | 8bdfc49 | 2023-02-11 12:53:13 -0800 | [diff] [blame] | 162 | void Flush(aos::monotonic_clock::time_point now); |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 163 | |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 164 | // write_return is what write(2) or writev(2) returned. write_size is the |
| 165 | // number of bytes we expected it to write. |
| 166 | void HandleWriteReturn(ssize_t write_return, size_t write_size); |
| 167 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 168 | void UpdateStatsForWrite(aos::monotonic_clock::duration duration, |
| 169 | ssize_t written, int iovec_size); |
| 170 | |
| 171 | // Flushes data if we've reached the threshold to do that as part of normal |
Austin Schuh | bd06ae4 | 2021-03-31 22:48:21 -0700 | [diff] [blame] | 172 | // operation either due to the outstanding queued data, or because we have |
| 173 | // passed our flush period. now is the current time to save some CPU grabbing |
| 174 | // the current time. It just needs to be close. |
| 175 | void FlushAtThreshold(aos::monotonic_clock::time_point now); |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 176 | |
Austin Schuh | 4c3cdb7 | 2023-02-11 15:05:26 -0800 | [diff] [blame^] | 177 | // Enables O_DIRECT on the open file if it is supported. Cheap to call if it |
| 178 | // is already enabled. |
| 179 | void EnableDirect(); |
| 180 | // Disables O_DIRECT on the open file if it is supported. Cheap to call if it |
| 181 | // is already disabld. |
| 182 | void DisableDirect(); |
| 183 | |
| 184 | // Writes a chunk of iovecs. aligned is true if all the data is kSector byte |
| 185 | // aligned and multiples of it in length, and counted_size is the sum of the |
| 186 | // sizes of all the chunks of data. Returns the size of data written. |
| 187 | size_t WriteV(struct iovec *iovec_data, size_t iovec_size, bool aligned, |
| 188 | size_t counted_size); |
| 189 | |
| 190 | bool ODirectEnabled() { return !!(flags_ & O_DIRECT); } |
| 191 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 192 | std::string filename_; |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 193 | std::unique_ptr<DataEncoder> encoder_; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 194 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 195 | int fd_ = -1; |
Brian Silverman | 0465fcf | 2020-09-24 00:29:18 -0700 | [diff] [blame] | 196 | bool ran_out_of_space_ = false; |
| 197 | bool acknowledge_ran_out_of_space_ = false; |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 198 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 199 | // List of iovecs to use with writev. This is a member variable to avoid |
| 200 | // churn. |
| 201 | std::vector<struct iovec> iovec_; |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 202 | |
| 203 | std::chrono::nanoseconds max_write_time_ = std::chrono::nanoseconds::zero(); |
| 204 | int max_write_time_bytes_ = -1; |
| 205 | int max_write_time_messages_ = -1; |
| 206 | std::chrono::nanoseconds total_write_time_ = std::chrono::nanoseconds::zero(); |
| 207 | int total_write_count_ = 0; |
| 208 | int total_write_messages_ = 0; |
| 209 | int total_write_bytes_ = 0; |
Austin Schuh | 4c3cdb7 | 2023-02-11 15:05:26 -0800 | [diff] [blame^] | 210 | int last_synced_bytes_ = 0; |
| 211 | |
| 212 | bool supports_odirect_ = true; |
| 213 | int flags_ = 0; |
Austin Schuh | bd06ae4 | 2021-03-31 22:48:21 -0700 | [diff] [blame] | 214 | |
| 215 | aos::monotonic_clock::time_point last_flush_time_ = |
| 216 | aos::monotonic_clock::min_time; |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 217 | }; |
| 218 | |
Austin Schuh | f2d0e68 | 2022-10-16 14:20:58 -0700 | [diff] [blame] | 219 | // Repacks the provided RemoteMessage into fbb. |
| 220 | flatbuffers::Offset<MessageHeader> PackRemoteMessage( |
| 221 | flatbuffers::FlatBufferBuilder *fbb, |
| 222 | const message_bridge::RemoteMessage *msg, int channel_index, |
| 223 | const aos::monotonic_clock::time_point monotonic_timestamp_time); |
| 224 | |
| 225 | constexpr flatbuffers::uoffset_t PackRemoteMessageSize() { return 96u; } |
| 226 | size_t PackRemoteMessageInline( |
| 227 | uint8_t *data, const message_bridge::RemoteMessage *msg, int channel_index, |
Austin Schuh | 71a40d4 | 2023-02-04 21:22:22 -0800 | [diff] [blame] | 228 | const aos::monotonic_clock::time_point monotonic_timestamp_time, |
| 229 | size_t start_byte, size_t end_byte); |
Austin Schuh | f2d0e68 | 2022-10-16 14:20:58 -0700 | [diff] [blame] | 230 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 231 | // Packes a message pointed to by the context into a MessageHeader. |
| 232 | flatbuffers::Offset<MessageHeader> PackMessage( |
| 233 | flatbuffers::FlatBufferBuilder *fbb, const Context &context, |
| 234 | int channel_index, LogType log_type); |
| 235 | |
Austin Schuh | fa30c35 | 2022-10-16 11:12:02 -0700 | [diff] [blame] | 236 | // Returns the size that the packed message from PackMessage or |
| 237 | // PackMessageInline will be. |
Austin Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 238 | flatbuffers::uoffset_t PackMessageSize(LogType log_type, size_t data_size); |
Austin Schuh | fa30c35 | 2022-10-16 11:12:02 -0700 | [diff] [blame] | 239 | |
| 240 | // Packs the provided message pointed to by context into the provided buffer. |
| 241 | // This is equivalent to PackMessage, but doesn't require allocating a |
| 242 | // FlatBufferBuilder underneath. |
| 243 | size_t PackMessageInline(uint8_t *data, const Context &contex, |
Austin Schuh | 71a40d4 | 2023-02-04 21:22:22 -0800 | [diff] [blame] | 244 | int channel_index, LogType log_type, size_t start_byte, |
| 245 | size_t end_byte); |
Austin Schuh | fa30c35 | 2022-10-16 11:12:02 -0700 | [diff] [blame] | 246 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 247 | // Class to read chunks out of a log file. |
| 248 | class SpanReader { |
| 249 | public: |
Austin Schuh | cd36842 | 2021-11-22 21:23:29 -0800 | [diff] [blame] | 250 | SpanReader(std::string_view filename, bool quiet = false); |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 251 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 252 | std::string_view filename() const { return filename_; } |
| 253 | |
Brian Smartt | ea913d4 | 2021-12-10 15:02:38 -0800 | [diff] [blame] | 254 | size_t TotalRead() const { return total_read_; } |
| 255 | size_t TotalConsumed() const { return total_consumed_; } |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 256 | bool IsIncomplete() const { |
| 257 | return is_finished_ && total_consumed_ < total_read_; |
| 258 | } |
Brian Smartt | ea913d4 | 2021-12-10 15:02:38 -0800 | [diff] [blame] | 259 | |
Austin Schuh | cf5f644 | 2021-07-06 10:43:28 -0700 | [diff] [blame] | 260 | // Returns a span with the data for the next message from the log file, |
| 261 | // including the size. The result is only guarenteed to be valid until |
| 262 | // ReadMessage() or PeekMessage() is called again. |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 263 | absl::Span<const uint8_t> ReadMessage(); |
| 264 | |
Austin Schuh | cf5f644 | 2021-07-06 10:43:28 -0700 | [diff] [blame] | 265 | // Returns a span with the data for the next message without consuming it. |
| 266 | // Multiple calls to PeekMessage return the same data. ReadMessage or |
| 267 | // ConsumeMessage must be called to get the next message. |
| 268 | absl::Span<const uint8_t> PeekMessage(); |
| 269 | // Consumes the message so the next call to ReadMessage or PeekMessage returns |
| 270 | // new data. This does not invalidate the data. |
| 271 | void ConsumeMessage(); |
| 272 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 273 | private: |
| 274 | // TODO(austin): Optimization: |
| 275 | // Allocate the 256k blocks like we do today. But, refcount them with |
| 276 | // shared_ptr pointed to by the messageheader that is returned. This avoids |
| 277 | // the copy. Need to do more benchmarking. |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 278 | // And (Brian): Consider just mmapping the file and handing out refcounted |
| 279 | // pointers into that too. |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 280 | |
| 281 | // Reads a chunk of data into data_. Returns false if no data was read. |
| 282 | bool ReadBlock(); |
| 283 | |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 284 | std::string filename_; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 285 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 286 | // File reader and data decoder. |
| 287 | std::unique_ptr<DataDecoder> decoder_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 288 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 289 | // Vector to read into. |
| 290 | ResizeableBuffer data_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 291 | |
| 292 | // Amount of data consumed already in data_. |
| 293 | size_t consumed_data_ = 0; |
Brian Smartt | ea913d4 | 2021-12-10 15:02:38 -0800 | [diff] [blame] | 294 | |
| 295 | // Accumulates the total volume of bytes read from filename_ |
| 296 | size_t total_read_ = 0; |
| 297 | |
| 298 | // Accumulates the total volume of read bytes that were 'consumed' into |
| 299 | // messages. May be less than total_read_, if the last message (span) is |
| 300 | // either truncated or somehow corrupt. |
| 301 | size_t total_consumed_ = 0; |
| 302 | |
| 303 | // Reached the end, no more readable messages. |
| 304 | bool is_finished_ = false; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 305 | }; |
| 306 | |
Brian Silverman | fee1697 | 2021-09-14 12:06:38 -0700 | [diff] [blame] | 307 | // Reads the last header from a log file. This handles any duplicate headers |
| 308 | // that were written. |
| 309 | std::optional<SizePrefixedFlatbufferVector<LogFileHeader>> ReadHeader( |
| 310 | SpanReader *span_reader); |
| 311 | std::optional<SizePrefixedFlatbufferVector<LogFileHeader>> ReadHeader( |
| 312 | std::string_view filename); |
| 313 | // Reads the Nth message from a log file, excluding the header. Note: this |
| 314 | // doesn't handle duplicate headers. |
| 315 | std::optional<SizePrefixedFlatbufferVector<MessageHeader>> ReadNthMessage( |
| 316 | std::string_view filename, size_t n); |
| 317 | |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 318 | class UnpackedMessageHeader; |
| 319 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 320 | // Class which handles reading the header and messages from the log file. This |
| 321 | // handles any per-file state left before merging below. |
| 322 | class MessageReader { |
| 323 | public: |
| 324 | MessageReader(std::string_view filename); |
| 325 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 326 | std::string_view filename() const { return span_reader_.filename(); } |
| 327 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 328 | // Returns the header from the log file. |
| 329 | const LogFileHeader *log_file_header() const { |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 330 | return &raw_log_file_header_.message(); |
| 331 | } |
| 332 | |
| 333 | // Returns the raw data of the header from the log file. |
Austin Schuh | add6eb3 | 2020-11-09 21:24:26 -0800 | [diff] [blame] | 334 | const SizePrefixedFlatbufferVector<LogFileHeader> &raw_log_file_header() |
| 335 | const { |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 336 | return raw_log_file_header_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | // Returns the minimum maount of data needed to queue up for sorting before |
| 340 | // ware guarenteed to not see data out of order. |
| 341 | std::chrono::nanoseconds max_out_of_order_duration() const { |
| 342 | return max_out_of_order_duration_; |
| 343 | } |
| 344 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 345 | // Returns the newest timestamp read out of the log file. |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 346 | monotonic_clock::time_point newest_timestamp() const { |
| 347 | return newest_timestamp_; |
| 348 | } |
| 349 | |
| 350 | // Returns the next message if there is one. |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 351 | std::shared_ptr<UnpackedMessageHeader> ReadMessage(); |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 352 | |
| 353 | // The time at which we need to read another chunk from the logfile. |
| 354 | monotonic_clock::time_point queue_data_time() const { |
| 355 | return newest_timestamp() - max_out_of_order_duration(); |
| 356 | } |
| 357 | |
Brian Smartt | ea913d4 | 2021-12-10 15:02:38 -0800 | [diff] [blame] | 358 | // Flag value setters for testing |
| 359 | void set_crash_on_corrupt_message_flag(bool b) { |
| 360 | crash_on_corrupt_message_flag_ = b; |
| 361 | } |
| 362 | void set_ignore_corrupt_messages_flag(bool b) { |
| 363 | ignore_corrupt_messages_flag_ = b; |
| 364 | } |
| 365 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 366 | private: |
| 367 | // Log chunk reader. |
| 368 | SpanReader span_reader_; |
| 369 | |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 370 | // Vector holding the raw data for the log file header. |
Austin Schuh | add6eb3 | 2020-11-09 21:24:26 -0800 | [diff] [blame] | 371 | SizePrefixedFlatbufferVector<LogFileHeader> raw_log_file_header_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 372 | |
| 373 | // Minimum amount of data to queue up for sorting before we are guarenteed |
| 374 | // to not see data out of order. |
| 375 | std::chrono::nanoseconds max_out_of_order_duration_; |
| 376 | |
| 377 | // Timestamp of the newest message in a channel queue. |
| 378 | monotonic_clock::time_point newest_timestamp_ = monotonic_clock::min_time; |
Brian Smartt | ea913d4 | 2021-12-10 15:02:38 -0800 | [diff] [blame] | 379 | |
| 380 | // Total volume of verifiable messages from the beginning of the file. |
| 381 | // TODO - are message counts also useful? |
| 382 | size_t total_verified_before_ = 0; |
| 383 | |
| 384 | // Total volume of messages with corrupted flatbuffer formatting, if any. |
| 385 | // Excludes corrupted message content. |
| 386 | // TODO - if the layout included something as simple as a CRC (relatively |
| 387 | // fast and robust enough) for each span, then corrupted content could be |
| 388 | // included in this check. |
| 389 | size_t total_corrupted_ = 0; |
| 390 | |
| 391 | // Total volume of verifiable messages intermixed with corrupted messages, |
| 392 | // if any. Will be == 0 if total_corrupted_ == 0. |
| 393 | size_t total_verified_during_ = 0; |
| 394 | |
| 395 | // Total volume of verifiable messages found after the last corrupted one, |
| 396 | // if any. Will be == 0 if total_corrupted_ == 0. |
| 397 | size_t total_verified_after_ = 0; |
| 398 | |
| 399 | bool is_corrupted() const { return total_corrupted_ > 0; } |
| 400 | |
| 401 | bool crash_on_corrupt_message_flag_ = true; |
| 402 | bool ignore_corrupt_messages_flag_ = false; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 403 | }; |
| 404 | |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 405 | // A class to seamlessly read messages from a list of part files. |
| 406 | class PartsMessageReader { |
| 407 | public: |
| 408 | PartsMessageReader(LogParts log_parts); |
| 409 | |
| 410 | std::string_view filename() const { return message_reader_.filename(); } |
| 411 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 412 | // Returns the LogParts that holds the filenames we are reading. |
| 413 | const LogParts &parts() const { return parts_; } |
| 414 | |
Austin Schuh | 4b5c22a | 2020-11-30 22:58:43 -0800 | [diff] [blame] | 415 | const LogFileHeader *log_file_header() const { |
| 416 | return message_reader_.log_file_header(); |
| 417 | } |
| 418 | |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 419 | // Returns the minimum amount of data needed to queue up for sorting before |
| 420 | // we are guarenteed to not see data out of order. |
| 421 | std::chrono::nanoseconds max_out_of_order_duration() const { |
| 422 | return message_reader_.max_out_of_order_duration(); |
| 423 | } |
| 424 | |
| 425 | // Returns the newest timestamp read out of the log file. |
| 426 | monotonic_clock::time_point newest_timestamp() const { |
| 427 | return newest_timestamp_; |
| 428 | } |
| 429 | |
| 430 | // Returns the next message if there is one, or nullopt if we have reached the |
| 431 | // end of all the files. |
| 432 | // Note: reading the next message may change the max_out_of_order_duration(). |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 433 | std::shared_ptr<UnpackedMessageHeader> ReadMessage(); |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 434 | |
Austin Schuh | 4850772 | 2021-07-17 17:29:24 -0700 | [diff] [blame] | 435 | // Returns the boot count for the requested node, or std::nullopt if we don't |
| 436 | // know. |
| 437 | std::optional<size_t> boot_count(size_t node_index) const { |
| 438 | CHECK_GE(node_index, 0u); |
| 439 | CHECK_LT(node_index, boot_counts_.size()); |
| 440 | return boot_counts_[node_index]; |
| 441 | } |
| 442 | |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 443 | private: |
| 444 | // Opens the next log and updates message_reader_. Sets done_ if there is |
| 445 | // nothing more to do. |
| 446 | void NextLog(); |
Austin Schuh | 4850772 | 2021-07-17 17:29:24 -0700 | [diff] [blame] | 447 | void ComputeBootCounts(); |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 448 | |
| 449 | const LogParts parts_; |
| 450 | size_t next_part_index_ = 1u; |
| 451 | bool done_ = false; |
| 452 | MessageReader message_reader_; |
Brian Silverman | fee1697 | 2021-09-14 12:06:38 -0700 | [diff] [blame] | 453 | // We instantiate the next one early, to allow implementations to prefetch. |
| 454 | // TODO(Brian): To get optimal performance when downloading, this needs more |
| 455 | // communication with the implementation to prioritize the next part and add |
| 456 | // more parallelism when it helps. Maybe some kind of a queue of parts in |
| 457 | // order, and the implementation gets to pull however many make sense off the |
| 458 | // front? |
| 459 | std::optional<MessageReader> next_message_reader_; |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 460 | |
Austin Schuh | 315b96b | 2020-12-11 21:21:12 -0800 | [diff] [blame] | 461 | // True after we have seen a message after the start of the log. The |
| 462 | // guarentees on logging essentially are that all data from before the |
| 463 | // starting time of the log may be arbitrarily out of order, but once we get |
| 464 | // max_out_of_order_duration past the start, everything will remain within |
| 465 | // max_out_of_order_duration. We shouldn't see anything before the start |
| 466 | // after we've seen a message that is at least max_out_of_order_duration after |
| 467 | // the start. |
| 468 | bool after_start_ = false; |
| 469 | |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 470 | monotonic_clock::time_point newest_timestamp_ = monotonic_clock::min_time; |
Austin Schuh | 4850772 | 2021-07-17 17:29:24 -0700 | [diff] [blame] | 471 | |
| 472 | // Per node boot counts. |
| 473 | std::vector<std::optional<size_t>> boot_counts_; |
Austin Schuh | c41603c | 2020-10-11 16:17:37 -0700 | [diff] [blame] | 474 | }; |
| 475 | |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 476 | // Stores MessageHeader as a flat header and inline, aligned block of data. |
| 477 | class UnpackedMessageHeader { |
| 478 | public: |
James Kuszmaul | 9776b39 | 2023-01-14 14:08:08 -0800 | [diff] [blame] | 479 | UnpackedMessageHeader( |
| 480 | uint32_t channel_index, monotonic_clock::time_point monotonic_sent_time, |
| 481 | realtime_clock::time_point realtime_sent_time, uint32_t queue_index, |
| 482 | std::optional<monotonic_clock::time_point> monotonic_remote_time, |
| 483 | std::optional<realtime_clock::time_point> realtime_remote_time, |
| 484 | std::optional<uint32_t> remote_queue_index, |
| 485 | monotonic_clock::time_point monotonic_timestamp_time, |
| 486 | bool has_monotonic_timestamp_time, absl::Span<const uint8_t> span) |
| 487 | : channel_index(channel_index), |
| 488 | monotonic_sent_time(monotonic_sent_time), |
| 489 | realtime_sent_time(realtime_sent_time), |
| 490 | queue_index(queue_index), |
| 491 | monotonic_remote_time(monotonic_remote_time), |
| 492 | realtime_remote_time(realtime_remote_time), |
| 493 | remote_queue_index(remote_queue_index), |
| 494 | monotonic_timestamp_time(monotonic_timestamp_time), |
| 495 | has_monotonic_timestamp_time(has_monotonic_timestamp_time), |
| 496 | span(span) {} |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 497 | UnpackedMessageHeader(const UnpackedMessageHeader &) = delete; |
| 498 | UnpackedMessageHeader &operator=(const UnpackedMessageHeader &) = delete; |
| 499 | |
| 500 | // The channel. |
| 501 | uint32_t channel_index = 0xffffffff; |
| 502 | |
| 503 | monotonic_clock::time_point monotonic_sent_time; |
| 504 | realtime_clock::time_point realtime_sent_time; |
| 505 | |
| 506 | // The local queue index. |
| 507 | uint32_t queue_index = 0xffffffff; |
| 508 | |
Austin Schuh | 826e6ce | 2021-11-18 20:33:10 -0800 | [diff] [blame] | 509 | std::optional<aos::monotonic_clock::time_point> monotonic_remote_time; |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 510 | |
| 511 | std::optional<realtime_clock::time_point> realtime_remote_time; |
| 512 | std::optional<uint32_t> remote_queue_index; |
| 513 | |
| 514 | // This field is defaulted in the flatbuffer, so we need to store both the |
| 515 | // possibly defaulted value and whether it is defaulted. |
| 516 | monotonic_clock::time_point monotonic_timestamp_time; |
| 517 | bool has_monotonic_timestamp_time; |
| 518 | |
| 519 | static std::shared_ptr<UnpackedMessageHeader> MakeMessage( |
| 520 | const MessageHeader &message); |
| 521 | |
| 522 | // Note: we are storing a span here because we need something to put in the |
| 523 | // SharedSpan pointer that RawSender takes. We are using the aliasing |
| 524 | // constructor of shared_ptr to avoid the allocation, and it needs a nice |
| 525 | // pointer to track. |
| 526 | absl::Span<const uint8_t> span; |
| 527 | |
| 528 | char actual_data[]; |
| 529 | |
| 530 | private: |
| 531 | ~UnpackedMessageHeader() {} |
| 532 | |
| 533 | static void DestroyAndFree(UnpackedMessageHeader *p) { |
| 534 | p->~UnpackedMessageHeader(); |
| 535 | free(p); |
| 536 | } |
| 537 | }; |
| 538 | |
| 539 | std::ostream &operator<<(std::ostream &os, |
| 540 | const UnpackedMessageHeader &message); |
| 541 | |
Austin Schuh | 1be0ce4 | 2020-11-29 22:43:26 -0800 | [diff] [blame] | 542 | // Struct to hold a message as it gets sorted on a single node. |
| 543 | struct Message { |
| 544 | // The channel. |
| 545 | uint32_t channel_index = 0xffffffff; |
| 546 | // The local queue index. |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 547 | // TODO(austin): Technically the boot inside queue_index is redundant with |
| 548 | // timestamp. In practice, it is less error-prone to duplicate it. Maybe a |
| 549 | // function to return the combined struct? |
| 550 | BootQueueIndex queue_index; |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 551 | // The local timestamp. |
| 552 | BootTimestamp timestamp; |
Austin Schuh | f16ef6a | 2021-06-30 21:48:17 -0700 | [diff] [blame] | 553 | |
Austin Schuh | 4850772 | 2021-07-17 17:29:24 -0700 | [diff] [blame] | 554 | // Remote boot when this is a timestamp. |
| 555 | size_t monotonic_remote_boot = 0xffffff; |
| 556 | |
| 557 | size_t monotonic_timestamp_boot = 0xffffff; |
| 558 | |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 559 | std::shared_ptr<UnpackedMessageHeader> data; |
Austin Schuh | 1be0ce4 | 2020-11-29 22:43:26 -0800 | [diff] [blame] | 560 | |
| 561 | bool operator<(const Message &m2) const; |
| 562 | bool operator>=(const Message &m2) const; |
Austin Schuh | 8f52ed5 | 2020-11-30 23:12:39 -0800 | [diff] [blame] | 563 | bool operator==(const Message &m2) const; |
Austin Schuh | 1be0ce4 | 2020-11-29 22:43:26 -0800 | [diff] [blame] | 564 | }; |
| 565 | |
| 566 | std::ostream &operator<<(std::ostream &os, const Message &m); |
| 567 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 568 | // Structure to hold a full message and all the timestamps, which may or may not |
| 569 | // have been sent from a remote node. The remote_queue_index will be invalid if |
| 570 | // this message is from the point of view of the node which sent it. |
| 571 | struct TimestampedMessage { |
| 572 | uint32_t channel_index = 0xffffffff; |
| 573 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 574 | BootQueueIndex queue_index; |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 575 | BootTimestamp monotonic_event_time; |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 576 | realtime_clock::time_point realtime_event_time = realtime_clock::min_time; |
| 577 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 578 | BootQueueIndex remote_queue_index; |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 579 | BootTimestamp monotonic_remote_time; |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 580 | realtime_clock::time_point realtime_remote_time = realtime_clock::min_time; |
| 581 | |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 582 | BootTimestamp monotonic_timestamp_time; |
Austin Schuh | 8bf1e63 | 2021-01-02 22:41:04 -0800 | [diff] [blame] | 583 | |
Tyler Chatow | b7c6eba | 2021-07-28 14:43:23 -0700 | [diff] [blame] | 584 | std::shared_ptr<UnpackedMessageHeader> data; |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 585 | }; |
| 586 | |
| 587 | std::ostream &operator<<(std::ostream &os, const TimestampedMessage &m); |
| 588 | |
Austin Schuh | 4b5c22a | 2020-11-30 22:58:43 -0800 | [diff] [blame] | 589 | // Class to sort the resulting messages from a PartsMessageReader. |
| 590 | class LogPartsSorter { |
| 591 | public: |
| 592 | LogPartsSorter(LogParts log_parts); |
| 593 | |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 594 | // Returns the parts that this is sorting messages from. |
| 595 | const LogParts &parts() const { return parts_message_reader_.parts(); } |
Austin Schuh | 4b5c22a | 2020-11-30 22:58:43 -0800 | [diff] [blame] | 596 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 597 | monotonic_clock::time_point monotonic_start_time() const { |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 598 | return parts().monotonic_start_time; |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 599 | } |
| 600 | realtime_clock::time_point realtime_start_time() const { |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 601 | return parts().realtime_start_time; |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 602 | } |
| 603 | |
Austin Schuh | 4b5c22a | 2020-11-30 22:58:43 -0800 | [diff] [blame] | 604 | // The time this data is sorted until. |
| 605 | monotonic_clock::time_point sorted_until() const { return sorted_until_; } |
| 606 | |
| 607 | // Returns the next sorted message from the log file. It is safe to call |
| 608 | // std::move() on the result to move the data flatbuffer from it. |
| 609 | Message *Front(); |
| 610 | // Pops the front message. This should only be called after a call to |
| 611 | // Front(). |
| 612 | void PopFront(); |
| 613 | |
| 614 | // Returns a debug string representing the contents of this sorter. |
| 615 | std::string DebugString() const; |
| 616 | |
| 617 | private: |
| 618 | // Log parts reader we are wrapping. |
| 619 | PartsMessageReader parts_message_reader_; |
| 620 | // Cache of the time we are sorted until. |
| 621 | aos::monotonic_clock::time_point sorted_until_ = monotonic_clock::min_time; |
| 622 | |
Austin Schuh | b000de6 | 2020-12-03 22:00:40 -0800 | [diff] [blame] | 623 | // Timestamp of the last message returned. Used to make sure nothing goes |
| 624 | // backwards. |
| 625 | monotonic_clock::time_point last_message_time_ = monotonic_clock::min_time; |
| 626 | |
Austin Schuh | 4b5c22a | 2020-11-30 22:58:43 -0800 | [diff] [blame] | 627 | // Set used for efficient sorting of messages. We can benchmark and evaluate |
| 628 | // other data structures if this proves to be the bottleneck. |
| 629 | absl::btree_set<Message> messages_; |
Austin Schuh | 4850772 | 2021-07-17 17:29:24 -0700 | [diff] [blame] | 630 | |
| 631 | // Mapping from channel to source node. |
| 632 | // TODO(austin): Should we put this in Boots so it can be cached for everyone? |
| 633 | std::vector<size_t> source_node_index_; |
Austin Schuh | 4b5c22a | 2020-11-30 22:58:43 -0800 | [diff] [blame] | 634 | }; |
| 635 | |
Austin Schuh | 8f52ed5 | 2020-11-30 23:12:39 -0800 | [diff] [blame] | 636 | // Class to run merge sort on the messages from multiple LogPartsSorter |
| 637 | // instances. |
| 638 | class NodeMerger { |
| 639 | public: |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 640 | NodeMerger(std::vector<LogParts> parts); |
| 641 | |
Austin Schuh | f16ef6a | 2021-06-30 21:48:17 -0700 | [diff] [blame] | 642 | // Copying and moving will mess up the internal raw pointers. Just don't do |
| 643 | // it. |
| 644 | NodeMerger(NodeMerger const &) = delete; |
| 645 | NodeMerger(NodeMerger &&) = delete; |
| 646 | void operator=(NodeMerger const &) = delete; |
| 647 | void operator=(NodeMerger &&) = delete; |
| 648 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 649 | // Node index in the configuration of this node. |
| 650 | int node() const { return node_; } |
Austin Schuh | 8f52ed5 | 2020-11-30 23:12:39 -0800 | [diff] [blame] | 651 | |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 652 | // List of parts being sorted together. |
| 653 | std::vector<const LogParts *> Parts() const; |
| 654 | |
| 655 | const Configuration *configuration() const { |
| 656 | return parts_sorters_[0].parts().config.get(); |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | monotonic_clock::time_point monotonic_start_time() const { |
| 660 | return monotonic_start_time_; |
| 661 | } |
| 662 | realtime_clock::time_point realtime_start_time() const { |
| 663 | return realtime_start_time_; |
Austin Schuh | 8f52ed5 | 2020-11-30 23:12:39 -0800 | [diff] [blame] | 664 | } |
Austin Schuh | 5dd2284 | 2021-11-17 16:09:39 -0800 | [diff] [blame] | 665 | monotonic_clock::time_point monotonic_oldest_time() const { |
| 666 | return monotonic_oldest_time_; |
| 667 | } |
Austin Schuh | 8f52ed5 | 2020-11-30 23:12:39 -0800 | [diff] [blame] | 668 | |
| 669 | // The time this data is sorted until. |
| 670 | monotonic_clock::time_point sorted_until() const { return sorted_until_; } |
| 671 | |
| 672 | // Returns the next sorted message from the set of log files. It is safe to |
| 673 | // call std::move() on the result to move the data flatbuffer from it. |
| 674 | Message *Front(); |
| 675 | // Pops the front message. This should only be called after a call to |
| 676 | // Front(). |
| 677 | void PopFront(); |
| 678 | |
| 679 | private: |
| 680 | // Unsorted list of all parts sorters. |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 681 | std::vector<LogPartsSorter> parts_sorters_; |
Austin Schuh | 8f52ed5 | 2020-11-30 23:12:39 -0800 | [diff] [blame] | 682 | // Pointer to the parts sorter holding the current Front message if one |
| 683 | // exists, or nullptr if a new one needs to be found. |
| 684 | LogPartsSorter *current_ = nullptr; |
| 685 | // Cached sorted_until value. |
| 686 | aos::monotonic_clock::time_point sorted_until_ = monotonic_clock::min_time; |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 687 | |
| 688 | // Cached node. |
| 689 | int node_; |
| 690 | |
Austin Schuh | b000de6 | 2020-12-03 22:00:40 -0800 | [diff] [blame] | 691 | // Timestamp of the last message returned. Used to make sure nothing goes |
| 692 | // backwards. |
| 693 | monotonic_clock::time_point last_message_time_ = monotonic_clock::min_time; |
| 694 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 695 | realtime_clock::time_point realtime_start_time_ = realtime_clock::max_time; |
| 696 | monotonic_clock::time_point monotonic_start_time_ = monotonic_clock::max_time; |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 697 | monotonic_clock::time_point monotonic_oldest_time_ = |
| 698 | monotonic_clock::max_time; |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 699 | }; |
| 700 | |
Austin Schuh | f16ef6a | 2021-06-30 21:48:17 -0700 | [diff] [blame] | 701 | // Class to concatenate multiple boots worth of logs into a single per-node |
| 702 | // stream. |
| 703 | class BootMerger { |
| 704 | public: |
| 705 | BootMerger(std::vector<LogParts> file); |
| 706 | |
| 707 | // Copying and moving will mess up the internal raw pointers. Just don't do |
| 708 | // it. |
| 709 | BootMerger(BootMerger const &) = delete; |
| 710 | BootMerger(BootMerger &&) = delete; |
| 711 | void operator=(BootMerger const &) = delete; |
| 712 | void operator=(BootMerger &&) = delete; |
| 713 | |
| 714 | // Node index in the configuration of this node. |
| 715 | int node() const { return node_mergers_[0]->node(); } |
| 716 | |
| 717 | // List of parts being sorted together. |
| 718 | std::vector<const LogParts *> Parts() const; |
| 719 | |
| 720 | const Configuration *configuration() const { |
| 721 | return node_mergers_[0]->configuration(); |
| 722 | } |
| 723 | |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 724 | monotonic_clock::time_point monotonic_start_time(size_t boot) const { |
| 725 | CHECK_LT(boot, node_mergers_.size()); |
| 726 | return node_mergers_[boot]->monotonic_start_time(); |
Austin Schuh | f16ef6a | 2021-06-30 21:48:17 -0700 | [diff] [blame] | 727 | } |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 728 | realtime_clock::time_point realtime_start_time(size_t boot) const { |
| 729 | CHECK_LT(boot, node_mergers_.size()); |
| 730 | return node_mergers_[boot]->realtime_start_time(); |
Austin Schuh | f16ef6a | 2021-06-30 21:48:17 -0700 | [diff] [blame] | 731 | } |
Austin Schuh | 5dd2284 | 2021-11-17 16:09:39 -0800 | [diff] [blame] | 732 | monotonic_clock::time_point monotonic_oldest_time(size_t boot) const { |
| 733 | CHECK_LT(boot, node_mergers_.size()); |
| 734 | return node_mergers_[boot]->monotonic_oldest_time(); |
| 735 | } |
Austin Schuh | f16ef6a | 2021-06-30 21:48:17 -0700 | [diff] [blame] | 736 | |
| 737 | bool started() const { |
| 738 | return node_mergers_[index_]->sorted_until() != monotonic_clock::min_time || |
| 739 | index_ != 0; |
| 740 | } |
| 741 | |
| 742 | // Returns the next sorted message from the set of log files. It is safe to |
| 743 | // call std::move() on the result to move the data flatbuffer from it. |
| 744 | Message *Front(); |
| 745 | // Pops the front message. This should only be called after a call to |
| 746 | // Front(). |
| 747 | void PopFront(); |
| 748 | |
| 749 | private: |
| 750 | int index_ = 0; |
| 751 | |
| 752 | // TODO(austin): Sanjay points out this is pretty inefficient. Don't keep so |
| 753 | // many things open. |
| 754 | std::vector<std::unique_ptr<NodeMerger>> node_mergers_; |
| 755 | }; |
| 756 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 757 | // Class to match timestamps with the corresponding data from other nodes. |
Austin Schuh | 79b3094 | 2021-01-24 22:32:21 -0800 | [diff] [blame] | 758 | // |
| 759 | // This class also buffers data for the node it represents, and supports |
| 760 | // notifying when new data is queued as well as queueing until a point in time. |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 761 | class TimestampMapper { |
| 762 | public: |
| 763 | TimestampMapper(std::vector<LogParts> file); |
| 764 | |
| 765 | // Copying and moving will mess up the internal raw pointers. Just don't do |
| 766 | // it. |
| 767 | TimestampMapper(TimestampMapper const &) = delete; |
| 768 | TimestampMapper(TimestampMapper &&) = delete; |
| 769 | void operator=(TimestampMapper const &) = delete; |
| 770 | void operator=(TimestampMapper &&) = delete; |
| 771 | |
| 772 | // TODO(austin): It would be super helpful to provide a way to queue up to |
| 773 | // time X without matching timestamps, and to then be able to pull the |
| 774 | // timestamps out of this queue. This lets us bootstrap time estimation |
| 775 | // without exploding memory usage worst case. |
| 776 | |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 777 | const Configuration *configuration() const { return configuration_.get(); } |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 778 | |
| 779 | // Returns which node this is sorting for. |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 780 | size_t node() const { return boot_merger_.node(); } |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 781 | |
| 782 | // The start time of this log. |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 783 | monotonic_clock::time_point monotonic_start_time(size_t boot) const { |
| 784 | return boot_merger_.monotonic_start_time(boot); |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 785 | } |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 786 | realtime_clock::time_point realtime_start_time(size_t boot) const { |
| 787 | return boot_merger_.realtime_start_time(boot); |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 788 | } |
Austin Schuh | 5dd2284 | 2021-11-17 16:09:39 -0800 | [diff] [blame] | 789 | // Returns the oldest timestamp on a message on this boot. |
| 790 | monotonic_clock::time_point monotonic_oldest_time(size_t boot) const { |
| 791 | return boot_merger_.monotonic_oldest_time(boot); |
| 792 | } |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 793 | |
| 794 | // Uses timestamp_mapper as the peer for its node. Only one mapper may be set |
| 795 | // for each node. Peers are used to look up the data for timestamps on this |
| 796 | // node. |
| 797 | void AddPeer(TimestampMapper *timestamp_mapper); |
| 798 | |
Austin Schuh | 24bf497 | 2021-06-29 22:09:08 -0700 | [diff] [blame] | 799 | // Returns true if anything has been queued up. |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 800 | bool started() const { return boot_merger_.started(); } |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 801 | |
| 802 | // Returns the next message for this node. |
| 803 | TimestampedMessage *Front(); |
| 804 | // Pops the next message. Front must be called first. |
| 805 | void PopFront(); |
| 806 | |
| 807 | // Returns debug information about this node. |
| 808 | std::string DebugString() const; |
| 809 | |
Austin Schuh | 79b3094 | 2021-01-24 22:32:21 -0800 | [diff] [blame] | 810 | // Queues data the provided time. |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 811 | void QueueUntil(BootTimestamp queue_time); |
Austin Schuh | e639ea1 | 2021-01-25 13:00:22 -0800 | [diff] [blame] | 812 | // Queues until we have time_estimation_buffer of data in the queue. |
| 813 | void QueueFor(std::chrono::nanoseconds time_estimation_buffer); |
Austin Schuh | 79b3094 | 2021-01-24 22:32:21 -0800 | [diff] [blame] | 814 | |
Austin Schuh | 0660122 | 2021-01-26 17:02:50 -0800 | [diff] [blame] | 815 | // Queues until the condition is met. |
| 816 | template <typename T> |
| 817 | void QueueUntilCondition(T fn) { |
| 818 | while (true) { |
| 819 | if (fn()) { |
| 820 | break; |
| 821 | } |
| 822 | if (!QueueMatched()) { |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
Eric Schmiedeberg | b38477e | 2022-12-02 16:08:04 -0700 | [diff] [blame] | 828 | // Sets the callback that can be used to skip messages. |
| 829 | void set_replay_channels_callback( |
| 830 | std::function<bool(const TimestampedMessage &)> fn) { |
| 831 | replay_channels_callback_ = fn; |
| 832 | } |
| 833 | |
Austin Schuh | 79b3094 | 2021-01-24 22:32:21 -0800 | [diff] [blame] | 834 | // Sets a callback to be called whenever a full message is queued. |
| 835 | void set_timestamp_callback(std::function<void(TimestampedMessage *)> fn) { |
| 836 | timestamp_callback_ = fn; |
| 837 | } |
| 838 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 839 | private: |
Eric Schmiedeberg | b38477e | 2022-12-02 16:08:04 -0700 | [diff] [blame] | 840 | // Result of MaybeQueueMatched |
| 841 | enum class MatchResult : uint8_t { |
| 842 | kEndOfFile, // End of the log file being read |
| 843 | kQueued, // Message was queued |
| 844 | kSkipped // Message was skipped over |
| 845 | }; |
| 846 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 847 | // The state for a remote node. This holds the data that needs to be matched |
| 848 | // with the remote node's timestamps. |
| 849 | struct NodeData { |
| 850 | // True if we should save data here. This should be true if any of the |
| 851 | // bools in delivered below are true. |
| 852 | bool any_delivered = false; |
| 853 | |
Austin Schuh | 36c0093 | 2021-07-19 18:13:21 -0700 | [diff] [blame] | 854 | // True if we have a peer and therefore should be saving data for it. |
| 855 | bool save_for_peer = false; |
| 856 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 857 | // Peer pointer. This node is only to be considered if a peer is set. |
| 858 | TimestampMapper *peer = nullptr; |
| 859 | |
| 860 | struct ChannelData { |
| 861 | // Deque per channel. This contains the data from the outside |
| 862 | // TimestampMapper node which is relevant for the node this NodeData |
| 863 | // points to. |
| 864 | std::deque<Message> messages; |
| 865 | // Bool tracking per channel if a message is delivered to the node this |
| 866 | // NodeData represents. |
| 867 | bool delivered = false; |
Austin Schuh | 6a7358f | 2021-11-18 22:40:40 -0800 | [diff] [blame] | 868 | // The TTL for delivery. |
| 869 | std::chrono::nanoseconds time_to_live = std::chrono::nanoseconds(0); |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 870 | }; |
| 871 | |
| 872 | // Vector with per channel data. |
| 873 | std::vector<ChannelData> channels; |
| 874 | }; |
| 875 | |
| 876 | // Returns (and forgets about) the data for the provided timestamp message |
| 877 | // showing when it was delivered to this node. |
| 878 | Message MatchingMessageFor(const Message &message); |
| 879 | |
| 880 | // Queues up a single message into our message queue, and any nodes that this |
| 881 | // message is delivered to. Returns true if one was available, false |
| 882 | // otherwise. |
| 883 | bool Queue(); |
| 884 | |
Austin Schuh | 79b3094 | 2021-01-24 22:32:21 -0800 | [diff] [blame] | 885 | // Queues up a single matched message into our matched message queue. Returns |
| 886 | // true if one was queued, and false otherwise. |
| 887 | bool QueueMatched(); |
| 888 | |
Eric Schmiedeberg | b38477e | 2022-12-02 16:08:04 -0700 | [diff] [blame] | 889 | // Queues a message if the replay_channels_callback is passed and the end of |
| 890 | // the log file has not been reached. |
| 891 | MatchResult MaybeQueueMatched(); |
| 892 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 893 | // Queues up data until we have at least one message >= to time t. |
| 894 | // Useful for triggering a remote node to read enough data to have the |
| 895 | // timestamp you care about available. |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 896 | void QueueUnmatchedUntil(BootTimestamp t); |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 897 | |
Austin Schuh | 79b3094 | 2021-01-24 22:32:21 -0800 | [diff] [blame] | 898 | // Queues m into matched_messages_. |
| 899 | void QueueMessage(Message *m); |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 900 | |
Eric Schmiedeberg | b38477e | 2022-12-02 16:08:04 -0700 | [diff] [blame] | 901 | // If a replay_channels_callback was set and the callback returns false, a |
| 902 | // matched message is popped and true is returned. Otherwise false is |
| 903 | // returned. |
| 904 | bool CheckReplayChannelsAndMaybePop(const TimestampedMessage &message); |
| 905 | |
Austin Schuh | 58646e2 | 2021-08-23 23:51:46 -0700 | [diff] [blame] | 906 | // Returns the name of the node this class is sorting for. |
| 907 | std::string_view node_name() const { |
| 908 | return configuration_->has_nodes() ? configuration_->nodes() |
| 909 | ->Get(boot_merger_.node()) |
| 910 | ->name() |
| 911 | ->string_view() |
| 912 | : "(single node)"; |
| 913 | } |
| 914 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 915 | // The node merger to source messages from. |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 916 | BootMerger boot_merger_; |
Austin Schuh | 0ca51f3 | 2020-12-25 21:51:45 -0800 | [diff] [blame] | 917 | |
| 918 | std::shared_ptr<const Configuration> configuration_; |
| 919 | |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 920 | // The buffer of messages for this node. These are not matched with any |
| 921 | // remote data. |
| 922 | std::deque<Message> messages_; |
| 923 | // The node index for the source node for each channel. |
| 924 | std::vector<size_t> source_node_; |
| 925 | |
| 926 | // Vector per node. Not all nodes will have anything. |
| 927 | std::vector<NodeData> nodes_data_; |
| 928 | |
| 929 | // Latest message to return. |
Austin Schuh | 79b3094 | 2021-01-24 22:32:21 -0800 | [diff] [blame] | 930 | std::deque<TimestampedMessage> matched_messages_; |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 931 | |
Austin Schuh | 79b3094 | 2021-01-24 22:32:21 -0800 | [diff] [blame] | 932 | // Tracks the state of the first message in matched_messages_. Do we need to |
| 933 | // update it, is it valid, or should we return nullptr? |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 934 | enum class FirstMessage { |
| 935 | kNeedsUpdate, |
| 936 | kInMessage, |
| 937 | kNullptr, |
| 938 | }; |
| 939 | FirstMessage first_message_ = FirstMessage::kNeedsUpdate; |
| 940 | |
| 941 | // Timestamp of the last message returned. Used to make sure nothing goes |
| 942 | // backwards. |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 943 | BootTimestamp last_message_time_ = BootTimestamp::min_time(); |
Austin Schuh | 6a7358f | 2021-11-18 22:40:40 -0800 | [diff] [blame] | 944 | BootTimestamp last_popped_message_time_ = BootTimestamp::min_time(); |
Austin Schuh | d2f9610 | 2020-12-01 20:27:29 -0800 | [diff] [blame] | 945 | // Time this node is queued up until. Used for caching. |
Austin Schuh | 2dc8c7d | 2021-07-01 17:41:28 -0700 | [diff] [blame] | 946 | BootTimestamp queued_until_ = BootTimestamp::min_time(); |
Austin Schuh | 79b3094 | 2021-01-24 22:32:21 -0800 | [diff] [blame] | 947 | |
| 948 | std::function<void(TimestampedMessage *)> timestamp_callback_; |
Eric Schmiedeberg | b38477e | 2022-12-02 16:08:04 -0700 | [diff] [blame] | 949 | std::function<bool(TimestampedMessage &)> replay_channels_callback_; |
Austin Schuh | 8f52ed5 | 2020-11-30 23:12:39 -0800 | [diff] [blame] | 950 | }; |
| 951 | |
Austin Schuh | ee71105 | 2020-08-24 16:06:09 -0700 | [diff] [blame] | 952 | // Returns the node name with a trailing space, or an empty string if we are on |
| 953 | // a single node. |
| 954 | std::string MaybeNodeName(const Node *); |
| 955 | |
Austin Schuh | 71a40d4 | 2023-02-04 21:22:22 -0800 | [diff] [blame] | 956 | // Class to copy a RemoteMessage into the provided buffer. |
| 957 | class RemoteMessageCopier : public DataEncoder::Copier { |
| 958 | public: |
| 959 | RemoteMessageCopier(const message_bridge::RemoteMessage *message, |
| 960 | int channel_index, |
| 961 | aos::monotonic_clock::time_point monotonic_timestamp_time, |
| 962 | EventLoop *event_loop) |
| 963 | : DataEncoder::Copier(PackRemoteMessageSize()), |
| 964 | message_(message), |
| 965 | channel_index_(channel_index), |
| 966 | monotonic_timestamp_time_(monotonic_timestamp_time), |
| 967 | event_loop_(event_loop) {} |
| 968 | |
| 969 | monotonic_clock::time_point end_time() const { return end_time_; } |
| 970 | |
| 971 | size_t Copy(uint8_t *data, size_t start_byte, size_t end_byte) final { |
| 972 | size_t result = PackRemoteMessageInline(data, message_, channel_index_, |
| 973 | monotonic_timestamp_time_, |
| 974 | start_byte, end_byte); |
| 975 | end_time_ = event_loop_->monotonic_now(); |
| 976 | return result; |
| 977 | } |
| 978 | |
| 979 | private: |
| 980 | const message_bridge::RemoteMessage *message_; |
| 981 | int channel_index_; |
| 982 | aos::monotonic_clock::time_point monotonic_timestamp_time_; |
| 983 | EventLoop *event_loop_; |
| 984 | monotonic_clock::time_point end_time_; |
| 985 | }; |
| 986 | |
| 987 | // Class to copy a context into the provided buffer. |
| 988 | class ContextDataCopier : public DataEncoder::Copier { |
| 989 | public: |
| 990 | ContextDataCopier(const Context &context, int channel_index, LogType log_type, |
| 991 | EventLoop *event_loop) |
| 992 | : DataEncoder::Copier(PackMessageSize(log_type, context.size)), |
| 993 | context_(context), |
| 994 | channel_index_(channel_index), |
| 995 | log_type_(log_type), |
| 996 | event_loop_(event_loop) {} |
| 997 | |
| 998 | monotonic_clock::time_point end_time() const { return end_time_; } |
| 999 | |
| 1000 | size_t Copy(uint8_t *data, size_t start_byte, size_t end_byte) final { |
| 1001 | size_t result = PackMessageInline(data, context_, channel_index_, log_type_, |
| 1002 | start_byte, end_byte); |
| 1003 | end_time_ = event_loop_->monotonic_now(); |
| 1004 | return result; |
| 1005 | } |
| 1006 | |
| 1007 | private: |
| 1008 | const Context &context_; |
| 1009 | const int channel_index_; |
| 1010 | const LogType log_type_; |
| 1011 | EventLoop *event_loop_; |
| 1012 | monotonic_clock::time_point end_time_; |
| 1013 | }; |
| 1014 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 1015 | } // namespace aos::logger |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 1016 | |
| 1017 | #endif // AOS_EVENTS_LOGGING_LOGFILE_UTILS_H_ |