bootstat: Special case logging for empty boot reason.
Empty boot reason is mostly unexpected but may take up the bulk of
unknown reported boot reason values.
Bug: none
Test: none
Change-Id: I9978658c2b052d5cf5d28299861b0d1125ba9fc0
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp
index 1954966..ac66b7f 100644
--- a/bootstat/bootstat.cpp
+++ b/bootstat/bootstat.cpp
@@ -129,6 +129,7 @@
property_set(key, val);
}
+constexpr int32_t kEmptyBootReason = 0;
constexpr int32_t kUnknownBootReason = 1;
// A mapping from boot reason string, as read from the ro.boot.bootreason
@@ -136,6 +137,7 @@
// the boot_reason metric may refer to this mapping to discern the histogram
// values.
const std::map<std::string, int32_t> kBootReasonMap = {
+ {"empty", kEmptyBootReason},
{"unknown", kUnknownBootReason},
{"normal", 2},
{"recovery", 3},
@@ -216,6 +218,10 @@
return mapping->second;
}
+ if (boot_reason.empty()) {
+ return kEmptyBootReason;
+ }
+
LOG(INFO) << "Unknown boot reason: " << boot_reason;
return kUnknownBootReason;
}
@@ -747,8 +753,16 @@
// property.
void RecordBootReason() {
const std::string reason(GetProperty(bootloader_reboot_reason_property));
- android::metricslogger::LogMultiAction(android::metricslogger::ACTION_BOOT,
- android::metricslogger::FIELD_PLATFORM_REASON, reason);
+
+ if (reason.empty()) {
+ // Log an empty boot reason value as '<EMPTY>' to ensure the value is intentional
+ // (and not corruption anywhere else in the reporting pipeline).
+ android::metricslogger::LogMultiAction(android::metricslogger::ACTION_BOOT,
+ android::metricslogger::FIELD_PLATFORM_REASON, "<EMPTY>");
+ } else {
+ android::metricslogger::LogMultiAction(android::metricslogger::ACTION_BOOT,
+ android::metricslogger::FIELD_PLATFORM_REASON, reason);
+ }
// Log the raw bootloader_boot_reason property value.
int32_t boot_reason = BootReasonStrToEnum(reason);