Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14b1e6d6 authored by Mark Salyzyn's avatar Mark Salyzyn
Browse files

bootstat: clang-format rebase

Code style has drifted too far from our current clang-format
settings.

Test: compile
Side-Effects: none
Bug: 63736262
Change-Id: Ie390459db123cfadf09aa06c8dafb1ae69a72af8
parent 22a10f67
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -66,8 +66,7 @@ void BootEventRecordStore::AddBootEvent(const std::string& event) {
// The implementation of AddBootEventValue makes use of the mtime file
// attribute to store the value associated with a boot event in order to
// optimize on-disk size requirements and small-file thrashing.
void BootEventRecordStore::AddBootEventWithValue(
    const std::string& event, int32_t value) {
void BootEventRecordStore::AddBootEventWithValue(const std::string& event, int32_t value) {
  std::string record_path = GetBootEventPath(event);
  int record_fd = creat(record_path.c_str(), S_IRUSR | S_IWUSR);
  if (record_fd == -1) {
@@ -96,8 +95,7 @@ void BootEventRecordStore::AddBootEventWithValue(
  close(record_fd);
}

bool BootEventRecordStore::GetBootEvent(
    const std::string& event, BootEventRecord* record) const {
bool BootEventRecordStore::GetBootEvent(const std::string& event, BootEventRecord* record) const {
  CHECK_NE(static_cast<BootEventRecord*>(nullptr), record);
  CHECK(!event.empty());

@@ -112,8 +110,7 @@ bool BootEventRecordStore::GetBootEvent(
  return true;
}

std::vector<BootEventRecordStore::BootEventRecord> BootEventRecordStore::
    GetAllBootEvents() const {
std::vector<BootEventRecordStore::BootEventRecord> BootEventRecordStore::GetAllBootEvents() const {
  std::vector<BootEventRecord> events;

  std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(store_path_.c_str()), closedir);
@@ -147,8 +144,7 @@ void BootEventRecordStore::SetStorePath(const std::string& path) {
  store_path_ = path;
}

std::string BootEventRecordStore::GetBootEventPath(
    const std::string& event) const {
std::string BootEventRecordStore::GetBootEventPath(const std::string& event) const {
  DCHECK_EQ('/', store_path_.back());
  return store_path_ + event;
}
+2 −2
Original line number Diff line number Diff line
@@ -17,12 +17,12 @@
#ifndef BOOT_EVENT_RECORD_STORE_H_
#define BOOT_EVENT_RECORD_STORE_H_

#include <android-base/macros.h>
#include <gtest/gtest_prod.h>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include <android-base/macros.h>
#include <gtest/gtest_prod.h>

// BootEventRecordStore manages the persistence of boot events to the record
// store and the retrieval of all boot event records from the store.
+6 −12
Original line number Diff line number Diff line
@@ -101,13 +101,9 @@ time_t GetUptimeSeconds() {

class BootEventRecordStoreTest : public ::testing::Test {
 public:
  BootEventRecordStoreTest() {
    store_path_ = std::string(store_dir_.path) + "/";
  }
  BootEventRecordStoreTest() { store_path_ = std::string(store_dir_.path) + "/"; }

  const std::string& GetStorePathForTesting() const {
    return store_path_;
  }
  const std::string& GetStorePathForTesting() const { return store_path_; }

 private:
  void TearDown() {
@@ -159,9 +155,7 @@ TEST_F(BootEventRecordStoreTest, AddMultipleBootEvents) {
  store.AddBootEvent("triassic");

  const std::string EXPECTED_NAMES[] = {
    "cretaceous",
    "jurassic",
    "triassic",
      "cretaceous", "jurassic", "triassic",
  };

  auto events = store.GetAllBootEvents();
+139 −141
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@
// uploaded to Android log storage via Tron.

#include <getopt.h>
#include <unistd.h>
#include <sys/klog.h>
#include <unistd.h>

#include <chrono>
#include <cmath>
@@ -61,8 +61,7 @@ void LogBootEvents() {
// Records the named boot |event| to the record store. If |value| is non-empty
// and is a proper string representation of an integer value, the converted
// integer value is associated with the boot event.
void RecordBootEventFromCommandLine(
    const std::string& event, const std::string& value_str) {
void RecordBootEventFromCommandLine(const std::string& event, const std::string& value_str) {
  BootEventRecordStore boot_event_store;
  if (!value_str.empty()) {
    int32_t value = 0;
@@ -221,6 +220,7 @@ int32_t BootReasonStrToEnum(const std::string& boot_reason) {

// Canonical list of supported primary reboot reasons.
const std::vector<const std::string> knownReasons = {
    // clang-format off
    // kernel
    "watchdog",
    "kernel_panic",
@@ -233,6 +233,7 @@ const std::vector<const std::string> knownReasons = {
    "warm",
    "shutdown",    // Can not happen from ro.boot.bootreason
    "reboot",      // Default catch-all for anything unknown
    // clang-format on
};

// Returns true if the supplied reason prefix is considered detailed enough.
@@ -320,8 +321,12 @@ bool addKernelPanicSubReason(const std::string& console, std::string& ret) {
// std::transform Helper callback functions:
// Converts a string value representing the reason the system booted to a
// string complying with Android system standard reason.
char tounderline(char c) { return ::isblank(c) ? '_' : c; }
char toprintable(char c) { return ::isprint(c) ? c : '?'; }
char tounderline(char c) {
  return ::isblank(c) ? '_' : c;
}
char toprintable(char c) {
  return ::isprint(c) ? c : '?';
}

const char system_reboot_reason_property[] = "sys.boot.reason";
const char last_reboot_reason_property[] = LAST_REBOOT_REASON_PROPERTY;
@@ -580,7 +585,7 @@ std::string CalculateBootCompletePrefix() {
  if (!boot_event_store.GetBootEvent(kBuildDateKey, &record)) {
    boot_complete_prefix = "factory_reset_" + boot_complete_prefix;
    boot_event_store.AddBootEventWithValue(kBuildDateKey, build_date);
    LOG(INFO) << "Canonical boot reason: " << "reboot,factory_reset";
    LOG(INFO) << "Canonical boot reason: reboot,factory_reset";
    SetProperty(system_reboot_reason_property, "reboot,factory_reset");
    if (GetProperty(bootloader_reboot_reason_property) == "") {
      SetProperty(bootloader_reboot_reason_property, "reboot,factory_reset");
@@ -588,7 +593,7 @@ std::string CalculateBootCompletePrefix() {
  } else if (build_date != record.second) {
    boot_complete_prefix = "ota_" + boot_complete_prefix;
    boot_event_store.AddBootEventWithValue(kBuildDateKey, build_date);
    LOG(INFO) << "Canonical boot reason: " << "reboot,ota";
    LOG(INFO) << "Canonical boot reason: reboot,ota";
    SetProperty(system_reboot_reason_property, "reboot,ota");
    if (GetProperty(bootloader_reboot_reason_property) == "") {
      SetProperty(bootloader_reboot_reason_property, "reboot,ota");
@@ -599,8 +604,7 @@ std::string CalculateBootCompletePrefix() {
}

// Records the value of a given ro.boottime.init property in milliseconds.
void RecordInitBootTimeProp(
    BootEventRecordStore* boot_event_store, const char* property) {
void RecordInitBootTimeProp(BootEventRecordStore* boot_event_store, const char* property) {
  std::string value = GetProperty(property);

  int32_t time_in_ms;
@@ -685,10 +689,8 @@ void RecordBootComplete() {

  if (boot_event_store.GetBootEvent("last_boot_time_utc", &record)) {
    time_t last_boot_time_utc = record.second;
    time_t time_since_last_boot = difftime(current_time_utc,
                                           last_boot_time_utc);
    boot_event_store.AddBootEventWithValue("time_since_last_boot",
                                           time_since_last_boot);
    time_t time_since_last_boot = difftime(current_time_utc, last_boot_time_utc);
    boot_event_store.AddBootEventWithValue("time_since_last_boot", time_since_last_boot);
  }

  boot_event_store.AddBootEventWithValue("last_boot_time_utc", current_time_utc);
@@ -714,8 +716,7 @@ void RecordBootComplete() {
    boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_post_decrypt",
                                           boot_complete.count());
  } else {
      boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_no_encryption",
                                             uptime.count());
    boot_event_store.AddBootEventWithValue(boot_complete_prefix + "_no_encryption", uptime.count());
  }

  // Record the total time from device startup to boot complete, regardless of
@@ -738,8 +739,7 @@ void RecordBootComplete() {
void RecordBootReason() {
  const std::string reason(GetProperty(bootloader_reboot_reason_property));
  android::metricslogger::LogMultiAction(android::metricslogger::ACTION_BOOT,
                                         android::metricslogger::FIELD_PLATFORM_REASON,
                                         reason);
                                         android::metricslogger::FIELD_PLATFORM_REASON, reason);

  // Log the raw bootloader_boot_reason property value.
  int32_t boot_reason = BootReasonStrToEnum(reason);
@@ -769,21 +769,20 @@ void RecordFactoryReset() {

  if (current_time_utc < 0) {
    // UMA does not display negative values in buckets, so convert to positive.
    android::metricslogger::LogHistogram(
        "factory_reset_current_time_failure", std::abs(current_time_utc));
    android::metricslogger::LogHistogram("factory_reset_current_time_failure",
                                         std::abs(current_time_utc));

    // Logging via BootEventRecordStore to see if using android::metricslogger::LogHistogram
    // is losing records somehow.
    boot_event_store.AddBootEventWithValue(
        "factory_reset_current_time_failure", std::abs(current_time_utc));
    boot_event_store.AddBootEventWithValue("factory_reset_current_time_failure",
                                           std::abs(current_time_utc));
    return;
  } else {
    android::metricslogger::LogHistogram("factory_reset_current_time", current_time_utc);

    // Logging via BootEventRecordStore to see if using android::metricslogger::LogHistogram
    // is losing records somehow.
    boot_event_store.AddBootEventWithValue(
        "factory_reset_current_time", current_time_utc);
    boot_event_store.AddBootEventWithValue("factory_reset_current_time", current_time_utc);
  }

  // The factory_reset boot event does not exist after the device is reset, so
@@ -803,13 +802,10 @@ void RecordFactoryReset() {

  // Logging via BootEventRecordStore to see if using android::metricslogger::LogHistogram
  // is losing records somehow.
  boot_event_store.AddBootEventWithValue(
      "factory_reset_record_value", factory_reset_utc);
  boot_event_store.AddBootEventWithValue("factory_reset_record_value", factory_reset_utc);

  time_t time_since_factory_reset = difftime(current_time_utc,
                                             factory_reset_utc);
  boot_event_store.AddBootEventWithValue("time_since_factory_reset",
                                         time_since_factory_reset);
  time_t time_since_factory_reset = difftime(current_time_utc, factory_reset_utc);
  boot_event_store.AddBootEventWithValue("time_since_factory_reset", time_since_factory_reset);
}

}  // namespace
@@ -826,6 +822,7 @@ int main(int argc, char **argv) {
  static const char boot_reason_str[] = "record_boot_reason";
  static const char factory_reset_str[] = "record_time_since_factory_reset";
  static const struct option long_options[] = {
      // clang-format off
      { "help",            no_argument,       NULL,   'h' },
      { "log",             no_argument,       NULL,   'l' },
      { "print",           no_argument,       NULL,   'p' },
@@ -835,6 +832,7 @@ int main(int argc, char **argv) {
      { boot_reason_str,   no_argument,       NULL,   0 },
      { factory_reset_str, no_argument,       NULL,   0 },
      { NULL,              0,                 NULL,   0 }
      // clang-format on
  };

  std::string boot_event;