]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PerformancePkg/Dp_App/DpTrace.c
BaseTools: Update Python Makefile to include the new added python files
[mirror_edk2.git] / PerformancePkg / Dp_App / DpTrace.c
index b70e3a2208f333ea177b4a8bd850e39b384cf5d5..9b4e0ed289ad19d9938eb07ad25e9c92ed672f36 100644 (file)
@@ -1,14 +1,15 @@
 /** @file\r
-  * Trace reporting for the Dp utility.\r
-  *\r
-  * Copyright (c) 2009 - 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
+  Trace reporting for the Dp utility.\r
+\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<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
 **/\r
 \r
 #include <Library/BaseLib.h>\r
@@ -16,7 +17,6 @@
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/TimerLib.h>\r
 #include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/PerformanceLib.h>\r
 #include <Library/PrintLib.h>\r
   \r
   @post The SummaryData and CumData structures contain statistics for the\r
         current performance logs.\r
+\r
+  @param[in, out] CustomCumulativeData  A pointer to the cumtom cumulative data.\r
+\r
 **/\r
 VOID\r
 GatherStatistics(\r
-  VOID\r
-)\r
+  IN OUT PERF_CUM_DATA              *CustomCumulativeData OPTIONAL\r
+  )\r
 {\r
   MEASUREMENT_RECORD        Measurement;\r
   UINT64                    Duration;\r
@@ -54,13 +57,14 @@ GatherStatistics(
   INTN                      TIndex;\r
 \r
   LogEntryKey = 0;\r
-  while ((LogEntryKey = GetPerformanceMeasurement (\r
+  while ((LogEntryKey = GetPerformanceMeasurementEx (\r
                         LogEntryKey,\r
                         &Measurement.Handle,\r
                         &Measurement.Token,\r
                         &Measurement.Module,\r
                         &Measurement.StartTimeStamp,\r
-                        &Measurement.EndTimeStamp)) != 0)\r
+                        &Measurement.EndTimeStamp,\r
+                        &Measurement.Identifier)) != 0)\r
   {\r
     ++SummaryData.NumTrace;           // Count the number of TRACE Measurement records\r
     if (Measurement.EndTimeStamp == 0) {\r
@@ -97,6 +101,20 @@ GatherStatistics(
         CumData[TIndex].MaxDur = Duration;\r
       }\r
     }\r
+\r
+    //\r
+    // Collect the data for custom cumulative data.\r
+    //\r
+    if ((CustomCumulativeData != NULL) && (AsciiStrCmp (Measurement.Token, CustomCumulativeData->Name) == 0)) {\r
+      CustomCumulativeData->Duration += Duration;\r
+      CustomCumulativeData->Count++;\r
+      if (Duration < CustomCumulativeData->MinDur) {\r
+        CustomCumulativeData->MinDur = Duration;\r
+      }\r
+      if (Duration > CustomCumulativeData->MaxDur) {\r
+        CustomCumulativeData->MaxDur = Duration;\r
+      }\r
+    }\r
   }\r
 }\r
 \r
@@ -117,8 +135,11 @@ GatherStatistics(
   @param[in]    Limit       The number of records to print.  Zero is ALL.\r
   @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display.\r
   \r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_ABORTED           The user aborts the operation.\r
+  @return Others                from a call to gBS->LocateHandleBuffer().\r
 **/\r
-VOID\r
+EFI_STATUS\r
 DumpAllTrace(\r
   IN UINTN             Limit,\r
   IN BOOLEAN           ExcludeFlag\r
@@ -134,8 +155,7 @@ DumpAllTrace(
   UINTN                     TIndex;\r
 \r
   EFI_HANDLE                *HandleBuffer;\r
-  UINTN                     Size;\r
-  EFI_HANDLE                TempHandle;\r
+  UINTN                     HandleCount;\r
   EFI_STATUS                Status;\r
   EFI_STRING                StringPtrUnknown;\r
 \r
@@ -147,17 +167,7 @@ DumpAllTrace(
 \r
   // Get Handle information\r
   //\r
-  Size = 0;\r
-  HandleBuffer = &TempHandle;\r
-  Status  = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, &TempHandle);\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    HandleBuffer = AllocatePool (Size);\r
-    ASSERT (HandleBuffer != NULL);\r
-    if (HandleBuffer == NULL) {\r
-      return;\r
-    }\r
-    Status  = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, HandleBuffer);\r
-  }\r
+  Status  = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);\r
   if (EFI_ERROR (Status)) {\r
     PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);\r
   }\r
