]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
index e459513e1508e6d0143481469c398261706509fd..0d507c445210f27a4130cc74c475a18b0f7213db 100644 (file)
 \r
   This library provides the performance measurement interfaces and initializes performance\r
   logging for DXE phase. It first initializes its private global data structure for\r
-  performance logging and saves the performance GUIDed HOB passed from PEI phase. \r
-  It initializes DXE phase performance logging by publishing the Performance Protocol,\r
-  which is consumed by DxePerformanceLib to logging performance data in DXE phase.\r
+  performance logging and saves the performance GUIDed HOB passed from PEI phase.\r
+  It initializes DXE phase performance logging by publishing the Performance and PerformanceEx Protocol,\r
+  which are consumed by DxePerformanceLib to logging performance data in DXE phase.\r
 \r
   This library is mainly used by DxeCore to start performance logging to ensure that\r
   Performance Protocol is installed at the very beginning of DXE phase.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
-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
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
 #include "DxeCorePerformanceLibInternal.h"\r
 \r
-\r
-//\r
-// The data structure to hold global performance data.\r
-//\r
-GAUGE_DATA_HEADER    *mGaugeData;\r
-\r
-//\r
-// The current maximum number of logging entries. If current number of \r
-// entries exceeds this value, it will re-allocate a larger array and\r
-// migration the old data to the larger array.\r
-//\r
-UINT32               mMaxGaugeRecords;\r
-\r
 //\r
-// The handle to install Performance Protocol instance.\r
+// Data for FPDT performance records.\r
 //\r
-EFI_HANDLE           mHandle = NULL;\r
+#define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))\r
+#define STRING_SIZE             (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))\r
+#define FIRMWARE_RECORD_BUFFER  0x10000\r
+#define CACHE_HANDLE_GUID_COUNT 0x800\r
+\r
+BOOT_PERFORMANCE_TABLE          *mAcpiBootPerformanceTable = NULL;\r
+BOOT_PERFORMANCE_TABLE          mBootPerformanceTableTemplate = {\r
+  {\r
+    EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE,\r
+    sizeof (BOOT_PERFORMANCE_TABLE)\r
+  },\r
+  {\r
+    {\r
+      EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT,    // Type\r
+      sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD),        // Length\r
+      EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT // Revision\r
+    },\r
+    0,  // Reserved\r
+    //\r
+    // These values will be updated at runtime.\r
+    //\r
+    0,  // ResetEnd\r
+    0,  // OsLoaderLoadImageStart\r
+    0,  // OsLoaderStartImageStart\r
+    0,  // ExitBootServicesEntry\r
+    0   // ExitBootServicesExit\r
+  }\r
+};\r
+\r
+typedef struct {\r
+  EFI_HANDLE    Handle;\r
+  CHAR8         NameString[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];\r
+  EFI_GUID      ModuleGuid;\r
+} HANDLE_GUID_MAP;\r
+\r
+HANDLE_GUID_MAP mCacheHandleGuidTable[CACHE_HANDLE_GUID_COUNT];\r
+UINTN           mCachePairCount = 0;\r
+\r
+UINT32  mLoadImageCount       = 0;\r
+UINT32  mPerformanceLength    = 0;\r
+UINT32  mMaxPerformanceLength = 0;\r
+UINT32  mBootRecordSize       = 0;\r
+UINT32  mBootRecordMaxSize    = 0;\r
+UINT32  mCachedLength         = 0;\r
+\r
+BOOLEAN mFpdtBufferIsReported = FALSE;\r
+BOOLEAN mLackSpaceIsReported  = FALSE;\r
+CHAR8   *mPlatformLanguage    = NULL;\r
+UINT8   *mPerformancePointer  = NULL;\r
+UINT8   *mBootRecordBuffer    = NULL;\r
+BOOLEAN  mLockInsertRecord    = FALSE;\r
+CHAR8   *mDevicePathString    = NULL;\r
+\r
+EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *mDevicePathToText = NULL;\r
 \r
 //\r
-// Interfaces for performance protocol.\r
+// Interfaces for PerformanceMeasurement Protocol.\r
 //\r
-PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
-  StartGauge,\r
-  EndGauge,\r
-  GetGauge\r
+EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {\r
+  CreatePerformanceMeasurement,\r
   };\r
 \r
+PERFORMANCE_PROPERTY  mPerformanceProperty;\r
+\r
 /**\r
-  Searches in the gauge array with keyword Handle, Token and Module.\r
+  Return the pointer to the FPDT record in the allocated memory.\r
 \r
-  This internal function searches for the gauge entry in the gauge array.\r
-  If there is an entry that exactly matches the given key word triple\r
-  and its end time stamp is zero, then the index of that gauge entry is returned;\r
-  otherwise, the the number of gauge entries in the array is returned.\r
+  @param  RecordSize             The size of FPDT record.\r
+  @param  FpdtRecordPtr          Pointer the FPDT record in the allocated memory.\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
+  @retval EFI_SUCCESS            Successfully get the pointer to the FPDT record.\r
+  @retval EFI_OUT_OF_RESOURCES   Ran out of space to store the records.\r
+**/\r
+EFI_STATUS\r
+GetFpdtRecordPtr (\r
+  IN     UINT8               RecordSize,\r
+  IN OUT FPDT_RECORD_PTR     *FpdtRecordPtr\r
+)\r
+{\r
+  if (mFpdtBufferIsReported) {\r
+    //\r
+    // Append Boot records to the boot performance table.\r
+    //\r
+    if (mBootRecordSize + RecordSize > mBootRecordMaxSize) {\r
+      if (!mLackSpaceIsReported) {\r
+        DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: No enough space to save boot records\n"));\r
+        mLackSpaceIsReported = TRUE;\r
+      }\r
+      return EFI_OUT_OF_RESOURCES;\r
+    } else {\r
+      //\r
+      // Save boot record into BootPerformance table\r
+      //\r
+      FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mBootRecordSize);\r
+    }\r
+  } else {\r
+    //\r
+    // Check if pre-allocated buffer is full\r
+    //\r
+    if (mPerformanceLength + RecordSize > mMaxPerformanceLength) {\r
+      mPerformancePointer = ReallocatePool (\r
+                              mPerformanceLength,\r
+                              mPerformanceLength + RecordSize + FIRMWARE_RECORD_BUFFER,\r
+                              mPerformancePointer\r
+                              );\r
+      if (mPerformancePointer == NULL) {\r
+         return EFI_OUT_OF_RESOURCES;\r
+       }\r
+      mMaxPerformanceLength = mPerformanceLength + RecordSize + FIRMWARE_RECORD_BUFFER;\r
+    }\r
+    //\r
+    // Covert buffer to FPDT Ptr Union type.\r
+    //\r
+    FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mPerformanceLength);\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+Check whether the Token is a known one which is uesed by core.\r
 \r
-  @retval The index of gauge entry in the array.\r
+@param  Token      Pointer to a Null-terminated ASCII string\r
+\r
+@retval TRUE       Is a known one used by core.\r
+@retval FALSE      Not a known one.\r
 \r
 **/\r
