blob: 5330c60106c07ebe1f5a93cc59082ba308263387 [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.");
James Kuszmaulc31d7362022-05-27 14:20:04 -07008DEFINE_string(mode, "json", "json or flatbuffer serialization.");
James Kuszmaul4ed5fb12022-03-22 15:20:04 -07009
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).
17int 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 Kuszmaul5c56ed32022-03-30 15:10:07 -070028 FLAGS_node.empty()
29 ? nullptr
30 : aos::configuration::GetNode(reader.configuration(), FLAGS_node);
James Kuszmaul4ed5fb12022-03-22 15:20:04 -070031 std::unique_ptr<aos::EventLoop> mcap_event_loop =
32 reader.event_loop_factory()->MakeEventLoop("mcap", node);
33 CHECK(!FLAGS_output_path.empty());
James Kuszmaulc31d7362022-05-27 14:20:04 -070034 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 Kuszmaul4ed5fb12022-03-22 15:20:04 -070038 reader.event_loop_factory()->Run();
39}