blob: bd80a0469d5447292b37befc0af9a05e324e3feb [file] [log] [blame]
Philipp Schrader790cb542023-07-05 21:06:52 -07001#include "gflags/gflags.h"
2#include "glog/logging.h"
3
James Kuszmaul440d8992022-04-29 17:26:59 -07004#include "aos/configuration.h"
Austin Schuh60e77942022-05-16 17:48:24 -07005#include "aos/events/logging/log_reader.h"
6#include "aos/events/timing_report_dump_lib.h"
James Kuszmaul440d8992022-04-29 17:26:59 -07007#include "aos/init.h"
8#include "aos/json_to_flatbuffer.h"
James Kuszmaul440d8992022-04-29 17:26:59 -07009
10DEFINE_string(application, "",
11 "Application filter to use. Empty for no filter.");
12DEFINE_bool(stream, false, "Stream out all the timing reports in the log.");
13DEFINE_bool(accumulate, true,
14 "Display accumulation of all timing reports at end of log.");
15
16namespace aos {
17struct DumperState {
18 std::unique_ptr<EventLoop> event_loop;
19 std::unique_ptr<TimingReportDump> dumper;
20};
21int Main(int argc, char *argv[]) {
22 if (argc < 2) {
23 LOG(ERROR) << "Expected at least 1 logfile as an argument";
24 return 1;
25 }
26 aos::logger::LogReader reader(
27 aos::logger::SortParts(aos::logger::FindLogs(argc, argv)));
28 reader.Register();
29 {
30 std::vector<DumperState> dumpers;
31 for (const aos::Node *node : aos::configuration::GetNodes(
32 reader.event_loop_factory()->configuration())) {
33 std::unique_ptr<aos::EventLoop> event_loop =
34 reader.event_loop_factory()->MakeEventLoop("timing_reports", node);
35 event_loop->SkipTimingReport();
36 event_loop->SkipAosLog();
37 std::unique_ptr<TimingReportDump> dumper =
38 std::make_unique<TimingReportDump>(
39 event_loop.get(),
40 FLAGS_accumulate ? TimingReportDump::AccumulateStatistics::kYes
41 : TimingReportDump::AccumulateStatistics::kNo,
42 FLAGS_stream ? TimingReportDump::StreamResults::kYes
43 : TimingReportDump::StreamResults::kNo);
44 if (!FLAGS_application.empty()) {
45 dumper->ApplicationFilter(FLAGS_application);
46 }
47 dumpers.push_back({std::move(event_loop), std::move(dumper)});
48 }
49 reader.event_loop_factory()->Run();
50 }
51 reader.Deregister();
52 return EXIT_SUCCESS;
53}
54} // namespace aos
55
56int main(int argc, char *argv[]) {
57 aos::InitGoogle(&argc, &argv);
58 return aos::Main(argc, argv);
59}