-UINT32\r
-InternalSearchForGaugeEntry (\r
-  IN CONST VOID                 *Handle,  OPTIONAL\r
-  IN CONST CHAR8                *Token,   OPTIONAL\r
-  IN CONST CHAR8                *Module   OPTIONAL\r
+BOOLEAN\r
+IsKnownTokens (\r
+  IN CONST CHAR8  *Token\r
   )\r
 {\r
-  UINT32                    Index;\r
-  UINT32                    NumberOfEntries;\r
-  GAUGE_DATA_ENTRY          *GaugeEntryArray;\r
-\r
   if (Token == NULL) {\r
-    Token = "";\r
+    return FALSE;\r
   }\r
-  if (Module == NULL) {\r
-    Module = "";\r
+\r
+  if (AsciiStrCmp (Token, SEC_TOK) == 0 ||\r
+      AsciiStrCmp (Token, PEI_TOK) == 0 ||\r
+      AsciiStrCmp (Token, DXE_TOK) == 0 ||\r
+      AsciiStrCmp (Token, BDS_TOK) == 0 ||\r
+      AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||\r
+      AsciiStrCmp (Token, DRIVERBINDING_SUPPORT_TOK) == 0 ||\r
+      AsciiStrCmp (Token, DRIVERBINDING_STOP_TOK) == 0 ||\r
+      AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0 ||\r
+      AsciiStrCmp (Token, START_IMAGE_TOK) == 0 ||\r
+      AsciiStrCmp (Token, PEIM_TOK) == 0) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
   }\r
+}\r
 \r
-  NumberOfEntries = mGaugeData->NumberOfEntries;\r
-  GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+/**\r
+Check whether the ID is a known one which map to the known Token.\r
 \r
-  for (Index = 0; Index < NumberOfEntries; Index++) {\r
-    if ((GaugeEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
-         AsciiStrnCmp (GaugeEntryArray[Index].Token, Token, DXE_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-         AsciiStrnCmp (GaugeEntryArray[Index].Module, Module, DXE_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-         GaugeEntryArray[Index].EndTimeStamp == 0\r
-       ) {\r
-      break;\r
-    }\r
-  }\r
+@param  Identifier  32-bit identifier.\r
+\r
+@retval TRUE        Is a known one used by core.\r
+@retval FALSE       Not a known one.\r
 \r
-  return Index;\r
+**/\r
+BOOLEAN\r
+IsKnownID (\r
+  IN UINT32       Identifier\r
+  )\r
+{\r
+  if (Identifier == MODULE_START_ID ||\r
+      Identifier == MODULE_END_ID ||\r
+      Identifier == MODULE_LOADIMAGE_START_ID ||\r
+      Identifier == MODULE_LOADIMAGE_END_ID ||\r
+      Identifier == MODULE_DB_START_ID ||\r
+      Identifier == MODULE_DB_END_ID ||\r
+      Identifier == MODULE_DB_SUPPORT_START_ID ||\r
+      Identifier == MODULE_DB_SUPPORT_END_ID ||\r
+      Identifier == MODULE_DB_STOP_START_ID ||\r
+      Identifier == MODULE_DB_STOP_END_ID) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
 }\r
 \r
 /**\r
-  Adds a record at the end of the performance measurement log\r
-  that records the start time of a performance measurement.\r
+  Allocate buffer for Boot Performance table.\r
 \r
-  Adds a record to the end of the performance measurement log\r
-  that contains the Handle, Token, and Module.\r
-  The end time of the new record must be set to zero.\r
-  If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
-  If TimeStamp is zero, the start time in the record is filled in with the value\r
-  read from the current time stamp.\r
+  @return Status code.\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
+**/\r
+EFI_STATUS\r
+AllocateBootPerformanceTable (\r
+  )\r
+{\r
+  EFI_STATUS                              Status;\r
+  UINTN                                   Size;\r
+  UINT8                                   *SmmBootRecordCommBuffer;\r
+  EFI_SMM_COMMUNICATE_HEADER              *SmmCommBufferHeader;\r
+  SMM_BOOT_RECORD_COMMUNICATE             *SmmCommData;\r
+  UINTN                                   CommSize;\r
+  UINTN                                   BootPerformanceDataSize;\r
+  UINT8                                   *BootPerformanceData;\r
+  EFI_SMM_COMMUNICATION_PROTOCOL          *Communication;\r
+  FIRMWARE_PERFORMANCE_VARIABLE           PerformanceVariable;\r
+  EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *SmmCommRegionTable;\r
+  EFI_MEMORY_DESCRIPTOR                   *SmmCommMemRegion;\r
+  UINTN                                   Index;\r
+  VOID                                    *SmmBootRecordData;\r
+  UINTN                                   SmmBootRecordDataSize;\r
+  UINTN                                   ReservedMemSize;\r
 \r
-  @retval EFI_SUCCESS             The data was read correctly from the device.\r
-  @retval EFI_OUT_OF_RESOURCES    There are not enough resources to record the measurement.\r
+  //\r
+  // Collect boot records from SMM drivers.\r
+  //\r
+  SmmBootRecordCommBuffer = NULL;\r
+  SmmCommData             = NULL;\r
+  SmmBootRecordData       = NULL;\r
+  SmmBootRecordDataSize   = 0;\r
+  ReservedMemSize         = 0;\r
+  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Initialize communicate buffer\r
+    // Get the prepared Reserved Memory Range\r
+    //\r
+    Status = EfiGetSystemConfigurationTable (\r
+              &gEdkiiPiSmmCommunicationRegionTableGuid,\r
+              (VOID **) &SmmCommRegionTable\r
+              );\r
+    if (!EFI_ERROR (Status)) {\r
+      ASSERT (SmmCommRegionTable != NULL);\r
+      SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) (SmmCommRegionTable + 1);\r
+      for (Index = 0; Index < SmmCommRegionTable->NumberOfEntries; Index ++) {\r
+        if (SmmCommMemRegion->Type == EfiConventionalMemory) {\r
+          break;\r
+        }\r
+        SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) SmmCommMemRegion + SmmCommRegionTable->DescriptorSize);\r
+      }\r
+      ASSERT (Index < SmmCommRegionTable->NumberOfEntries);\r
+      ASSERT (SmmCommMemRegion->PhysicalStart > 0);\r
+      ASSERT (SmmCommMemRegion->NumberOfPages > 0);\r
+      ReservedMemSize = (UINTN) SmmCommMemRegion->NumberOfPages * EFI_PAGE_SIZE;\r
+\r
+      //\r
+      // Check enough reserved memory space\r
+      //\r
+      if (ReservedMemSize > SMM_BOOT_RECORD_COMM_SIZE) {\r
+        SmmBootRecordCommBuffer = (VOID *) (UINTN) SmmCommMemRegion->PhysicalStart;\r
+        SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER*)SmmBootRecordCommBuffer;\r
+        SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE*)SmmCommBufferHeader->Data;\r
+        ZeroMem((UINT8*)SmmCommData, sizeof(SMM_BOOT_RECORD_COMMUNICATE));\r
+\r
+        CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid);\r
+        SmmCommBufferHeader->MessageLength = sizeof(SMM_BOOT_RECORD_COMMUNICATE);\r
+        CommSize = SMM_BOOT_RECORD_COMM_SIZE;\r
+\r
+        //\r
+        // Get the size of boot records.\r
+        //\r
+        SmmCommData->Function       = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE;\r
+        SmmCommData->BootRecordData = NULL;\r
+        Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
+\r
+        if (!EFI_ERROR (Status) && !EFI_ERROR (SmmCommData->ReturnStatus) && SmmCommData->BootRecordSize != 0) {\r
+          //\r
+          // Get all boot records\r
+          //\r
+          SmmCommData->Function       = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET;\r
+          SmmBootRecordDataSize       = SmmCommData->BootRecordSize;\r
+          SmmBootRecordData           = AllocateZeroPool(SmmBootRecordDataSize);\r
+          ASSERT (SmmBootRecordData  != NULL);\r
+          SmmCommData->BootRecordOffset = 0;\r
+          SmmCommData->BootRecordData   = (VOID *) ((UINTN) SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);\r
+          SmmCommData->BootRecordSize   = ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE;\r
+          while (SmmCommData->BootRecordOffset < SmmBootRecordDataSize) {\r
+            Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
+            ASSERT_EFI_ERROR (Status);\r
+            ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);\r
+            if (SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {\r
+              CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmBootRecordDataSize - SmmCommData->BootRecordOffset);\r
+            } else {\r
+              CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);\r
+            }\r
+            SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
 \r
