X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PerformancePkg%2FDp_App%2FDpUtilities.c;h=d5840e8d6f833b39da257720f2f96918ea41829b;hb=1393510;hp=5e160708b852c30d1ce93729b935744e15b28b4b;hpb=f01b91ae42edcf979a52ba08b515d3b4525b55fa;p=mirror_edk2.git diff --git a/PerformancePkg/Dp_App/DpUtilities.c b/PerformancePkg/Dp_App/DpUtilities.c index 5e160708b8..d5840e8d6f 100644 --- a/PerformancePkg/Dp_App/DpUtilities.c +++ b/PerformancePkg/Dp_App/DpUtilities.c @@ -1,7 +1,8 @@ /** @file Utility functions used by the Dp application. - Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP
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 @@ -16,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -31,7 +31,6 @@ #include #include #include -#include #include @@ -83,6 +82,10 @@ GetDuration ( UINT64 Duration; BOOLEAN Error; + if (Measurement->EndTimeStamp == 0) { + return 0; + } + // PERF_START macros are called with a value of 1 to indicate // the beginning of time. So, adjust the start ticker value // to the real beginning of time. @@ -157,10 +160,10 @@ GetShortPdbFileName ( UINTN StartIndex; UINTN EndIndex; - ZeroMem (UnicodeBuffer, DXE_PERFORMANCE_STRING_LENGTH * sizeof (CHAR16)); + ZeroMem (UnicodeBuffer, (DP_GAUGE_STRING_LENGTH + 1) * sizeof (CHAR16)); if (PdbFileName == NULL) { - StrCpy (UnicodeBuffer, L" "); + StrCpyS (UnicodeBuffer, DP_GAUGE_STRING_LENGTH + 1, L" "); } else { StartIndex = 0; for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++) @@ -179,8 +182,8 @@ GetShortPdbFileName ( for (IndexA = StartIndex; IndexA < EndIndex; IndexA++) { UnicodeBuffer[IndexU] = (CHAR16) PdbFileName[IndexA]; IndexU++; - if (IndexU >= DXE_PERFORMANCE_STRING_LENGTH) { - UnicodeBuffer[DXE_PERFORMANCE_STRING_LENGTH] = 0; + if (IndexU >= DP_GAUGE_STRING_LENGTH) { + UnicodeBuffer[DP_GAUGE_STRING_LENGTH] = 0; break; } } @@ -219,8 +222,14 @@ GetNameFromHandle ( CHAR16 *NameString; UINTN StringSize; CHAR8 *PlatformLanguage; + CHAR8 *BestLanguage; EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2; - EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToText; + + Image = NULL; + LoadedImageDevicePath = NULL; + DevicePath = NULL; + BestLanguage = NULL; + PlatformLanguage = NULL; // // Method 1: Get the name string from image PDB @@ -271,15 +280,29 @@ GetNameFromHandle ( // Get the current platform language setting // GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL); + + BestLanguage = GetBestLanguage( + ComponentName2->SupportedLanguages, + FALSE, + PlatformLanguage, + ComponentName2->SupportedLanguages, + NULL + ); + + SafeFreePool (PlatformLanguage); Status = ComponentName2->GetDriverName ( ComponentName2, - PlatformLanguage != NULL ? PlatformLanguage : "en-US", + BestLanguage, &StringPtr ); + SafeFreePool (BestLanguage); if (!EFI_ERROR (Status)) { - SafeFreePool (PlatformLanguage); - StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH); - mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; + StrnCpyS ( + mGaugeString, + DP_GAUGE_STRING_LENGTH + 1, + StringPtr, + DP_GAUGE_STRING_LENGTH + ); return; } } @@ -291,9 +314,13 @@ GetNameFromHandle ( ); if (!EFI_ERROR (Status) && (LoadedImageDevicePath != NULL)) { DevicePath = LoadedImageDevicePath; + } else if (Image != NULL) { + DevicePath = Image->FilePath; + } + if (DevicePath != NULL) { // - // Try to get image GUID from LoadedImageDevicePath protocol + // Try to get image GUID from image DevicePath // NameGuid = NULL; while (!IsDevicePathEndType (DevicePath)) { @@ -322,8 +349,12 @@ GetNameFromHandle ( // // Method 3. Get the name string from FFS UI section // - StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH); - mGaugeString[DP_GAUGE_STRING_LENGTH] = 0; + StrnCpyS ( + mGaugeString, + DP_GAUGE_STRING_LENGTH + 1, + NameString, + DP_GAUGE_STRING_LENGTH + ); FreePool (NameString); } else { // @@ -336,19 +367,16 @@ GetNameFromHandle ( // // 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; - } + NameString = ConvertDevicePathToText (DevicePath, TRUE, FALSE); + if (NameString != NULL) { + StrnCpyS ( + mGaugeString, + DP_GAUGE_STRING_LENGTH + 1, + NameString, + DP_GAUGE_STRING_LENGTH + ); + FreePool (NameString); + return; } } } @@ -358,7 +386,7 @@ GetNameFromHandle ( // StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL); ASSERT (StringPtr != NULL); - StrCpy (mGaugeString, StringPtr); + StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr); FreePool (StringPtr); return; } @@ -397,6 +425,7 @@ DurationInMicroSeconds ( **/ UINTN +EFIAPI PrintToken ( IN UINT16 Token, ...