blob: 49aca69bfda7322bfd72ccc4d8e1230b2d03f907 [file] [log] [blame]
James Kuszmaul4ed5fb12022-03-22 15:20:04 -07001#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
6DEFINE_string(node, "", "Node to replay from the perspective of.");
7DEFINE_string(output_path, "/tmp/log.mcap", "Log to output.");
8
9// Converts an AOS log to an MCAP log that can be fed into Foxglove. To try this
10// out, run:
11// bazel run -c opt //aos/util:log_to_mcap -- --node NODE_NAME /path/to/logfile
12//
13// Then navigate to http://studio.foxglove.dev (or spin up your own instance
14// locally), and use it to open the file (this doesn't upload the file to
15// foxglove's servers or anything).
16int main(int argc, char *argv[]) {
17 aos::InitGoogle(&argc, &argv);
18
19 const std::vector<aos::logger::LogFile> logfiles =
20 aos::logger::SortParts(aos::logger::FindLogs(argc, argv));
21
22 aos::logger::LogReader reader(logfiles);
23
24 reader.Register();
25
26 const aos::Node *node =
James Kuszmaul5c56ed32022-03-30 15:10:07 -070027 FLAGS_node.empty()
28 ? nullptr
29 : aos::configuration::GetNode(reader.configuration(), FLAGS_node);
James Kuszmaul4ed5fb12022-03-22 15:20:04 -070030 std::unique_ptr<aos::EventLoop> mcap_event_loop =
31 reader.event_loop_factory()->MakeEventLoop("mcap", node);
32 CHECK(!FLAGS_output_path.empty());
33 aos::McapLogger relogger(mcap_event_loop.get(), FLAGS_output_path);
34 reader.event_loop_factory()->Run();
35}