]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/DynamicCommand/DpDynamicCommand/DpUtilities.c
MdeModulePkg/Variable: Initialize local variable "RtPtrTrack"
[mirror_edk2.git] / ShellPkg / DynamicCommand / DpDynamicCommand / DpUtilities.c
index b98ec4b5bd8764b61dc202acfbc5b6caf59e5ec4..d1753fe00b8480483e79a44c77e39d3f747d4441 100644 (file)
@@ -1,15 +1,9 @@
 /** @file\r
   Utility functions used by the Dp application.\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
-  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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
 #include <Library/BaseLib.h>\r
 #include "Literals.h"\r
 #include "DpInternal.h"\r
 \r
-/** \r
+/**\r
   Calculate an event's duration in timer ticks.\r
-  \r
+\r
   Given the count direction and the event's start and end timer values,\r
   calculate the duration of the event in timer ticks.  Information for\r
   the current measurement is pointed to by the parameter.\r
-  \r
+\r
   If the measurement's start time is 1, it indicates that the developer\r
   is indicating that the measurement began at the release of reset.\r
   The start time is adjusted to the timer's starting count before performing\r
   the elapsed time calculation.\r
-  \r
+\r
   The calculated duration, in ticks, is the absolute difference between\r
   the measurement's ending and starting counts.\r
-  \r
+\r
   @param Measurement   Pointer to a MEASUREMENT_RECORD structure containing\r
                        data for the current measurement.\r
-  \r
+\r
   @return              The 64-bit duration of the event.\r
 **/\r
 UINT64\r
@@ -71,22 +65,8 @@ GetDuration (
     return 0;\r
   }\r
 \r
