From aa32ea0f64e4035ac929e09ee85d268c3185221c Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 16 Aug 2022 16:37:58 -0700 Subject: [PATCH] loggerd: log all disk space usage in initData (#25455) * bootlog: log all disk space usage * not just agnos * move to initData * cleanup --- cereal | 2 +- selfdrive/loggerd/bootlog.cc | 22 +++++++++------------- selfdrive/loggerd/logger.cc | 27 +++++++++++++++++++++------ 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/cereal b/cereal index 5ab1970017..2d648b0dc4 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 5ab19700178f01c14f362735532ee2662ab755fc +Subproject commit 2d648b0dc4654fc7088ffb81fd301352707de749 diff --git a/selfdrive/loggerd/bootlog.cc b/selfdrive/loggerd/bootlog.cc index 882b749fe9..90ba487ff0 100644 --- a/selfdrive/loggerd/bootlog.cc +++ b/selfdrive/loggerd/bootlog.cc @@ -7,12 +7,6 @@ static kj::Array build_boot_log() { - std::vector bootlog_commands; - if (Hardware::AGNOS()) { - bootlog_commands.push_back("journalctl"); - bootlog_commands.push_back("sudo nvme smart-log --output-format=json /dev/nvme0"); - } - MessageBuilder msg; auto boot = msg.initEvent().initBoot(); @@ -31,17 +25,19 @@ static kj::Array build_boot_log() { } // Gather output of commands - i = 0; + std::vector bootlog_commands = { + "[ -e /dev/nvme0 ] && sudo nvme smart-log --output-format=json /dev/nvme0", + "[ -x \"$(command -v journalctl)\" ] && journalctl", + }; + auto commands = boot.initCommands().initEntries(bootlog_commands.size()); - for (auto &command : bootlog_commands) { - auto lentry = commands[i]; + for (int j = 0; j < bootlog_commands.size(); j++) { + auto lentry = commands[j]; - lentry.setKey(command); + lentry.setKey(bootlog_commands[j]); - const std::string result = util::check_output(command); + const std::string result = util::check_output(bootlog_commands[j]); lentry.setValue(capnp::Data::Reader((const kj::byte*)result.data(), result.size())); - - i++; } boot.setLaunchLog(util::read_file("/tmp/launch_log")); diff --git a/selfdrive/loggerd/logger.cc b/selfdrive/loggerd/logger.cc index 8038f1926c..da3710cc72 100644 --- a/selfdrive/loggerd/logger.cc +++ b/selfdrive/loggerd/logger.cc @@ -24,9 +24,11 @@ kj::Array logger_build_init_data() { MessageBuilder msg; auto init = msg.initEvent().initInitData(); - init.setDeviceType(Hardware::get_device_type()); init.setVersion(COMMA_VERSION); + init.setDirty(!getenv("CLEAN")); + init.setDeviceType(Hardware::get_device_type()); + // log kernel args std::ifstream cmdline_stream("/proc/cmdline"); std::vector kernel_args; std::string buf; @@ -42,8 +44,6 @@ kj::Array logger_build_init_data() { init.setKernelVersion(util::read_file("/proc/version")); init.setOsVersion(util::read_file("/VERSION")); - init.setDirty(!getenv("CLEAN")); - // log params auto params = Params(); std::map params_map = params.readAll(); @@ -55,16 +55,31 @@ kj::Array logger_build_init_data() { init.setDongleId(params_map["DongleId"]); auto lparams = init.initParams().initEntries(params_map.size()); - int i = 0; + int j = 0; for (auto& [key, value] : params_map) { - auto lentry = lparams[i]; + auto lentry = lparams[j]; lentry.setKey(key); if ( !(params.getKeyType(key) & DONT_LOG) ) { lentry.setValue(capnp::Data::Reader((const kj::byte*)value.data(), value.size())); } - i++; + j++; + } + + // log commands + std::vector log_commands = { + "df -h", // usage for all filesystems + }; + + auto commands = init.initCommands().initEntries(log_commands.size()); + for (int i = 0; i < log_commands.size(); i++) { + auto lentry = commands[i]; + lentry.setKey(log_commands[i]); + + const std::string result = util::check_output(log_commands[i]); + lentry.setValue(capnp::Data::Reader((const kj::byte*)result.data(), result.size())); } + return capnp::messageToFlatArray(msg); }