]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PerformancePkg/Dp_App/DpTrace.c
ArmPlatformPkg: Fix stack switch bug after commit 7945b29
[mirror_edk2.git] / PerformancePkg / Dp_App / DpTrace.c
index 1f627e1f84455f1e7ed68c5742ae92a978feab68..d3df30ff28ab79c8e4a5b2c25e5d8a4c1af05856 100644 (file)
@@ -1,14 +1,15 @@
 /** @file\r
-  * Trace reporting for the Dp utility.\r
-  *\r
-  * Copyright (c) 2009 - 2011, 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 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2015 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
   \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 +58,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 +102,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
@@ -168,27 +187,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
@@ -225,20 +248,32 @@ DumpAllTrace(
       mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
       mUnicodeToken[13] = 0;\r
 \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
+      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
     }\r
   }\r
   if (HandleBuffer != &TempHandle) {\r
     FreePool (HandleBuffer);\r
   }\r
-  FreePool ((void *)IncFlag);\r
+  SafeFreePool ((VOID *) IncFlag);\r
 }\r
 \r
 /** \r
@@ -282,20 +317,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
@@ -310,14 +351,27 @@ 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
   }\r
 }\r
 \r
@@ -363,13 +417,14 @@ 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
@@ -512,18 +567,23 @@ ProcessHandles(
     Print (L"There are %,d Handles defined.\n", (Size / sizeof(HandleBuffer[0])));\r
 #endif\r
 \r
-    PrintToken (STRING_TOKEN (STR_DP_HANDLE_SECTION) );\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
@@ -549,14 +609,26 @@ ProcessHandles(
       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
     }\r
   }\r
@@ -592,17 +664,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
@@ -615,12 +692,22 @@ 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_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
+      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
   }\r
 }\r
@@ -654,23 +741,28 @@ 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
-    mGaugeString[26] = 0;\r
+    mGaugeString[25] = 0;\r
     mUnicodeToken[31] = 0;\r
     if ( ! ( IsPhase( &Measurement)  ||\r
         (Measurement.Handle != NULL)      ||\r
@@ -680,13 +772,24 @@ ProcessGlobal(
       Duration = GetDuration (&Measurement);\r
       ElapsedTime = DurationInMicroSeconds ( Duration );\r
       if (ElapsedTime >= mInterestThreshold) {\r
-        PrintToken (\r
-          STRING_TOKEN (STR_DP_GLOBAL_VARS),\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
     Index++;\r
@@ -700,12 +803,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
@@ -744,4 +849,30 @@ ProcessCumulative(
                  );\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
+                CustomCumulativeData->Name,\r
+                CustomCumulativeData->Count,\r
+                Dur,\r
+                AvgDur,\r
+                MinDur,\r
+                MaxDur\r
+                );\r
+  }\r
 }\r