]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/DynamicCommand/DpDynamicCommand/DpTrace.c
ShellPkg/Dp: Updated to dump perf log based on FPDT table
[mirror_edk2.git] / ShellPkg / DynamicCommand / DpDynamicCommand / DpTrace.c
index bc882be622abc2a0e4bccea6a101982fee79d1ba..7f7d296946fe7ca01fd26846671ae182d15011c1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Trace reporting for the Dp utility.\r
 \r
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.\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
 #include <Library/HiiLib.h>\r
 #include <Library/PcdLib.h>\r
 \r
-#include <Guid/Performance.h>\r
-\r
 #include "Dp.h"\r
 #include "Literals.h"\r
 #include "DpInternal.h"\r
 \r
+/**\r
+  Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
+\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
+  @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
+GetPerformanceMeasurementRecord (\r
+ IN  UINTN       LogEntryKey,\r
+ OUT CONST VOID  **Handle,\r
+ OUT CONST CHAR8 **Token,\r
+ OUT CONST CHAR8 **Module,\r
+ OUT UINT64      *StartTimeStamp,\r
+ OUT UINT64      *EndTimeStamp,\r
+ OUT UINT32      *Identifier\r
+  )\r
+{\r
+  if (LogEntryKey == mMeasurementNum) {\r
+    return 0;\r
+  }\r
+\r
+  *Handle         = (VOID *) (UINTN) mMeasurementList[LogEntryKey].Handle;\r
+  *Token          = mMeasurementList[LogEntryKey].Token;\r
+  *Module         = mMeasurementList[LogEntryKey].Module;\r
+  *StartTimeStamp = mMeasurementList[LogEntryKey].StartTimeStamp;\r
+  *EndTimeStamp   = mMeasurementList[LogEntryKey].EndTimeStamp;\r
+  *Identifier     = mMeasurementList[LogEntryKey].Identifier;\r
+\r
+  LogEntryKey ++;\r
+\r
+  return LogEntryKey;\r
+}\r
+\r
 /**\r
   Collect verbose statistics about the logged performance measurements.\r
 \r
@@ -57,7 +105,7 @@ GatherStatistics(
   INTN                      TIndex;\r
 \r
   LogEntryKey = 0;\r
-  while ((LogEntryKey = GetPerformanceMeasurementEx (\r
+  while ((LogEntryKey = GetPerformanceMeasurementRecord (\r
                         LogEntryKey,\r
                         &Measurement.Handle,\r
                         &Measurement.Token,\r
@@ -79,13 +127,13 @@ GatherStatistics(
     if (IsPhase( &Measurement)) {\r
       ++SummaryData.NumSummary;       // Count the number of major phases\r
     }\r
-    else {  // !IsPhase(...\r
+    else {  // !IsPhase\r
       if(Measurement.Handle == NULL) {\r
         ++SummaryData.NumGlobal;\r
       }\r
     }\r
 \r
-    if (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) == 0) {\r
+    if (AsciiStrCmp (Measurement.Token, ALit_PEIM) == 0) {\r
       ++SummaryData.NumPEIMs;         // Count PEIM measurements\r
     }\r
 \r
@@ -190,7 +238,7 @@ DumpAllTrace(
     Count = 0;\r
     Index = 0;\r
     while ( WITHIN_LIMIT(Count, Limit) &&\r
-            ((LogEntryKey = GetPerformanceMeasurementEx (\r
+            ((LogEntryKey = GetPerformanceMeasurementRecord (\r
                             LogEntryKey,\r
                             &Measurement.Handle,\r
                             &Measurement.Token,\r
@@ -231,7 +279,7 @@ DumpAllTrace(
         }\r
       }\r
 \r
-      if (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) == 0) {\r
+      if (AsciiStrCmp (Measurement.Token, ALit_PEIM) == 0) {\r
         UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", Measurement.Handle);\r
       }\r
 \r
@@ -331,7 +379,7 @@ DumpRawTrace(
   Count = 0;\r
   Index = 0;\r
   while ( WITHIN_LIMIT(Count, Limit) &&\r
-          ((LogEntryKey = GetPerformanceMeasurementEx (\r
+          ((LogEntryKey = GetPerformanceMeasurementRecord (\r
                           LogEntryKey,\r
                           &Measurement.Handle,\r
                           &Measurement.Token,\r
@@ -420,7 +468,7 @@ ProcessPhases(
   FreePool (StringPtrUnknown);\r
 \r
   LogEntryKey = 0;\r
-  while ((LogEntryKey = GetPerformanceMeasurementEx (\r
+  while ((LogEntryKey = GetPerformanceMeasurementRecord (\r
                           LogEntryKey,\r
                           &Measurement.Handle,\r
                           &Measurement.Token,\r
@@ -434,17 +482,17 @@ ProcessPhases(
     }\r
     Duration = GetDuration (&Measurement);\r
     if (   Measurement.Handle != NULL\r
-        && (AsciiStrnCmp (Measurement.Token, ALit_BdsTO, PERF_TOKEN_LENGTH) == 0)\r
+        && (AsciiStrCmp (Measurement.Token, ALit_BdsTO) == 0)\r
        )\r
     {\r
       BdsTimeoutValue = Duration;\r
-    } else if (AsciiStrnCmp (Measurement.Token, ALit_SEC, PERF_TOKEN_LENGTH) == 0) {\r
+    } else if (AsciiStrCmp (Measurement.Token, ALit_SEC) == 0) {\r
       SecTime     = Duration;\r
-    } else if (AsciiStrnCmp (Measurement.Token, ALit_PEI, PERF_TOKEN_LENGTH) == 0) {\r
+    } else if (AsciiStrCmp (Measurement.Token, ALit_PEI) == 0) {\r
       PeiTime     = Duration;\r
-    } else if (AsciiStrnCmp (Measurement.Token, ALit_DXE, PERF_TOKEN_LENGTH) == 0) {\r
+    } else if (AsciiStrCmp (Measurement.Token, ALit_DXE) == 0) {\r
       DxeTime      = Duration;\r
-    } else if (AsciiStrnCmp (Measurement.Token, ALit_BDS, PERF_TOKEN_LENGTH) == 0) {\r
+    } else if (AsciiStrCmp (Measurement.Token, ALit_BDS) == 0) {\r
       BdsTime      = Duration;\r
     }\r
   }\r
@@ -462,10 +510,7 @@ ProcessPhases(
   // print PEI phase duration time\r
   //\r
   if (PeiTime > 0) {\r
-    ElapsedTime = DivU64x32 (\r
-                    PeiTime,\r
-                    (UINT32)TimerInfo.Frequency\r
-                    );\r
+    ElapsedTime = DivU64x32 (PeiTime, 1000000);\r
     Total += ElapsedTime;\r
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_PEI, ElapsedTime);\r
   }\r
@@ -473,10 +518,7 @@ ProcessPhases(
   // print DXE phase duration time\r
   //\r
   if (DxeTime > 0) {\r
-    ElapsedTime = DivU64x32 (\r
-                    DxeTime,\r
-                    (UINT32)TimerInfo.Frequency\r
-                    );\r
+    ElapsedTime = DivU64x32 (DxeTime, 1000000);\r
     Total += ElapsedTime;\r
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_DXE, ElapsedTime);\r
   }\r
@@ -484,19 +526,13 @@ ProcessPhases(
   // print BDS phase duration time\r
   //\r
   if (BdsTime > 0) {\r
-    ElapsedTime = DivU64x32 (\r
-                    BdsTime,\r
-                    (UINT32)TimerInfo.Frequency\r
-                    );\r
+    ElapsedTime = DivU64x32 (BdsTime, 1000000);\r
     Total += ElapsedTime;\r
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_BDS, ElapsedTime);\r
   }\r
 \r
   if (BdsTimeoutValue > 0) {\r
-    ElapsedTime = DivU64x32 (\r
-                    BdsTimeoutValue,\r
-                    (UINT32)TimerInfo.Frequency\r
-                    );\r
+    ElapsedTime = DivU64x32 (BdsTimeoutValue, 1000000);\r
     ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_BDSTO), mDpHiiHandle, ALit_BdsTO, ElapsedTime);\r
   }\r
 \r
@@ -554,7 +590,7 @@ ProcessHandles(
 \r
     LogEntryKey = 0;\r
     Count   = 0;\r
-    while ((LogEntryKey = GetPerformanceMeasurementEx (\r
+    while ((LogEntryKey = GetPerformanceMeasurementRecord (\r
                             LogEntryKey,\r
                             &Measurement.Handle,\r
                             &Measurement.Token,\r
@@ -657,7 +693,7 @@ ProcessPeims(
   ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);\r
   TIndex  = 0;\r
   LogEntryKey = 0;\r
-  while ((LogEntryKey = GetPerformanceMeasurementEx (\r
+  while ((LogEntryKey = GetPerformanceMeasurementRecord (\r
                           LogEntryKey,\r
                           &Measurement.Handle,\r
                           &Measurement.Token,\r
@@ -668,7 +704,7 @@ ProcessPeims(
   {\r
     TIndex++;\r
     if ((Measurement.EndTimeStamp == 0) ||\r
-        (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) != 0)\r
+        (AsciiStrCmp (Measurement.Token, ALit_PEIM) != 0)\r
        ) {\r
       continue;\r
     }\r
@@ -680,7 +716,6 @@ ProcessPeims(
       if (mShowId) {\r
         ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_VARS2), mDpHiiHandle,\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
@@ -688,7 +723,6 @@ ProcessPeims(
       } else {\r
         ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_VARS), mDpHiiHandle,\r
               TIndex,   // 1 based, Which measurement record is being printed\r
-              Measurement.Handle,  // base address\r
               Measurement.Handle,  // file guid\r
               ElapsedTime\r
         );\r
@@ -746,7 +780,7 @@ ProcessGlobal(
   Index = 1;\r
   LogEntryKey = 0;\r
 \r
-  while ((LogEntryKey = GetPerformanceMeasurementEx (\r
+  while ((LogEntryKey = GetPerformanceMeasurementRecord (\r
                           LogEntryKey,\r
                           &Measurement.Handle,\r
                           &Measurement.Token,\r