diff options
author | Mark Salyzyn | 2018-03-16 10:57:20 -0500 |
---|---|---|
committer | Mark Salyzyn | 2018-03-16 12:37:03 -0500 |
commit | 1e7d1c77fa384c0016da66781a5a10a3fd61f85a (patch) | |
tree | 989d3d38685cffe1c0084b1e6d17ae9df783f3b1 /bootstat | |
parent | 2b820536e6e3a0a939ffa34a2ed63523e87166d6 (diff) | |
download | platform-system-core-1e7d1c77fa384c0016da66781a5a10a3fd61f85a.tar.gz platform-system-core-1e7d1c77fa384c0016da66781a5a10a3fd61f85a.tar.xz platform-system-core-1e7d1c77fa384c0016da66781a5a10a3fd61f85a.zip |
bootstat: alias underline to space in bit error rate handling
When we are matching existing known boot reasons, we should try with
compliant underlines first, then again with underlines replaced with
spaces. Replace references to Ber with BitError for maintenance
clarity. Replace helper functions with C++11 lambdas.
Test: boot_reason_test.sh
Bug: 63736262
Change-Id: I91b865013513526a55a85523080c7127f198968c
Diffstat (limited to 'bootstat')
-rw-r--r-- | bootstat/bootstat.cpp | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp index 74ba188c7..4ba430ce3 100644 --- a/bootstat/bootstat.cpp +++ b/bootstat/bootstat.cpp | |||
@@ -468,7 +468,7 @@ class pstoreConsole { | |||
468 | 468 | ||
469 | // If bit error match to needle, correct it. | 469 | // If bit error match to needle, correct it. |
470 | // Return true if any corrections were discovered and applied. | 470 | // Return true if any corrections were discovered and applied. |
471 | bool correctForBer(std::string& reason, const std::string& needle) { | 471 | bool correctForBitError(std::string& reason, const std::string& needle) { |
472 | bool corrected = false; | 472 | bool corrected = false; |
473 | if (reason.length() < needle.length()) return corrected; | 473 | if (reason.length() < needle.length()) return corrected; |
474 | const pstoreConsole console(reason); | 474 | const pstoreConsole console(reason); |
@@ -486,6 +486,20 @@ bool correctForBer(std::string& reason, const std::string& needle) { | |||
486 | return corrected; | 486 | return corrected; |
487 | } | 487 | } |
488 | 488 | ||
489 | // If bit error match to needle, correct it. | ||
490 | // Return true if any corrections were discovered and applied. | ||
491 | // Try again if we can replace underline with spaces. | ||
492 | bool correctForBitErrorOrUnderline(std::string& reason, const std::string& needle) { | ||
493 | bool corrected = correctForBitError(reason, needle); | ||
494 | std::string _needle(needle); | ||
495 | std::transform(_needle.begin(), _needle.end(), _needle.begin(), | ||
496 | [](char c) { return (c == '_') ? ' ' : c; }); | ||
497 | if (needle != _needle) { | ||
498 | corrected |= correctForBitError(reason, _needle); | ||
499 | } | ||
500 | return corrected; | ||
501 | } | ||
502 | |||
489 | bool addKernelPanicSubReason(const pstoreConsole& console, std::string& ret) { | 503 | bool addKernelPanicSubReason(const pstoreConsole& console, std::string& ret) { |
490 | // Check for kernel panic types to refine information | 504 | // Check for kernel panic types to refine information |
491 | if ((console.rfind("SysRq : Trigger a crash") != std::string::npos) || | 505 | if ((console.rfind("SysRq : Trigger a crash") != std::string::npos) || |
@@ -510,22 +524,14 @@ bool addKernelPanicSubReason(const std::string& content, std::string& ret) { | |||
510 | return addKernelPanicSubReason(pstoreConsole(content), ret); | 524 | return addKernelPanicSubReason(pstoreConsole(content), ret); |
511 | } | 525 | } |
512 | 526 | ||
513 | // std::transform Helper callback functions: | ||
514 | // Converts a string value representing the reason the system booted to a | 527 | // Converts a string value representing the reason the system booted to a |
515 | // string complying with Android system standard reason. | 528 | // string complying with Android system standard reason. |
516 | char tounderline(char c) { | ||
517 | return ::isblank(c) ? '_' : c; | ||
518 | } | ||
519 | |||
520 | char toprintable(char c) { | ||
521 | return ::isprint(c) ? c : '?'; | ||
522 | } | ||
523 | |||
524 | // Cleanup boot_reason regarding acceptable character set | ||
525 | void transformReason(std::string& reason) { | 529 | void transformReason(std::string& reason) { |
526 | std::transform(reason.begin(), reason.end(), reason.begin(), ::tolower); | 530 | std::transform(reason.begin(), reason.end(), reason.begin(), ::tolower); |
527 | std::transform(reason.begin(), reason.end(), reason.begin(), tounderline); | 531 | std::transform(reason.begin(), reason.end(), reason.begin(), |
528 | std::transform(reason.begin(), reason.end(), reason.begin(), toprintable); | 532 | [](char c) { return ::isblank(c) ? '_' : c; }); |
533 | std::transform(reason.begin(), reason.end(), reason.begin(), | ||
534 | [](char c) { return ::isprint(c) ? c : '?'; }); | ||
529 | } | 535 | } |
530 | 536 | ||
531 | const char system_reboot_reason_property[] = "sys.boot.reason"; | 537 | const char system_reboot_reason_property[] = "sys.boot.reason"; |
@@ -632,14 +638,14 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { | |||
632 | std::string subReason(content.substr(pos, max_reason_length)); | 638 | std::string subReason(content.substr(pos, max_reason_length)); |
633 | // Correct against any known strings that Bit Error Match | 639 | // Correct against any known strings that Bit Error Match |
634 | for (const auto& s : knownReasons) { | 640 | for (const auto& s : knownReasons) { |
635 | correctForBer(subReason, s); | 641 | correctForBitErrorOrUnderline(subReason, s); |
636 | } | 642 | } |
637 | for (const auto& m : kBootReasonMap) { | 643 | for (const auto& m : kBootReasonMap) { |
638 | if (m.first.length() <= strlen("cold")) continue; // too short? | 644 | if (m.first.length() <= strlen("cold")) continue; // too short? |
639 | if (correctForBer(subReason, m.first + "'")) continue; | 645 | if (correctForBitErrorOrUnderline(subReason, m.first + "'")) continue; |
640 | if (m.first.length() <= strlen("reboot,cold")) continue; // short? | 646 | if (m.first.length() <= strlen("reboot,cold")) continue; // short? |
641 | if (!android::base::StartsWith(m.first, "reboot,")) continue; | 647 | if (!android::base::StartsWith(m.first, "reboot,")) continue; |
642 | correctForBer(subReason, m.first.substr(strlen("reboot,")) + "'"); | 648 | correctForBitErrorOrUnderline(subReason, m.first.substr(strlen("reboot,")) + "'"); |
643 | } | 649 | } |
644 | for (pos = 0; pos < subReason.length(); ++pos) { | 650 | for (pos = 0; pos < subReason.length(); ++pos) { |
645 | char c = subReason[pos]; | 651 | char c = subReason[pos]; |
@@ -687,7 +693,7 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { | |||
687 | if (pos != std::string::npos) { | 693 | if (pos != std::string::npos) { |
688 | digits = content.substr(pos + strlen(battery), strlen("100 ")); | 694 | digits = content.substr(pos + strlen(battery), strlen("100 ")); |
689 | // correct common errors | 695 | // correct common errors |
690 | correctForBer(digits, "100 "); | 696 | correctForBitError(digits, "100 "); |
691 | if (digits[0] == '!') digits[0] = '1'; | 697 | if (digits[0] == '!') digits[0] = '1'; |
692 | if (digits[1] == '!') digits[1] = '1'; | 698 | if (digits[1] == '!') digits[1] = '1'; |
693 | } | 699 | } |