James Kuszmaul | 4ed5fb1 | 2022-03-22 15:20:04 -0700 | [diff] [blame] | 1 | #include "aos/events/event_loop_generated.h" |
| 2 | #include "aos/events/logging/log_reader.h" |
| 3 | #include "aos/init.h" |
| 4 | #include "aos/util/mcap_logger.h" |
| 5 | |
| 6 | DEFINE_string(node, "", "Node to replay from the perspective of."); |
| 7 | DEFINE_string(output_path, "/tmp/log.mcap", "Log to output."); |
James Kuszmaul | c31d736 | 2022-05-27 14:20:04 -0700 | [diff] [blame^] | 8 | DEFINE_string(mode, "json", "json or flatbuffer serialization."); |
James Kuszmaul | 4ed5fb1 | 2022-03-22 15:20:04 -0700 | [diff] [blame] | 9 | |
| 10 | // Converts an AOS log to an MCAP log that can be fed into Foxglove. To try this |
| 11 | // out, run: |
| 12 | // bazel run -c opt //aos/util:log_to_mcap -- --node NODE_NAME /path/to/logfile |
| 13 | // |
| 14 | // Then navigate to http://studio.foxglove.dev (or spin up your own instance |
| 15 | // locally), and use it to open the file (this doesn't upload the file to |
| 16 | // foxglove's servers or anything). |
| 17 | int main(int argc, char *argv[]) { |
| 18 | aos::InitGoogle(&argc, &argv); |
| 19 | |
| 20 | const std::vector<aos::logger::LogFile> logfiles = |
| 21 | aos::logger::SortParts(aos::logger::FindLogs(argc, argv)); |
| 22 | |
| 23 | aos::logger::LogReader reader(logfiles); |
| 24 | |
| 25 | reader.Register(); |
| 26 | |
| 27 | const aos::Node *node = |
James Kuszmaul | 5c56ed3 | 2022-03-30 15:10:07 -0700 | [diff] [blame] | 28 | FLAGS_node.empty() |
| 29 | ? nullptr |
| 30 | : aos::configuration::GetNode(reader.configuration(), FLAGS_node); |
James Kuszmaul | 4ed5fb1 | 2022-03-22 15:20:04 -0700 | [diff] [blame] | 31 | std::unique_ptr<aos::EventLoop> mcap_event_loop = |
| 32 | reader.event_loop_factory()->MakeEventLoop("mcap", node); |
| 33 | CHECK(!FLAGS_output_path.empty()); |
James Kuszmaul | c31d736 | 2022-05-27 14:20:04 -0700 | [diff] [blame^] | 34 | aos::McapLogger relogger(mcap_event_loop.get(), FLAGS_output_path, |
| 35 | FLAGS_mode == "flatbuffer" |
| 36 | ? aos::McapLogger::Serialization::kFlatbuffer |
| 37 | : aos::McapLogger::Serialization::kJson); |
James Kuszmaul | 4ed5fb1 | 2022-03-22 15:20:04 -0700 | [diff] [blame] | 38 | reader.event_loop_factory()->Run(); |
| 39 | } |