-  // PERF_START macros are called with a value of 1 to indicate\r
-  // the beginning of time.  So, adjust the start ticker value\r
-  // to the real beginning of time.\r
-  // Assumes no wraparound.  Even then, there is a very low probability\r
-  // of having a valid StartTicker value of 1.\r
-  if (Measurement->StartTimeStamp == 1) {\r
-    Measurement->StartTimeStamp = TimerInfo.StartCount;\r
-  }\r
-  if (TimerInfo.CountUp) {\r
-    Duration = Measurement->EndTimeStamp - Measurement->StartTimeStamp;\r
-    Error = (BOOLEAN)(Duration > Measurement->EndTimeStamp);\r
-  }\r
-  else {\r
-    Duration = Measurement->StartTimeStamp - Measurement->EndTimeStamp;\r
-    Error = (BOOLEAN)(Duration > Measurement->StartTimeStamp);\r
-  }\r
+  Duration = Measurement->EndTimeStamp - Measurement->StartTimeStamp;\r
+  Error = (BOOLEAN)(Duration > Measurement->EndTimeStamp);\r
 \r
   if (Error) {\r
     DEBUG ((EFI_D_ERROR, ALit_TimerLibError));\r
@@ -95,14 +75,14 @@ GetDuration (
   return Duration;\r
 }\r
 \r
-/** \r
+/**\r
   Determine whether the Measurement record is for an EFI Phase.\r
-  \r
+\r
   The Token and Module members of the measurement record are checked.\r
   Module must be empty and Token must be one of SEC, PEI, DXE, BDS, or SHELL.\r
-  \r
+\r
   @param[in]  Measurement A pointer to the Measurement record to test.\r
-  \r
+\r
   @retval     TRUE        The measurement record is for an EFI Phase.\r
   @retval     FALSE       The measurement record is NOT for an EFI Phase.\r
 **/\r
@@ -113,26 +93,57 @@ IsPhase(
 {\r
   BOOLEAN   RetVal;\r
 \r
-  RetVal = (BOOLEAN)( ( *Measurement->Module == '\0')                               &&\r
-            ((AsciiStrnCmp (Measurement->Token, ALit_SEC, PERF_TOKEN_LENGTH) == 0)    ||\r
-             (AsciiStrnCmp (Measurement->Token, ALit_PEI, PERF_TOKEN_LENGTH) == 0)    ||\r
-             (AsciiStrnCmp (Measurement->Token, ALit_DXE, PERF_TOKEN_LENGTH) == 0)    ||\r
-             (AsciiStrnCmp (Measurement->Token, ALit_BDS, PERF_TOKEN_LENGTH) == 0))\r
+  RetVal = (BOOLEAN)(\r
+            ((AsciiStrCmp (Measurement->Token, ALit_SEC) == 0)    ||\r
+             (AsciiStrCmp (Measurement->Token, ALit_PEI) == 0)    ||\r
+             (AsciiStrCmp (Measurement->Token, ALit_DXE) == 0)    ||\r
+             (AsciiStrCmp (Measurement->Token, ALit_BDS) == 0))\r
             );\r
   return RetVal;\r
 }\r
 \r
-/** \r
+/**\r
+  Determine whether the Measurement record is for core code.\r
+\r
+  @param[in] Measurement  A pointer to the Measurement record to test.\r
+\r
+  @retval     TRUE        The measurement record is used for core.\r
+  @retval     FALSE       The measurement record is NOT used for core.\r
+\r
+**/\r
+BOOLEAN\r
+IsCorePerf(\r
+  IN MEASUREMENT_RECORD        *Measurement\r
+  )\r
+{\r
+  BOOLEAN   RetVal;\r
+\r
+  RetVal = (BOOLEAN)(\r
+            ((Measurement->Identifier == MODULE_START_ID)            ||\r
+             (Measurement->Identifier == MODULE_END_ID)              ||\r
+             (Measurement->Identifier == MODULE_LOADIMAGE_START_ID)  ||\r
+             (Measurement->Identifier == MODULE_LOADIMAGE_END_ID)    ||\r
+             (Measurement->Identifier == MODULE_DB_START_ID)         ||\r
+             (Measurement->Identifier == MODULE_DB_END_ID)           ||\r
+             (Measurement->Identifier == MODULE_DB_SUPPORT_START_ID) ||\r
+             (Measurement->Identifier == MODULE_DB_SUPPORT_END_ID)   ||\r
+             (Measurement->Identifier == MODULE_DB_STOP_START_ID)    ||\r
+             (Measurement->Identifier == MODULE_DB_STOP_START_ID))\r
+            );\r
+  return RetVal;\r
+}\r
+\r
+/**\r
   Get the file name portion of the Pdb File Name.\r
-  \r
+\r
   The portion of the Pdb File Name between the last backslash and\r
   either a following period or the end of the string is converted\r
   to Unicode and copied into UnicodeBuffer.  The name is truncated,\r
   if necessary, to ensure that UnicodeBuffer is not overrun.\r
-  \r
+\r
   @param[in]  PdbFileName     Pdb file name.\r
   @param[out] UnicodeBuffer   The resultant Unicode File Name.\r
-  \r
+\r
 **/\r
 VOID\r
 DpGetShortPdbFileName (\r
@@ -175,7 +186,7 @@ DpGetShortPdbFileName (
   }\r
 }\r
 \r
-/** \r
+/**\r
   Get a human readable name for an image handle.\r
   The following methods will be tried orderly:\r
     1. Image PDB\r
@@ -360,17 +371,17 @@ DpGetNameFromHandle (
   FreePool (StringPtr);\r
 }\r
 \r
-/** \r
+/**\r
   Calculate the Duration in microseconds.\r
-  \r
+\r
   Duration is multiplied by 1000, instead of Frequency being divided by 1000 or\r
   multiplying the result by 1000, in order to maintain precision.  Since Duration is\r
   a 64-bit value, multiplying it by 1000 is unlikely to produce an overflow.\r
-  \r
+\r
   The time is calculated as (Duration * 1000) / Timer_Frequency.\r
-  \r
+\r
   @param[in]  Duration   The event duration in timer ticks.\r
-  \r
+\r
   @return     A 64-bit value which is the Elapsed time in microseconds.\r
 **/\r
 UINT64\r
@@ -378,22 +389,19 @@ DurationInMicroSeconds (
   IN UINT64 Duration\r
   )\r
 {\r
-  UINT64 Temp;\r
-\r
-  Temp = MultU64x32 (Duration, 1000);\r
-  return DivU64x32 (Temp, TimerInfo.Frequency);\r
+  return DivU64x32 (Duration, 1000);\r
 }\r
 \r
-/** \r
+/**\r
   Get index of Measurement Record's match in the CumData array.\r
-  \r
+\r
   If the Measurement's Token value matches a Token in one of the CumData\r
   records, the index of the matching record is returned.  The returned\r
   index is a signed value so that negative values can indicate that\r
   the Measurement didn't match any entry in the CumData array.\r
-  \r
+\r
   @param[in]  Measurement A pointer to a Measurement Record to match against the CumData array.\r
-  \r
+\r
   @retval     <0    Token is not in the CumData array.\r
   @retval     >=0   Return value is the index into CumData where Token is found.\r
 **/\r
@@ -405,7 +413,7 @@ GetCumulativeItem(
   INTN    Index;\r
 \r
   for( Index = 0; Index < (INTN)NumCum; ++Index) {\r
-    if (AsciiStrnCmp (Measurement->Token, CumData[Index].Name, PERF_TOKEN_LENGTH) == 0) {\r
+    if (AsciiStrCmp (Measurement->Token, CumData[Index].Name) == 0) {\r
       return Index;  // Exit, we found a match\r
     }\r
   }\r