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

Commit fe3e762b authored by Tej Singh's avatar Tej Singh
Browse files

Fix performance degradation from BootSequence atom

Adding the boot sequence reported atom in ag/3518079 caused the duration
of bootstat to increase, as seen in b/72864061. I isolated the cause
down to calling BootReasonStrToReason. However, this function also gets
called in ReportBootReason, so I created another function that does the
parsing and sets the system boot reason property, and made
RecordBootReason and statsd logging get that property.

Bug: 72864061
Test: rebooted phone, verified boot events were received in adb shell
logcat -b stats and verified adb shell bootstat -p printed correct
values. Ran timing tests as well on walleye with 20 boots: before this
change, the average was ~150-160ms. After, it was ~80ms.

Change-Id: I92dbc9880328835647be7d9d50c7861b42f27bdb
parent 181056b4
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -943,13 +943,20 @@ void LogBootInfoToStatsd(std::chrono::milliseconds end_time,
    return;
  }

  const std::string system_reason(BootReasonStrToReason(reason));
  const std::string system_reason(GetProperty(system_reboot_reason_property));
  android::util::stats_write(android::util::BOOT_SEQUENCE_REPORTED, reason.c_str(),
                             system_reason.c_str(), end_time.count(), total_duration.count(),
                             (int64_t)bootloader_duration_ms,
                             (int64_t)time_since_last_boot_sec * 1000);
}

void SetSystemBootReason() {
  const std::string bootloader_boot_reason(GetProperty(bootloader_reboot_reason_property));
  const std::string system_boot_reason(BootReasonStrToReason(bootloader_boot_reason));
  // Record the scrubbed system_boot_reason to the property
  SetProperty(system_reboot_reason_property, system_boot_reason);
}

// Records several metrics related to the time it takes to boot the device,
// including disambiguating boot time on encrypted or non-encrypted devices.
void RecordBootComplete() {
@@ -1037,12 +1044,10 @@ void RecordBootReason() {
  boot_event_store.AddBootEventWithValue("boot_reason", boot_reason);

  // Log the scrubbed system_boot_reason.
  const std::string system_reason(BootReasonStrToReason(reason));
  const std::string system_reason(GetProperty(system_reboot_reason_property));
  int32_t system_boot_reason = BootReasonStrToEnum(system_reason);
  boot_event_store.AddBootEventWithValue("system_boot_reason", system_boot_reason);

  // Record the scrubbed system_boot_reason to the property
  SetProperty(system_reboot_reason_property, system_reason);
  if (reason == "") {
    SetProperty(bootloader_reboot_reason_property, system_reason);
  }
@@ -1108,6 +1113,7 @@ int main(int argc, char** argv) {

  int option_index = 0;
  static const char value_str[] = "value";
  static const char system_boot_reason_str[] = "set_system_boot_reason";
  static const char boot_complete_str[] = "record_boot_complete";
  static const char boot_reason_str[] = "record_boot_reason";
  static const char factory_reset_str[] = "record_time_since_factory_reset";
@@ -1118,6 +1124,7 @@ int main(int argc, char** argv) {
      { "print",                no_argument,       NULL,   'p' },
      { "record",               required_argument, NULL,   'r' },
      { value_str,              required_argument, NULL,   0 },
      { system_boot_reason_str, no_argument,       NULL,   0 },
      { boot_complete_str,      no_argument,       NULL,   0 },
      { boot_reason_str,        no_argument,       NULL,   0 },
      { factory_reset_str,      no_argument,       NULL,   0 },
@@ -1137,6 +1144,8 @@ int main(int argc, char** argv) {
          // |optarg| is an external variable set by getopt representing
          // the option argument.
          value = optarg;
        } else if (option_name == system_boot_reason_str) {
          SetSystemBootReason();
        } else if (option_name == boot_complete_str) {
          RecordBootComplete();
        } else if (option_name == boot_reason_str) {
+2 −1
Original line number Diff line number Diff line
@@ -68,8 +68,9 @@ on property:init.svc.zygote=stopping

# Record boot complete metrics.
on property:sys.boot_completed=1 && property:sys.logbootcomplete=1
    # Converts bootloader boot reason to system boot reason
    # Record boot_complete and related stats (decryption, etc).
    # Record the boot reason.
    # Record time since factory reset.
    # Log all boot events.
    exec_background - system log -- /system/bin/bootstat --record_boot_complete --record_boot_reason --record_time_since_factory_reset -l
    exec_background - system log -- /system/bin/bootstat --set_system_boot_reason --record_boot_complete --record_boot_reason --record_time_since_factory_reset -l