From a2daf8dbecddcc04fb4317b6772bc154f0773f7a Mon Sep 17 00:00:00 2001 From: lzeng14 Date: Fri, 25 Nov 2011 02:24:07 +0000 Subject: [PATCH] Update DP to get Image name with the following methods orderly. 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 | 20 +-- PerformancePkg/Dp_App/Dp.inf | 7 +- PerformancePkg/Dp_App/DpInternal.h | 28 +++- PerformancePkg/Dp_App/DpStrings.uni | Bin 36232 -> 29764 bytes PerformancePkg/Dp_App/DpTrace.c | 32 +++-- PerformancePkg/Dp_App/DpUtilities.c | 207 +++++++++++++++++++++++----- 6 files changed, 221 insertions(+), 73 deletions(-) diff --git a/PerformancePkg/Dp_App/Dp.c b/PerformancePkg/Dp_App/Dp.c index 755f68833a..094919c695 100644 --- a/PerformancePkg/Dp_App/Dp.c +++ b/PerformancePkg/Dp_App/Dp.c @@ -46,8 +46,8 @@ EFI_HII_HANDLE gHiiHandle; SHELL_PARAM_ITEM *DpParamList = NULL; CHAR16 *mPrintTokenBuffer = NULL; -CHAR16 mGaugeString[DXE_PERFORMANCE_STRING_SIZE]; -CHAR16 mUnicodeToken[PERF_TOKEN_LENGTH + 1]; +CHAR16 mGaugeString[DP_GAUGE_STRING_LENGTH + 1]; +CHAR16 mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE]; UINT64 mInterestThreshold; PERF_SUMMARY_DATA SummaryData = { 0 }; ///< Create the SummaryData structure and init. to ZERO. @@ -85,22 +85,6 @@ PARAM_ITEM_LIST ParamList[] = { ///@} -/** - Wrap original FreePool to check NULL pointer first. - - @param[in] Buffer The pointer to the buffer to free. - -**/ -VOID -SafeFreePool ( - IN VOID *Buffer - ) -{ - if (Buffer != NULL) { - FreePool (Buffer); - } -} - /** Transfer the param list value and get the command line parse. diff --git a/PerformancePkg/Dp_App/Dp.inf b/PerformancePkg/Dp_App/Dp.inf index f1c6180989..a27ebe65ac 100644 --- a/PerformancePkg/Dp_App/Dp.inf +++ b/PerformancePkg/Dp_App/Dp.inf @@ -58,10 +58,15 @@ UefiLib HiiLib PcdLib + DevicePathLib + DxeServicesLib [Protocols] gEfiLoadedImageProtocolGuid # ALWAYS_CONSUMED - gEfiDriverBindingProtocolGuid # ALWAYS_CONSUMED + gEfiDriverBindingProtocolGuid # SOMETIMES_CONSUMED + gEfiComponentName2ProtocolGuid # SOMETIMES_CONSUMED + gEfiLoadedImageDevicePathProtocolGuid # SOMETIMES_CONSUMED + gEfiDevicePathToTextProtocolGuid # SOMETIMES_CONSUMED [Pcd] gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize diff --git a/PerformancePkg/Dp_App/DpInternal.h b/PerformancePkg/Dp_App/DpInternal.h index d2454060bc..a8630c2621 100644 --- a/PerformancePkg/Dp_App/DpInternal.h +++ b/PerformancePkg/Dp_App/DpInternal.h @@ -6,7 +6,7 @@ * Dp application. In addition to global data, function declarations for * DpUtilities.c, DpTrace.c, and DpProfile.c are included here. * - * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ * Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
* This program and the accompanying materials * are licensed and made available under the terms and conditions of the BSD License * which accompanies this distribution. The full text of the license may be found at @@ -17,13 +17,16 @@ **/ #ifndef _DP_INTELNAL_H_ #define _DP_INTELNAL_H_ + +#define DP_GAUGE_STRING_LENGTH 36 + // /// Module-Global Variables ///@{ extern EFI_HII_HANDLE gHiiHandle; extern CHAR16 *mPrintTokenBuffer; -extern CHAR16 mGaugeString[DXE_PERFORMANCE_STRING_SIZE]; -extern CHAR16 mUnicodeToken[PERF_TOKEN_LENGTH + 1]; +extern CHAR16 mGaugeString[DP_GAUGE_STRING_LENGTH + 1]; +extern CHAR16 mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE]; extern UINT64 mInterestThreshold; extern PERF_SUMMARY_DATA SummaryData; ///< Create the SummaryData structure and init. to ZERO. @@ -100,6 +103,13 @@ GetShortPdbFileName ( /** Get a human readable name for an image handle. + The following methods will be tried orderly: + 1. Image PDB + 2. ComponentName2 protocol + 3. FFS UI section + 4. Image GUID + 5. Image DevicePath + 6. Unknown Driver Name @param[in] Handle @@ -341,4 +351,16 @@ DumpRawProfile( IN UINTN Limit, IN BOOLEAN ExcludeFlag ); + +/** + Wrap original FreePool to check NULL pointer first. + + @param[in] Buffer The pointer to the buffer to free. + +**/ +VOID +SafeFreePool ( + IN VOID *Buffer + ); + #endif diff --git a/PerformancePkg/Dp_App/DpStrings.uni b/PerformancePkg/Dp_App/DpStrings.uni index ee3b277b64245b123330a6501fd69688c5ef0273..22925ba348c18d9ed5ef1d76160bd3e863ab18c7 100644 GIT binary patch delta 602 zcmeB}&2;1i=+?2~AG2z6Ygk zCVvQ$+q}ufh-LB??*K-t$$@!_lNUG%O%5{tk3{wS$Xa-dVV}=TbSOx_!1o6xmilICOpsXPfBJ+JF%cpjlgH)5F z_hPE;<}8;WMxbL4x|)L>^uyHy?7$ zne5=D#tn0-4}-;IeUJ9Z4h1Ze?YuOQ#W&}Aon@Sy5C{qbIdB+s_?(%X!~yfW)#PQ~ zd`QM0;M17=E`>|c2+jA#SbX12ges6fU-{OsvKlfZGAK;e5AmI>ms-LO3QQn>vwp~b zKCox?+=PIh@0oldxdzG?fOtNM1Icv{bo79(QxJy43@A>F!EvI>0E&%;*u*zqOwHxo JTu?eq007)?oWKA8 delta 2184 zcmb_d-%ne06h9rKKUM}*t)no;EpUPIYb_PJ(QZ%~6as~=1Lx{oQ@c)xz@V_j>CB>L znKN6|oyEkUQ=WVyTkapACVMh5nZ{=m-^P=~2j9&6oZH?~V9b~0=6>(_o_p^3@%fzZ zxep(kK3UoGdCcT}aB{z58>DfXq(O>v%G%5eWiRo4OXX;cvXr4ETngUhEg&z`MXYJ8 z^N?q-UV>dabj`Gg+px&cyLh`yy`=D;jaQ;$l)}4(g4YaoIlpl{cY4fj@wtR}Sv_7> z_qf=umPToq63DsD$l0ap*(&g+(h)k3XA6ndd+h7ER;;tsk}m=3p5J|-qw?w z=D%Fm)DtKv1xPYjFF`M0=71GYrHE--lGL<&?w|L#W5N;KPhgEw7{LahN$T3TXgO8Z zAlz}Nq1?2Wcm(bU!$ z*1AGrh;txkkz;n3NS+;$5aB$^R#1WX-xAX~Nh7FFDidh{;7V`)RNdDR!8gmWP6M7S zu8iJ;(s461r~4BrP47U?qE>dsA*FF&M)foJLIDYS^`pzQ4tX6NlZJiE)F+#;lE45Ws@&LExKg4wSfN8Lv5M#UH4Cxa6sr$=bN^6Y#)V!vKw zFX-)xp*G!^uyb!`75{$t4|!@2y|?!AkHPu^cjLX~JfAvX-OBQ zcx5=s%J5~8wUyx~<$Uk-3p}1Sml_aW=g{j{4Q&auY(MNT4WsZez8R_ISg4m@PEVfASCv^^}fA$kMUoT&j<(YHJ~2nZ)|lOb2SO-wK>+MS+~X0x&Q3UjsLND z($vPCA+s|{r;uCRh=E-az4Jw2&|&x%0R89!4?B)re~K2Fil>Tgo{(+f|6r3|70l!a zeeB4~`VZ_ZMngUO{1Y5ntk>4kUsiJ0Vv|F-96__mgp7lhK|rS(&;ibz4u9Q(oSJsO kxcSu(02`Ci^sdYQ?`)e|d}%N2@(J|&`}uj^3)aT}0G=M#$N&HU diff --git a/PerformancePkg/Dp_App/DpTrace.c b/PerformancePkg/Dp_App/DpTrace.c index f4cdb88aaf..1f627e1f84 100644 --- a/PerformancePkg/Dp_App/DpTrace.c +++ b/PerformancePkg/Dp_App/DpTrace.c @@ -1,7 +1,7 @@ /** @file * Trace reporting for the Dp utility. * - * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ * Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
* This program and the accompanying materials * are licensed and made available under the terms and conditions of the BSD License * which accompanies this distribution. The full text of the license may be found at @@ -197,14 +197,11 @@ DumpAllTrace( else { IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL); // Mark incomplete records } - if ((ElapsedTime < mInterestThreshold) || + if (((Measurement.EndTimeStamp != 0) && (ElapsedTime < mInterestThreshold)) || ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0)) ) { // Ignore "uninteresting" or excluded records continue; } - if (Measurement.EndTimeStamp == 0) { - ElapsedTime = Measurement.StartTimeStamp; - } ++Count; // Count the number of records printed // If Handle is non-zero, see if we can determine a name for the driver @@ -219,11 +216,16 @@ DumpAllTrace( } } } - // Ensure that the argument strings are not too long. - mGaugeString[31] = 0; - mUnicodeToken[18] = 0; - PrintToken( STRING_TOKEN (STR_DP_ALL_STATS), + if (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) == 0) { + UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", Measurement.Handle); + } + + // Ensure that the argument strings are not too long. + mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; + mUnicodeToken[13] = 0; + + PrintToken( STRING_TOKEN (STR_DP_ALL_VARS), Index, // 1 based, Which measurement record is being printed IncFlag, Measurement.Handle, @@ -510,7 +512,7 @@ ProcessHandles( Print (L"There are %,d Handles defined.\n", (Size / sizeof(HandleBuffer[0]))); #endif - PrintToken (STRING_TOKEN (STR_DP_HANDLE_GUID) ); + PrintToken (STRING_TOKEN (STR_DP_HANDLE_SECTION) ); PrintToken (STRING_TOKEN (STR_DP_DASHES) ); LogEntryKey = 0; @@ -543,8 +545,8 @@ ProcessHandles( } } // Ensure that the argument strings are not too long. - mGaugeString[31] = 0; - mUnicodeToken[18] = 0; + mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; + mUnicodeToken[11] = 0; if (mGaugeString[0] != 0) { // Display the record if it has a valid handle. PrintToken ( @@ -613,7 +615,7 @@ ProcessPeims( ElapsedTime = DurationInMicroSeconds ( Duration ); // Calculate elapsed time in microseconds if (ElapsedTime >= mInterestThreshold) { // PEIM FILE Handle is the start address of its FFS file that contains its file guid. - PrintToken (STRING_TOKEN (STR_DP_PEIM_STAT2), + PrintToken (STRING_TOKEN (STR_DP_PEIM_VARS), TIndex, // 1 based, Which measurement record is being printed Measurement.Handle, // base address Measurement.Handle, // file guid @@ -668,6 +670,8 @@ ProcessGlobal( { AsciiStrToUnicodeStr (Measurement.Module, mGaugeString); AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken); + mGaugeString[26] = 0; + mUnicodeToken[31] = 0; if ( ! ( IsPhase( &Measurement) || (Measurement.Handle != NULL) || (Measurement.EndTimeStamp == 0) @@ -677,7 +681,7 @@ ProcessGlobal( ElapsedTime = DurationInMicroSeconds ( Duration ); if (ElapsedTime >= mInterestThreshold) { PrintToken ( - STRING_TOKEN (STR_DP_FOUR_VARS_2), + STRING_TOKEN (STR_DP_GLOBAL_VARS), Index, mGaugeString, mUnicodeToken, diff --git a/PerformancePkg/Dp_App/DpUtilities.c b/PerformancePkg/Dp_App/DpUtilities.c index 48e2952aa7..6f296c29ee 100644 --- a/PerformancePkg/Dp_App/DpUtilities.c +++ b/PerformancePkg/Dp_App/DpUtilities.c @@ -1,7 +1,7 @@ /** @file * Utility functions used by the Dp application. * - * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ * Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
* This program and the accompanying materials * are licensed and made available under the terms and conditions of the BSD License * which accompanies this distribution. The full text of the license may be found at @@ -21,9 +21,17 @@ #include #include #include +#include +#include + +#include +#include #include #include +#include +#include +#include #include @@ -31,6 +39,22 @@ #include "Literals.h" #include "DpInternal.h" +/** + Wrap original FreePool to check NULL pointer first. + + @param[in] Buffer The pointer to the buffer to free. + +**/ +VOID +SafeFreePool ( + IN VOID *Buffer + ) +{ + if (Buffer != NULL) { + FreePool (Buffer); + } +} + /** Calculate an event's duration in timer ticks. @@ -165,12 +189,19 @@ GetShortPdbFileName ( /** Get a human readable name for an image handle. - + The following methods will be tried orderly: + 1. Image PDB + 2. ComponentName2 protocol + 3. FFS UI section + 4. Image GUID + 5. Image DevicePath + 6. Unknown Driver Name + @param[in] Handle - + @post The resulting Unicode name string is stored in the mGaugeString global array. - + **/ VOID GetNameFromHandle ( @@ -182,52 +213,154 @@ GetNameFromHandle ( CHAR8 *PdbFileName; EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; EFI_STRING StringPtr; + EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_GUID *NameGuid; + CHAR16 *NameString; + UINTN StringSize; + CHAR8 *PlatformLanguage; + EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2; + EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToText; - // Proactively get the error message so it will be ready if needed - StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL); - ASSERT (StringPtr != NULL); - - // Get handle name from image protocol + // + // Method 1: Get the name string from image PDB // Status = gBS->HandleProtocol ( - Handle, - &gEfiLoadedImageProtocolGuid, - (VOID**) &Image - ); + Handle, + &gEfiLoadedImageProtocolGuid, + (VOID **) &Image + ); if (EFI_ERROR (Status)) { Status = gBS->OpenProtocol ( + Handle, + &gEfiDriverBindingProtocolGuid, + (VOID **) &DriverBinding, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + Status = gBS->HandleProtocol ( + DriverBinding->ImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **) &Image + ); + } + } + + if (!EFI_ERROR (Status)) { + PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase); + + if (PdbFileName != NULL) { + GetShortPdbFileName (PdbFileName, mGaugeString); + return; + } + } + + // + // Method 2: Get the name string from ComponentName2 protocol + // + Status = gBS->HandleProtocol ( Handle, - &gEfiDriverBindingProtocolGuid, - (VOID **) &DriverBinding, - NULL, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL + &gEfiComponentName2ProtocolGuid, + (VOID **) &ComponentName2 ); - if (EFI_ERROR (Status)) { - StrCpy (mGaugeString, StringPtr); - FreePool (StringPtr); - return ; + if (!EFI_ERROR (Status)) { + // + // Get the current platform language setting + // + PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang"); + Status = ComponentName2->GetDriverName ( + ComponentName2, + PlatformLanguage != NULL ? PlatformLanguage : "en-US", + &StringPtr + ); + if (!EFI_ERROR (Status)) { + SafeFreePool (PlatformLanguage); + StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH); + mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; + return; + } + } + + Status = gBS->HandleProtocol ( + Handle, + &gEfiLoadedImageDevicePathProtocolGuid, + (VOID **) &LoadedImageDevicePath + ); + if (!EFI_ERROR (Status)) { + DevicePath = LoadedImageDevicePath; + + // + // Try to get image GUID from LoadedImageDevicePath protocol + // + NameGuid = NULL; + while (!IsDevicePathEndType (DevicePath)) { + NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevicePath); + if (NameGuid != NULL) { + break; + } + DevicePath = NextDevicePathNode (DevicePath); } - // Get handle name from image protocol - // - Status = gBS->HandleProtocol ( - DriverBinding->ImageHandle, - &gEfiLoadedImageProtocolGuid, - (VOID**) &Image - ); + if (NameGuid != NULL) { + // + // Try to get the image's FFS UI section by image GUID + // + NameString = NULL; + StringSize = 0; + Status = GetSectionFromAnyFv ( + NameGuid, + EFI_SECTION_USER_INTERFACE, + 0, + &NameString, + &StringSize + ); + + if (!EFI_ERROR (Status)) { + // + // Method 3. Get the name string from FFS UI section + // + StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH); + mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; + FreePool (NameString); + } else { + // + // Method 4: Get the name string from image GUID + // + UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", NameGuid); + } + return; + } else { + // + // Method 5: Get the name string from image DevicePath + // + Status = gBS->LocateProtocol ( + &gEfiDevicePathToTextProtocolGuid, + NULL, + (VOID **) &DevicePathToText + ); + if (!EFI_ERROR (Status)) { + NameString = DevicePathToText->ConvertDevicePathToText (LoadedImageDevicePath, TRUE, FALSE); + if (NameString != NULL) { + StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH); + mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; + FreePool (NameString); + return; + } + } + } } - PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase); - - if (PdbFileName != NULL) { - GetShortPdbFileName (PdbFileName, mGaugeString); - } else { - StrCpy (mGaugeString, StringPtr); - } + // + // Method 6: Unknown Driver Name + // + StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL); + ASSERT (StringPtr != NULL); + StrCpy (mGaugeString, StringPtr); FreePool (StringPtr); - return ; + return; } /**