]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Update DP to get Image name with the following methods orderly.
authorlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Nov 2011 02:24:07 +0000 (02:24 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Nov 2011 02:24:07 +0000 (02:24 +0000)
  1. Image PDB
  2. ComponentName2 protocol
  3. FFS UI section
  4. Image GUID
  5. Image DevicePath
  6. Unknown Driver Name

Signed-off-by: lzeng14
Reviewed-by: lgao4
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12779 6f19259b-4bc3-4df7-8a09-765794883524

PerformancePkg/Dp_App/Dp.c
PerformancePkg/Dp_App/Dp.inf
PerformancePkg/Dp_App/DpInternal.h
PerformancePkg/Dp_App/DpStrings.uni
PerformancePkg/Dp_App/DpTrace.c
PerformancePkg/Dp_App/DpUtilities.c

index 755f68833accf2e08b7dd0c0fb2223e0207d5dc0..094919c695de4e4fcd4ea2fbd633539cb7c0c94c 100644 (file)
@@ -46,8 +46,8 @@
 EFI_HII_HANDLE   gHiiHandle;\r
 SHELL_PARAM_ITEM *DpParamList       = NULL;\r
 CHAR16           *mPrintTokenBuffer = NULL;\r
-CHAR16           mGaugeString[DXE_PERFORMANCE_STRING_SIZE];\r
-CHAR16           mUnicodeToken[PERF_TOKEN_LENGTH + 1];\r
+CHAR16           mGaugeString[DP_GAUGE_STRING_LENGTH + 1];\r
+CHAR16           mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE];\r
 UINT64           mInterestThreshold;\r
 \r
 PERF_SUMMARY_DATA SummaryData = { 0 };    ///< Create the SummaryData structure and init. to ZERO.\r
@@ -85,22 +85,6 @@ PARAM_ITEM_LIST  ParamList[] = {
 \r
 ///@}\r
 \r
-/**\r
-  Wrap original FreePool to check NULL pointer first.\r
-\r
-  @param[in]    Buffer      The pointer to the buffer to free.\r
-\r
-**/\r
-VOID\r
-SafeFreePool (\r
-  IN VOID   *Buffer\r
-  )\r
-{\r
-  if (Buffer != NULL) {\r
-    FreePool (Buffer);\r
-  }\r
-}\r
-\r
 /**\r
   Transfer the param list value and get the command line parse.\r
 \r
index f1c6180989f87529163754b89117eb7cc6755955..a27ebe65ac0b9497197f889dbae208fbb6b8f336 100644 (file)
   UefiLib\r
   HiiLib\r
   PcdLib\r
+  DevicePathLib\r
+  DxeServicesLib\r
 \r
 [Protocols]\r
   gEfiLoadedImageProtocolGuid                             # ALWAYS_CONSUMED\r
-  gEfiDriverBindingProtocolGuid                           # ALWAYS_CONSUMED\r
+  gEfiDriverBindingProtocolGuid                           # SOMETIMES_CONSUMED\r
+  gEfiComponentName2ProtocolGuid                          # SOMETIMES_CONSUMED\r
+  gEfiLoadedImageDevicePathProtocolGuid                   # SOMETIMES_CONSUMED\r
+  gEfiDevicePathToTextProtocolGuid                        # SOMETIMES_CONSUMED\r
 \r
 [Pcd]\r
   gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize\r
index d2454060bcbd8ddb5835a752c1e79f9d08636954..a8630c2621b19518f7395c0c590d5f4e53aa9cbd 100644 (file)
@@ -6,7 +6,7 @@
   * Dp application.  In addition to global data, function declarations for\r
   * DpUtilities.c, DpTrace.c, and DpProfile.c are included here.\r
   *\r
-  * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\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
 **/\r
 #ifndef _DP_INTELNAL_H_\r
 #define _DP_INTELNAL_H_\r
+\r
+#define DP_GAUGE_STRING_LENGTH   36\r
+\r
 //\r
 /// Module-Global Variables\r
 ///@{\r
 extern EFI_HII_HANDLE     gHiiHandle;\r
 extern CHAR16             *mPrintTokenBuffer;\r
-extern CHAR16             mGaugeString[DXE_PERFORMANCE_STRING_SIZE];\r
-extern CHAR16             mUnicodeToken[PERF_TOKEN_LENGTH + 1];\r
+extern CHAR16             mGaugeString[DP_GAUGE_STRING_LENGTH + 1];\r
+extern CHAR16             mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE];\r
 extern UINT64             mInterestThreshold;\r
 \r
 extern PERF_SUMMARY_DATA  SummaryData;    ///< Create the SummaryData structure and init. to ZERO.\r
@@ -100,6 +103,13 @@ GetShortPdbFileName (
 \r
 /** \r
   Get a human readable name for an image handle.\r
+  The following methods will be tried orderly:\r
+    1. Image PDB\r
+    2. ComponentName2 protocol\r
+    3. FFS UI section\r
+    4. Image GUID\r
+    5. Image DevicePath\r
+    6. Unknown Driver Name\r
   \r
   @param[in]    Handle\r
   \r
@@ -341,4 +351,16 @@ DumpRawProfile(
   IN UINTN          Limit,\r
   IN BOOLEAN        ExcludeFlag\r
   );\r
+\r
+/**\r
+  Wrap original FreePool to check NULL pointer first.\r
+\r
+  @param[in]    Buffer      The pointer to the buffer to free.\r
+\r
+**/\r
+VOID\r
+SafeFreePool (\r
+  IN VOID   *Buffer\r
+  );\r
+\r
 #endif\r
index ee3b277b64245b123330a6501fd69688c5ef0273..22925ba348c18d9ed5ef1d76160bd3e863ab18c7 100644 (file)
Binary files a/PerformancePkg/Dp_App/DpStrings.uni and b/PerformancePkg/Dp_App/DpStrings.uni differ
index f4cdb88aafff218e1de757553224ad23222da6cd..1f627e1f84455f1e7ed68c5742ae92a978feab68 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   * Trace reporting for the Dp utility.\r
   *\r
-  * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\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
@@ -197,14 +197,11 @@ DumpAllTrace(
       else {\r
         IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL);  // Mark incomplete records\r
       }\r
-      if ((ElapsedTime < mInterestThreshold)                 ||\r
+      if (((Measurement.EndTimeStamp != 0) && (ElapsedTime < mInterestThreshold)) ||\r
           ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))\r
          ) {      // Ignore "uninteresting" or excluded records\r
         continue;\r
       }\r
-      if (Measurement.EndTimeStamp == 0) {\r
-        ElapsedTime = Measurement.StartTimeStamp;\r
-      }\r
       ++Count;    // Count the number of records printed\r
 \r
       // If Handle is non-zero, see if we can determine a name for the driver\r
@@ -219,11 +216,16 @@ DumpAllTrace(
           }\r
         }\r
       }\r
+\r
+      if (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) == 0) {\r
+        UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", Measurement.Handle);\r
+      }\r
+\r
       // Ensure that the argument strings are not too long.\r
-      mGaugeString[31] = 0;\r
-      mUnicodeToken[18] = 0;\r
+      mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+      mUnicodeToken[13] = 0;\r
 \r
-      PrintToken( STRING_TOKEN (STR_DP_ALL_STATS),\r
+      PrintToken( STRING_TOKEN (STR_DP_ALL_VARS),\r
         Index,      // 1 based, Which measurement record is being printed\r
         IncFlag,\r
         Measurement.Handle,\r
@@ -510,7 +512,7 @@ ProcessHandles(
     Print (L"There are %,d Handles defined.\n", (Size / sizeof(HandleBuffer[0])));\r
 #endif\r
 \r
-    PrintToken (STRING_TOKEN (STR_DP_HANDLE_GUID) );\r
+    PrintToken (STRING_TOKEN (STR_DP_HANDLE_SECTION) );\r
     PrintToken (STRING_TOKEN (STR_DP_DASHES) );\r
 \r
     LogEntryKey = 0;\r
@@ -543,8 +545,8 @@ ProcessHandles(
         }\r
       }\r
       // Ensure that the argument strings are not too long.\r
-      mGaugeString[31] = 0;\r
-      mUnicodeToken[18] = 0;\r
+      mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+      mUnicodeToken[11] = 0;\r
       if (mGaugeString[0] != 0) {\r
         // Display the record if it has a valid handle.\r
         PrintToken (\r
@@ -613,7 +615,7 @@ 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_STAT2),\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
@@ -668,6 +670,8 @@ ProcessGlobal(
   {\r
     AsciiStrToUnicodeStr (Measurement.Module, mGaugeString);\r
     AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);\r
+    mGaugeString[26] = 0;\r
+    mUnicodeToken[31] = 0;\r
     if ( ! ( IsPhase( &Measurement)  ||\r
         (Measurement.Handle != NULL)      ||\r
         (Measurement.EndTimeStamp == 0)\r
@@ -677,7 +681,7 @@ ProcessGlobal(
       ElapsedTime = DurationInMicroSeconds ( Duration );\r
       if (ElapsedTime >= mInterestThreshold) {\r
         PrintToken (\r
-          STRING_TOKEN (STR_DP_FOUR_VARS_2),\r
+          STRING_TOKEN (STR_DP_GLOBAL_VARS),\r
           Index,\r
           mGaugeString,\r
           mUnicodeToken,\r
index 48e2952aa79eed2d108de7a1bb3e37717d7dc7d1..6f296c29ee31b5ecf481903dd65b4b4b9182019e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   * Utility functions used by the Dp application.\r
   *\r
-  * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\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
 #include <Library/PrintLib.h>\r
 #include <Library/HiiLib.h>\r
 #include <Library/PcdLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/DevicePathLib.h>\r
+\r
+#include <Pi/PiFirmwareFile.h>\r
+#include <Library/DxeServicesLib.h>\r
 \r
 #include <Protocol/LoadedImage.h>\r
 #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
 #include "Literals.h"\r
 #include "DpInternal.h"\r
 \r
+/**\r
+  Wrap original FreePool to check NULL pointer first.\r
+\r
+  @param[in]    Buffer      The pointer to the buffer to free.\r
+\r
+**/\r
+VOID\r
+SafeFreePool (\r
+  IN VOID   *Buffer\r
+  )\r
+{\r
+  if (Buffer != NULL) {\r
+    FreePool (Buffer);\r
+  }\r
+}\r
+\r
 /** \r
   Calculate an event's duration in timer ticks.\r
   \r
@@ -165,12 +189,19 @@ GetShortPdbFileName (
 \r
 /** \r
   Get a human readable name for an image handle.\r
-  \r
+  The following methods will be tried orderly:\r
+    1. Image PDB\r
+    2. ComponentName2 protocol\r
+    3. FFS UI section\r
+    4. Image GUID\r
+    5. Image DevicePath\r
+    6. Unknown Driver Name\r
+\r
   @param[in]    Handle\r
-  \r
+\r
   @post   The resulting Unicode name string is stored in the\r
           mGaugeString global array.\r
-  \r
+\r
 **/\r
 VOID\r
 GetNameFromHandle (\r
@@ -182,52 +213,154 @@ GetNameFromHandle (
   CHAR8                       *PdbFileName;\r
   EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;\r
   EFI_STRING                  StringPtr;\r
+  EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL    *DevicePath;\r
+  EFI_GUID                    *NameGuid;\r
+  CHAR16                      *NameString;\r
+  UINTN                       StringSize;\r
+  CHAR8                       *PlatformLanguage;\r
+  EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;\r
+  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *DevicePathToText;\r
 \r
-  // Proactively get the error message so it will be ready if needed\r
-  StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);\r
-  ASSERT (StringPtr != NULL);\r
-\r
-  // Get handle name from image protocol\r
+  //\r
+  // Method 1: Get the name string from image PDB\r
   //\r
   Status = gBS->HandleProtocol (\r
-                Handle,\r
-                &gEfiLoadedImageProtocolGuid,\r
-                (VOID**) &Image\r
-                );\r
+                  Handle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID **) &Image\r
+                  );\r
 \r
   if (EFI_ERROR (Status)) {\r
     Status = gBS->OpenProtocol (\r
+                    Handle,\r
+                    &gEfiDriverBindingProtocolGuid,\r
+                    (VOID **) &DriverBinding,\r
+                    NULL,\r
+                    NULL,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = gBS->HandleProtocol (\r
+                      DriverBinding->ImageHandle,\r
+                      &gEfiLoadedImageProtocolGuid,\r
+                      (VOID **) &Image\r
+                      );\r
+    }\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase);\r
+\r
+    if (PdbFileName != NULL) {\r
+      GetShortPdbFileName (PdbFileName, mGaugeString);\r
+      return;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Method 2: Get the name string from ComponentName2 protocol\r
+  //\r
+  Status = gBS->HandleProtocol (\r
                   Handle,\r
-                  &gEfiDriverBindingProtocolGuid,\r
-                  (VOID **) &DriverBinding,\r
-                  NULL,\r
-                  NULL,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  &gEfiComponentName2ProtocolGuid,\r
+                  (VOID **) &ComponentName2\r
                   );\r
-    if (EFI_ERROR (Status)) {\r
-      StrCpy (mGaugeString, StringPtr);\r
-      FreePool (StringPtr);\r
-      return ;\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Get the current platform language setting\r
+    //\r
+    PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang");\r
+    Status = ComponentName2->GetDriverName (\r
+                               ComponentName2,\r
+                               PlatformLanguage != NULL ? PlatformLanguage : "en-US",\r
+                               &StringPtr\r
+                               );\r
+    if (!EFI_ERROR (Status)) {\r
+      SafeFreePool (PlatformLanguage);\r
+      StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH);\r
+      mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+      return;\r
     }\r
+  }\r
 \r
-    // Get handle name from image protocol\r
-    //\r
-    Status = gBS->HandleProtocol (\r
-                  DriverBinding->ImageHandle,\r
-                  &gEfiLoadedImageProtocolGuid,\r
-                  (VOID**) &Image\r
+  Status = gBS->HandleProtocol (\r
+                  Handle,\r
+                  &gEfiLoadedImageDevicePathProtocolGuid,\r
+                  (VOID **) &LoadedImageDevicePath\r
                   );\r
-  }\r
+  if (!EFI_ERROR (Status)) {\r
+    DevicePath = LoadedImageDevicePath;\r
 \r
-  PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase);\r
+    //\r
+    // Try to get image GUID from LoadedImageDevicePath protocol\r
+    //\r
+    NameGuid = NULL;\r
+    while (!IsDevicePathEndType (DevicePath)) {\r
+      NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevicePath);\r
+      if (NameGuid != NULL) {\r
+        break;\r
+      }\r
+      DevicePath = NextDevicePathNode (DevicePath);\r
+    }\r
 \r
-  if (PdbFileName != NULL) {\r
-    GetShortPdbFileName (PdbFileName, mGaugeString);\r
-  } else {\r
-    StrCpy (mGaugeString, StringPtr);\r
+    if (NameGuid != NULL) {\r
+      //\r
+      // Try to get the image's FFS UI section by image GUID\r
+      //\r
+      NameString = NULL;\r
+      StringSize = 0;\r
+      Status = GetSectionFromAnyFv (\r
+                NameGuid,\r
+                EFI_SECTION_USER_INTERFACE,\r
+                0,\r
+                &NameString,\r
+                &StringSize\r
+                );\r
+\r
+      if (!EFI_ERROR (Status)) {\r
+        //\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
+        FreePool (NameString);\r
+      } else {\r
+        //\r
+        // Method 4: Get the name string from image GUID\r
+        //\r
+        UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", NameGuid);\r
+      }\r
+      return;\r
+    } else {\r
+      //\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
+      }\r
+    }\r
   }\r
+\r
+  //\r
+  // Method 6: Unknown Driver Name\r
+  //\r
+  StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);\r
+  ASSERT (StringPtr != NULL);\r
+  StrCpy (mGaugeString, StringPtr);\r
   FreePool (StringPtr);\r
-  return ;\r
+  return;\r
 }\r
 \r
 /** \r