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 | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 17 | #include "absl/types/span.h" |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 18 | #include "aos/containers/resizeable_buffer.h" |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 19 | #include "aos/events/event_loop.h" |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 20 | #include "aos/events/logging/buffer_encoder.h" |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 21 | #include "aos/events/logging/logger_generated.h" |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 22 | #include "aos/flatbuffers.h" |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 23 | #include "flatbuffers/flatbuffers.h" |
| 24 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 25 | namespace aos::logger { |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 26 | |
| 27 | enum class LogType : uint8_t { |
| 28 | // The message originated on this node and should be logged here. |
| 29 | kLogMessage, |
| 30 | // The message originated on another node, but only the delivery times are |
| 31 | // logged here. |
| 32 | kLogDeliveryTimeOnly, |
| 33 | // The message originated on another node. Log it and the delivery times |
| 34 | // together. The message_gateway is responsible for logging any messages |
| 35 | // which didn't get delivered. |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 36 | kLogMessageAndDeliveryTime, |
| 37 | // The message originated on the other node and should be logged on this node. |
| 38 | kLogRemoteMessage |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 39 | }; |
| 40 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 41 | // This class manages efficiently writing a sequence of detached buffers to a |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 42 | // file. It encodes them, queues them up, and batches the write operation. |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 43 | class DetachedBufferWriter { |
| 44 | public: |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 45 | DetachedBufferWriter(std::string_view filename, |
| 46 | std::unique_ptr<DetachedBufferEncoder> encoder); |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 47 | DetachedBufferWriter(DetachedBufferWriter &&other); |
| 48 | DetachedBufferWriter(const DetachedBufferWriter &) = delete; |
| 49 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 50 | ~DetachedBufferWriter(); |
| 51 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 52 | DetachedBufferWriter &operator=(DetachedBufferWriter &&other); |
Brian Silverman | 98360e2 | 2020-04-28 16:51:20 -0700 | [diff] [blame] | 53 | DetachedBufferWriter &operator=(const DetachedBufferWriter &) = delete; |
| 54 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 55 | std::string_view filename() const { return filename_; } |
| 56 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 57 | // Rewrites a location in a file (relative to the start) to have new data in |
| 58 | // it. The main use case is updating start times after a log file starts. |
| 59 | void RewriteLocation(off64_t offset, absl::Span<const uint8_t> data); |
| 60 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 61 | // Queues up a finished FlatBufferBuilder to be encoded and written. |
| 62 | // |
| 63 | // Triggers a flush if there's enough data queued up. |
| 64 | // |
| 65 | // Steals the detached buffer from it. |
| 66 | void QueueSizedFlatbuffer(flatbuffers::FlatBufferBuilder *fbb) { |
| 67 | QueueSizedFlatbuffer(fbb->Release()); |
| 68 | } |
| 69 | // May steal the backing storage of buffer, or may leave it alone. |
| 70 | void QueueSizedFlatbuffer(flatbuffers::DetachedBuffer &&buffer) { |
| 71 | encoder_->Encode(std::move(buffer)); |
| 72 | FlushAtThreshold(); |
| 73 | } |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 74 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 75 | // Queues up data in span. May copy or may write it to disk immediately. |
| 76 | void QueueSpan(absl::Span<const uint8_t> span); |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 77 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 78 | // Returns the total number of bytes written and currently queued. |
| 79 | size_t total_bytes() const { return encoder_->total_bytes(); } |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 80 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 81 | // The maximum time for a single write call, or 0 if none have been performed. |
| 82 | std::chrono::nanoseconds max_write_time() const { return max_write_time_; } |
| 83 | // The number of bytes in the longest write call, or -1 if none have been |
| 84 | // performed. |
| 85 | int max_write_time_bytes() const { return max_write_time_bytes_; } |
| 86 | // The number of buffers in the longest write call, or -1 if none have been |
| 87 | // performed. |
| 88 | int max_write_time_messages() const { return max_write_time_messages_; } |
| 89 | // The total time spent in write calls. |
| 90 | std::chrono::nanoseconds total_write_time() const { |
| 91 | return total_write_time_; |
| 92 | } |
| 93 | // The total number of writes which have been performed. |
| 94 | int total_write_count() const { return total_write_count_; } |
| 95 | // The total number of messages which have been written. |
| 96 | int total_write_messages() const { return total_write_messages_; } |
| 97 | // The total number of bytes which have been written. |
| 98 | int total_write_bytes() const { return total_write_bytes_; } |
| 99 | void ResetStatistics() { |
| 100 | max_write_time_ = std::chrono::nanoseconds::zero(); |
| 101 | max_write_time_bytes_ = -1; |
| 102 | max_write_time_messages_ = -1; |
| 103 | total_write_time_ = std::chrono::nanoseconds::zero(); |
| 104 | total_write_count_ = 0; |
| 105 | total_write_messages_ = 0; |
| 106 | total_write_bytes_ = 0; |
| 107 | } |
Brian Silverman | 98360e2 | 2020-04-28 16:51:20 -0700 | [diff] [blame] | 108 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 109 | private: |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 110 | // Performs a single writev call with as much of the data we have queued up as |
| 111 | // possible. |
| 112 | // |
| 113 | // This will normally take all of the data we have queued up, unless an |
| 114 | // encoder has spit out a big enough chunk all at once that we can't manage |
| 115 | // all of it. |
| 116 | void Flush(); |
| 117 | |
| 118 | void UpdateStatsForWrite(aos::monotonic_clock::duration duration, |
| 119 | ssize_t written, int iovec_size); |
| 120 | |
| 121 | // Flushes data if we've reached the threshold to do that as part of normal |
| 122 | // operation. |
| 123 | void FlushAtThreshold(); |
| 124 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 125 | std::string filename_; |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 126 | std::unique_ptr<DetachedBufferEncoder> encoder_; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 127 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 128 | int fd_ = -1; |
| 129 | |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 130 | // List of iovecs to use with writev. This is a member variable to avoid |
| 131 | // churn. |
| 132 | std::vector<struct iovec> iovec_; |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 133 | |
| 134 | std::chrono::nanoseconds max_write_time_ = std::chrono::nanoseconds::zero(); |
| 135 | int max_write_time_bytes_ = -1; |
| 136 | int max_write_time_messages_ = -1; |
| 137 | std::chrono::nanoseconds total_write_time_ = std::chrono::nanoseconds::zero(); |
| 138 | int total_write_count_ = 0; |
| 139 | int total_write_messages_ = 0; |
| 140 | int total_write_bytes_ = 0; |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | // Packes a message pointed to by the context into a MessageHeader. |
| 144 | flatbuffers::Offset<MessageHeader> PackMessage( |
| 145 | flatbuffers::FlatBufferBuilder *fbb, const Context &context, |
| 146 | int channel_index, LogType log_type); |
| 147 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 148 | FlatbufferVector<LogFileHeader> ReadHeader(std::string_view filename); |
Austin Schuh | 5212cad | 2020-09-09 23:12:09 -0700 | [diff] [blame] | 149 | FlatbufferVector<MessageHeader> ReadNthMessage(std::string_view filename, |
| 150 | size_t n); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 151 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 152 | // Class to read chunks out of a log file. |
| 153 | class SpanReader { |
| 154 | public: |
| 155 | SpanReader(std::string_view filename); |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 156 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 157 | std::string_view filename() const { return filename_; } |
| 158 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 159 | // Returns a span with the data for a message from the log file, excluding |
| 160 | // the size. |
| 161 | absl::Span<const uint8_t> ReadMessage(); |
| 162 | |
| 163 | // Returns true if there is a full message available in the buffer, or if we |
| 164 | // will have to read more data from disk. |
| 165 | bool MessageAvailable(); |
| 166 | |
| 167 | private: |
| 168 | // TODO(austin): Optimization: |
| 169 | // Allocate the 256k blocks like we do today. But, refcount them with |
| 170 | // shared_ptr pointed to by the messageheader that is returned. This avoids |
| 171 | // the copy. Need to do more benchmarking. |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 172 | // And (Brian): Consider just mmapping the file and handing out refcounted |
| 173 | // pointers into that too. |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 174 | |
| 175 | // Reads a chunk of data into data_. Returns false if no data was read. |
| 176 | bool ReadBlock(); |
| 177 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 178 | const std::string filename_; |
| 179 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 180 | // File reader and data decoder. |
| 181 | std::unique_ptr<DataDecoder> decoder_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 182 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 183 | // Vector to read into. |
| 184 | ResizeableBuffer data_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 185 | |
| 186 | // Amount of data consumed already in data_. |
| 187 | size_t consumed_data_ = 0; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | // Class which handles reading the header and messages from the log file. This |
| 191 | // handles any per-file state left before merging below. |
| 192 | class MessageReader { |
| 193 | public: |
| 194 | MessageReader(std::string_view filename); |
| 195 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 196 | std::string_view filename() const { return span_reader_.filename(); } |
| 197 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 198 | // Returns the header from the log file. |
| 199 | const LogFileHeader *log_file_header() const { |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 200 | return &raw_log_file_header_.message(); |
| 201 | } |
| 202 | |
| 203 | // Returns the raw data of the header from the log file. |
| 204 | const FlatbufferVector<LogFileHeader> &raw_log_file_header() const { |
| 205 | return raw_log_file_header_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | // Returns the minimum maount of data needed to queue up for sorting before |
| 209 | // ware guarenteed to not see data out of order. |
| 210 | std::chrono::nanoseconds max_out_of_order_duration() const { |
| 211 | return max_out_of_order_duration_; |
| 212 | } |
| 213 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 214 | // Returns the newest timestamp read out of the log file. |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 215 | monotonic_clock::time_point newest_timestamp() const { |
| 216 | return newest_timestamp_; |
| 217 | } |
| 218 | |
| 219 | // Returns the next message if there is one. |
| 220 | std::optional<FlatbufferVector<MessageHeader>> ReadMessage(); |
| 221 | |
| 222 | // The time at which we need to read another chunk from the logfile. |
| 223 | monotonic_clock::time_point queue_data_time() const { |
| 224 | return newest_timestamp() - max_out_of_order_duration(); |
| 225 | } |
| 226 | |
| 227 | private: |
| 228 | // Log chunk reader. |
| 229 | SpanReader span_reader_; |
| 230 | |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 231 | // Vector holding the raw data for the log file header. |
| 232 | FlatbufferVector<LogFileHeader> raw_log_file_header_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 233 | |
| 234 | // Minimum amount of data to queue up for sorting before we are guarenteed |
| 235 | // to not see data out of order. |
| 236 | std::chrono::nanoseconds max_out_of_order_duration_; |
| 237 | |
| 238 | // Timestamp of the newest message in a channel queue. |
| 239 | monotonic_clock::time_point newest_timestamp_ = monotonic_clock::min_time; |
| 240 | }; |
| 241 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 242 | class TimestampMerger; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 243 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 244 | // A design requirement is that the relevant data for a channel is not more than |
| 245 | // max_out_of_order_duration out of order. We approach sorting in layers. |
| 246 | // |
| 247 | // 1) Split each (maybe chunked) log file into one queue per channel. Read this |
| 248 | // log file looking for data pertaining to a specific node. |
| 249 | // (SplitMessageReader) |
| 250 | // 2) Merge all the data per channel from the different log files into a sorted |
| 251 | // list of timestamps and messages. (TimestampMerger) |
| 252 | // 3) Combine the timestamps and messages. (TimestampMerger) |
| 253 | // 4) Merge all the channels to produce the next message on a node. |
| 254 | // (ChannelMerger) |
| 255 | // 5) Duplicate this entire stack per node. |
| 256 | |
| 257 | // This class splits messages and timestamps up into a queue per channel, and |
| 258 | // handles reading data from multiple chunks. |
| 259 | class SplitMessageReader { |
| 260 | public: |
| 261 | SplitMessageReader(const std::vector<std::string> &filenames); |
| 262 | |
| 263 | // Sets the TimestampMerger that gets notified for each channel. The node |
| 264 | // that the TimestampMerger is merging as needs to be passed in. |
| 265 | void SetTimestampMerger(TimestampMerger *timestamp_merger, int channel, |
| 266 | const Node *target_node); |
| 267 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 268 | // Returns the (timestamp, queue_index, message_header) for the oldest message |
| 269 | // in a channel, or max_time if there is nothing in the channel. |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 270 | std::tuple<monotonic_clock::time_point, uint32_t, const MessageHeader *> |
| 271 | oldest_message(int channel) { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 272 | return channels_[channel].data.front_timestamp(); |
| 273 | } |
| 274 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 275 | // Returns the (timestamp, queue_index, message_header) for the oldest |
| 276 | // delivery time in a channel, or max_time if there is nothing in the channel. |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 277 | std::tuple<monotonic_clock::time_point, uint32_t, const MessageHeader *> |
| 278 | oldest_message(int channel, int destination_node) { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 279 | return channels_[channel].timestamps[destination_node].front_timestamp(); |
| 280 | } |
| 281 | |
| 282 | // Returns the timestamp, queue_index, and message for the oldest data on a |
| 283 | // channel. Requeues data as needed. |
| 284 | std::tuple<monotonic_clock::time_point, uint32_t, |
| 285 | FlatbufferVector<MessageHeader>> |
| 286 | PopOldest(int channel_index); |
| 287 | |
| 288 | // Returns the timestamp, queue_index, and message for the oldest timestamp on |
| 289 | // a channel delivered to a node. Requeues data as needed. |
| 290 | std::tuple<monotonic_clock::time_point, uint32_t, |
| 291 | FlatbufferVector<MessageHeader>> |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 292 | PopOldestTimestamp(int channel, int node_index); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 293 | |
| 294 | // Returns the header for the log files. |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 295 | const LogFileHeader *log_file_header() const { |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 296 | return &log_file_header_.message(); |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 297 | } |
| 298 | |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 299 | const FlatbufferVector<LogFileHeader> &raw_log_file_header() const { |
| 300 | return log_file_header_; |
| 301 | } |
| 302 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 303 | // Returns the starting time for this set of log files. |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 304 | monotonic_clock::time_point monotonic_start_time() { |
| 305 | return monotonic_clock::time_point( |
| 306 | std::chrono::nanoseconds(log_file_header()->monotonic_start_time())); |
| 307 | } |
| 308 | realtime_clock::time_point realtime_start_time() { |
| 309 | return realtime_clock::time_point( |
| 310 | std::chrono::nanoseconds(log_file_header()->realtime_start_time())); |
| 311 | } |
| 312 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 313 | // Returns the configuration from the log file header. |
| 314 | const Configuration *configuration() const { |
| 315 | return log_file_header()->configuration(); |
| 316 | } |
| 317 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 318 | // Returns the node who's point of view this log file is from. Make sure this |
| 319 | // is a pointer in the configuration() nodes list so it can be consumed |
| 320 | // elsewhere. |
| 321 | const Node *node() const { |
| 322 | if (configuration()->has_nodes()) { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 323 | return configuration::GetNodeOrDie(configuration(), |
| 324 | log_file_header()->node()); |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 325 | } else { |
| 326 | CHECK(!log_file_header()->has_node()); |
| 327 | return nullptr; |
| 328 | } |
| 329 | } |
| 330 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 331 | // Returns the timestamp of the newest message read from the log file, and the |
| 332 | // timestamp that we need to re-queue data. |
| 333 | monotonic_clock::time_point newest_timestamp() const { |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 334 | return newest_timestamp_; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 337 | // Returns the next time to trigger a requeue. |
| 338 | monotonic_clock::time_point time_to_queue() const { return time_to_queue_; } |
| 339 | |
| 340 | // Returns the minimum amount of data needed to queue up for sorting before |
| 341 | // ware guarenteed to not see data out of order. |
| 342 | std::chrono::nanoseconds max_out_of_order_duration() const { |
| 343 | return message_reader_->max_out_of_order_duration(); |
| 344 | } |
| 345 | |
| 346 | std::string_view filename() const { return message_reader_->filename(); } |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 347 | |
| 348 | // Adds more messages to the sorted list. This reads enough data such that |
| 349 | // oldest_message_time can be replayed safely. Returns false if the log file |
| 350 | // has all been read. |
| 351 | bool QueueMessages(monotonic_clock::time_point oldest_message_time); |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 352 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 353 | // Returns debug strings for a channel, and timestamps for a node. |
| 354 | std::string DebugString(int channel) const; |
| 355 | std::string DebugString(int channel, int node_index) const; |
| 356 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 357 | // Returns true if all the messages have been queued from the last log file in |
| 358 | // the list of log files chunks. |
| 359 | bool at_end() const { return at_end_; } |
| 360 | |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 361 | private: |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 362 | // TODO(austin): Need to copy or refcount the message instead of running |
| 363 | // multiple copies of the reader. Or maybe have a "as_node" index and hide it |
| 364 | // inside. |
| 365 | |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 366 | // Moves to the next log file in the list. |
| 367 | bool NextLogFile(); |
| 368 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 369 | // Filenames of the log files. |
| 370 | std::vector<std::string> filenames_; |
| 371 | // And the index of the next file to open. |
| 372 | size_t next_filename_index_ = 0; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 373 | |
Austin Schuh | ee71105 | 2020-08-24 16:06:09 -0700 | [diff] [blame] | 374 | // Node we are reading as. |
| 375 | const Node *target_node_ = nullptr; |
| 376 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 377 | // Log file header to report. This is a copy. |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 378 | FlatbufferVector<LogFileHeader> log_file_header_; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 379 | // Current log file being read. |
| 380 | std::unique_ptr<MessageReader> message_reader_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 381 | |
| 382 | // Datastructure to hold the list of messages, cached timestamp for the |
| 383 | // oldest message, and sender to send with. |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 384 | struct MessageHeaderQueue { |
| 385 | // If true, this is a timestamp queue. |
| 386 | bool timestamps = false; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 387 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 388 | // Returns a reference to the the oldest message. |
| 389 | FlatbufferVector<MessageHeader> &front() { |
| 390 | CHECK_GT(data_.size(), 0u); |
| 391 | return data_.front(); |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 392 | } |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 393 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 394 | // Adds a message to the back of the queue. Returns true if it was actually |
| 395 | // emplaced. |
| 396 | bool emplace_back(FlatbufferVector<MessageHeader> &&msg); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 397 | |
| 398 | // Drops the front message. Invalidates the front() reference. |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 399 | void PopFront(); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 400 | |
| 401 | // The size of the queue. |
| 402 | size_t size() { return data_.size(); } |
| 403 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 404 | // Returns a debug string with info about each message in the queue. |
| 405 | std::string DebugString() const; |
| 406 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 407 | // Returns the (timestamp, queue_index, message_header) for the oldest |
| 408 | // message. |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 409 | const std::tuple<monotonic_clock::time_point, uint32_t, |
| 410 | const MessageHeader *> |
| 411 | front_timestamp() { |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 412 | const MessageHeader &message = front().message(); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 413 | return std::make_tuple( |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 414 | monotonic_clock::time_point( |
| 415 | std::chrono::nanoseconds(message.monotonic_sent_time())), |
| 416 | message.queue_index(), &message); |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | // Pointer to the timestamp merger for this queue if available. |
| 420 | TimestampMerger *timestamp_merger = nullptr; |
| 421 | // Pointer to the reader which feeds this queue. |
| 422 | SplitMessageReader *split_reader = nullptr; |
| 423 | |
| 424 | private: |
| 425 | // The data. |
| 426 | std::deque<FlatbufferVector<MessageHeader>> data_; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 427 | }; |
| 428 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 429 | // All the queues needed for a channel. There isn't going to be data in all |
| 430 | // of these. |
| 431 | struct ChannelData { |
| 432 | // The data queue for the channel. |
| 433 | MessageHeaderQueue data; |
| 434 | // Queues for timestamps for each node. |
| 435 | std::vector<MessageHeaderQueue> timestamps; |
| 436 | }; |
Austin Schuh | fa89589 | 2020-01-07 20:07:41 -0800 | [diff] [blame] | 437 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 438 | // Data for all the channels. |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 439 | std::vector<ChannelData> channels_; |
| 440 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 441 | // Once we know the node that this SplitMessageReader will be writing as, |
| 442 | // there will be only one MessageHeaderQueue that a specific channel matches. |
| 443 | // Precompute this here for efficiency. |
| 444 | std::vector<MessageHeaderQueue *> channels_to_write_; |
| 445 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 446 | monotonic_clock::time_point time_to_queue_ = monotonic_clock::min_time; |
| 447 | |
| 448 | // Latches true when we hit the end of the last log file and there is no sense |
| 449 | // poking it further. |
| 450 | bool at_end_ = false; |
| 451 | |
| 452 | // Timestamp of the newest message that was read and actually queued. We want |
| 453 | // to track this independently from the log file because we need the |
| 454 | // timestamps here to be timestamps of messages that are queued. |
| 455 | monotonic_clock::time_point newest_timestamp_ = monotonic_clock::min_time; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 456 | }; |
| 457 | |
| 458 | class ChannelMerger; |
| 459 | |
| 460 | // Sorts channels (and timestamps) from multiple log files for a single channel. |
| 461 | class TimestampMerger { |
| 462 | public: |
| 463 | TimestampMerger(const Configuration *configuration, |
| 464 | std::vector<SplitMessageReader *> split_message_readers, |
| 465 | int channel_index, const Node *target_node, |
| 466 | ChannelMerger *channel_merger); |
| 467 | |
| 468 | // Metadata used to schedule the message. |
| 469 | struct DeliveryTimestamp { |
| 470 | monotonic_clock::time_point monotonic_event_time = |
| 471 | monotonic_clock::min_time; |
| 472 | realtime_clock::time_point realtime_event_time = realtime_clock::min_time; |
| 473 | |
| 474 | monotonic_clock::time_point monotonic_remote_time = |
| 475 | monotonic_clock::min_time; |
| 476 | realtime_clock::time_point realtime_remote_time = realtime_clock::min_time; |
| 477 | uint32_t remote_queue_index = 0xffffffff; |
| 478 | }; |
| 479 | |
| 480 | // Pushes SplitMessageReader onto the timestamp heap. This should only be |
| 481 | // called when timestamps are placed in the channel this class is merging for |
| 482 | // the reader. |
| 483 | void UpdateTimestamp( |
| 484 | SplitMessageReader *split_message_reader, |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 485 | std::tuple<monotonic_clock::time_point, uint32_t, const MessageHeader *> |
| 486 | oldest_message_time) { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 487 | PushTimestampHeap(oldest_message_time, split_message_reader); |
| 488 | } |
| 489 | // Pushes SplitMessageReader onto the message heap. This should only be |
| 490 | // called when data is placed in the channel this class is merging for the |
| 491 | // reader. |
| 492 | void Update( |
| 493 | SplitMessageReader *split_message_reader, |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 494 | std::tuple<monotonic_clock::time_point, uint32_t, const MessageHeader *> |
| 495 | oldest_message_time) { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 496 | PushMessageHeap(oldest_message_time, split_message_reader); |
| 497 | } |
| 498 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 499 | // Returns the oldest combined timestamp and data for this channel. If there |
| 500 | // isn't a matching piece of data, returns only the timestamp with no data. |
| 501 | // The caller can determine what the appropriate action is to recover. |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 502 | std::tuple<DeliveryTimestamp, FlatbufferVector<MessageHeader>> PopOldest(); |
| 503 | |
| 504 | // Tracks if the channel merger has pushed this onto it's heap or not. |
| 505 | bool pushed() { return pushed_; } |
| 506 | // Sets if this has been pushed to the channel merger heap. Should only be |
| 507 | // called by the channel merger. |
| 508 | void set_pushed(bool pushed) { pushed_ = pushed; } |
| 509 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 510 | // Returns a debug string with the heaps printed out. |
| 511 | std::string DebugString() const; |
| 512 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 513 | // Returns true if we have timestamps. |
| 514 | bool has_timestamps() const { return has_timestamps_; } |
| 515 | |
| 516 | // Records that one of the log files ran out of data. This should only be |
| 517 | // called by a SplitMessageReader. |
| 518 | void NoticeAtEnd(); |
| 519 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 520 | aos::monotonic_clock::time_point channel_merger_time() { |
| 521 | if (has_timestamps_) { |
| 522 | return std::get<0>(timestamp_heap_[0]); |
| 523 | } else { |
| 524 | return std::get<0>(message_heap_[0]); |
| 525 | } |
| 526 | } |
| 527 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 528 | private: |
| 529 | // Pushes messages and timestamps to the corresponding heaps. |
| 530 | void PushMessageHeap( |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 531 | std::tuple<monotonic_clock::time_point, uint32_t, const MessageHeader *> |
| 532 | timestamp, |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 533 | SplitMessageReader *split_message_reader); |
| 534 | void PushTimestampHeap( |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 535 | std::tuple<monotonic_clock::time_point, uint32_t, const MessageHeader *> |
| 536 | timestamp, |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 537 | SplitMessageReader *split_message_reader); |
| 538 | |
| 539 | // Pops a message from the message heap. This automatically triggers the |
| 540 | // split message reader to re-fetch any new data. |
| 541 | std::tuple<monotonic_clock::time_point, uint32_t, |
| 542 | FlatbufferVector<MessageHeader>> |
| 543 | PopMessageHeap(); |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 544 | |
| 545 | std::tuple<monotonic_clock::time_point, uint32_t, const MessageHeader *> |
| 546 | oldest_message() const; |
| 547 | std::tuple<monotonic_clock::time_point, uint32_t, const MessageHeader *> |
| 548 | oldest_timestamp() const; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 549 | // Pops a message from the timestamp heap. This automatically triggers the |
| 550 | // split message reader to re-fetch any new data. |
| 551 | std::tuple<monotonic_clock::time_point, uint32_t, |
| 552 | FlatbufferVector<MessageHeader>> |
| 553 | PopTimestampHeap(); |
| 554 | |
| 555 | const Configuration *configuration_; |
| 556 | |
| 557 | // If true, this is a forwarded channel and timestamps should be matched. |
| 558 | bool has_timestamps_ = false; |
| 559 | |
| 560 | // Tracks if the ChannelMerger has pushed this onto it's queue. |
| 561 | bool pushed_ = false; |
| 562 | |
| 563 | // The split message readers used for source data. |
| 564 | std::vector<SplitMessageReader *> split_message_readers_; |
| 565 | |
| 566 | // The channel to merge. |
| 567 | int channel_index_; |
| 568 | |
| 569 | // Our node. |
| 570 | int node_index_; |
| 571 | |
| 572 | // Heaps for messages and timestamps. |
| 573 | std::vector< |
| 574 | std::tuple<monotonic_clock::time_point, uint32_t, SplitMessageReader *>> |
| 575 | message_heap_; |
| 576 | std::vector< |
| 577 | std::tuple<monotonic_clock::time_point, uint32_t, SplitMessageReader *>> |
| 578 | timestamp_heap_; |
| 579 | |
| 580 | // Parent channel merger. |
| 581 | ChannelMerger *channel_merger_; |
| 582 | }; |
| 583 | |
| 584 | // This class handles constructing all the split message readers, channel |
| 585 | // mergers, and combining the results. |
| 586 | class ChannelMerger { |
| 587 | public: |
| 588 | // Builds a ChannelMerger around a set of log files. These are of the format: |
| 589 | // { |
| 590 | // {log1_part0, log1_part1, ...}, |
| 591 | // {log2} |
| 592 | // } |
| 593 | // The inner vector is a list of log file chunks which form up a log file. |
| 594 | // The outer vector is a list of log files with subsets of the messages, or |
| 595 | // messages from different nodes. |
| 596 | ChannelMerger(const std::vector<std::vector<std::string>> &filenames); |
| 597 | |
| 598 | // Returns the nodes that we know how to merge. |
| 599 | const std::vector<const Node *> nodes() const; |
| 600 | // Sets the node that we will return messages as. Returns true if the node |
| 601 | // has log files and will produce data. This can only be called once, and |
| 602 | // will likely corrupt state if called a second time. |
| 603 | bool SetNode(const Node *target_node); |
| 604 | |
| 605 | // Everything else needs the node set before it works. |
| 606 | |
| 607 | // Returns a timestamp for the oldest message in this group of logfiles. |
Austin Schuh | 858c9f3 | 2020-08-31 16:56:12 -0700 | [diff] [blame] | 608 | monotonic_clock::time_point OldestMessageTime() const; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 609 | // Pops the oldest message. |
| 610 | std::tuple<TimestampMerger::DeliveryTimestamp, int, |
| 611 | FlatbufferVector<MessageHeader>> |
| 612 | PopOldest(); |
| 613 | |
| 614 | // Returns the config for this set of log files. |
| 615 | const Configuration *configuration() const { |
| 616 | return log_file_header()->configuration(); |
| 617 | } |
| 618 | |
| 619 | const LogFileHeader *log_file_header() const { |
| 620 | return &log_file_header_.message(); |
| 621 | } |
| 622 | |
| 623 | // Returns the start times for the configured node's log files. |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 624 | monotonic_clock::time_point monotonic_start_time() const { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 625 | return monotonic_clock::time_point( |
| 626 | std::chrono::nanoseconds(log_file_header()->monotonic_start_time())); |
| 627 | } |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 628 | realtime_clock::time_point realtime_start_time() const { |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 629 | return realtime_clock::time_point( |
| 630 | std::chrono::nanoseconds(log_file_header()->realtime_start_time())); |
| 631 | } |
| 632 | |
| 633 | // Returns the node set by SetNode above. |
| 634 | const Node *node() const { return node_; } |
| 635 | |
| 636 | // Called by the TimestampMerger when new data is available with the provided |
| 637 | // timestamp and channel_index. |
| 638 | void Update(monotonic_clock::time_point timestamp, int channel_index) { |
| 639 | PushChannelHeap(timestamp, channel_index); |
| 640 | } |
| 641 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 642 | // Returns a debug string with all the heaps in it. Generally only useful for |
| 643 | // debugging what went wrong. |
| 644 | std::string DebugString() const; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 645 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 646 | // Returns true if one of the log files has finished reading everything. When |
| 647 | // log file chunks are involved, this means that the last chunk in a log file |
| 648 | // has been read. It is acceptable to be missing data at this point in time. |
| 649 | bool at_end() const { return at_end_; } |
| 650 | |
| 651 | // Marks that one of the log files is at the end. This should only be called |
| 652 | // by timestamp mergers. |
| 653 | void NoticeAtEnd() { at_end_ = true; } |
| 654 | |
Austin Schuh | cde938c | 2020-02-02 17:30:07 -0800 | [diff] [blame] | 655 | private: |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 656 | // Pushes the timestamp for new data on the provided channel. |
| 657 | void PushChannelHeap(monotonic_clock::time_point timestamp, |
| 658 | int channel_index); |
| 659 | |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 660 | // CHECKs that channel_heap_ and timestamp_heap_ are valid heaps. |
| 661 | void VerifyHeaps(); |
| 662 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 663 | // All the message readers. |
| 664 | std::vector<std::unique_ptr<SplitMessageReader>> split_message_readers_; |
| 665 | |
| 666 | // The log header we are claiming to be. |
Austin Schuh | 97789fc | 2020-08-01 14:42:45 -0700 | [diff] [blame] | 667 | FlatbufferVector<LogFileHeader> log_file_header_; |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 668 | |
| 669 | // The timestamp mergers which combine data from the split message readers. |
| 670 | std::vector<TimestampMerger> timestamp_mergers_; |
| 671 | |
| 672 | // A heap of the channel readers and timestamps for the oldest data in each. |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 673 | std::vector<std::pair<monotonic_clock::time_point, int>> channel_heap_; |
| 674 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 675 | // Configured node. |
| 676 | const Node *node_; |
| 677 | |
Austin Schuh | 8bd9632 | 2020-02-13 21:18:22 -0800 | [diff] [blame] | 678 | bool at_end_ = false; |
| 679 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 680 | // Cached copy of the list of nodes. |
| 681 | std::vector<const Node *> nodes_; |
Austin Schuh | 2f8fd75 | 2020-09-01 22:38:28 -0700 | [diff] [blame] | 682 | |
| 683 | // Last time popped. Used to detect events being returned out of order. |
| 684 | monotonic_clock::time_point last_popped_time_ = monotonic_clock::min_time; |
Austin Schuh | 05b7047 | 2020-01-01 17:11:17 -0800 | [diff] [blame] | 685 | }; |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 686 | |
Austin Schuh | ee71105 | 2020-08-24 16:06:09 -0700 | [diff] [blame] | 687 | // Returns the node name with a trailing space, or an empty string if we are on |
| 688 | // a single node. |
| 689 | std::string MaybeNodeName(const Node *); |
| 690 | |
Brian Silverman | f51499a | 2020-09-21 12:49:08 -0700 | [diff] [blame] | 691 | } // namespace aos::logger |
Austin Schuh | a36c890 | 2019-12-30 18:07:15 -0800 | [diff] [blame] | 692 | |
| 693 | #endif // AOS_EVENTS_LOGGING_LOGFILE_UTILS_H_ |