Merge "bootstat: alias underline to space in bit error rate handling"
am: 40858e95b6
Change-Id: I8094305ff1b9610f8726d62476a5d5890f024618
This commit is contained in:
commit
ee3c8e64dc
1 changed files with 23 additions and 17 deletions
|
|
@ -468,7 +468,7 @@ class pstoreConsole {
|
||||||
|
|
||||||
// If bit error match to needle, correct it.
|
// If bit error match to needle, correct it.
|
||||||
// Return true if any corrections were discovered and applied.
|
// Return true if any corrections were discovered and applied.
|
||||||
bool correctForBer(std::string& reason, const std::string& needle) {
|
bool correctForBitError(std::string& reason, const std::string& needle) {
|
||||||
bool corrected = false;
|
bool corrected = false;
|
||||||
if (reason.length() < needle.length()) return corrected;
|
if (reason.length() < needle.length()) return corrected;
|
||||||
const pstoreConsole console(reason);
|
const pstoreConsole console(reason);
|
||||||
|
|
@ -486,6 +486,20 @@ bool correctForBer(std::string& reason, const std::string& needle) {
|
||||||
return corrected;
|
return corrected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If bit error match to needle, correct it.
|
||||||
|
// Return true if any corrections were discovered and applied.
|
||||||
|
// Try again if we can replace underline with spaces.
|
||||||
|
bool correctForBitErrorOrUnderline(std::string& reason, const std::string& needle) {
|
||||||
|
bool corrected = correctForBitError(reason, needle);
|
||||||
|
std::string _needle(needle);
|
||||||
|
std::transform(_needle.begin(), _needle.end(), _needle.begin(),
|
||||||
|
[](char c) { return (c == '_') ? ' ' : c; });
|
||||||
|
if (needle != _needle) {
|
||||||
|
corrected |= correctForBitError(reason, _needle);
|
||||||
|
}
|
||||||
|
return corrected;
|
||||||
|
}
|
||||||
|
|
||||||
bool addKernelPanicSubReason(const pstoreConsole& console, std::string& ret) {
|
bool addKernelPanicSubReason(const pstoreConsole& console, std::string& ret) {
|
||||||
// Check for kernel panic types to refine information
|
// Check for kernel panic types to refine information
|
||||||
if ((console.rfind("SysRq : Trigger a crash") != std::string::npos) ||
|
if ((console.rfind("SysRq : Trigger a crash") != std::string::npos) ||
|
||||||
|
|
@ -510,22 +524,14 @@ bool addKernelPanicSubReason(const std::string& content, std::string& ret) {
|
||||||
return addKernelPanicSubReason(pstoreConsole(content), ret);
|
return addKernelPanicSubReason(pstoreConsole(content), ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::transform Helper callback functions:
|
|
||||||
// Converts a string value representing the reason the system booted to a
|
// Converts a string value representing the reason the system booted to a
|
||||||
// string complying with Android system standard reason.
|
// string complying with Android system standard reason.
|
||||||
char tounderline(char c) {
|
|
||||||
return ::isblank(c) ? '_' : c;
|
|
||||||
}
|
|
||||||
|
|
||||||
char toprintable(char c) {
|
|
||||||
return ::isprint(c) ? c : '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup boot_reason regarding acceptable character set
|
|
||||||
void transformReason(std::string& reason) {
|
void transformReason(std::string& reason) {
|
||||||
std::transform(reason.begin(), reason.end(), reason.begin(), ::tolower);
|
std::transform(reason.begin(), reason.end(), reason.begin(), ::tolower);
|
||||||
std::transform(reason.begin(), reason.end(), reason.begin(), tounderline);
|
std::transform(reason.begin(), reason.end(), reason.begin(),
|
||||||
std::transform(reason.begin(), reason.end(), reason.begin(), toprintable);
|
[](char c) { return ::isblank(c) ? '_' : c; });
|
||||||
|
std::transform(reason.begin(), reason.end(), reason.begin(),
|
||||||
|
[](char c) { return ::isprint(c) ? c : '?'; });
|
||||||
}
|
}
|
||||||
|
|
||||||
const char system_reboot_reason_property[] = "sys.boot.reason";
|
const char system_reboot_reason_property[] = "sys.boot.reason";
|
||||||
|
|
@ -632,14 +638,14 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
|
||||||
std::string subReason(content.substr(pos, max_reason_length));
|
std::string subReason(content.substr(pos, max_reason_length));
|
||||||
// Correct against any known strings that Bit Error Match
|
// Correct against any known strings that Bit Error Match
|
||||||
for (const auto& s : knownReasons) {
|
for (const auto& s : knownReasons) {
|
||||||
correctForBer(subReason, s);
|
correctForBitErrorOrUnderline(subReason, s);
|
||||||
}
|
}
|
||||||
for (const auto& m : kBootReasonMap) {
|
for (const auto& m : kBootReasonMap) {
|
||||||
if (m.first.length() <= strlen("cold")) continue; // too short?
|
if (m.first.length() <= strlen("cold")) continue; // too short?
|
||||||
if (correctForBer(subReason, m.first + "'")) continue;
|
if (correctForBitErrorOrUnderline(subReason, m.first + "'")) continue;
|
||||||
if (m.first.length() <= strlen("reboot,cold")) continue; // short?
|
if (m.first.length() <= strlen("reboot,cold")) continue; // short?
|
||||||
if (!android::base::StartsWith(m.first, "reboot,")) continue;
|
if (!android::base::StartsWith(m.first, "reboot,")) continue;
|
||||||
correctForBer(subReason, m.first.substr(strlen("reboot,")) + "'");
|
correctForBitErrorOrUnderline(subReason, m.first.substr(strlen("reboot,")) + "'");
|
||||||
}
|
}
|
||||||
for (pos = 0; pos < subReason.length(); ++pos) {
|
for (pos = 0; pos < subReason.length(); ++pos) {
|
||||||
char c = subReason[pos];
|
char c = subReason[pos];
|
||||||
|
|
@ -687,7 +693,7 @@ std::string BootReasonStrToReason(const std::string& boot_reason) {
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
digits = content.substr(pos + strlen(battery), strlen("100 "));
|
digits = content.substr(pos + strlen(battery), strlen("100 "));
|
||||||
// correct common errors
|
// correct common errors
|
||||||
correctForBer(digits, "100 ");
|
correctForBitError(digits, "100 ");
|
||||||
if (digits[0] == '!') digits[0] = '1';
|
if (digits[0] == '!') digits[0] = '1';
|
||||||
if (digits[1] == '!') digits[1] = '1';
|
if (digits[1] == '!') digits[1] = '1';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue