]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Include/Library/PerformanceLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Include / Library / PerformanceLib.h
index 43e898bfb8ae3d5d5088f2b8c78794aed9bf2b50..34ec956b9c0ee94586dd7a1e12a8cd03f4027e2a 100644 (file)
@@ -1,30 +1,61 @@
 /** @file\r
-  Library that provides services to measure module execution performance\r
+  Provides services to log the execution times and retrieve them later.\r
 \r
-  Copyright (c) 2006, Intel Corporation.\r
-  All rights reserved. This program and the accompanying materials                          \r
-  are licensed and made available under the terms and conditions of the BSD License         \r
-  which accompanies this distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
-\r
-  Module Name:  PerformanceLib.h\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #ifndef __PERFORMANCE_LIB_H__\r
 #define __PERFORMANCE_LIB_H__\r
 \r
+///\r
+/// Performance library propery mask bits\r
+///\r
+#define PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED  0x00000001\r
+\r
 //\r
-// Performance library propery mask bits\r
+// Public Progress Identifiers for Event Records.\r
 //\r
-#define PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED  0x00000001\r
+#define PERF_EVENT_ID  0x00\r
+\r
+#define MODULE_START_ID             0x01\r
+#define MODULE_END_ID               0x02\r
+#define MODULE_LOADIMAGE_START_ID   0x03\r
+#define MODULE_LOADIMAGE_END_ID     0x04\r
+#define MODULE_DB_START_ID          0x05\r
+#define MODULE_DB_END_ID            0x06\r
+#define MODULE_DB_SUPPORT_START_ID  0x07\r
+#define MODULE_DB_SUPPORT_END_ID    0x08\r
+#define MODULE_DB_STOP_START_ID     0x09\r
+#define MODULE_DB_STOP_END_ID       0x0A\r
+\r
+#define PERF_EVENTSIGNAL_START_ID  0x10\r
+#define PERF_EVENTSIGNAL_END_ID    0x11\r
+#define PERF_CALLBACK_START_ID     0x20\r
+#define PERF_CALLBACK_END_ID       0x21\r
+#define PERF_FUNCTION_START_ID     0x30\r
+#define PERF_FUNCTION_END_ID       0x31\r
+#define PERF_INMODULE_START_ID     0x40\r
+#define PERF_INMODULE_END_ID       0x41\r
+#define PERF_CROSSMODULE_START_ID  0x50\r
+#define PERF_CROSSMODULE_END_ID    0x51\r
+\r
+//\r
+// Declare bits for PcdPerformanceLibraryPropertyMask and\r
+// also used as the Type parameter of LogPerformanceMeasurementEnabled().\r
+//\r
+#define PERF_CORE_START_IMAGE  0x0002\r
+#define PERF_CORE_LOAD_IMAGE   0x0004\r
+#define PERF_CORE_DB_SUPPORT   0x0008\r
+#define PERF_CORE_DB_START     0x0010\r
+#define PERF_CORE_DB_STOP      0x0020\r
+\r
+#define PERF_GENERAL_TYPE  0x0040\r
 \r
 /**\r
-  Creates a record for the beginning of a performance measurement. \r
-  \r
+  Creates a record for the beginning of a performance measurement.\r
+\r
   Creates a record that contains the Handle, Token, and Module.\r
   If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
   If TimeStamp is zero, then this function reads the current time stamp\r
 \r
   @retval RETURN_SUCCESS          The start of the measurement was recorded.\r
   @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
+  @retval RETURN_DEVICE_ERROR     A device error reading the time stamp.\r
 \r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
 StartPerformanceMeasurement (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN CONST VOID   *Handle   OPTIONAL,\r
+  IN CONST CHAR8  *Token    OPTIONAL,\r
+  IN CONST CHAR8  *Module   OPTIONAL,\r
   IN UINT64       TimeStamp\r
   );\r
 \r
 /**\r
-  Fills in the end time of a performance measurement. \r
-  \r
+  Fills in the end time of a performance measurement.\r
+\r
   Looks up the record that matches Handle, Token, and Module.\r
   If the record can not be found then return RETURN_NOT_FOUND.\r
   If the record is found and TimeStamp is not zero,\r
   then TimeStamp is added to the record as the end time.\r
   If the record is found and TimeStamp is zero, then this function reads\r
   the current time stamp and adds that time stamp value to the record as the end time.\r
-  If this function is called multiple times for the same record, then the end time is overwritten.\r
 \r
   @param  Handle                  Pointer to environment specific context used\r
                                   to identify the component being measured.\r
@@ -72,20 +103,23 @@ StartPerformanceMeasurement (
 \r
   @retval RETURN_SUCCESS          The end of  the measurement was recorded.\r
   @retval RETURN_NOT_FOUND        The specified measurement record could not be found.\r
+  @retval RETURN_DEVICE_ERROR     A device error reading the time stamp.\r
 \r
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
 EndPerformanceMeasurement (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\r
+  IN CONST VOID   *Handle   OPTIONAL,\r
+  IN CONST CHAR8  *Token    OPTIONAL,\r
+  IN CONST CHAR8  *Module   OPTIONAL,\r
   IN UINT64       TimeStamp\r
   );\r
 \r
 /**\r
-  Attempts to retrieve a performance measurement log entry from the performance measurement log. \r
-  \r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
+  It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
+  and then eliminate the Identifier.\r
+\r
   Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
   zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
   and the key for the second entry in the log is returned.  If the performance log is empty,\r
@@ -107,9 +141,9 @@ EndPerformanceMeasurement (
                                   0, then the first performance measurement log entry is retrieved.\r
                                   On exit, the key of the next performance lof entry entry.\r
   @param  Handle                  Pointer to environment specific context used to identify the component\r
-                                  being measured.  \r
+                                  being measured.\r
   @param  Token                   Pointer to a Null-terminated ASCII string that identifies the component\r
-                                  being measured. \r
+                                  being measured.\r
   @param  Module                  Pointer to a Null-terminated ASCII string that identifies the module\r
                                   being measured.\r
   @param  StartTimeStamp          Pointer to the 64-bit time stamp that was recorded when the measurement\r
@@ -123,17 +157,138 @@ EndPerformanceMeasurement (
 UINTN\r
 EFIAPI\r
 GetPerformanceMeasurement (\r
-  IN  UINTN       LogEntryKey, \r
-  OUT CONST VOID  **Handle,\r
-  OUT CONST CHAR8 **Token,\r
-  OUT CONST CHAR8 **Module,\r
-  OUT UINT64      *StartTimeStamp,\r
-  OUT UINT64      *EndTimeStamp\r
+  IN  UINTN        LogEntryKey,\r
+  OUT CONST VOID   **Handle,\r
+  OUT CONST CHAR8  **Token,\r
+  OUT CONST CHAR8  **Module,\r
+  OUT UINT64       *StartTimeStamp,\r
+  OUT UINT64       *EndTimeStamp\r
+  );\r
+\r
+/**\r
+  Creates a record for the beginning of a performance measurement.\r
+\r
+  Creates a record that contains the Handle, Token, Module and Identifier.\r
+  If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
+  If TimeStamp is zero, then this function reads the current time stamp\r
+  and adds that time stamp value to the record as the start time.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the created record\r
+                                  is same as the one created by StartPerformanceMeasurement.\r
+\r
+  @retval RETURN_SUCCESS          The start of the measurement was recorded.\r
+  @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
+  @retval RETURN_DEVICE_ERROR     A device error reading the time stamp.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+StartPerformanceMeasurementEx (\r
+  IN CONST VOID   *Handle   OPTIONAL,\r
+  IN CONST CHAR8  *Token    OPTIONAL,\r
+  IN CONST CHAR8  *Module   OPTIONAL,\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
+  );\r
+\r
+/**\r
+  Fills in the end time of a performance measurement.\r
+\r
+  Looks up the record that matches Handle, Token and Module.\r
+  If the record can not be found then return RETURN_NOT_FOUND.\r
+  If the record is found and TimeStamp is not zero,\r
+  then TimeStamp is added to the record as the end time.\r
+  If the record is found and TimeStamp is zero, then this function reads\r
+  the current time stamp and adds that time stamp value to the record as the end time.\r
+\r
+  @param  Handle                  Pointer to environment specific context used\r
+                                  to identify the component being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string\r
+                                  that identifies the component being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string\r
+                                  that identifies the module being measured.\r
+  @param  TimeStamp               64-bit time stamp.\r
+  @param  Identifier              32-bit identifier. If the value is 0, the found record\r
+                                  is same as the one found by EndPerformanceMeasurement.\r
+\r
+  @retval RETURN_SUCCESS          The end of  the measurement was recorded.\r
+  @retval RETURN_NOT_FOUND        The specified measurement record could not be found.\r
+  @retval RETURN_DEVICE_ERROR     A device error reading the time stamp.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+EndPerformanceMeasurementEx (\r
+  IN CONST VOID   *Handle   OPTIONAL,\r
+  IN CONST CHAR8  *Token    OPTIONAL,\r
+  IN CONST CHAR8  *Module   OPTIONAL,\r
+  IN UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
+  );\r
+\r
+/**\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
+  It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
+  and then assign the Identifier with 0.\r
+\r
+  Attempts to retrieve the performance log entry specified by LogEntryKey.  If LogEntryKey is\r
+  zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
+  and the key for the second entry in the log is returned.  If the performance log is empty,\r
+  then no entry is retrieved and zero is returned.  If LogEntryKey is not zero, then the performance\r
+  log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
+  returned.  If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
+  retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
+  log is returned.  If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
+  is retrieved and zero is returned.  In the cases where a performance log entry can be returned,\r
+  the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
+  If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
+  If Handle is NULL, then ASSERT().\r
+  If Token is NULL, then ASSERT().\r
+  If Module is NULL, then ASSERT().\r
+  If StartTimeStamp is NULL, then ASSERT().\r
+  If EndTimeStamp is NULL, then ASSERT().\r
+  If Identifier is NULL, then ASSERT().\r
+\r
+  @param  LogEntryKey             On entry, the key of the performance measurement log entry to retrieve.\r
+                                  0, then the first performance measurement log entry is retrieved.\r
+                                  On exit, the key of the next performance of entry entry.\r
+  @param  Handle                  Pointer to environment specific context used to identify the component\r
+                                  being measured.\r
+  @param  Token                   Pointer to a Null-terminated ASCII string that identifies the component\r
+                                  being measured.\r
+  @param  Module                  Pointer to a Null-terminated ASCII string that identifies the module\r
+                                  being measured.\r
+  @param  StartTimeStamp          Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was started.\r
+  @param  EndTimeStamp            Pointer to the 64-bit time stamp that was recorded when the measurement\r
+                                  was ended.\r
+  @param  Identifier              Pointer to the 32-bit identifier that was recorded.\r
+\r
+  @return The key for the next performance log entry (in general case).\r
+\r
+**/\r
+UINTN\r
+EFIAPI\r
+GetPerformanceMeasurementEx (\r
+  IN  UINTN        LogEntryKey,\r
+  OUT CONST VOID   **Handle,\r
+  OUT CONST CHAR8  **Token,\r
+  OUT CONST CHAR8  **Module,\r
+  OUT UINT64       *StartTimeStamp,\r
+  OUT UINT64       *EndTimeStamp,\r
+  OUT UINT32       *Identifier\r
   );\r
 \r
 /**\r
-  Returns TRUE if the performance measurement macros are enabled. \r
-  \r
+  Returns TRUE if the performance measurement macros are enabled.\r
+\r
   This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
   PcdPerformanceLibraryPropertyMask is set.  Otherwise FALSE is returned.\r
 \r
@@ -149,6 +304,372 @@ PerformanceMeasurementEnabled (
   VOID\r
   );\r
 \r
+/**\r
+  Check whether the specified performance measurement can be logged.\r
+\r
+  This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set\r
+  and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.\r
+\r
+  @param Type        - Type of the performance measurement entry.\r
+\r
+  @retval TRUE         The performance measurement can be logged.\r
+  @retval FALSE        The performance measurement can NOT be logged.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LogPerformanceMeasurementEnabled (\r
+  IN  CONST UINTN  Type\r
+  );\r
+\r
+/**\r
+  Create performance record with event description.\r
+\r
+  @param CallerIdentifier - Image handle or pointer to caller ID GUID\r
+  @param Guid             - Pointer to a GUID.\r
+                            Used for event signal perf and callback perf to cache the event guid.\r
+  @param String           - Pointer to a string describing the measurement\r
+  @param Address          - Pointer to a location in memory relevant to the measurement.\r
+  @param Identifier       - Performance identifier describing the type of measurement.\r
+\r
+  @retval RETURN_SUCCESS           - Successfully created performance record\r
+  @retval RETURN_OUT_OF_RESOURCES  - Ran out of space to store the records\r
+  @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
+                                     pointer or invalid Identifier.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LogPerformanceMeasurement (\r
+  IN CONST VOID   *CallerIdentifier  OPTIONAL,\r
+  IN CONST VOID   *Guid     OPTIONAL,\r
+  IN CONST CHAR8  *String   OPTIONAL,\r
+  IN UINT64       Address   OPTIONAL,\r
+  IN UINT32       Identifier\r
+  );\r
+\r
+/**\r
+  Begin Macro to measure the performance of StartImage in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT1 (disable PERF_CORE_START_IMAGE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_START_IMAGE_BEGIN(ModuleHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_START_IMAGE)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of StartImage in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT1 (disable PERF_CORE_START_IMAGE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_START_IMAGE_END(ModuleHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_START_IMAGE)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Begin Macro to measure the performance of LoadImage in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT2 (disable PERF_CORE_LOAD_IMAGE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_LOAD_IMAGE_BEGIN(ModuleHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_LOAD_IMAGE)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_LOADIMAGE_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of LoadImage in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT2 (disable PERF_CORE_LOAD_IMAGE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_LOAD_IMAGE_END(ModuleHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_LOAD_IMAGE)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_LOADIMAGE_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Start Macro to measure the performance of DriverBinding Support in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT3 (disable PERF_CORE_DB_SUPPORT) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_DRIVER_BINDING_SUPPORT_BEGIN(ModuleHandle, ControllerHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_SUPPORT)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_SUPPORT_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of DriverBinding Support in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT3 (disable PERF_CORE_DB_SUPPORT) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_DRIVER_BINDING_SUPPORT_END(ModuleHandle, ControllerHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_SUPPORT)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_SUPPORT_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Begin Macro to measure the performance of DriverBinding Start in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT4 (disable PERF_CORE_DB_START) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_DRIVER_BINDING_START_BEGIN(ModuleHandle, ControllerHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_START)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of DriverBinding Start in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT4 (disable PERF_CORE_DB_START) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_DRIVER_BINDING_START_END(ModuleHandle, ControllerHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_START)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Start Macro to measure the performance of DriverBinding Stop in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT5 (disable PERF_CORE_DB_STOP) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_DRIVER_BINDING_STOP_BEGIN(ModuleHandle, ControllerHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_STOP)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_STOP_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of DriverBinding Stop in core.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT5 (disable PERF_CORE_DB_STOP) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_DRIVER_BINDING_STOP_END(ModuleHandle, ControllerHandle) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_STOP)) { \\r
+      LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_STOP_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Macro to measure the time from power-on to this macro execution.\r
+  It can be used to log a meaningful thing which happens at a time point.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_EVENT(EventString) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, EventString , 0, PERF_EVENT_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Begin Macro to measure the performance of evnent signal behavior in any module.\r
+  The event guid will be passed with this macro.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_EVENT_SIGNAL_BEGIN(EventGuid) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, EventGuid, __FUNCTION__ , 0, PERF_EVENTSIGNAL_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of evnent signal behavior in any module.\r
+  The event guid will be passed with this macro.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_EVENT_SIGNAL_END(EventGuid) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, EventGuid, __FUNCTION__ , 0, PERF_EVENTSIGNAL_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Begin Macro to measure the performance of a callback function in any module.\r
+  The event guid which trigger the callback function will be passed with this macro.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_CALLBACK_BEGIN(TriggerGuid) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, TriggerGuid, __FUNCTION__ , 0, PERF_CALLBACK_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of a callback function in any module.\r
+  The event guid which trigger the callback function will be passed with this macro.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_CALLBACK_END(TriggerGuid) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, TriggerGuid, __FUNCTION__ , 0, PERF_CALLBACK_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Begin Macro to measure the performance of a general function in any module.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_FUNCTION_BEGIN() \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, __FUNCTION__ , 0, PERF_FUNCTION_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of a general function in any module.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_FUNCTION_END() \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, __FUNCTION__ , 0, PERF_FUNCTION_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Begin Macro to measure the performance of a behavior within one module.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_INMODULE_BEGIN(MeasurementString) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_INMODULE_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of a behavior within one module.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_INMODULE_END(MeasurementString) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_INMODULE_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Begin Macro to measure the performance of a behavior in different modules.\r
+  Such as the performance of PEI phase, DXE phase, BDS phase.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_CROSSMODULE_BEGIN(MeasurementString) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_CROSSMODULE_START_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
+/**\r
+  End Macro to measure the performance of a behavior in different modules.\r
+  Such as the performance of PEI phase, DXE phase, BDS phase.\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  and the BIT6 (disable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set,\r
+  then LogPerformanceMeasurement() is called.\r
+\r
+**/\r
+#define PERF_CROSSMODULE_END(MeasurementString) \\r
+  do { \\r
+    if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
+      LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_CROSSMODULE_END_ID); \\r
+    } \\r
+  } while (FALSE)\r
+\r
 /**\r
   Macro that calls EndPerformanceMeasurement().\r
 \r
@@ -177,6 +698,34 @@ PerformanceMeasurementEnabled (
     }                                                                 \\r
   } while (FALSE)\r
 \r
+/**\r
+  Macro that calls EndPerformanceMeasurementEx().\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  then EndPerformanceMeasurementEx() is called.\r
+\r
+**/\r
+#define PERF_END_EX(Handle, Token, Module, TimeStamp, Identifier)                   \\r
+  do {                                                                              \\r
+    if (PerformanceMeasurementEnabled ()) {                                         \\r
+      EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, Identifier);   \\r
+    }                                                                               \\r
+  } while (FALSE)\r
+\r
+/**\r
+  Macro that calls StartPerformanceMeasurementEx().\r
+\r
+  If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
+  then StartPerformanceMeasurementEx() is called.\r
+\r
+**/\r
+#define PERF_START_EX(Handle, Token, Module, TimeStamp, Identifier)                 \\r
+  do {                                                                              \\r
+    if (PerformanceMeasurementEnabled ()) {                                         \\r
+      StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, Identifier); \\r
+    }                                                                               \\r
+  } while (FALSE)\r
+\r
 /**\r
   Macro that marks the beginning of performance measurement source code.\r
 \r
@@ -195,7 +744,7 @@ PerformanceMeasurementEnabled (
   Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.\r
 \r
 **/\r
-#define PERF_CODE_END()    __PerformanceCodeLocal = 0; } } while (FALSE)\r
+#define PERF_CODE_END()  __PerformanceCodeLocal = 0; __PerformanceCodeLocal++; } } while (FALSE)\r
 \r
 /**\r
   Macro that declares a section of performance measurement source code.\r
@@ -212,5 +761,4 @@ PerformanceMeasurementEnabled (
   Expression                   \\r
   PERF_CODE_END ()\r
 \r
-\r
 #endif\r