]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmPerformance.c
MdeModulePkg UefiBootManagerLib: Do not assume perf entry count has no change
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmPerformance.c
index e45c0bd23a5b3c4f735ba74ecc731ec3f4ef2564..0abd0194409cc2b0b55b4e8f4e591fb4b554b338 100644 (file)
@@ -62,7 +62,7 @@ BmGetShortPdbFileName (
     for (Index = StartIndex; Index < EndIndex; Index++) {\r
       GaugeString[Index1] = PdbFileName[Index];\r
       Index1++;\r
-      if (Index1 == PERF_TOKEN_LENGTH - 1) {\r
+      if (Index1 == StringSize - 1) {\r
         break;\r
       }\r
     }\r
@@ -157,7 +157,7 @@ BmWriteBootToOsPerformanceData (
   UINT32                    LimitCount;\r
   EFI_HANDLE                *Handles;\r
   UINTN                     NoHandles;\r
-  CHAR8                     GaugeString[PERF_TOKEN_LENGTH];\r
+  CHAR8                     GaugeString[PERF_TOKEN_SIZE];\r
   UINT8                     *Ptr;\r
   UINT32                    Index;\r
   UINT64                    Ticker;\r
@@ -172,24 +172,14 @@ BmWriteBootToOsPerformanceData (
   UINT64                    StartValue;\r
   UINT64                    EndValue;\r
   BOOLEAN                   CountUp;\r
-  UINTN                     EntryIndex;\r
-  UINTN                     NumPerfEntries;\r
-  //\r
-  // List of flags indicating PerfEntry contains DXE handle\r
-  //\r
-  BOOLEAN                   *PerfEntriesAsDxeHandle;\r
   UINTN                     VarSize;\r
+  BOOLEAN                   Found;\r
 \r
   //\r
   // Record the performance data for End of BDS\r
   //\r
   PERF_END(NULL, "BDS", NULL, 0);\r
 \r
-  //\r
-  // Reset the entry count\r
-  //\r
-  mBmPerfHeader.Count = 0;\r
-\r
   //\r
   // Retrieve time stamp count as early as possible\r
   //\r
@@ -212,6 +202,11 @@ BmWriteBootToOsPerformanceData (
     CountUp            = FALSE;\r
   }\r
 \r
+  //\r
+  // Reset the entry count\r
+  //\r
+  mBmPerfHeader.Count = 0;\r
+\r
   if (mBmAcpiLowMemoryBase == 0x0FFFFFFFF) {\r
     VarSize = sizeof (EFI_PHYSICAL_ADDRESS);\r
     Status = gRT->GetVariable (\r
@@ -247,73 +242,10 @@ BmWriteBootToOsPerformanceData (
   Ptr        = (UINT8 *) ((UINT32) mBmAcpiLowMemoryBase + sizeof (PERF_HEADER));\r
   LimitCount = (UINT32) (PERF_DATA_MAX_LENGTH - sizeof (PERF_HEADER)) / sizeof (PERF_DATA);\r
 \r
-  NumPerfEntries = 0;\r
-  LogEntryKey    = 0;\r
-  while ((LogEntryKey = GetPerformanceMeasurement (\r
-                          LogEntryKey,\r
-                          &Handle,\r
-                          &Token,\r
-                          &Module,\r
-                          &StartTicker,\r
-                          &EndTicker)) != 0) {\r
-    NumPerfEntries++;\r
-  }\r
-  PerfEntriesAsDxeHandle = AllocateZeroPool (NumPerfEntries * sizeof (BOOLEAN));\r
-  ASSERT (PerfEntriesAsDxeHandle != NULL);\r
-  \r
   //\r
-  // Get DXE drivers performance\r
-  //\r
-  for (Index = 0; Index < NoHandles; Index++) {\r
-    Ticker = 0;\r
-    LogEntryKey = 0;\r
-    EntryIndex  = 0;\r
-    while ((LogEntryKey = GetPerformanceMeasurement (\r
-                            LogEntryKey,\r
-                            &Handle,\r
-                            &Token,\r
-                            &Module,\r
-                            &StartTicker,\r
-                            &EndTicker)) != 0) {\r
-      if (Handle == Handles[Index] && !PerfEntriesAsDxeHandle[EntryIndex]) {\r
-        PerfEntriesAsDxeHandle[EntryIndex] = TRUE;\r
-      }\r
-      EntryIndex++;\r
-      if ((Handle == Handles[Index]) && (EndTicker != 0)) {\r
-        if (StartTicker == 1) {\r
-          StartTicker = StartValue;\r
-        }\r
-        if (EndTicker == 1) {\r
-          EndTicker = StartValue;\r
-        }\r
-        Ticker += CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);\r
-      }\r
-    }\r
-\r
-    Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);\r
-\r
-    if (Duration > 0) {\r
-\r
-      BmGetNameFromHandle (Handles[Index], GaugeString, PERF_TOKEN_LENGTH);\r
-\r
-      AsciiStrCpyS (mBmPerfData.Token, PERF_TOKEN_SIZE, GaugeString);\r
-      mBmPerfData.Duration = Duration;\r
-\r
-      CopyMem (Ptr, &mBmPerfData, sizeof (PERF_DATA));\r
-      Ptr += sizeof (PERF_DATA);\r
-\r
-      mBmPerfHeader.Count++;\r
-      if (mBmPerfHeader.Count == LimitCount) {\r
-        goto Done;\r
-      }\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get inserted performance data\r
+  // Get performance data\r
   //\r
   LogEntryKey = 0;\r
-  EntryIndex  = 0;\r
   while ((LogEntryKey = GetPerformanceMeasurement (\r
                           LogEntryKey,\r
                           &Handle,\r
@@ -321,11 +253,7 @@ BmWriteBootToOsPerformanceData (
                           &Module,\r
                           &StartTicker,\r
                           &EndTicker)) != 0) {\r
-    if (!PerfEntriesAsDxeHandle[EntryIndex] && EndTicker != 0) {\r
-\r
-      ZeroMem (&mBmPerfData, sizeof (PERF_DATA));\r
-\r
-      AsciiStrnCpyS (mBmPerfData.Token, PERF_TOKEN_SIZE, Token, PERF_TOKEN_LENGTH);\r
+    if (EndTicker != 0) {\r
       if (StartTicker == 1) {\r
         StartTicker = StartValue;\r
       }\r
@@ -334,7 +262,31 @@ BmWriteBootToOsPerformanceData (
       }\r
       Ticker = CountUp ? (EndTicker - StartTicker) : (StartTicker - EndTicker);\r
 \r
-      mBmPerfData.Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);\r
+      Duration = (UINT32) DivU64x32 (Ticker, (UINT32) Freq);\r
+      if (Duration == 0) {\r
+        continue;\r
+      }\r
+\r
+      ZeroMem (&mBmPerfData, sizeof (PERF_DATA));\r
+\r
+      mBmPerfData.Duration = Duration;\r
+\r
+      //\r
+      // See if the Handle is in the handle buffer\r
+      //\r
+      Found = FALSE;\r
+      for (Index = 0; Index < NoHandles; Index++) {\r
+        if (Handle == Handles[Index]) {\r
+          BmGetNameFromHandle (Handles[Index], GaugeString, PERF_TOKEN_SIZE);\r
+          AsciiStrCpyS (mBmPerfData.Token, PERF_TOKEN_SIZE, GaugeString);\r
+          Found = TRUE;\r
+          break;\r
+        }\r
+      }\r
+\r
+      if (!Found) {\r
+        AsciiStrnCpyS (mBmPerfData.Token, PERF_TOKEN_SIZE, Token, PERF_TOKEN_LENGTH);\r
+      }\r
 \r
       CopyMem (Ptr, &mBmPerfData, sizeof (PERF_DATA));\r
       Ptr += sizeof (PERF_DATA);\r
@@ -344,13 +296,11 @@ BmWriteBootToOsPerformanceData (
         goto Done;\r
       }\r
     }\r
-    EntryIndex++;\r
   }\r
 \r
 Done:\r
 \r
   FreePool (Handles);\r
-  FreePool (PerfEntriesAsDxeHandle);\r
 \r
   mBmPerfHeader.Signiture = PERFORMANCE_SIGNATURE;\r
 \r