PerformancePkg/Dp_App: Refine the code of locating all handles in DpTrace.c.

Replace gBS->LocateHandle with gBS->LocateHandleBuffer

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Cinnamon Shia <cinnamon.shia@hpe.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Samer El-Haj-Mahmoud <elhaj@hpe.com>
This commit is contained in:
Cinnamon Shia 2016-02-15 17:07:14 +08:00 committed by Star Zeng
parent 64c51ed181
commit aae1a87555
1 changed files with 9 additions and 31 deletions

View File

@ -2,7 +2,7 @@
Trace reporting for the Dp utility. Trace reporting for the Dp utility.
Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 which accompanies this distribution. The full text of the license may be found at
@ -153,8 +153,7 @@ DumpAllTrace(
UINTN TIndex; UINTN TIndex;
EFI_HANDLE *HandleBuffer; EFI_HANDLE *HandleBuffer;
UINTN Size; UINTN HandleCount;
EFI_HANDLE TempHandle;
EFI_STATUS Status; EFI_STATUS Status;
EFI_STRING StringPtrUnknown; EFI_STRING StringPtrUnknown;
@ -166,17 +165,7 @@ DumpAllTrace(
// Get Handle information // Get Handle information
// //
Size = 0; Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);
HandleBuffer = &TempHandle;
Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, &TempHandle);
if (Status == EFI_BUFFER_TOO_SMALL) {
HandleBuffer = AllocatePool (Size);
ASSERT (HandleBuffer != NULL);
if (HandleBuffer == NULL) {
return;
}
Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, HandleBuffer);
}
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status); PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);
} }
@ -232,7 +221,7 @@ DumpAllTrace(
AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken); AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);
if (Measurement.Handle != NULL) { if (Measurement.Handle != NULL) {
// See if the Handle is in the HandleBuffer // See if the Handle is in the HandleBuffer
for (TIndex = 0; TIndex < (Size / sizeof(HandleBuffer[0])); TIndex++) { for (TIndex = 0; TIndex < HandleCount; TIndex++) {
if (Measurement.Handle == HandleBuffer[TIndex]) { if (Measurement.Handle == HandleBuffer[TIndex]) {
GetNameFromHandle (HandleBuffer[TIndex]); GetNameFromHandle (HandleBuffer[TIndex]);
break; break;
@ -270,7 +259,7 @@ DumpAllTrace(
} }
} }
} }
if (HandleBuffer != &TempHandle) { if (HandleBuffer != NULL) {
FreePool (HandleBuffer); FreePool (HandleBuffer);
} }
SafeFreePool ((VOID *) IncFlag); SafeFreePool ((VOID *) IncFlag);
@ -536,8 +525,7 @@ ProcessHandles(
UINTN Index; UINTN Index;
UINTN LogEntryKey; UINTN LogEntryKey;
UINTN Count; UINTN Count;
UINTN Size; UINTN HandleCount;
EFI_HANDLE TempHandle;
EFI_STATUS Status; EFI_STATUS Status;
EFI_STRING StringPtrUnknown; EFI_STRING StringPtrUnknown;
@ -548,17 +536,7 @@ ProcessHandles(
FreePool (StringPtr); FreePool (StringPtr);
FreePool (StringPtrUnknown); FreePool (StringPtrUnknown);
Size = 0; Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);
HandleBuffer = &TempHandle;
Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, &TempHandle);
if (Status == EFI_BUFFER_TOO_SMALL) {
HandleBuffer = AllocatePool (Size);
ASSERT (HandleBuffer != NULL);
if (HandleBuffer == NULL) {
return Status;
}
Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, HandleBuffer);
}
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status); PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);
} }
@ -598,7 +576,7 @@ ProcessHandles(
mGaugeString[0] = 0; // Empty driver name by default mGaugeString[0] = 0; // Empty driver name by default
AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken); AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);
// See if the Handle is in the HandleBuffer // See if the Handle is in the HandleBuffer
for (Index = 0; Index < (Size / sizeof(HandleBuffer[0])); Index++) { for (Index = 0; Index < HandleCount; Index++) {
if (Measurement.Handle == HandleBuffer[Index]) { if (Measurement.Handle == HandleBuffer[Index]) {
GetNameFromHandle (HandleBuffer[Index]); // Name is put into mGaugeString GetNameFromHandle (HandleBuffer[Index]); // Name is put into mGaugeString
break; break;
@ -632,7 +610,7 @@ ProcessHandles(
} }
} }
} }
if (HandleBuffer != &TempHandle) { if (HandleBuffer != NULL) {
FreePool (HandleBuffer); FreePool (HandleBuffer);
} }
return Status; return Status;