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
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index 1ec5451..d8ee899 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -943,13 +943,20 @@
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 @@
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,20 +1113,22 @@
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";
static const struct option long_options[] = {
// clang-format off
- { "help", no_argument, NULL, 'h' },
- { "log", no_argument, NULL, 'l' },
- { "print", no_argument, NULL, 'p' },
- { "record", required_argument, NULL, 'r' },
- { value_str, required_argument, NULL, 0 },
- { boot_complete_str, no_argument, NULL, 0 },
- { boot_reason_str, no_argument, NULL, 0 },
- { factory_reset_str, no_argument, NULL, 0 },
- { NULL, 0, NULL, 0 }
+ { "help", no_argument, NULL, 'h' },
+ { "log", no_argument, NULL, 'l' },
+ { "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 },
+ { NULL, 0, NULL, 0 }
// clang-format on
};
@@ -1137,6 +1144,8 @@
// |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) {