]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PerformancePkg/Dp_App/DpTrace.c
Enhance inf to follow spec.
[mirror_edk2.git] / PerformancePkg / Dp_App / DpTrace.c
index 77939c596e3e2db37a7ba804198b16fb090fc2a0..f4cdb88aafff218e1de757553224ad23222da6cd 100644 (file)
 #include "Literals.h"\r
 #include "DpInternal.h"\r
 \r
-/** Collect verbose statistics about the logged performance measurements.\r
-  *\r
-  * General Summary information for all Trace measurements is gathered and\r
-  * stored within the SummaryData structure.  This information is both\r
-  * used internally by subsequent reporting functions, and displayed\r
-  * at the end of verbose reports.\r
-  *\r
-  * @pre  The SummaryData and CumData structures must be initialized\r
-  *       prior to calling this function.\r
-  *\r
-  * @post The SummaryData and CumData structures contain statistics for the\r
-  *       current performance logs.\r
+/** \r
+  Collect verbose statistics about the logged performance measurements.\r
+  \r
+  General Summary information for all Trace measurements is gathered and\r
+  stored within the SummaryData structure.  This information is both\r
+  used internally by subsequent reporting functions, and displayed\r
+  at the end of verbose reports.\r
+  \r
+  @pre  The SummaryData and CumData structures must be initialized\r
+        prior to calling this function.\r
+  \r
+  @post The SummaryData and CumData structures contain statistics for the\r
+        current performance logs.\r
 **/\r
 VOID\r
 GatherStatistics(\r
@@ -50,7 +51,7 @@ GatherStatistics(
   MEASUREMENT_RECORD        Measurement;\r
   UINT64                    Duration;\r
   UINTN                     LogEntryKey;\r
-  UINTN                     TIndex;\r
+  INTN                      TIndex;\r
 \r
   LogEntryKey = 0;\r
   while ((LogEntryKey = GetPerformanceMeasurement (\r
@@ -99,22 +100,23 @@ GatherStatistics(
   }\r
 }\r
 \r
-/** Gather and print ALL Trace Records.\r
-  *\r
-  * Displays all "interesting" Trace measurements in order.<BR>\r
-  * The number of records displayed is controlled by:\r
-  *   - records with a duration less than mInterestThreshold microseconds are not displayed.\r
-  *   - No more than Limit records are displayed.  A Limit of zero will not limit the output.\r
-  *   - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r
-  *     displayed.\r
-  *\r
-  * @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.\r
-  *         The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.\r
-  *         They must not be in use by a calling function.\r
-  *\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
+  Gather and print ALL Trace Records.\r
+  \r
+  Displays all "interesting" Trace measurements in order.<BR>\r
+  The number of records displayed is controlled by:\r
+     - records with a duration less than mInterestThreshold microseconds are not displayed.\r
+     - No more than Limit records are displayed.  A Limit of zero will not limit the output.\r
+     - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r
+       displayed.\r
+  \r
+  @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.\r
+           The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.\r
+           They must not be in use by a calling function.\r
+  \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
 VOID\r
 DumpAllTrace(\r
@@ -135,19 +137,25 @@ DumpAllTrace(
   UINTN                     Size;\r
   EFI_HANDLE                TempHandle;\r
   EFI_STATUS                Status;\r
+  EFI_STRING                StringPtrUnknown;\r
 \r
+  StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  \r
   IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_ALL), NULL);\r
   PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
-              (IncFlag == NULL) ? ALit_UNKNOWN: IncFlag);\r
+              (IncFlag == NULL) ? StringPtrUnknown : IncFlag);\r
+  FreePool (StringPtrUnknown);\r
 \r
   // Get Handle information\r
   //\r
   Size = 0;\r
-  HandleBuffer = NULL;\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
   if (EFI_ERROR (Status)) {\r
@@ -178,13 +186,16 @@ DumpAllTrace(
     {\r
       ++Index;    // Count every record.  First record is 1.\r
       ElapsedTime = 0;\r
+      if (IncFlag != NULL) {\r
+        FreePool ((void *)IncFlag);\r
+      }\r
       if (Measurement.EndTimeStamp != 0) {\r
         Duration = GetDuration (&Measurement);\r
         ElapsedTime = DurationInMicroSeconds ( Duration );\r
-        IncFlag = STR_DP_COMPLETE;\r
+        IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_COMPLETE), NULL);\r
       }\r
       else {\r
-        IncFlag = STR_DP_INCOMPLETE;  // Mark incomplete records\r
+        IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL);  // Mark incomplete records\r
       }\r
       if ((ElapsedTime < mInterestThreshold)                 ||\r
           ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))\r
@@ -222,25 +233,29 @@ DumpAllTrace(
       );\r
     }\r
   }\r
-  FreePool (HandleBuffer);\r
+  if (HandleBuffer != &TempHandle) {\r
+    FreePool (HandleBuffer);\r
+  }\r
+  FreePool ((void *)IncFlag);\r
 }\r
 \r
-/** Gather and print Raw Trace Records.\r
-  *\r
-  * All Trace measurements with a duration greater than or equal to\r
-  * mInterestThreshold are printed without interpretation.\r
-  *\r
-  * The number of records displayed is controlled by:\r
-  *   - records with a duration less than mInterestThreshold microseconds are not displayed.\r
-  *   - No more than Limit records are displayed.  A Limit of zero will not limit the output.\r
-  *   - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r
-  *     displayed.\r
-  *\r
-  * @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.\r
-  *\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
+  Gather and print Raw Trace Records.\r
+  \r
+  All Trace measurements with a duration greater than or equal to\r
+  mInterestThreshold are printed without interpretation.\r
+  \r
+  The number of records displayed is controlled by:\r
+     - records with a duration less than mInterestThreshold microseconds are not displayed.\r
+     - No more than Limit records are displayed.  A Limit of zero will not limit the output.\r
+     - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r
+       displayed.\r
+  \r
+  @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.\r
+  \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
 VOID\r
 DumpRawTrace(\r
@@ -256,10 +271,14 @@ DumpRawTrace(
   UINTN                     Index;\r
 \r
   EFI_STRING    StringPtr;\r
+  EFI_STRING    StringPtrUnknown;\r
 \r
+  StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  \r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWTRACE), NULL);\r
   PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
-              (StringPtr == NULL) ? ALit_UNKNOWN: StringPtr);\r
+              (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
+  FreePool (StringPtr);\r
+  FreePool (StringPtrUnknown);\r
 \r
   PrintToken (STRING_TOKEN (STR_DP_RAW_HEADR) );\r
   PrintToken (STRING_TOKEN (STR_DP_RAW_DASHES) );\r
@@ -300,35 +319,46 @@ DumpRawTrace(
   }\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
+  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
+  IN UINT64            Ticker\r
   )\r
 {\r
   MEASUREMENT_RECORD        Measurement;\r
-  UINT64                    BdsTimeoutValue = 0;\r
-  UINT64                    SecTime         = 0;\r
-  UINT64                    PeiTime         = 0;\r
-  UINT64                    DxeTime         = 0;\r
-  UINT64                    BdsTime         = 0;\r
-  UINT64                    ShellTime       = 0;\r
+  UINT64                    BdsTimeoutValue;\r
+  UINT64                    SecTime;\r
+  UINT64                    PeiTime;\r
+  UINT64                    DxeTime;\r
+  UINT64                    BdsTime;\r
+  UINT64                    ShellTime;\r
   UINT64                    ElapsedTime;\r
   UINT64                    Duration;\r
   UINT64                    Total;\r
   EFI_STRING                StringPtr;\r
   UINTN                     LogEntryKey;\r
-\r
+  EFI_STRING                StringPtrUnknown;\r
+\r
+  BdsTimeoutValue = 0;\r
+  SecTime         = 0;\r
+  PeiTime         = 0;\r
+  DxeTime         = 0;\r
+  BdsTime         = 0;\r
+  ShellTime       = 0;   \r
   //\r
   // Get Execution Phase Statistics\r
   //\r
+  StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);   \r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_PHASES), NULL);\r
   PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
-              (StringPtr == NULL) ? ALit_UNKNOWN: StringPtr);\r
+              (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
+  FreePool (StringPtr);\r
+  FreePool (StringPtrUnknown);\r
 \r
   LogEntryKey = 0;\r
   while ((LogEntryKey = GetPerformanceMeasurement (\r
@@ -429,11 +459,12 @@ ProcessPhases(
   PrintToken (STRING_TOKEN (STR_DP_TOTAL_DURATION), Total);\r
 }\r
 \r
-/** 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
+  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
 EFI_STATUS\r
 ProcessHandles(\r
@@ -451,17 +482,24 @@ ProcessHandles(
   UINTN                     Size;\r
   EFI_HANDLE                TempHandle;\r
   EFI_STATUS                Status;\r
+  EFI_STRING                StringPtrUnknown;\r
 \r
+  StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  \r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_DRIVERS), NULL);\r
   PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
-              (StringPtr == NULL) ? ALit_UNKNOWN: StringPtr);\r
+              (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
+  FreePool (StringPtr);\r
+  FreePool (StringPtrUnknown);\r
 \r
   Size = 0;\r
-  HandleBuffer = NULL;\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
   if (EFI_ERROR (Status)) {\r
@@ -520,14 +558,17 @@ ProcessHandles(
       }\r
     }\r
   }\r
-  FreePool (HandleBuffer);\r
+  if (HandleBuffer != &TempHandle) {\r
+    FreePool (HandleBuffer);\r
+  }\r
   return Status;\r
 }\r
 \r
-/** Gather and print PEIM data.\r
-  *\r
-  * Only prints complete PEIM records\r
-  *\r
+/** \r
+  Gather and print PEIM data.\r
+  \r
+  Only prints complete PEIM records\r
+  \r
 **/\r
 VOID\r
 ProcessPeims(\r
@@ -540,11 +581,14 @@ ProcessPeims(
   EFI_STRING                StringPtr;\r
   UINTN                     LogEntryKey;\r
   UINTN                     TIndex;\r
+  EFI_STRING                StringPtrUnknown;\r
 \r
-\r
+  StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  \r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_PEIMS), NULL);\r
   PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
-              (StringPtr == NULL) ? ALit_UNKNOWN: StringPtr);\r
+              (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
+  FreePool (StringPtr);\r
+  FreePool (StringPtrUnknown);\r
 \r
   PrintToken (STRING_TOKEN (STR_DP_PEIM_SECTION));\r
   PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
@@ -568,25 +612,25 @@ ProcessPeims(
     Duration = GetDuration (&Measurement);\r
     ElapsedTime = DurationInMicroSeconds ( Duration );  // Calculate elapsed time in microseconds\r
     if (ElapsedTime >= mInterestThreshold) {\r
-      GetNameFromHandle (Measurement.Handle);           // Name placed in mGaugeString\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,\r
-            mGaugeString,\r
+            Measurement.Handle,  // base address\r
+            Measurement.Handle,  // file guid\r
             ElapsedTime\r
       );\r
     }\r
   }\r
 }\r
 \r
-/** Gather and print global data.\r
-  *\r
-  * Strips out incomplete or "Execution Phase" records\r
-  * 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
+/** \r
+  Gather and print global data.\r
+  \r
+  Strips out incomplete or "Execution Phase" records\r
+  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
 VOID\r
 ProcessGlobal(\r
@@ -599,10 +643,14 @@ ProcessGlobal(
   EFI_STRING                StringPtr;\r
   UINTN                     LogEntryKey;\r
   UINTN                     Index;        // Index, or number, of the measurement record being processed\r
+  EFI_STRING                StringPtrUnknown;\r
 \r
+  StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  \r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_GENERAL), NULL);\r
   PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
-              (StringPtr == NULL) ? ALit_UNKNOWN: StringPtr);\r
+              (StringPtr == NULL) ? StringPtrUnknown: StringPtr);\r
+  FreePool (StringPtr);\r
+  FreePool (StringPtrUnknown);\r
 \r
   PrintToken (STRING_TOKEN (STR_DP_GLOBAL_SECTION));\r
   PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
@@ -641,41 +689,55 @@ ProcessGlobal(
   }\r
 }\r
 \r
-/** Gather and print cumulative data.\r
-  *\r
-  * Traverse the measurement records and:<BR>\r
-  * 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
+  Gather and print cumulative data.\r
+  \r
+  Traverse the measurement records and:<BR>\r
+  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
 VOID\r
 ProcessCumulative(\r
   VOID\r
 )\r
 {\r
-  UINT64                    avgval;         // the computed average duration\r
+  UINT64                    AvgDur;         // the computed average duration\r
+  UINT64                    Dur;\r
+  UINT64                    MinDur;\r
+  UINT64                    MaxDur;\r
   EFI_STRING                StringPtr;\r
   UINTN                     TIndex;\r
+  EFI_STRING                StringPtrUnknown;\r
 \r
-\r
+  StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  \r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_CUMULATIVE), NULL);\r
   PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
-              (StringPtr == NULL) ? ALit_UNKNOWN: StringPtr);\r
+              (StringPtr == NULL) ? StringPtrUnknown: StringPtr);\r
+  FreePool (StringPtr);\r
+  FreePool (StringPtrUnknown);\r
 \r
   PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_SECT_1));\r
   PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_SECT_2));\r
   PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
 \r
   for ( TIndex = 0; TIndex < NumCum; ++TIndex) {\r
-    avgval = DivU64x32 (CumData[TIndex].Duration, CumData[TIndex].Count);\r
-    PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_STATS),\r
-                CumData[TIndex].Name,\r
-                CumData[TIndex].Count,\r
-                DurationInMicroSeconds(CumData[TIndex].Duration),\r
-                DurationInMicroSeconds(avgval),\r
-                DurationInMicroSeconds(CumData[TIndex].MinDur),\r
-                DurationInMicroSeconds(CumData[TIndex].MaxDur)\r
-               );\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