+  //\r
+  // Prepare memory for Boot Performance table.\r
+  // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.\r
+  //\r
+  BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mPerformanceLength + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
+  if (SmmCommData != NULL && SmmBootRecordData != NULL) {\r
+    BootPerformanceDataSize += SmmBootRecordDataSize;\r
+  }\r
+\r
+  //\r
+  // Try to allocate the same runtime buffer as last time boot.\r
+  //\r
+  ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));\r
+  Size = sizeof (PerformanceVariable);\r
+  Status = gRT->GetVariable (\r
+                  EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
+                  &gEfiFirmwarePerformanceGuid,\r
+                  NULL,\r
+                  &Size,\r
+                  &PerformanceVariable\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->AllocatePages (\r
+                    AllocateAddress,\r
+                    EfiReservedMemoryType,\r
+                    EFI_SIZE_TO_PAGES (BootPerformanceDataSize),\r
+                    &PerformanceVariable.BootPerformanceTablePointer\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer;\r
+    }\r
+  }\r
+\r
+  if (mAcpiBootPerformanceTable == NULL) {\r
+    //\r
+    // Fail to allocate at specified address, continue to allocate at any address.\r
+    //\r
+    mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (\r
+                                                             EfiReservedMemoryType,\r
+                                                             EFI_SIZE_TO_PAGES (BootPerformanceDataSize)\r
+                                                             );\r
+    if (mAcpiBootPerformanceTable != NULL) {\r
+      ZeroMem (mAcpiBootPerformanceTable, BootPerformanceDataSize);\r
+    }\r
+  }\r
+  DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
+\r
+  if (mAcpiBootPerformanceTable == NULL) {\r
+    if (SmmCommData != NULL && SmmBootRecordData != NULL) {\r
+      FreePool (SmmBootRecordData);\r
+    }\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Prepare Boot Performance Table.\r
+  //\r
+  BootPerformanceData = (UINT8 *) mAcpiBootPerformanceTable;\r
+  //\r
+  // Fill Basic Boot record to Boot Performance Table.\r
+  //\r
+  CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));\r
+  BootPerformanceData = BootPerformanceData + mAcpiBootPerformanceTable->Header.Length;\r
+  //\r
+  // Fill Boot records from boot drivers.\r
+  //\r
+  if (mPerformancePointer != NULL) {\r
+    CopyMem (BootPerformanceData, mPerformancePointer, mPerformanceLength);\r
+    mAcpiBootPerformanceTable->Header.Length += mPerformanceLength;\r
+    BootPerformanceData = BootPerformanceData + mPerformanceLength;\r
+    FreePool (mPerformancePointer);\r
+    mPerformancePointer   = NULL;\r
+    mPerformanceLength    = 0;\r
+    mMaxPerformanceLength = 0;\r
+  }\r
+  if (SmmCommData != NULL && SmmBootRecordData != NULL) {\r
+    //\r
+    // Fill Boot records from SMM drivers.\r
+    //\r
+    CopyMem (BootPerformanceData, SmmBootRecordData, SmmBootRecordDataSize);\r
+    FreePool (SmmBootRecordData);\r
+    mAcpiBootPerformanceTable->Header.Length = (UINT32) (mAcpiBootPerformanceTable->Header.Length + SmmBootRecordDataSize);\r
+    BootPerformanceData = BootPerformanceData + SmmBootRecordDataSize;\r
+  }\r
+\r
+  mBootRecordBuffer  = (UINT8 *) mAcpiBootPerformanceTable;\r
+  mBootRecordSize    = mAcpiBootPerformanceTable->Header.Length;\r
+  mBootRecordMaxSize = mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Get a human readable module name and module guid for the given image handle.\r
+  If module name can't be found, "" string will return.\r
+  If module guid can't be found, Zero Guid will return.\r
+\r
+  @param    Handle        Image handle or Controller handle.\r
+  @param    NameString    The ascii string will be filled into it. If not found, null string will return.\r
+  @param    BufferSize    Size of the input NameString buffer.\r
+  @param    ModuleGuid    Point to the guid buffer to store the got module guid value.\r
+\r
+  @retval EFI_SUCCESS     Successfully get module name and guid.\r
+  @retval EFI_INVALID_PARAMETER  The input parameter NameString is NULL.\r
+  @retval other value  Module Name can't be got.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-StartGauge (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+GetModuleInfoFromHandle (\r
+  IN EFI_HANDLE  Handle,\r
+  OUT CHAR8            *NameString,\r
+  IN UINTN             BufferSize,\r
+  OUT EFI_GUID         *ModuleGuid OPTIONAL\r
   )\r
 {\r
-  GAUGE_DATA_ENTRY          *GaugeEntryArray;\r
-  UINTN                     GaugeDataSize;\r
-  UINTN                     OldGaugeDataSize;\r
-  GAUGE_DATA_HEADER         *OldGaugeData;\r
-  UINT32                    Index;\r
+  EFI_STATUS                  Status;\r
+  EFI_LOADED_IMAGE_PROTOCOL   *LoadedImage;\r
+  EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;\r
+  CHAR8                       *PdbFileName;\r
+  EFI_GUID                    *TempGuid;\r
+  UINTN                       StartIndex;\r
+  UINTN                       Index;\r
+  INTN                        Count;\r
+  BOOLEAN                     ModuleGuidIsGet;\r
+  UINTN                       StringSize;\r
+  CHAR16                      *StringPtr;\r
+  EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;\r
+  MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;\r
+\r
+  if (NameString == NULL || BufferSize == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Try to get the ModuleGuid and name string form the caached array.\r
+  //\r
+  if (mCachePairCount > 0) {\r
+    for (Count = mCachePairCount -1; Count >= 0; Count--) {\r
+      if (Handle == mCacheHandleGuidTable[Count].Handle) {\r
+        CopyGuid (ModuleGuid, &mCacheHandleGuidTable[Count].ModuleGuid);\r
+        AsciiStrCpyS (NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, mCacheHandleGuidTable[Count].NameString);\r
+        return EFI_SUCCESS;\r
+      }\r
+    }\r
+  }\r
+\r
+  Status = EFI_INVALID_PARAMETER;\r
+  LoadedImage     = NULL;\r
+  ModuleGuidIsGet = FALSE;\r
 \r
-  Index = mGaugeData->NumberOfEntries;\r
-  if (Index >= mMaxGaugeRecords) {\r
+  //\r
+  // Initialize GUID as zero value.\r
+  //\r
+  TempGuid    = &gZeroGuid;\r
+  //\r
+  // Initialize it as "" string.\r
+  //\r
+  NameString[0] = 0;\r
+\r
+  if (Handle != NULL) {\r
     //\r
-    // Try to enlarge the scale of gauge array.\r
+    // Try Handle as ImageHandle.\r
     //\r
-    OldGaugeData      = mGaugeData;\r
-    OldGaugeDataSize  = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
-\r
-    mMaxGaugeRecords *= 2;\r
-    GaugeDataSize     = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
+    Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID**) &LoadedImage\r
+                  );\r
 \r
-    mGaugeData = AllocateZeroPool (GaugeDataSize);\r
-    if (mGaugeData == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Try Handle as Controller Handle\r
+      //\r
+      Status = gBS->OpenProtocol (\r
+                    Handle,\r
+                    &gEfiDriverBindingProtocolGuid,\r
+                    (VOID **) &DriverBinding,\r
+                    NULL,\r
+                    NULL,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+      if (!EFI_ERROR (Status)) {\r
+        //\r
+        // Get Image protocol from ImageHandle\r
+        //\r
+        Status = gBS->HandleProtocol (\r
+                      DriverBinding->ImageHandle,\r
+                      &gEfiLoadedImageProtocolGuid,\r
+                      (VOID**) &LoadedImage\r
+                      );\r
+      }\r
     }\r
+  }\r
+\r
+  if (!EFI_ERROR (Status) && LoadedImage != NULL) {\r
     //\r
-    // Initialize new data array and migrate old data one.\r
+    // Get Module Guid from DevicePath.\r
     //\r
-    mGaugeData = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);\r
+    if (LoadedImage->FilePath != NULL &&\r
+        LoadedImage->FilePath->Type == MEDIA_DEVICE_PATH &&\r
+        LoadedImage->FilePath->SubType == MEDIA_PIWG_FW_FILE_DP\r
+       ) {\r
+      //\r
+      // Determine GUID associated with module logging performance\r
+      //\r
+      ModuleGuidIsGet = TRUE;\r
+      FvFilePath      = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LoadedImage->FilePath;\r
+      TempGuid        = &FvFilePath->FvFileName;\r
+    }\r
 \r
-    FreePool (OldGaugeData);\r
+    //\r
+    // Method 1 Get Module Name from PDB string.\r
+    //\r
+    PdbFileName = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);\r
+    if (PdbFileName != NULL && BufferSize > 0) {\r
+      StartIndex = 0;\r
+      for (Index = 0; PdbFileName[Index] != 0; Index++) {\r
+        if ((PdbFileName[Index] == '\\') || (PdbFileName[Index] == '/')) {\r
+          StartIndex = Index + 1;\r
+        }\r
+      }\r
+      //\r
+      // Copy the PDB file name to our temporary string.\r
+      // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.\r
+      //\r
+      for (Index = 0; Index < BufferSize - 1; Index++) {\r
+        NameString[Index] = PdbFileName[Index + StartIndex];\r
+        if (NameString[Index] == 0 || NameString[Index] == '.') {\r
+          NameString[Index] = 0;\r
+          break;\r
+        }\r
+      }\r
+\r
+      if (Index == BufferSize - 1) {\r
+        NameString[Index] = 0;\r
+      }\r
+      //\r
+      // Module Name is got.\r
+      //\r
+      goto Done;\r
+    }\r
   }\r
 \r
-  GaugeEntryArray               = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
-  GaugeEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
+  //\r
+  // Method 2: Get the name string from ComponentName2 protocol\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  (VOID **) &ComponentName2\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Get the current platform language setting\r
+    //\r
+    if (mPlatformLanguage == NULL) {\r
+      GetEfiGlobalVariable2 (L"PlatformLang", (VOID **) &mPlatformLanguage, NULL);\r
+    }\r
+    if (mPlatformLanguage != NULL) {\r
+      Status = ComponentName2->GetDriverName (\r
+                                 ComponentName2,\r
+                                 mPlatformLanguage != NULL ? mPlatformLanguage : "en-US",\r
+                                 &StringPtr\r
+                                 );\r
+      if (!EFI_ERROR (Status)) {\r
+        for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {\r
+          NameString[Index] = (CHAR8) StringPtr[Index];\r
+        }\r
+        NameString[Index] = 0;\r
+        //\r
+        // Module Name is got.\r
+        //\r
+        goto Done;\r
+      }\r
+    }\r
+  }\r
 \r
-  if (Token != NULL) {\r
-    AsciiStrnCpy (GaugeEntryArray[Index].Token, Token, DXE_PERFORMANCE_STRING_LENGTH);\r
+  if (ModuleGuidIsGet) {\r
+    //\r
+    // Method 3 Try to get the image's FFS UI section by image GUID\r
+    //\r
+    StringPtr  = NULL;\r
+    StringSize = 0;\r
+    Status = GetSectionFromAnyFv (\r
+              TempGuid,\r
+              EFI_SECTION_USER_INTERFACE,\r
+              0,\r
+              (VOID **) &StringPtr,\r
+              &StringSize\r
+              );\r
+\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Method 3. Get the name string from FFS UI section\r
+      //\r
+      for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {\r
+        NameString[Index] = (CHAR8) StringPtr[Index];\r
+      }\r
+      NameString[Index] = 0;\r
+      FreePool (StringPtr);\r
+    }\r
   }\r
