From 8bab184ff523a0730d48a933e94f4805891ce07f Mon Sep 17 00:00:00 2001 From: Ravago Jones Date: Sat, 12 Dec 2020 17:36:39 -0800 Subject: [PATCH] Give log_stats the same logfile opening interface as log cat. Change-Id: Ic40af04703c160419e5c40f23d7e8093b67ac2e3 --- aos/events/logging/log_stats.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/aos/events/logging/log_stats.cc b/aos/events/logging/log_stats.cc index f9010563c6..47f3c5c911 100644 --- a/aos/events/logging/log_stats.cc +++ b/aos/events/logging/log_stats.cc @@ -8,8 +8,6 @@ #include "aos/time/time.h" #include "gflags/gflags.h" -DEFINE_string(logfile, "/tmp/logfile.bfbs", - "Name and path of the logfile to read from."); DEFINE_string( name, "", "Name to match for printing out channels. Empty means no name filter."); @@ -45,6 +43,8 @@ struct LogfileStats { int main(int argc, char **argv) { gflags::SetUsageMessage( + "Usage: \n" + " log_stats [args] logfile1 logfile2 ...\n" "This program provides statistics on a given log file. Supported " "statistics are:\n" " - Logfile start time;\n" @@ -57,11 +57,24 @@ int main(int argc, char **argv) { aos::InitGoogle(&argc, &argv); + if (argc < 2) { + LOG(FATAL) << "Expected at least 1 logfile as an argument."; + } + + // find logfiles + std::vector unsorted_logfiles = + aos::logger::FindLogs(argc, argv); + + // sort logfiles + const std::vector logfiles = + aos::logger::SortParts(unsorted_logfiles); + + // open logfiles + aos::logger::LogReader reader(logfiles); + LogfileStats logfile_stats; std::vector channel_stats; - // Open LogFile - aos::logger::LogReader reader(aos::logger::SortParts({FLAGS_logfile})); aos::SimulatedEventLoopFactory log_reader_factory(reader.configuration()); reader.Register(&log_reader_factory); @@ -175,7 +188,7 @@ int main(int argc, char **argv) { } } std::cout << std::setfill('-') << std::setw(80) << "-" - << "\nLogfile statistics for: " << FLAGS_logfile << "\n" + << "\nLogfile statistics:\n" << "Log starts at:\t" << reader.realtime_start_time(node) << "\n" << "Log ends at:\t" << logfile_stats.logfile_end_time << "\n" << "Log file size:\t" << logfile_stats.logfile_length << "\n"