@@ -168,27 +178,31 @@ DumpAllTrace(
     //    Display only records with Elapsed times >= mInterestThreshold\r
     //    Display driver names in Module field for records with Handles.\r
     //\r
-    PrintToken (STRING_TOKEN (STR_DP_ALL_HEADR) );\r
-    PrintToken (STRING_TOKEN (STR_DP_DASHES) );\r
+    if (mShowId) {\r
+      PrintToken (STRING_TOKEN (STR_DP_ALL_HEADR2) );\r
+      PrintToken (STRING_TOKEN (STR_DP_ALL_DASHES2) );\r
+    } else {\r
+      PrintToken (STRING_TOKEN (STR_DP_ALL_HEADR) );\r
+      PrintToken (STRING_TOKEN (STR_DP_DASHES) );\r
+    }\r
 \r
     LogEntryKey = 0;\r
     Count = 0;\r
     Index = 0;\r
     while ( WITHIN_LIMIT(Count, Limit) &&\r
-            ((LogEntryKey = GetPerformanceMeasurement (\r
+            ((LogEntryKey = GetPerformanceMeasurementEx (\r
                             LogEntryKey,\r
                             &Measurement.Handle,\r
                             &Measurement.Token,\r
                             &Measurement.Module,\r
                             &Measurement.StartTimeStamp,\r
-                            &Measurement.EndTimeStamp)) != 0)\r
+                            &Measurement.EndTimeStamp,\r
+                            &Measurement.Identifier)) != 0)\r
           )\r
     {\r
       ++Index;    // Count every record.  First record is 1.\r
       ElapsedTime = 0;\r
-      if (IncFlag != NULL) {\r
-        FreePool ((void *)IncFlag);\r
-      }\r
+      SafeFreePool ((VOID *) IncFlag);\r
       if (Measurement.EndTimeStamp != 0) {\r
         Duration = GetDuration (&Measurement);\r
         ElapsedTime = DurationInMicroSeconds ( Duration );\r
@@ -197,46 +211,65 @@ DumpAllTrace(
       else {\r
         IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL);  // Mark incomplete records\r
       }\r
-      if ((ElapsedTime < mInterestThreshold)                 ||\r
+      if (((Measurement.EndTimeStamp != 0) && (ElapsedTime < mInterestThreshold)) ||\r
           ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))\r
          ) {      // Ignore "uninteresting" or excluded records\r
         continue;\r
       }\r
-      if (Measurement.EndTimeStamp == 0) {\r
-        ElapsedTime = Measurement.StartTimeStamp;\r
-      }\r
       ++Count;    // Count the number of records printed\r
 \r
       // If Handle is non-zero, see if we can determine a name for the driver\r
-      AsciiStrToUnicodeStr (Measurement.Module, mGaugeString); // Use Module by default\r
-      AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);\r
+      AsciiStrToUnicodeStrS (Measurement.Module, mGaugeString, ARRAY_SIZE (mGaugeString)); // Use Module by default\r
+      AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));\r
       if (Measurement.Handle != NULL) {\r
         // See if the Handle is in the HandleBuffer\r
-        for (TIndex = 0; TIndex < (Size / sizeof(HandleBuffer[0])); TIndex++) {\r
+        for (TIndex = 0; TIndex < HandleCount; TIndex++) {\r
           if (Measurement.Handle == HandleBuffer[TIndex]) {\r
             GetNameFromHandle (HandleBuffer[TIndex]);\r
             break;\r
           }\r
         }\r
       }\r
-      // Ensure that the argument strings are not too long.\r
-      mGaugeString[31] = 0;\r
-      mUnicodeToken[18] = 0;\r
 \r
-      PrintToken( STRING_TOKEN (STR_DP_ALL_STATS),\r
-        Index,      // 1 based, Which measurement record is being printed\r
-        IncFlag,\r
-        Measurement.Handle,\r
-        mGaugeString,\r
-        mUnicodeToken,\r
-        ElapsedTime\r
-      );\r
+      if (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) == 0) {\r
+        UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", Measurement.Handle);\r
+      }\r
+\r
+      // Ensure that the argument strings are not too long.\r
+      mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+      mUnicodeToken[13] = 0;\r
+\r
+      if (mShowId) {\r
+        PrintToken( STRING_TOKEN (STR_DP_ALL_VARS2),\r
+          Index,      // 1 based, Which measurement record is being printed\r
+          IncFlag,\r
+          Measurement.Handle,\r
+          mGaugeString,\r
+          mUnicodeToken,\r
+          ElapsedTime,\r
+          Measurement.Identifier\r
+        );\r
+      } else {\r
+        PrintToken( STRING_TOKEN (STR_DP_ALL_VARS),\r
+          Index,      // 1 based, Which measurement record is being printed\r
+          IncFlag,\r
+          Measurement.Handle,\r
+          mGaugeString,\r
+          mUnicodeToken,\r
+          ElapsedTime\r
+        );\r
+      }\r
+      if (ShellGetExecutionBreakFlag ()) {\r
+        Status = EFI_ABORTED;\r
+        break;\r
+      }\r
     }\r
   }\r
-  if (HandleBuffer != &TempHandle) {\r
+  if (HandleBuffer != NULL) {\r
     FreePool (HandleBuffer);\r
   }\r
-  FreePool ((void *)IncFlag);\r
+  SafeFreePool ((VOID *) IncFlag);\r
+  return Status;\r
 }\r
 \r
 /** \r
@@ -255,9 +288,11 @@ DumpAllTrace(
   \r
   @param[in]    Limit       The number of records to print.  Zero is ALL.\r
   @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display.\r
-  \r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_ABORTED           The user aborts the operation.\r
 **/\r
-VOID\r
+EFI_STATUS\r
 DumpRawTrace(\r
   IN UINTN          Limit,\r
   IN BOOLEAN        ExcludeFlag\r
@@ -272,6 +307,9 @@ DumpRawTrace(
 \r
   EFI_STRING    StringPtr;\r
   EFI_STRING    StringPtrUnknown;\r
+  EFI_STATUS    Status;\r
+\r
+  Status = EFI_SUCCESS;\r
 \r
   StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  \r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWTRACE), NULL);\r
@@ -280,20 +318,26 @@ DumpRawTrace(
   FreePool (StringPtr);\r
   FreePool (StringPtrUnknown);\r
 \r
-  PrintToken (STRING_TOKEN (STR_DP_RAW_HEADR) );\r
-  PrintToken (STRING_TOKEN (STR_DP_RAW_DASHES) );\r
+  if (mShowId) {\r
+    PrintToken (STRING_TOKEN (STR_DP_RAW_HEADR2) );\r
+    PrintToken (STRING_TOKEN (STR_DP_RAW_DASHES2) );\r
+  } else {\r
+    PrintToken (STRING_TOKEN (STR_DP_RAW_HEADR) );\r
+    PrintToken (STRING_TOKEN (STR_DP_RAW_DASHES) );\r
+  }\r
 \r
   LogEntryKey = 0;\r
   Count = 0;\r
   Index = 0;\r
   while ( WITHIN_LIMIT(Count, Limit) &&\r
-          ((LogEntryKey = GetPerformanceMeasurement (\r
+          ((LogEntryKey = GetPerformanceMeasurementEx (\r
                           LogEntryKey,\r
                           &Measurement.Handle,\r
                           &Measurement.Token,\r
                           &Measurement.Module,\r
                           &Measurement.StartTimeStamp,\r
-                          &Measurement.EndTimeStamp)) != 0)\r
+                          &Measurement.EndTimeStamp,\r
+                          &Measurement.Identifier)) != 0)\r
         )\r
   {\r
     ++Index;    // Count every record.  First record is 1.\r
@@ -308,26 +352,42 @@ DumpRawTrace(
       continue;\r
     }\r
     ++Count;    // Count the number of records printed\r
-    PrintToken (STRING_TOKEN (STR_DP_RAW_VARS),\r
-      Index,      // 1 based, Which measurement record is being printed\r
-      Measurement.Handle,\r
-      Measurement.StartTimeStamp,\r
-      Measurement.EndTimeStamp,\r
-      Measurement.Token,\r
-      Measurement.Module\r
-    );\r
+\r
+    if (mShowId) {\r
+      PrintToken (STRING_TOKEN (STR_DP_RAW_VARS2),\r
+        Index,      // 1 based, Which measurement record is being printed\r
+        Measurement.Handle,\r
+        Measurement.StartTimeStamp,\r
+        Measurement.EndTimeStamp,\r
+        Measurement.Token,\r
+        Measurement.Module,\r
+        Measurement.Identifier\r
+      );\r
+    } else {\r
+      PrintToken (STRING_TOKEN (STR_DP_RAW_VARS),\r
+        Index,      // 1 based, Which measurement record is being printed\r
+        Measurement.Handle,\r
+        Measurement.StartTimeStamp,\r
+        Measurement.EndTimeStamp,\r
+        Measurement.Token,\r
+        Measurement.Module\r
+      );\r
+    }\r
+    if (ShellGetExecutionBreakFlag ()) {\r
+      Status = EFI_ABORTED;\r
+      break;\r
+    }\r
   }\r
+  return Status;\r
 }\r
 \r
 /** \r
   Gather and print Major Phase metrics.\r
   \r
-  @param[in]    Ticker      The timer value for the END of Shell phase\r
-  \r
 **/\r
 VOID\r
 ProcessPhases(\r
-  UINT64            Ticker\r
+  VOID\r
   )\r
 {\r
   MEASUREMENT_RECORD        Measurement;\r
@@ -336,7 +396,6 @@ ProcessPhases(
   UINT64                    PeiTime;\r
   UINT64                    DxeTime;\r
   UINT64                    BdsTime;\r
-  UINT64                    ShellTime;\r
   UINT64                    ElapsedTime;\r
   UINT64                    Duration;\r
   UINT64                    Total;\r
@@ -349,7 +408,6 @@ ProcessPhases(
   PeiTime         = 0;\r
   DxeTime         = 0;\r
   BdsTime         = 0;\r
-  ShellTime       = 0;   \r
   //\r
   // Get Execution Phase Statistics\r
   //\r
@@ -361,17 +419,15 @@ ProcessPhases(
   FreePool (StringPtrUnknown);\r
 \r
   LogEntryKey = 0;\r
-  while ((LogEntryKey = GetPerformanceMeasurement (\r
+  while ((LogEntryKey = GetPerformanceMeasurementEx (\r
                           LogEntryKey,\r
                           &Measurement.Handle,\r
                           &Measurement.Token,\r
                           &Measurement.Module,\r
                           &Measurement.StartTimeStamp,\r
-                          &Measurement.EndTimeStamp)) != 0)\r
+                          &Measurement.EndTimeStamp,\r
+                          &Measurement.Identifier)) != 0)\r
   {\r
-    if (AsciiStrnCmp (Measurement.Token, ALit_SHELL, PERF_TOKEN_LENGTH) == 0) {\r
-      Measurement.EndTimeStamp = Ticker;\r
-    }\r
     if (Measurement.EndTimeStamp == 0) { // Skip "incomplete" records\r
       continue;\r
     }\r
@@ -389,8 +445,6 @@ ProcessPhases(
       DxeTime      = Duration;\r
     } else if (AsciiStrnCmp (Measurement.Token, ALit_BDS, PERF_TOKEN_LENGTH) == 0) {\r
       BdsTime      = Duration;\r
-    } else if (AsciiStrnCmp (Measurement.Token, ALit_SHELL, PERF_TOKEN_LENGTH) == 0) {\r
-      ShellTime    = Duration;\r
     }\r
   }\r
 \r
@@ -445,17 +499,6 @@ ProcessPhases(
     PrintToken (STRING_TOKEN (STR_DP_PHASE_BDSTO), ALit_BdsTO, ElapsedTime);\r
   }\r
 \r
-  // print SHELL phase duration time\r
-  //\r
-  if (ShellTime > 0) {\r
-    ElapsedTime = DivU64x32 (\r
-                    ShellTime,\r
-                    (UINT32)TimerInfo.Frequency\r
-                    );\r
-    Total += ElapsedTime;\r
-    PrintToken (STRING_TOKEN (STR_DP_PHASE_DURATION), ALit_SHELL, ElapsedTime);\r
-  }\r
-\r
   PrintToken (STRING_TOKEN (STR_DP_TOTAL_DURATION), Total);\r
 }\r
 \r
@@ -463,8 +506,10 @@ ProcessPhases(
   Gather and print Handle data.\r
   \r
   @param[in]    ExcludeFlag   TRUE to exclude individual Cumulative items from display.\r
-  \r
-  @return       Status from a call to gBS->LocateHandle().\r
+\r
+  @retval EFI_SUCCESS             The operation was successful.\r
+  @retval EFI_ABORTED             The user aborts the operation.\r
+  @return Others                  from a call to gBS->LocateHandleBuffer().\r
 **/\r
 EFI_STATUS\r
 ProcessHandles(\r
@@ -479,8 +524,7 @@ ProcessHandles(
   UINTN                     Index;\r
   UINTN                     LogEntryKey;\r
   UINTN                     Count;\r
-  UINTN                     Size;\r
-  EFI_HANDLE                TempHandle;\r
+  UINTN                     HandleCount;\r
   EFI_STATUS                Status;\r
   EFI_STRING                StringPtrUnknown;\r
 \r
@@ -491,17 +535,7 @@ ProcessHandles(
   FreePool (StringPtr);\r
   FreePool (StringPtrUnknown);\r
 \r
-  Size = 0;\r
-  HandleBuffer = &TempHandle;\r
-  Status  = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, &TempHandle);\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    HandleBuffer = AllocatePool (Size);\r
-    ASSERT (HandleBuffer != NULL);\r
-    if (HandleBuffer == NULL) {\r
-      return Status;\r
-    }\r
-    Status  = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, HandleBuffer);\r
-  }\r
+  Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);\r
   if (EFI_ERROR (Status)) {\r
     PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);\r
   }\r
@@ -510,18 +544,23 @@ ProcessHandles(
     Print (L"There are %,d Handles defined.\n", (Size / sizeof(HandleBuffer[0])));\r
 #endif\r
 \r
-    PrintToken (STRING_TOKEN (STR_DP_HANDLE_GUID) );\r
+    if (mShowId) {\r
+      PrintToken (STRING_TOKEN (STR_DP_HANDLE_SECTION2) );\r
+    } else {\r
+      PrintToken (STRING_TOKEN (STR_DP_HANDLE_SECTION) );\r
+    }\r
     PrintToken (STRING_TOKEN (STR_DP_DASHES) );\r
 \r
     LogEntryKey = 0;\r
     Count   = 0;\r
-    while ((LogEntryKey = GetPerformanceMeasurement (\r
+    while ((LogEntryKey = GetPerformanceMeasurementEx (\r
                             LogEntryKey,\r
                             &Measurement.Handle,\r
                             &Measurement.Token,\r
                             &Measurement.Module,\r
                             &Measurement.StartTimeStamp,\r
-                            &Measurement.EndTimeStamp)) != 0)\r
+                            &Measurement.EndTimeStamp,\r
+                            &Measurement.Identifier)) != 0)\r
     {\r
       Count++;\r
       Duration = GetDuration (&Measurement);\r
@@ -534,31 +573,47 @@ ProcessHandles(
         continue;\r
       }\r
       mGaugeString[0] = 0;    // Empty driver name by default\r
-      AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);\r
+      AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));\r
       // See if the Handle is in the HandleBuffer\r
-      for (Index = 0; Index < (Size / sizeof(HandleBuffer[0])); Index++) {\r
+      for (Index = 0; Index < HandleCount; Index++) {\r
         if (Measurement.Handle == HandleBuffer[Index]) {\r
           GetNameFromHandle (HandleBuffer[Index]); // Name is put into mGaugeString\r
           break;\r
         }\r
       }\r
       // Ensure that the argument strings are not too long.\r
-      mGaugeString[31] = 0;\r
-      mUnicodeToken[18] = 0;\r
+      mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+      mUnicodeToken[11] = 0;\r
       if (mGaugeString[0] != 0) {\r
         // Display the record if it has a valid handle.\r
-        PrintToken (\r
-          STRING_TOKEN (STR_DP_HANDLE_VARS),\r
-          Count,      // 1 based, Which measurement record is being printed\r
-          Index + 1,  // 1 based, Which handle is being printed\r
-          mGaugeString,\r
-          mUnicodeToken,\r
-          ElapsedTime\r
-        );\r
+        if (mShowId) {\r
+          PrintToken (\r
+            STRING_TOKEN (STR_DP_HANDLE_VARS2),\r
+            Count,      // 1 based, Which measurement record is being printed\r
+            Index + 1,  // 1 based, Which handle is being printed\r
+            mGaugeString,\r
+            mUnicodeToken,\r
+            ElapsedTime,\r
+            Measurement.Identifier\r
+          );\r
+        } else {\r
+          PrintToken (\r
+            STRING_TOKEN (STR_DP_HANDLE_VARS),\r
+            Count,      // 1 based, Which measurement record is being printed\r
+            Index + 1,  // 1 based, Which handle is being printed\r
+            mGaugeString,\r
+            mUnicodeToken,\r
+            ElapsedTime\r
+          );\r
+        }\r
+      }\r
+      if (ShellGetExecutionBreakFlag ()) {\r
+        Status = EFI_ABORTED;\r
+        break;\r
       }\r
     }\r
   }\r