-  if (Module != NULL) {\r
-    AsciiStrnCpy (GaugeEntryArray[Index].Module, Module, DXE_PERFORMANCE_STRING_LENGTH);\r
+\r
+Done:\r
+  //\r
+  // Copy Module Guid\r
+  //\r
+  if (ModuleGuid != NULL) {\r
+    CopyGuid (ModuleGuid, TempGuid);\r
+    if (IsZeroGuid(TempGuid) && (Handle != NULL) && !ModuleGuidIsGet) {\r
+        // Handle is GUID\r
+      CopyGuid (ModuleGuid, (EFI_GUID *) Handle);\r
+    }\r
   }\r
 \r
-  if (TimeStamp == 0) {\r
-    TimeStamp = GetPerformanceCounter ();\r
+  //\r
+  // Cache the Handle and Guid pairs.\r
+  //\r
+  if (mCachePairCount < CACHE_HANDLE_GUID_COUNT) {\r
+    mCacheHandleGuidTable[mCachePairCount].Handle = Handle;\r
+    CopyGuid (&mCacheHandleGuidTable[mCachePairCount].ModuleGuid, ModuleGuid);\r
+    AsciiStrCpyS (mCacheHandleGuidTable[mCachePairCount].NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, NameString);\r
+    mCachePairCount ++;\r
   }\r
-  GaugeEntryArray[Index].StartTimeStamp = TimeStamp;\r
 \r
-  mGaugeData->NumberOfEntries++;\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Get the FPDT record identifier.\r
+\r
+  @param Attribute                The attribute of the Record.\r
+                                  PerfStartEntry: Start Record.\r
+                                  PerfEndEntry: End Record.\r
+  @param  Handle                  Pointer to environment specific context used to identify the component being measured.\r
+  @param  String                  Pointer to a Null-terminated ASCII string that identifies the component being measured.\r
+  @param  ProgressID              On return, pointer to the ProgressID.\r
 \r
+  @retval EFI_SUCCESS              Get record info successfully.\r
+  @retval EFI_INVALID_PARAMETER    No matched FPDT record.\r
+\r
+**/\r
+EFI_STATUS\r
+GetFpdtRecordId (\r
+  IN       PERF_MEASUREMENT_ATTRIBUTE  Attribute,\r
+  IN CONST VOID                       *Handle,\r
+  IN CONST CHAR8                      *String,\r
+  OUT UINT16                          *ProgressID\r
+  )\r
+{\r
+  //\r
+  // Token to PerfId.\r
+  //\r
+  if (String != NULL) {\r
+    if (AsciiStrCmp (String, START_IMAGE_TOK) == 0) {                // "StartImage:"\r
+      if (Attribute == PerfStartEntry) {\r
+        *ProgressID  = MODULE_START_ID;\r
+      } else {\r
+        *ProgressID  = MODULE_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (String, LOAD_IMAGE_TOK) == 0) {          // "LoadImage:"\r
+      if (Attribute == PerfStartEntry) {\r
+        *ProgressID  = MODULE_LOADIMAGE_START_ID;\r
+      } else {\r
+        *ProgressID  = MODULE_LOADIMAGE_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (String, DRIVERBINDING_START_TOK) == 0) {  // "DB:Start:"\r
+      if (Attribute == PerfStartEntry) {\r
+        *ProgressID  = MODULE_DB_START_ID;\r
+      } else {\r
+        *ProgressID  = MODULE_DB_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (String, DRIVERBINDING_SUPPORT_TOK) == 0) { // "DB:Support:"\r
+      if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+        return RETURN_UNSUPPORTED;\r
+      }\r
+      if (Attribute == PerfStartEntry) {\r
+        *ProgressID  = MODULE_DB_SUPPORT_START_ID;\r
+      } else {\r
+        *ProgressID  = MODULE_DB_SUPPORT_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (String, DRIVERBINDING_STOP_TOK) == 0) {    // "DB:Stop:"\r
+      if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+         return RETURN_UNSUPPORTED;\r
+      }\r
+      if (Attribute == PerfStartEntry) {\r
+        *ProgressID  = MODULE_DB_STOP_START_ID;\r
+      } else {\r
+        *ProgressID  = MODULE_DB_STOP_END_ID;\r
+      }\r
+    } else if (AsciiStrCmp (String, PEI_TOK) == 0 ||                   // "PEI"\r
+               AsciiStrCmp (String, DXE_TOK) == 0 ||                   // "DXE"\r
+               AsciiStrCmp (String, BDS_TOK) == 0) {                   // "BDS"\r
+      if (Attribute == PerfStartEntry) {\r
+        *ProgressID  = PERF_CROSSMODULE_START_ID;\r
+      } else {\r
+        *ProgressID  = PERF_CROSSMODULE_END_ID;\r
+      }\r
+    } else {                                                          // Pref used in Modules.\r
+      if (Attribute == PerfStartEntry) {\r
+        *ProgressID  = PERF_INMODULE_START_ID;\r
+      } else {\r
+        *ProgressID  = PERF_INMODULE_END_ID;\r
+      }\r
+    }\r
+  } else if (Handle!= NULL) {                                         // Pref used in Modules.\r
+    if (Attribute == PerfStartEntry) {\r
+      *ProgressID    = PERF_INMODULE_START_ID;\r
+    } else {\r
+      *ProgressID    = PERF_INMODULE_END_ID;\r
+    }\r
+  } else {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Searches the performance measurement log from the beginning of the log\r
-  for the first matching record that contains a zero end time and fills in a valid end time.\r
+  Copies the string from Source into Destination and updates Length with the\r
+  size of the string.\r
 \r
-  Searches the performance measurement log from the beginning of the log\r
-  for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
-  If the record can not be found then return EFI_NOT_FOUND.\r
-  If the record is found and TimeStamp is not zero,\r
-  then the end time in the record is filled in with the value specified by TimeStamp.\r
-  If the record is found and TimeStamp is zero, then the end time in the matching record\r
-  is filled in with the current time stamp value.\r
+  @param Destination - destination of the string copy\r
+  @param Source      - pointer to the source string which will get copied\r
+  @param Length      - pointer to a length variable to be updated\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
+**/\r
+VOID\r
+CopyStringIntoPerfRecordAndUpdateLength (\r
+  IN OUT CHAR8  *Destination,\r
+  IN     CONST CHAR8  *Source,\r
+  IN OUT UINT8  *Length\r
+  )\r
+{\r
+  UINTN  StringLen;\r
+  UINTN  DestMax;\r
+\r
+  ASSERT (Source != NULL);\r
+\r
+  if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+    DestMax = STRING_SIZE;\r
+  } else {\r
+    DestMax = AsciiStrSize (Source);\r
+    if (DestMax > STRING_SIZE) {\r
+      DestMax = STRING_SIZE;\r
+    }\r
+  }\r
+  StringLen = AsciiStrLen (Source);\r
+  if (StringLen >= DestMax) {\r
+    StringLen = DestMax -1;\r
+  }\r
+\r
+  AsciiStrnCpyS(Destination, DestMax, Source, StringLen);\r
+  *Length += (UINT8)DestMax;\r
+\r
+  return;\r
+}\r
+\r
+/**\r
+  Get a string description for device for the given controller handle and update record\r
+  length. If ComponentName2 GetControllerName is supported, the value is included in the string,\r
+  followed by device path, otherwise just device path.\r
+\r
+  @param Handle              - Image handle\r
+  @param ControllerHandle    - Controller handle.\r
+  @param ComponentNameString - Pointer to a location where the string will be saved\r
+  @param Length              - Pointer to record length to be updated\r
 \r
-  @retval EFI_SUCCESS             The end of  the measurement was recorded.\r
-  @retval EFI_NOT_FOUND           The specified measurement record could not be found.\r
+  @retval EFI_SUCCESS     - Successfully got string description for device\r
+  @retval EFI_UNSUPPORTED - Neither ComponentName2 ControllerName nor DevicePath were found\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-EndGauge (\r
-  IN CONST VOID   *Handle,  OPTIONAL\r
-  IN CONST CHAR8  *Token,   OPTIONAL\r
-  IN CONST CHAR8  *Module,  OPTIONAL\r
-  IN UINT64       TimeStamp\r
+GetDeviceInfoFromHandleAndUpdateLength (\r
+  IN CONST VOID        *Handle,\r
+  IN EFI_HANDLE        ControllerHandle,\r
+  OUT CHAR8            *ComponentNameString,\r
+  IN OUT UINT8         *Length\r
   )\r
 {\r
-  GAUGE_DATA_ENTRY  *GaugeEntryArray;\r
-  UINT32            Index;\r
+  EFI_DEVICE_PATH_PROTOCOL      *DevicePathProtocol;\r
+  EFI_COMPONENT_NAME2_PROTOCOL  *ComponentName2;\r
+  EFI_STATUS                    Status;\r
+  CHAR16                        *StringPtr;\r
+  CHAR8                         *AsciiStringPtr;\r
+  UINTN                         ControllerNameStringSize;\r
+  UINTN                         DevicePathStringSize;\r
+\r
+  ControllerNameStringSize = 0;\r
+\r
+  Status = gBS->HandleProtocol (\r
+                  (EFI_HANDLE) Handle,\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  (VOID **) &ComponentName2\r
+                  );\r
 \r
-  if (TimeStamp == 0) {\r
-    TimeStamp = GetPerformanceCounter ();\r
-  }\r
+  if (!EFI_ERROR(Status)) {\r
+    //\r
+    // Get the current platform language setting\r
+    //\r
+    if (mPlatformLanguage == NULL) {\r
+      GetEfiGlobalVariable2 (L"PlatformLang", (VOID **)&mPlatformLanguage, NULL);\r
+    }\r
 \r
-  Index = InternalSearchForGaugeEntry (Handle, Token, Module);\r
-  if (Index >= mGaugeData->NumberOfEntries) {\r
-    return EFI_NOT_FOUND;\r
+    Status = ComponentName2->GetControllerName (\r
+                               ComponentName2,\r
+                               ControllerHandle,\r
+                               NULL,\r
+                               mPlatformLanguage != NULL ? mPlatformLanguage : "en-US",\r
+                               &StringPtr\r
+                               );\r
   }\r
-  GaugeEntryArray = (GAUGE_DATA_ENTRY  *) (mGaugeData + 1);\r
-  GaugeEntryArray[Index].EndTimeStamp = TimeStamp;\r
 \r
-  return EFI_SUCCESS;\r
-}\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // This will produce the size of the unicode string, which is twice as large as the ASCII one\r
+    // This must be an even number, so ok to divide by 2\r
+    //\r
+    ControllerNameStringSize = StrSize(StringPtr) / 2;\r
 \r
-/**\r
-  Retrieves a previously logged performance measurement.\r
+    //\r
+    // The + 1 is because we want to add a space between the ControllerName and the device path\r
+    //\r
+    if ((ControllerNameStringSize + (*Length) + 1) > FPDT_MAX_PERF_RECORD_SIZE) {\r
+      //\r
+      // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record\r
+      //\r
+      ControllerNameStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length) - 1;\r
+    }\r
+\r
+    UnicodeStrToAsciiStrS(StringPtr, ComponentNameString, ControllerNameStringSize);\r
 \r
-  Retrieves the performance log entry from the performance log specified by LogEntryKey.\r
-  If it stands for a valid entry, then EFI_SUCCESS is returned and\r
-  GaugeDataEntry stores the pointer to that entry.\r
+    //\r
+    // Add a space in the end of the ControllerName\r
+    //\r
+    AsciiStringPtr = ComponentNameString + ControllerNameStringSize - 1;\r
+    *AsciiStringPtr = 0x20;\r
+    AsciiStringPtr++;\r
+    *AsciiStringPtr = 0;\r
+    ControllerNameStringSize++;\r
+\r
+    *Length += (UINT8)ControllerNameStringSize;\r
+  }\r
+\r
+  //\r
+  // This function returns the device path protocol from the handle specified by Handle.  If Handle is\r
+  // NULL or Handle does not contain a device path protocol, then NULL is returned.\r
+  //\r
+  DevicePathProtocol = DevicePathFromHandle(ControllerHandle);\r
+\r
+  if (DevicePathProtocol != NULL) {\r
+    StringPtr = ConvertDevicePathToText (DevicePathProtocol, TRUE, FALSE);\r
+    if (StringPtr != NULL) {\r
+      //\r
+      // This will produce the size of the unicode string, which is twice as large as the ASCII one\r
+      // This must be an even number, so ok to divide by 2\r
+      //\r
+      DevicePathStringSize = StrSize(StringPtr) / 2;\r
+\r
+      if ((DevicePathStringSize + (*Length)) > FPDT_MAX_PERF_RECORD_SIZE) {\r
+        //\r
+        // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record\r
+        //\r
+        DevicePathStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length);\r
+      }\r
+\r
+      if (ControllerNameStringSize != 0) {\r
+        AsciiStringPtr = ComponentNameString + ControllerNameStringSize - 1;\r
+      } else {\r
+        AsciiStringPtr = ComponentNameString;\r
+      }\r
+\r
+      UnicodeStrToAsciiStrS(StringPtr, AsciiStringPtr, DevicePathStringSize);\r
+      *Length += (UINT8)DevicePathStringSize;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
 \r
-  @param  LogEntryKey             The key for the previous performance measurement log entry.\r
-                                  If 0, then the first performance measurement log entry is retrieved.\r
-  @param  GaugeDataEntry          The indirect pointer to the gauge data entry specified by LogEntryKey\r
-                                  if the retrieval is successful.\r
+  return EFI_UNSUPPORTED;\r
+}\r
 \r
-  @retval EFI_SUCCESS             The GuageDataEntry is successfully found based on LogEntryKey.\r
-  @retval EFI_NOT_FOUND           The LogEntryKey is the last entry (equals to the total entry number).\r
-  @retval EFI_INVALIDE_PARAMETER  The LogEntryKey is not a valid entry (greater than the total entry number).\r
-  @retval EFI_INVALIDE_PARAMETER  GaugeDataEntry is NULL.\r
+/**\r
+  Create performance record with event description and a timestamp.\r
+\r
+  @param CallerIdentifier  - Image handle or pointer to caller ID GUID.\r
+  @param Guid              - Pointer to a GUID.\r
+  @param String            - Pointer to a string describing the measurement.\r
+  @param Ticker            - 64-bit time stamp.\r
+  @param Address           - Pointer to a location in memory relevant to the measurement.\r
+  @param PerfId            - Performance identifier describing the type of measurement.\r
+  @param Attribute         - The attribute of the measurement. According to attribute can create a start\r
+                             record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,\r
+                             or a general record for other Perf macros.\r
+\r
+  @retval EFI_SUCCESS           - Successfully created performance record.\r
+  @retval EFI_OUT_OF_RESOURCES  - Ran out of space to store the records.\r
+  @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
+                                  pointer or invalid PerfId.\r
+\r
+  @retval EFI_SUCCESS           - Successfully created performance record\r
+  @retval EFI_OUT_OF_RESOURCES  - Ran out of space to store the records\r
+  @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
+                                  pointer or invalid PerfId\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-GetGauge (\r
-  IN  UINTN               LogEntryKey,\r
-  OUT GAUGE_DATA_ENTRY    **GaugeDataEntry\r
+InsertFpdtRecord (\r
+  IN CONST VOID                        *CallerIdentifier,  OPTIONAL\r
+  IN CONST VOID                        *Guid,    OPTIONAL\r
+  IN CONST CHAR8                       *String,  OPTIONAL\r
+  IN       UINT64                      Ticker,\r
+  IN       UINT64                      Address,  OPTIONAL\r
+  IN       UINT16                      PerfId,\r
+  IN       PERF_MEASUREMENT_ATTRIBUTE  Attribute\r
   )\r
 {\r
-  UINTN               NumberOfEntries;\r
-  GAUGE_DATA_ENTRY    *LogEntryArray;\r
+  EFI_GUID                     ModuleGuid;\r
+  CHAR8                        ModuleName[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];\r
+  FPDT_RECORD_PTR              FpdtRecordPtr;\r
+  FPDT_RECORD_PTR              CachedFpdtRecordPtr;\r
+  UINT64                       TimeStamp;\r
+  CONST CHAR8                  *StringPtr;\r
+  UINTN                        DestMax;\r
+  UINTN                        StringLen;\r
+  EFI_STATUS                   Status;\r
+  UINT16                       ProgressId;\r
+\r
+  StringPtr     = NULL;\r
+  ProgressId    = 0;\r
+  ZeroMem (ModuleName, sizeof (ModuleName));\r
 \r
-  NumberOfEntries = (UINTN) (mGaugeData->NumberOfEntries);\r
-  if (LogEntryKey > NumberOfEntries) {\r
-    return EFI_INVALID_PARAMETER;\r
+  //\r
+  // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.\r
+  //    notes: For other Perf macros (Attribute == PerfEntry), their Id is known.\r
+  //\r
+  if (Attribute != PerfEntry) {\r
+    //\r
+    // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.\r
+    // !!! Note: If the Perf is not the known Token used in the core but have same\r
+    // ID with the core Token, this case will not be supported.\r
+    // And in currtnt usage mode, for the unkown ID, there is a general rule:\r
+    // If it is start pref: the lower 4 bits of the ID should be 0.\r
+    // If it is end pref: the lower 4 bits of the ID should not be 0.\r
+    // If input ID doesn't follow the rule, we will adjust it.\r
+    //\r
+    if ((PerfId != 0) && (IsKnownID (PerfId)) && (!IsKnownTokens (String))) {\r
+      return EFI_INVALID_PARAMETER;\r
+    } else if ((PerfId != 0) && (!IsKnownID (PerfId)) && (!IsKnownTokens (String))) {\r
+      if ((Attribute == PerfStartEntry) && ((PerfId & 0x000F) != 0)) {\r
+        PerfId &= 0xFFF0;\r
+      } else if ((Attribute == PerfEndEntry) && ((PerfId & 0x000F) == 0)) {\r
+        PerfId += 1;\r
+      }\r
+    } else if (PerfId == 0) {\r
+      //\r
+      // Get ProgressID form the String Token.\r
+      //\r
+      Status = GetFpdtRecordId (Attribute, CallerIdentifier, String, &ProgressId);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+      PerfId = ProgressId;\r
+    }\r
+  }\r
+\r
+  //\r
+  // 2. Get the buffer to store the FPDT record.\r
+  //\r
+  Status = GetFpdtRecordPtr (FPDT_MAX_PERF_RECORD_SIZE, &FpdtRecordPtr);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  //3. Get the TimeStamp.\r
+  //\r
+  if (Ticker == 0) {\r
+    Ticker    = GetPerformanceCounter ();\r
+    TimeStamp = GetTimeInNanoSecond (Ticker);\r
+  } else if (Ticker == 1) {\r
+    TimeStamp = 0;\r
+  } else {\r
+    TimeStamp = GetTimeInNanoSecond (Ticker);\r
   }\r
-  if (LogEntryKey == NumberOfEntries) {\r
-    return EFI_NOT_FOUND;\r
+\r
+  //\r
+  // 4. Fill in the FPDT record according to different Performance Identifier.\r
+  //\r
+  switch (PerfId) {\r
+  case MODULE_START_ID:\r
+  case MODULE_END_ID:\r
+    GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
+    StringPtr = ModuleName;\r
+    //\r
+    // Cache the offset of start image start record and use to update the start image end record if needed.\r
+    //\r
+    if (Attribute == PerfEntry && PerfId == MODULE_START_ID) {\r
+      if (mFpdtBufferIsReported) {\r
+        mCachedLength = mBootRecordSize;\r
+      } else {\r
+        mCachedLength = mPerformanceLength;\r
+      }\r
+    }\r
+    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+      FpdtRecordPtr.GuidEvent->Header.Type                = FPDT_GUID_EVENT_TYPE;\r
+      FpdtRecordPtr.GuidEvent->Header.Length              = sizeof (FPDT_GUID_EVENT_RECORD);\r
+      FpdtRecordPtr.GuidEvent->Header.Revision            = FPDT_RECORD_REVISION_1;\r
+      FpdtRecordPtr.GuidEvent->ProgressID                 = PerfId;\r
+      FpdtRecordPtr.GuidEvent->Timestamp                  = TimeStamp;\r
+      CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidEvent->Guid));\r
+      if (CallerIdentifier == NULL && PerfId == MODULE_END_ID && mCachedLength != 0) {\r
+        if (mFpdtBufferIsReported) {\r
+          CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);\r
+        } else {\r
+          CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);\r
+        }\r
+        CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &CachedFpdtRecordPtr.GuidEvent->Guid, sizeof (FpdtRecordPtr.GuidEvent->Guid));\r
+        mCachedLength = 0;\r
+      }\r
+    }\r
+    break;\r
+\r
+  case MODULE_LOADIMAGE_START_ID:\r
+  case MODULE_LOADIMAGE_END_ID:\r
+    GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
+    StringPtr = ModuleName;\r
+    if (PerfId == MODULE_LOADIMAGE_START_ID) {\r
+      mLoadImageCount ++;\r
+      //\r
+      // Cache the offset of load image start record and use to be updated by the load image end record if needed.\r
+      //\r
+      if (CallerIdentifier == NULL && Attribute == PerfEntry) {\r
+        if (mFpdtBufferIsReported) {\r
+          mCachedLength = mBootRecordSize;\r
+        } else {\r
+          mCachedLength = mPerformanceLength;\r
+        }\r
+      }\r
+    }\r
+    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+      FpdtRecordPtr.GuidQwordEvent->Header.Type           = FPDT_GUID_QWORD_EVENT_TYPE;\r
+      FpdtRecordPtr.GuidQwordEvent->Header.Length         = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);\r
+      FpdtRecordPtr.GuidQwordEvent->Header.Revision       = FPDT_RECORD_REVISION_1;\r
+      FpdtRecordPtr.GuidQwordEvent->ProgressID            = PerfId;\r
+      FpdtRecordPtr.GuidQwordEvent->Timestamp             = TimeStamp;\r
+      FpdtRecordPtr.GuidQwordEvent->Qword                 = mLoadImageCount;\r
+      CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));\r
+      if (PerfId == MODULE_LOADIMAGE_END_ID && mCachedLength != 0) {\r
+        if (mFpdtBufferIsReported) {\r
+          CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);\r
+        } else {\r
+          CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);\r
+        }\r
+        CopyMem (&CachedFpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (CachedFpdtRecordPtr.GuidQwordEvent->Guid));\r
+        mCachedLength = 0;\r
+      }\r
+    }\r
+    break;\r
+\r
+  case MODULE_DB_START_ID:\r
+  case MODULE_DB_SUPPORT_START_ID:\r
+  case MODULE_DB_SUPPORT_END_ID:\r
+  case MODULE_DB_STOP_START_ID:\r
+  case MODULE_DB_STOP_END_ID:\r
+    GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
+    StringPtr = ModuleName;\r
+    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+      FpdtRecordPtr.GuidQwordEvent->Header.Type           = FPDT_GUID_QWORD_EVENT_TYPE;\r
+      FpdtRecordPtr.GuidQwordEvent->Header.Length         = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);\r
+      FpdtRecordPtr.GuidQwordEvent->Header.Revision       = FPDT_RECORD_REVISION_1;\r
+      FpdtRecordPtr.GuidQwordEvent->ProgressID            = PerfId;\r
+      FpdtRecordPtr.GuidQwordEvent->Timestamp             = TimeStamp;\r
+      FpdtRecordPtr.GuidQwordEvent->Qword                 = Address;\r
+      CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));\r
+    }\r
+    break;\r
+\r
+  case MODULE_DB_END_ID:\r
+    GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
+    StringPtr = ModuleName;\r
+    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+      FpdtRecordPtr.GuidQwordStringEvent->Header.Type     = FPDT_GUID_QWORD_STRING_EVENT_TYPE;\r
+      FpdtRecordPtr.GuidQwordStringEvent->Header.Length   = sizeof (FPDT_GUID_QWORD_STRING_EVENT_RECORD);;\r
+      FpdtRecordPtr.GuidQwordStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
+      FpdtRecordPtr.GuidQwordStringEvent->ProgressID      = PerfId;\r
+      FpdtRecordPtr.GuidQwordStringEvent->Timestamp       = TimeStamp;\r
+      FpdtRecordPtr.GuidQwordStringEvent->Qword           = Address;\r
+      CopyMem (&FpdtRecordPtr.GuidQwordStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordStringEvent->Guid));\r
+      if (Address != 0) {\r
+        GetDeviceInfoFromHandleAndUpdateLength(CallerIdentifier, (EFI_HANDLE)(UINTN)Address, FpdtRecordPtr.GuidQwordStringEvent->String, &FpdtRecordPtr.GuidQwordStringEvent->Header.Length);\r
+      }\r
+    }\r
+    break;\r
+\r
+  case PERF_EVENTSIGNAL_START_ID:\r
+  case PERF_EVENTSIGNAL_END_ID:\r
+  case PERF_CALLBACK_START_ID:\r
+  case PERF_CALLBACK_END_ID:\r
+    if (String == NULL || Guid == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    StringPtr = String;\r
+    if (AsciiStrLen (String) == 0) {\r
+      StringPtr = "unknown name";\r
+    }\r
+    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+      FpdtRecordPtr.DualGuidStringEvent->Header.Type      = FPDT_DUAL_GUID_STRING_EVENT_TYPE;\r
+      FpdtRecordPtr.DualGuidStringEvent->Header.Length    = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);\r
+      FpdtRecordPtr.DualGuidStringEvent->Header.Revision  = FPDT_RECORD_REVISION_1;\r
+      FpdtRecordPtr.DualGuidStringEvent->ProgressID       = PerfId;\r
+      FpdtRecordPtr.DualGuidStringEvent->Timestamp        = TimeStamp;\r
+      CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid1, CallerIdentifier, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid1));\r
+      CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid2, Guid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid2));\r
+      CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DualGuidStringEvent->String, StringPtr, &FpdtRecordPtr.DualGuidStringEvent->Header.Length);\r
+    }\r
+    break;\r
+\r
+  case PERF_EVENT_ID:\r
+  case PERF_FUNCTION_START_ID:\r
+  case PERF_FUNCTION_END_ID:\r
+  case PERF_INMODULE_START_ID:\r
+  case PERF_INMODULE_END_ID:\r
+  case PERF_CROSSMODULE_START_ID:\r
+  case PERF_CROSSMODULE_END_ID:\r
+    GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
+    if (String != NULL) {\r
+      StringPtr = String;\r
+    } else {\r
+      StringPtr = ModuleName;\r
+    }\r
+    if (AsciiStrLen (StringPtr) == 0) {\r
+      StringPtr = "unknown name";\r
+    }\r
+    if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+      FpdtRecordPtr.DynamicStringEvent->Header.Type       = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
+      FpdtRecordPtr.DynamicStringEvent->Header.Length     = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
+      FpdtRecordPtr.DynamicStringEvent->Header.Revision   = FPDT_RECORD_REVISION_1;\r
+      FpdtRecordPtr.DynamicStringEvent->ProgressID        = PerfId;\r
+      FpdtRecordPtr.DynamicStringEvent->Timestamp         = TimeStamp;\r
+      CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
+      CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
+    }\r
+    break;\r
+\r
+  default:\r
+    if (Attribute != PerfEntry) {\r
+      GetModuleInfoFromHandle ((EFI_HANDLE *)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
+      if (String != NULL) {\r
+        StringPtr = String;\r
+      } else {\r
+        StringPtr = ModuleName;\r
+      }\r
+      if (AsciiStrLen (StringPtr) == 0) {\r
+        StringPtr = "unknown name";\r
+      }\r
+      if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+        FpdtRecordPtr.DynamicStringEvent->Header.Type       = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
+        FpdtRecordPtr.DynamicStringEvent->Header.Length     = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
+        FpdtRecordPtr.DynamicStringEvent->Header.Revision   = FPDT_RECORD_REVISION_1;\r
+        FpdtRecordPtr.DynamicStringEvent->ProgressID        = PerfId;\r
+        FpdtRecordPtr.DynamicStringEvent->Timestamp         = TimeStamp;\r
+        CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
+        CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
+      }\r
+    } else {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    break;\r
   }\r
 \r
-  LogEntryArray   = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+  //\r
+  // 4.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.\r
+  //\r
+  if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
+    if (StringPtr == NULL ||PerfId == MODULE_DB_SUPPORT_START_ID || PerfId == MODULE_DB_SUPPORT_END_ID) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    FpdtRecordPtr.DynamicStringEvent->Header.Type       = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
+    FpdtRecordPtr.DynamicStringEvent->Header.Length     = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
+    FpdtRecordPtr.DynamicStringEvent->Header.Revision   = FPDT_RECORD_REVISION_1;\r
+    FpdtRecordPtr.DynamicStringEvent->ProgressID        = PerfId;\r
+    FpdtRecordPtr.DynamicStringEvent->Timestamp         = TimeStamp;\r
+    if (Guid != NULL) {\r
+      //\r
+      // Cache the event guid in string event record.\r
+      //\r
+      CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, Guid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
+    } else {\r
+      CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
+    }\r
+    if (AsciiStrLen (StringPtr) == 0) {\r
+      StringPtr = "unknown name";\r
+    }\r
+    CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
 \r
-  if (GaugeDataEntry == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
+    if ((PerfId == MODULE_LOADIMAGE_START_ID) || (PerfId == MODULE_END_ID)) {\r
+      FpdtRecordPtr.DynamicStringEvent->Header.Length = (UINT8)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD)+ STRING_SIZE);\r
+    }\r
+    if ((PerfId == MODULE_LOADIMAGE_END_ID || PerfId == MODULE_END_ID) && mCachedLength != 0) {\r
+      if (mFpdtBufferIsReported) {\r
+        CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);\r
+      } else {\r
+        CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);\r
+      }\r
+      if (PerfId == MODULE_LOADIMAGE_END_ID) {\r
+        DestMax = CachedFpdtRecordPtr.DynamicStringEvent->Header.Length - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
+        StringLen = AsciiStrLen (StringPtr);\r
+        if (StringLen >= DestMax) {\r
+          StringLen = DestMax -1;\r
+        }\r
+        CopyMem (&CachedFpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (CachedFpdtRecordPtr.DynamicStringEvent->Guid));\r
+        AsciiStrnCpyS (CachedFpdtRecordPtr.DynamicStringEvent->String, DestMax, StringPtr, StringLen);\r
+      } else if (PerfId == MODULE_END_ID) {\r
+        DestMax = FpdtRecordPtr.DynamicStringEvent->Header.Length - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
+        StringLen = AsciiStrLen (CachedFpdtRecordPtr.DynamicStringEvent->String);\r
+        if (StringLen >= DestMax) {\r
+          StringLen = DestMax -1;\r
+        }\r
+        CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &CachedFpdtRecordPtr.DynamicStringEvent->Guid, sizeof (CachedFpdtRecordPtr.DynamicStringEvent->Guid));\r
+        AsciiStrnCpyS (FpdtRecordPtr.DynamicStringEvent->String, DestMax, CachedFpdtRecordPtr.DynamicStringEvent->String, StringLen);\r
+      }\r
+      mCachedLength = 0;\r
+    }\r
   }\r
-  *GaugeDataEntry = &LogEntryArray[LogEntryKey];\r
 \r
+  //\r
+  // 5. Update the length of the used buffer after fill in the record.\r
+  //\r
+  if (mFpdtBufferIsReported) {\r
+    mBootRecordSize += FpdtRecordPtr.RecordHeader->Length;\r
+    mAcpiBootPerformanceTable->Header.Length += FpdtRecordPtr.RecordHeader->Length;\r
+  } else {\r
+    mPerformanceLength += FpdtRecordPtr.RecordHeader->Length;\r
+  }\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Dumps all the PEI performance log to DXE performance gauge array.\r
+  Dumps all the PEI performance.\r
+\r
+  @param  HobStart      A pointer to a Guid.\r
 \r
   This internal function dumps all the PEI performance log to the DXE performance gauge array.\r
   It retrieves the optional GUID HOB for PEI performance and then saves the performance data\r
@@ -290,44 +1256,90 @@ GetGauge (
 **/\r
 VOID\r
 InternalGetPeiPerformance (\r
-  VOID\r
+  VOID  *HobStart\r
   )\r
 {\r
-  EFI_HOB_GUID_TYPE                 *GuidHob;\r
-  PEI_PERFORMANCE_LOG_HEADER        *LogHob;\r
-  PEI_PERFORMANCE_LOG_ENTRY         *LogEntryArray;\r
-  GAUGE_DATA_ENTRY                  *GaugeEntryArray;\r
-  UINT32                            Index;\r
-  UINT32                            NumberOfEntries;\r
+  UINT8                                *FirmwarePerformanceHob;\r
+  FPDT_PEI_EXT_PERF_HEADER             *PeiPerformanceLogHeader;\r
+  UINT8                                *EventRec;\r
+  EFI_HOB_GUID_TYPE                    *GuidHob;\r
+\r
+  GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, HobStart);\r
+  while (GuidHob != NULL) {\r
+    FirmwarePerformanceHob  = GET_GUID_HOB_DATA (GuidHob);\r
+    PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)FirmwarePerformanceHob;\r
+\r
+    if (mPerformanceLength + PeiPerformanceLogHeader->SizeOfAllEntries > mMaxPerformanceLength) {\r
+      mPerformancePointer = ReallocatePool (\r
+                              mPerformanceLength,\r
+                              mPerformanceLength +\r
+                              (UINTN)PeiPerformanceLogHeader->SizeOfAllEntries +\r
+                              FIRMWARE_RECORD_BUFFER,\r
+                              mPerformancePointer\r
+                              );\r
+      ASSERT (mPerformancePointer != NULL);\r
+      mMaxPerformanceLength = mPerformanceLength +\r
+                              (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries) +\r
+                              FIRMWARE_RECORD_BUFFER;\r
+    }\r
 \r
-  NumberOfEntries = 0;\r
-  GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+    EventRec = mPerformancePointer + mPerformanceLength;\r
+    CopyMem (EventRec, FirmwarePerformanceHob + sizeof (FPDT_PEI_EXT_PERF_HEADER), (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries));\r
+    //\r
+    // Update the used buffer size.\r
+    //\r
+    mPerformanceLength += (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries);\r
+    mLoadImageCount    += PeiPerformanceLogHeader->LoadImageCount;\r
 \r
-  //\r
-  // Dump PEI Log Entries to DXE Guage Data structure.\r
-  //\r
-  GuidHob = GetFirstGuidHob (&gPerformanceProtocolGuid);\r
-  if (GuidHob != NULL) {\r
-    LogHob          = GET_GUID_HOB_DATA (GuidHob);\r
-    LogEntryArray   = (PEI_PERFORMANCE_LOG_ENTRY *) (LogHob + 1);\r
-    GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
+    //\r
+    // Get next performance guid hob\r
+    //\r
+    GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));\r
+  }\r
+}\r
+\r
+/**\r
+  Report Boot Perforamnce table address as report status code.\r
+\r
+  @param  Event    The event of notify protocol.\r
+  @param  Context  Notify event context.\r
 \r
-    NumberOfEntries = LogHob->NumberOfEntries;\r
-    for (Index = 0; Index < NumberOfEntries; Index++) {\r
-      GaugeEntryArray[Index].Handle         = LogEntryArray[Index].Handle;\r
-      AsciiStrnCpy (GaugeEntryArray[Index].Token,  LogEntryArray[Index].Token,  DXE_PERFORMANCE_STRING_LENGTH);\r
-      AsciiStrnCpy (GaugeEntryArray[Index].Module, LogEntryArray[Index].Module, DXE_PERFORMANCE_STRING_LENGTH);\r
-      GaugeEntryArray[Index].StartTimeStamp = LogEntryArray[Index].StartTimeStamp;\r
-      GaugeEntryArray[Index].EndTimeStamp   = LogEntryArray[Index].EndTimeStamp;\r
+**/\r
+VOID\r
+EFIAPI\r
+ReportFpdtRecordBuffer (\r
+  IN EFI_EVENT     Event,\r
+  IN VOID          *Context\r
+  )\r
+{\r
+  EFI_STATUS      Status;\r
+  UINT64          BPDTAddr;\r
+\r
+  if (!mFpdtBufferIsReported) {\r
+    Status = AllocateBootPerformanceTable ();\r
+    if (!EFI_ERROR(Status)) {\r
+      BPDTAddr = (UINT64)(UINTN)mAcpiBootPerformanceTable;\r
+      REPORT_STATUS_CODE_EX (\r
+          EFI_PROGRESS_CODE,\r
+          EFI_SOFTWARE_DXE_BS_DRIVER,\r
+          0,\r
+          NULL,\r
+          &gEdkiiFpdtExtendedFirmwarePerformanceGuid,\r
+          &BPDTAddr,\r
+          sizeof (UINT64)\r
+          );\r
     }\r
+    //\r
+    // Set FPDT report state to TRUE.\r
+    //\r
+    mFpdtBufferIsReported = TRUE;\r
   }\r
-  mGaugeData->NumberOfEntries = NumberOfEntries;\r
 }\r
 \r
 /**\r
   The constructor function initializes Performance infrastructure for DXE phase.\r
 \r
-  The constructor function publishes Performance protocol, allocates memory to log DXE performance\r
+  The constructor function publishes Performance and PerformanceEx protocol, allocates memory to log DXE performance\r
   and merges PEI performance data to DXE performance log.\r
   It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.\r
 \r
@@ -345,6 +1357,9 @@ DxeCorePerformanceLibConstructor (
   )\r
 {\r
   EFI_STATUS                Status;\r
+  EFI_HANDLE                Handle;\r
+  EFI_EVENT                 ReadyToBootEvent;\r
+  PERFORMANCE_PROPERTY      *PerformanceProperty;\r
 \r
   if (!PerformanceMeasurementEnabled ()) {\r
     //\r
@@ -352,23 +1367,98 @@ DxeCorePerformanceLibConstructor (
     //\r
     return EFI_SUCCESS;\r
   }\r
+\r
+  //\r
+  // Dump normal PEI performance records\r
+  //\r
+  InternalGetPeiPerformance (GetHobList());\r
+\r
+  //\r
+  // Install the protocol interfaces for DXE performance library instance.\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEdkiiPerformanceMeasurementProtocolGuid,\r
+                  &mPerformanceMeasurementInterface,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   //\r
-  // Install the protocol interfaces.\r
+  // Register ReadyToBoot event to report StatusCode data\r
   //\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &mHandle,\r
-                  &gPerformanceProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &mPerformanceInterface\r
+  Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  ReportFpdtRecordBuffer,\r
+                  NULL,\r
+                  &gEfiEventReadyToBootGuid,\r
+                  &ReadyToBootEvent\r
                   );\r
+\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + PcdGet8 (PcdMaxPeiPerformanceLogEntries);\r
+  Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Install configuration table for performance property.\r
+    //\r
+    mPerformanceProperty.Revision  = PERFORMANCE_PROPERTY_REVISION;\r
+    mPerformanceProperty.Reserved  = 0;\r
+    mPerformanceProperty.Frequency = GetPerformanceCounterProperties (\r
+                                       &mPerformanceProperty.TimerStartValue,\r
+                                       &mPerformanceProperty.TimerEndValue\r
+                                       );\r
+    Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, &mPerformanceProperty);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
 \r
-  mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords));\r
-  ASSERT (mGaugeData != NULL);\r
+/**\r
+  Create performance record with event description and a timestamp.\r
+\r
+  @param CallerIdentifier  - Image handle or pointer to caller ID GUID.\r
+  @param Guid              - Pointer to a GUID.\r
+  @param String            - Pointer to a string describing the measurement.\r
+  @param TimeStamp         - 64-bit time stamp.\r
+  @param Address           - Pointer to a location in memory relevant to the measurement.\r
+  @param Identifier        - Performance identifier describing the type of measurement.\r
+  @param Attribute         - The attribute of the measurement. According to attribute can create a start\r
+                             record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,\r
+                             or a general record for other Perf macros.\r
+\r
+  @retval EFI_SUCCESS           - Successfully created performance record.\r
+  @retval EFI_OUT_OF_RESOURCES  - Ran out of space to store the records.\r
+  @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
+                                  pointer or invalid PerfId.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+CreatePerformanceMeasurement (\r
+  IN CONST VOID                        *CallerIdentifier,\r
+  IN CONST VOID                        *Guid,   OPTIONAL\r
+  IN CONST CHAR8                       *String, OPTIONAL\r
+  IN       UINT64                      TimeStamp,\r
+  IN       UINT64                      Address,  OPTIONAL\r
+  IN       UINT32                      Identifier,\r
+  IN       PERF_MEASUREMENT_ATTRIBUTE  Attribute\r
+  )\r
+{\r
+  EFI_STATUS   Status;\r
 \r
-  InternalGetPeiPerformance ();\r
+  Status = EFI_SUCCESS;\r
+\r
+  if (mLockInsertRecord) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  mLockInsertRecord = TRUE;\r
+\r
+  Status = InsertFpdtRecord (CallerIdentifier, Guid, String, TimeStamp, Address, (UINT16)Identifier, Attribute);\r
+\r
+  mLockInsertRecord = FALSE;\r
 \r
   return Status;\r
 }\r
@@ -378,7 +1468,7 @@ DxeCorePerformanceLibConstructor (
   that records the start time of a performance measurement.\r
 \r
   Adds a record to the end of the performance measurement log\r
-  that contains the Handle, Token, and Module.\r
+  that contains the Handle, Token, Module and Identifier.\r
   The end time of the new record must be set to zero.\r
   If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
   If TimeStamp is zero, the start time in the record is filled in with the value\r
@@ -391,6 +1481,8 @@ DxeCorePerformanceLibConstructor (
   @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
@@ -398,17 +1490,25 @@ DxeCorePerformanceLibConstructor (
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
-StartPerformanceMeasurement (\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 UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  CONST CHAR8     *String;\r
 \r
-  Status = StartGauge (Handle, Token, Module, TimeStamp);\r
-  return (RETURN_STATUS) Status;\r
+  if (Token != NULL) {\r
+    String = Token;\r
+  } else if (Module != NULL) {\r
+    String = Module;\r
+  } else {\r
+    String = NULL;\r
+  }\r
+\r
+  return (RETURN_STATUS)CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfStartEntry);\r
 }\r
 \r
 /**\r
@@ -416,7 +1516,7 @@ StartPerformanceMeasurement (
   for the first matching record that contains a zero end time and fills in a valid end time.\r
 \r
   Searches the performance measurement log from the beginning of the log\r
-  for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
+  for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\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 the end time in the record is filled in with the value specified by TimeStamp.\r
@@ -430,6 +1530,8 @@ StartPerformanceMeasurement (
   @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
@@ -437,21 +1539,33 @@ StartPerformanceMeasurement (
 **/\r
 RETURN_STATUS\r
 EFIAPI\r
-EndPerformanceMeasurement (\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 UINT64       TimeStamp,\r
+  IN UINT32       Identifier\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  CONST CHAR8     *String;\r
 \r
-  Status = EndGauge (Handle, Token, Module, TimeStamp);\r
-  return (RETURN_STATUS) Status;\r
+  if (Token != NULL) {\r
+    String = Token;\r
+  } else if (Module != NULL) {\r
+    String = Module;\r
+  } else {\r
+    String = NULL;\r
+  }\r
+\r
+  return (RETURN_STATUS)CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfEndEntry);\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
+    !!! Not support!!!\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
@@ -462,13 +1576,14 @@ EndPerformanceMeasurement (
   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, and EndTimeStamp.\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
@@ -483,55 +1598,151 @@ EndPerformanceMeasurement (
                                   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 when the measurement\r
+                                  was ended.\r
 \r
   @return The key for the next performance log entry (in general case).\r
 \r
 **/\r
 UINTN\r
 EFIAPI\r
-GetPerformanceMeasurement (\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 UINT64      *EndTimeStamp,\r
+  OUT UINT32      *Identifier\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  GAUGE_DATA_ENTRY  *GaugeData;\r
+  return 0;\r
+}\r
 \r
-  GaugeData = NULL;\r
-  \r
-  ASSERT (Handle != NULL);\r
-  ASSERT (Token != NULL);\r
-  ASSERT (Module != NULL);\r
-  ASSERT (StartTimeStamp != NULL);\r
-  ASSERT (EndTimeStamp != NULL);\r
+/**\r
+  Adds a record at the end of the performance measurement log\r
+  that records the start time of a performance measurement.\r
 \r
-  Status = GetGauge (LogEntryKey++, &GaugeData);\r
+  Adds a record to the end of the performance measurement log\r
+  that contains the Handle, Token, and Module.\r
+  The end time of the new record must be set to zero.\r
+  If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
+  If TimeStamp is zero, the start time in the record is filled in with the value\r
+  read from the current time stamp.\r
 \r
-  //\r
-  // Make sure that LogEntryKey is a valid log entry key,\r
-  //\r
-  ASSERT (Status != EFI_INVALID_PARAMETER);\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
 \r
-  if (EFI_ERROR (Status)) {\r
-    //\r
-    // The LogEntryKey is the last entry (equals to the total entry number).\r
-    //\r
-    return 0;\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
+\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 UINT64       TimeStamp\r
+  )\r
+{\r
+  return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
+}\r
 \r
-  ASSERT (GaugeData != NULL);\r
+/**\r
+  Searches the performance measurement log from the beginning of the log\r
+  for the first matching record that contains a zero end time and fills in a valid end time.\r
 \r
-  *Handle         = (VOID *) (UINTN) GaugeData->Handle;\r
-  *Token          = GaugeData->Token;\r
-  *Module         = GaugeData->Module;\r
-  *StartTimeStamp = GaugeData->StartTimeStamp;\r
-  *EndTimeStamp   = GaugeData->EndTimeStamp;\r
+  Searches the performance measurement log from the beginning of the log\r
+  for the first record that matches Handle, Token, and Module and has an end time value of zero.\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 the end time in the record is filled in with the value specified by TimeStamp.\r
+  If the record is found and TimeStamp is zero, then the end time in the matching record\r
+  is filled in with the current time stamp value.\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
 \r
-  return LogEntryKey;\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
+\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 UINT64       TimeStamp\r
+  )\r
+{\r
+  return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\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 StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
+  and then eliminate the Identifier.\r
+\r
+  !!! Not support!!!\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, and EndTimeStamp.\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
+\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 log 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
+\r
+  @return The key for the next performance log entry (in general case).\r
+\r
+**/\r
+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
+  )\r
+{\r
+  return 0;\r
 }\r
 \r
 /**\r
@@ -554,3 +1765,58 @@ PerformanceMeasurementEnabled (
 {\r
   return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
 }\r
+\r
+/**\r
+  Create performance record with event description and a timestamp.\r
+\r
+  @param CallerIdentifier  - Image handle or pointer to caller ID GUID\r
+  @param Guid              - Pointer to a 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 PerfId\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LogPerformanceMeasurement (\r
+  IN CONST VOID   *CallerIdentifier,\r
+  IN CONST VOID   *Guid,    OPTIONAL\r
+  IN CONST CHAR8  *String,  OPTIONAL\r
+  IN UINT64       Address, OPTIONAL\r
+  IN UINT32       Identifier\r
+  )\r
+{\r
+  return (RETURN_STATUS)CreatePerformanceMeasurement (CallerIdentifier, Guid, String, 0, Address, Identifier, PerfEntry);\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
+  // When Performance measurement is enabled and the type is not filtered, the performance can be logged.\r
+  //\r
+  if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask) & Type) == 0) {\r
+    return TRUE;\r
+  }\r
+  return FALSE;\r
+}\r