From 243bd187e4aa6ac68a3eb323d07554576d39ad47 Mon Sep 17 00:00:00 2001 From: liqiqiii <132628835+liqiqiii@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:01:31 -0700 Subject: [PATCH] Add debug level prefix for advanced logger memory message entries (#523) # Preface Please ensure you have read the [contribution docs](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md) prior to submitting the pull request. In particular, [pull request guidelines](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md#pull-request-best-practices). ## Description This change added the existing metadata - debug level into the final advanced logger memory entries, it can differentiate the different debug levels, DEBUG_INFO, DEBUG_ERROR, etc. We don't need to touch firmware as debug level info is already part of metadata, so we only need to update the decode script. It's useful to be able to filter out the specific debug level msgs that we care about and make data processing of uefi logs possible. For example, DEBUG_ERROR level prints are generally very important and worth analyzing. One blocking thing now is that we can't tell the difference between different debug level msgs because not all DEBUG_ERROR will have an "error:" as the prefix of the debug msg, and search for "error" will also be noisy as it's a commonly used word. After this PR checked in, we can easily track the DEBUG_ERRORs. For each item, place an "x" in between `[` and `]` if true. Example: `[x]`. _(you can also check items in the GitHub UI)_ - [ ] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested Tested with a platform that uses advancedlogger and can seedebug level prefixes in the msg. 22:36:22.840 : [MM_CORE] [DEBUG_INFO]AdvancedLoggerGetLoggerInfo: LoggerInfo=70F37000 22:36:22.857 : [MM_CORE] [DEBUG_ERROR]ERROR - The FV at 0xFFE60000 is invalid! ## Integration Instructions N/A --------- Co-authored-by: kenlautner <85201046+kenlautner@users.noreply.github.com> --- .../DecodeUefiLog/DecodeUefiLog.py | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/AdvLoggerPkg/Application/DecodeUefiLog/DecodeUefiLog.py b/AdvLoggerPkg/Application/DecodeUefiLog/DecodeUefiLog.py index 4e3c1adc6d..10e0492cdf 100644 --- a/AdvLoggerPkg/Application/DecodeUefiLog/DecodeUefiLog.py +++ b/AdvLoggerPkg/Application/DecodeUefiLog/DecodeUefiLog.py @@ -263,6 +263,59 @@ class AdvLogParser (): PHASE_STRING_LIST = ["[UNSPECIFIED] ", "[SEC] ", "[PEI] ", "[PEI64] ", "[DXE] ", "[RUNTIME] ", "[MM_CORE] ", "[MM] ", "[SMM_CORE] ", "[SMM] ", "[TFA] "] + + # Debug levels from MU_BASECORE\MdePkg\Include\Library\DebugLib.h + # // + # // Declare bits for PcdDebugPrintErrorLevel and the ErrorLevel parameter of DebugPrint() + # // + # #define DEBUG_INIT 0x00000001 // Initialization + # #define DEBUG_WARN 0x00000002 // Warnings + # #define DEBUG_LOAD 0x00000004 // Load events + # #define DEBUG_FS 0x00000008 // EFI File system + # #define DEBUG_POOL 0x00000010 // Alloc & Free (pool) + # #define DEBUG_PAGE 0x00000020 // Alloc & Free (page) + # #define DEBUG_INFO 0x00000040 // Informational debug messages + # #define DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers + # #define DEBUG_VARIABLE 0x00000100 // Variable + # #define DEBUG_SMI 0x00000200 // MS_CHANGE_141550: Added for SMI audting options. + # #define DEBUG_BM 0x00000400 // Boot Manager + # #define DEBUG_BLKIO 0x00001000 // BlkIo Driver + # #define DEBUG_NET 0x00004000 // Network Io Driver + # #define DEBUG_UNDI 0x00010000 // UNDI Driver + # #define DEBUG_LOADFILE 0x00020000 // LoadFile + # #define DEBUG_EVENT 0x00080000 // Event messages + # #define DEBUG_GCD 0x00100000 // Global Coherency Database changes + # #define DEBUG_CACHE 0x00200000 // Memory range cachability changes + # #define DEBUG_VERBOSE 0x00400000 // Detailed debug messages that may + # // significantly impact boot performance + # #define DEBUG_MANAGEABILITY 0x00800000 // Detailed debug and payload message of manageability + # // related modules, such Redfish, IPMI, MCTP and etc. + # #define DEBUG_ERROR 0x80000000 // Error + + debug_levels_dict = { + 0x00000001: "[DEBUG_INIT]", + 0x00000002: "[DEBUG_WARN]", + 0x00000004: "[DEBUG_LOAD]", + 0x00000008: "[DEBUG_FS]", + 0x00000010: "[DEBUG_POOL]", + 0x00000020: "[DEBUG_PAGE]", + 0x00000040: "[DEBUG_INFO]", + 0x00000080: "[DEBUG_DISPATCH]", + 0x00000100: "[DEBUG_VARIABLE]", + 0x00000200: "[DEBUG_SMI]", + 0x00000400: "[DEBUG_BM]", + 0x00001000: "[DEBUG_BLKIO]", + 0x00004000: "[DEBUG_NET]", + 0x00010000: "[DEBUG_UNDI]", + 0x00020000: "[DEBUG_LOADFILE]", + 0x00080000: "[DEBUG_EVENT]", + 0x00100000: "[DEBUG_GCD]", + 0x00200000: "[DEBUG_CACHE]", + 0x00400000: "[DEBUG_VERBOSE]", + 0x00800000: "[DEBUG_MANAGEABILITY]", + 0x80000000: "[DEBUG_ERROR]" + } + # # ---------------------------------------------------------------------- # # @@ -662,6 +715,16 @@ def _GetPhaseString(self, Phase): else: PhaseString = self.PHASE_STRING_LIST[Phase] return PhaseString + + # + # Get the formatted debug level string + # + def _GetDebugLevelString(self, DebugLevel): + if DebugLevel in list(self.debug_levels_dict.keys()): + DebugLevelString = self.debug_levels_dict[DebugLevel] + else: + DebugLevelString = "" + return DebugLevelString # # This helper function will help to identify the @@ -873,7 +936,8 @@ def _GetLines(self, lines, LoggerInfo): if CurrentLine >= StartLine: Ticks = MessageLine["TimeStamp"] PhaseString = self._GetPhaseString(MessageLine["Phase"]) - NewLine = self._GetTimeStamp(Ticks, LoggerInfo["Frequency"], LoggerInfo["BaseTime"]) + PhaseString + MessageLine["Message"].rstrip("\r\n") + DebugLevelString = self._GetDebugLevelString(MessageLine["DebugLevel"]) + NewLine = self._GetTimeStamp(Ticks, LoggerInfo["Frequency"], LoggerInfo["BaseTime"]) + PhaseString + DebugLevelString + MessageLine["Message"].rstrip("\r\n") lines.append(NewLine + '\n') CurrentLine += 1