]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PerformancePkg/Dp_App/DpUtilities.c
PerformancePkg Dp_App: Remove TimerLib dependency
[mirror_edk2.git] / PerformancePkg / Dp_App / DpUtilities.c
index 6f296c29ee31b5ecf481903dd65b4b4b9182019e..d5840e8d6f833b39da257720f2f96918ea41829b 100644 (file)
@@ -1,14 +1,15 @@
 /** @file\r
-  * Utility functions used by the Dp application.\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
+  Utility functions used by the Dp application.\r
+\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 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
 **/\r
 \r
 #include <Library/BaseLib.h>\r
@@ -16,7 +17,6 @@
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/TimerLib.h>\r
 #include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/PrintLib.h>\r
 #include <Library/HiiLib.h>\r
@@ -31,7 +31,6 @@
 #include <Protocol/DriverBinding.h>\r
 #include <Protocol/ComponentName2.h>\r
 #include <Protocol/DevicePath.h>\r
-#include <Protocol/DevicePathToText.h>\r
 \r
 #include <Guid/Performance.h>\r
 \r
@@ -83,6 +82,10 @@ GetDuration (
   UINT64    Duration;\r
   BOOLEAN   Error;\r
 \r
+  if (Measurement->EndTimeStamp == 0) {\r
+    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
@@ -157,10 +160,10 @@ GetShortPdbFileName (
   UINTN StartIndex;\r
   UINTN EndIndex;\r
 \r
-  ZeroMem (UnicodeBuffer, DXE_PERFORMANCE_STRING_LENGTH * sizeof (CHAR16));\r
+  ZeroMem (UnicodeBuffer, (DP_GAUGE_STRING_LENGTH + 1) * sizeof (CHAR16));\r
 \r
   if (PdbFileName == NULL) {\r
-    StrCpy (UnicodeBuffer, L" ");\r
+    StrCpyS (UnicodeBuffer, DP_GAUGE_STRING_LENGTH + 1, L" ");\r
   } else {\r
     StartIndex = 0;\r
     for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++)\r
@@ -179,8 +182,8 @@ GetShortPdbFileName (
     for (IndexA = StartIndex; IndexA < EndIndex; IndexA++) {\r
       UnicodeBuffer[IndexU] = (CHAR16) PdbFileName[IndexA];\r
       IndexU++;\r
-      if (IndexU >= DXE_PERFORMANCE_STRING_LENGTH) {\r
-        UnicodeBuffer[DXE_PERFORMANCE_STRING_LENGTH] = 0;\r
+      if (IndexU >= DP_GAUGE_STRING_LENGTH) {\r
+        UnicodeBuffer[DP_GAUGE_STRING_LENGTH] = 0;\r
         break;\r
       }\r
     }\r
@@ -219,8 +222,14 @@ GetNameFromHandle (
   CHAR16                      *NameString;\r
   UINTN                       StringSize;\r
   CHAR8                       *PlatformLanguage;\r
+  CHAR8                       *BestLanguage;\r
   EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;\r
-  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *DevicePathToText;\r
+\r
+  Image = NULL;\r
+  LoadedImageDevicePath = NULL;\r
+  DevicePath = NULL;\r
+  BestLanguage     = NULL;\r
+  PlatformLanguage = NULL;\r
 \r
   //\r
   // Method 1: Get the name string from image PDB\r
@@ -270,16 +279,30 @@ GetNameFromHandle (
     //\r
     // Get the current platform language setting\r
     //\r
-    PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang");\r
+    GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);\r
+\r
+    BestLanguage = GetBestLanguage(\r
+                     ComponentName2->SupportedLanguages,\r
+                     FALSE,\r
+                     PlatformLanguage,\r
+                     ComponentName2->SupportedLanguages,\r
+                     NULL\r
+                     );\r
+\r
+    SafeFreePool (PlatformLanguage);\r
     Status = ComponentName2->GetDriverName (\r
                                ComponentName2,\r
-                               PlatformLanguage != NULL ? PlatformLanguage : "en-US",\r
+                               BestLanguage,\r
                                &StringPtr\r
                                );\r
+    SafeFreePool (BestLanguage);\r
     if (!EFI_ERROR (Status)) {\r
-      SafeFreePool (PlatformLanguage);\r
-      StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH);\r
-      mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+      StrnCpyS (\r
+        mGaugeString,\r
+        DP_GAUGE_STRING_LENGTH + 1,\r
+        StringPtr,\r
+        DP_GAUGE_STRING_LENGTH\r
+        );\r
       return;\r
     }\r
   }\r
@@ -289,11 +312,15 @@ GetNameFromHandle (
                   &gEfiLoadedImageDevicePathProtocolGuid,\r
                   (VOID **) &LoadedImageDevicePath\r
                   );\r
-  if (!EFI_ERROR (Status)) {\r
+  if (!EFI_ERROR (Status) && (LoadedImageDevicePath != NULL)) {\r
     DevicePath = LoadedImageDevicePath;\r
+  } else if (Image != NULL) {\r
+    DevicePath = Image->FilePath;\r
+  }\r
 \r
+  if (DevicePath != NULL) {\r
     //\r
-    // Try to get image GUID from LoadedImageDevicePath protocol\r
+    // Try to get image GUID from image DevicePath\r
     //\r
     NameGuid = NULL;\r
     while (!IsDevicePathEndType (DevicePath)) {\r
@@ -314,7 +341,7 @@ GetNameFromHandle (
                 NameGuid,\r
                 EFI_SECTION_USER_INTERFACE,\r
                 0,\r
-                &NameString,\r
+                (VOID **) &NameString,\r
                 &StringSize\r
                 );\r
 \r
@@ -322,8 +349,12 @@ GetNameFromHandle (
         //\r
         // Method 3. Get the name string from FFS UI section\r
         //\r
-        StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);\r
-        mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+        StrnCpyS (\r
+          mGaugeString,\r
+          DP_GAUGE_STRING_LENGTH + 1,\r
+          NameString,\r
+          DP_GAUGE_STRING_LENGTH\r
+          );\r
         FreePool (NameString);\r
       } else {\r
         //\r
@@ -336,19 +367,16 @@ GetNameFromHandle (
       //\r
       // Method 5: Get the name string from image DevicePath\r
       //\r
-      Status = gBS->LocateProtocol (\r
-                      &gEfiDevicePathToTextProtocolGuid,\r
-                      NULL,\r
-                      (VOID **) &DevicePathToText\r
-                      );\r
-      if (!EFI_ERROR (Status)) {\r
-        NameString = DevicePathToText->ConvertDevicePathToText (LoadedImageDevicePath, TRUE, FALSE);\r
-        if (NameString != NULL) {\r
-          StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);\r
-          mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
-          FreePool (NameString);\r
-          return;\r
-        }\r
+      NameString = ConvertDevicePathToText (DevicePath, TRUE, FALSE);\r
+      if (NameString != NULL) {\r
+        StrnCpyS (\r
+          mGaugeString,\r
+          DP_GAUGE_STRING_LENGTH + 1,\r
+          NameString,\r
+          DP_GAUGE_STRING_LENGTH\r
+          );\r
+        FreePool (NameString);\r
+        return;\r
       }\r
     }\r
   }\r
@@ -358,7 +386,7 @@ GetNameFromHandle (
   //\r
   StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);\r
   ASSERT (StringPtr != NULL);\r
-  StrCpy (mGaugeString, StringPtr);\r
+  StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr);\r
   FreePool (StringPtr);\r
   return;\r
 }\r
@@ -397,6 +425,7 @@ DurationInMicroSeconds (
   \r
 **/\r
 UINTN\r
+EFIAPI\r
 PrintToken (\r
   IN UINT16           Token,\r
   ...\r
@@ -421,6 +450,8 @@ PrintToken (
   SetMem( mPrintTokenBuffer, BufferSize, 0);\r
 \r
   Return = UnicodeVSPrint (mPrintTokenBuffer, BufferSize, StringPtr, Marker);\r
+  VA_END (Marker);\r
+  \r
   if (Return > 0 && gST->ConOut != NULL) {\r
     gST->ConOut->OutputString (gST->ConOut, mPrintTokenBuffer);\r
   }\r