-  if (HandleBuffer != &TempHandle) {\r
+  if (HandleBuffer != NULL) {\r
     FreePool (HandleBuffer);\r
   }\r
   return Status;\r
@@ -568,9 +623,11 @@ ProcessHandles(
   Gather and print PEIM data.\r
   \r
   Only prints complete PEIM records\r
-  \r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_ABORTED           The user aborts the operation.\r
 **/\r
-VOID\r
+EFI_STATUS\r
 ProcessPeims(\r
   VOID\r
 )\r
@@ -582,6 +639,9 @@ ProcessPeims(
   UINTN                     LogEntryKey;\r
   UINTN                     TIndex;\r
   EFI_STRING                StringPtrUnknown;\r
+  EFI_STATUS                Status;\r
+\r
+  Status = EFI_SUCCESS;\r
 \r
   StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  \r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_PEIMS), NULL);\r
@@ -590,17 +650,22 @@ ProcessPeims(
   FreePool (StringPtr);\r
   FreePool (StringPtrUnknown);\r
 \r
-  PrintToken (STRING_TOKEN (STR_DP_PEIM_SECTION));\r
+  if (mShowId) {\r
+    PrintToken (STRING_TOKEN (STR_DP_PEIM_SECTION2));\r
+  } else {\r
+    PrintToken (STRING_TOKEN (STR_DP_PEIM_SECTION));\r
+  }\r
   PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
   TIndex  = 0;\r
   LogEntryKey = 0;\r
-  while ((LogEntryKey = GetPerformanceMeasurement (\r
+  while ((LogEntryKey = GetPerformanceMeasurementEx (\r
                           LogEntryKey,\r
                           &Measurement.Handle,\r
                           &Measurement.Token,\r
                           &Measurement.Module,\r
                           &Measurement.StartTimeStamp,\r
-                          &Measurement.EndTimeStamp)) != 0)\r
+                          &Measurement.EndTimeStamp,\r
+                          &Measurement.Identifier)) != 0)\r
   {\r
     TIndex++;\r
     if ((Measurement.EndTimeStamp == 0) ||\r
@@ -613,14 +678,29 @@ ProcessPeims(
     ElapsedTime = DurationInMicroSeconds ( Duration );  // Calculate elapsed time in microseconds\r
     if (ElapsedTime >= mInterestThreshold) {\r
       // PEIM FILE Handle is the start address of its FFS file that contains its file guid.\r
-      PrintToken (STRING_TOKEN (STR_DP_PEIM_STAT2),\r
-            TIndex,   // 1 based, Which measurement record is being printed\r
-            Measurement.Handle,  // base address\r
-            Measurement.Handle,  // file guid\r
-            ElapsedTime\r
-      );\r
+      if (mShowId) {\r
+        PrintToken (STRING_TOKEN (STR_DP_PEIM_VARS2),\r
+              TIndex,   // 1 based, Which measurement record is being printed\r
+              Measurement.Handle,  // base address\r
+              Measurement.Handle,  // file guid\r
+              ElapsedTime,\r
+              Measurement.Identifier\r
+        );\r
+      } else {\r
+        PrintToken (STRING_TOKEN (STR_DP_PEIM_VARS),\r
+              TIndex,   // 1 based, Which measurement record is being printed\r
+              Measurement.Handle,  // base address\r
+              Measurement.Handle,  // file guid\r
+              ElapsedTime\r
+        );\r
+      }\r
+    }\r
+    if (ShellGetExecutionBreakFlag ()) {\r
+      Status = EFI_ABORTED;\r
+      break;\r
     }\r
   }\r
+  return Status;\r
 }\r
 \r
 /** \r
@@ -630,9 +710,11 @@ ProcessPeims(
   Only prints records where Handle is NULL\r
   Increment TIndex for every record, even skipped ones, so that we have an\r
   indication of every measurement record taken.\r
-  \r
+\r
+  @retval EFI_SUCCESS           The operation was successful.\r
+  @retval EFI_ABORTED           The user aborts the operation.\r
 **/\r
-VOID\r
+EFI_STATUS\r
 ProcessGlobal(\r
   VOID\r
 )\r
@@ -644,6 +726,9 @@ ProcessGlobal(
   UINTN                     LogEntryKey;\r
   UINTN                     Index;        // Index, or number, of the measurement record being processed\r
   EFI_STRING                StringPtrUnknown;\r
+  EFI_STATUS                Status;\r
+\r
+  Status = EFI_SUCCESS;\r
 \r
   StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  \r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_GENERAL), NULL);\r
@@ -652,22 +737,29 @@ ProcessGlobal(
   FreePool (StringPtr);\r
   FreePool (StringPtrUnknown);\r
 \r
-  PrintToken (STRING_TOKEN (STR_DP_GLOBAL_SECTION));\r
+  if (mShowId) {\r
+    PrintToken (STRING_TOKEN (STR_DP_GLOBAL_SECTION2));\r
+  } else {\r
+    PrintToken (STRING_TOKEN (STR_DP_GLOBAL_SECTION));\r
+  }\r
   PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
 \r
   Index = 1;\r
   LogEntryKey = 0;\r
 \r
-  while ((LogEntryKey = GetPerformanceMeasurement (\r
+  while ((LogEntryKey = GetPerformanceMeasurementEx (\r
                           LogEntryKey,\r
                           &Measurement.Handle,\r
                           &Measurement.Token,\r
                           &Measurement.Module,\r
                           &Measurement.StartTimeStamp,\r
-                          &Measurement.EndTimeStamp)) != 0)\r
+                          &Measurement.EndTimeStamp,\r
+                          &Measurement.Identifier)) != 0)\r
   {\r
-    AsciiStrToUnicodeStr (Measurement.Module, mGaugeString);\r
-    AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);\r
+    AsciiStrToUnicodeStrS (Measurement.Module, mGaugeString, ARRAY_SIZE (mGaugeString));\r
+    AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));\r
+    mGaugeString[25] = 0;\r
+    mUnicodeToken[31] = 0;\r
     if ( ! ( IsPhase( &Measurement)  ||\r
         (Measurement.Handle != NULL)      ||\r
         (Measurement.EndTimeStamp == 0)\r
@@ -676,17 +768,33 @@ ProcessGlobal(
       Duration = GetDuration (&Measurement);\r
       ElapsedTime = DurationInMicroSeconds ( Duration );\r
       if (ElapsedTime >= mInterestThreshold) {\r
-        PrintToken (\r
-          STRING_TOKEN (STR_DP_FOUR_VARS_2),\r
-          Index,\r
-          mGaugeString,\r
-          mUnicodeToken,\r
-          ElapsedTime\r
-          );\r
+        if (mShowId) {\r
+          PrintToken (\r
+            STRING_TOKEN (STR_DP_GLOBAL_VARS2),\r
+            Index,\r
+            mGaugeString,\r
+            mUnicodeToken,\r
+            ElapsedTime,\r
+            Measurement.Identifier\r
+            );\r
+        } else {\r
+           PrintToken (\r
+            STRING_TOKEN (STR_DP_GLOBAL_VARS),\r
+            Index,\r
+            mGaugeString,\r
+            mUnicodeToken,\r
+            ElapsedTime\r
+            );\r
+        }\r
       }\r
     }\r
+    if (ShellGetExecutionBreakFlag ()) {\r
+      Status = EFI_ABORTED;\r
+      break;\r
+    }\r
     Index++;\r
   }\r
+  return Status;\r
 }\r
 \r
 /** \r
@@ -696,12 +804,14 @@ ProcessGlobal(
   For each record with a Token listed in the CumData array:<BR>\r
      - Update the instance count and the total, minimum, and maximum durations.\r
   Finally, print the gathered cumulative statistics.\r
-  \r
+\r
+  @param[in]    CustomCumulativeData  A pointer to the cumtom cumulative data.\r
+\r
 **/\r
 VOID\r
 ProcessCumulative(\r
-  VOID\r
-)\r
+  IN PERF_CUM_DATA                  *CustomCumulativeData OPTIONAL\r
+  )\r
 {\r
   UINT64                    AvgDur;         // the computed average duration\r
   UINT64                    Dur;\r
@@ -723,19 +833,47 @@ ProcessCumulative(
   PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
 \r
   for ( TIndex = 0; TIndex < NumCum; ++TIndex) {\r
-    AvgDur = DivU64x32 (CumData[TIndex].Duration, CumData[TIndex].Count);\r
-    AvgDur = DurationInMicroSeconds(AvgDur);\r
-    Dur    = DurationInMicroSeconds(CumData[TIndex].Duration);\r
-    MaxDur = DurationInMicroSeconds(CumData[TIndex].MaxDur);\r
-    MinDur = DurationInMicroSeconds(CumData[TIndex].MinDur);\r
+    if (CumData[TIndex].Count != 0) {\r
+      AvgDur = DivU64x32 (CumData[TIndex].Duration, CumData[TIndex].Count);\r
+      AvgDur = DurationInMicroSeconds(AvgDur);\r
+      Dur    = DurationInMicroSeconds(CumData[TIndex].Duration);\r
+      MaxDur = DurationInMicroSeconds(CumData[TIndex].MaxDur);\r
+      MinDur = DurationInMicroSeconds(CumData[TIndex].MinDur);\r
     \r
+      PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_STATS),\r
+                  CumData[TIndex].Name,\r
+                  CumData[TIndex].Count,\r
+                  Dur,\r
+                  AvgDur,\r
+                  MinDur,\r
+                  MaxDur\r
+                 );\r
+    }\r
+  }\r
+\r
+  //\r
+  // Print the custom cumulative data.\r
+  //\r
+  if (CustomCumulativeData != NULL) {\r
+    if (CustomCumulativeData->Count != 0) {\r
+      AvgDur = DivU64x32 (CustomCumulativeData->Duration, CustomCumulativeData->Count);\r
+      AvgDur = DurationInMicroSeconds (AvgDur);\r
+      Dur    = DurationInMicroSeconds (CustomCumulativeData->Duration);\r
+      MaxDur = DurationInMicroSeconds (CustomCumulativeData->MaxDur);\r
+      MinDur = DurationInMicroSeconds (CustomCumulativeData->MinDur);\r
+    } else {\r
+      AvgDur = 0;\r
+      Dur    = 0;\r
+      MaxDur = 0;\r
+      MinDur = 0;\r
+    }\r
     PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_STATS),\r
-                CumData[TIndex].Name,\r
-                CumData[TIndex].Count,\r
+                CustomCumulativeData->Name,\r
+                CustomCumulativeData->Count,\r
                 Dur,\r
                 AvgDur,\r
                 MinDur,\r
                 MaxDur\r
-               );\r
+                );\r
   }\r
 }\r