Merge "bootstat: Special case logging for empty boot reason."

am: b93357bdb2

Change-Id: I07374a59888eba48d1f9b8d112729e8d793adca6
This commit is contained in:
James Hawkins 2017-10-11 20:07:55 +00:00 committed by android-build-merger
commit 79afacdd61

View file

@ -129,6 +129,7 @@ void SetProperty(const char* key, const char* val) {
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 @@ constexpr int32_t kUnknownBootReason = 1;
// 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 @@ int32_t BootReasonStrToEnum(const std::string& boot_reason) {
return mapping->second;
}
if (boot_reason.empty()) {
return kEmptyBootReason;
}
LOG(INFO) << "Unknown boot reason: " << boot_reason;
return kUnknownBootReason;
}
@ -747,8 +753,16 @@ void RecordBootComplete() {
// 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);