X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=PerformancePkg%2FDp_App%2FDp.c;h=4cdc39edb42e75ccf0221839550df5fa9fab0f2b;hp=c5b80102984217666f6bcdfd3319e6a9f3788148;hb=9555c09717ee0b1ed4619942257c7b64aeb57f6e;hpb=cdd95292799fc93a59ac175ded2fe7f9e8d14f1c diff --git a/PerformancePkg/Dp_App/Dp.c b/PerformancePkg/Dp_App/Dp.c index c5b8010298..4cdc39edb4 100644 --- a/PerformancePkg/Dp_App/Dp.c +++ b/PerformancePkg/Dp_App/Dp.c @@ -1,35 +1,37 @@ /** @file - * Shell application for Displaying Performance Metrics. - * - * The Dp application reads performance data and presents it in several - * different formats depending upon the needs of the user. Both - * Trace and Measured Profiling information is processed and presented. - * - * Dp uses the "PerformanceLib" to read the measurement records. - * The "TimerLib" provides information about the timer, such as frequency, - * beginning, and ending counter values. - * Measurement records contain identifying information (Handle, Token, Module) - * and start and end time values. - * Dp uses this information to group records in different ways. It also uses - * timer information to calculate elapsed time for each measurement. - * - * 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 - * http://opensource.org/licenses/bsd-license.php - * - * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + Shell application for Displaying Performance Metrics. + + The Dp application reads performance data and presents it in several + different formats depending upon the needs of the user. Both + Trace and Measured Profiling information is processed and presented. + + Dp uses the "PerformanceLib" to read the measurement records. + The "TimerLib" provides information about the timer, such as frequency, + beginning, and ending counter values. + Measurement records contain identifying information (Handle, Token, Module) + and start and end time values. + Dp uses this information to group records in different ways. It also uses + timer information to calculate elapsed time for each measurement. + + Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+ (C) Copyright 2015-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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include +#include #include #include #include #include -#include #include +#include #include #include @@ -40,15 +42,26 @@ #include "Literals.h" #include "DpInternal.h" +// +// String token ID of help message text. +// Shell supports to find help message in the resource section of an application image if +// .MAN file is not found. This global variable is added to make build tool recognizes +// that the help string is consumed by user and then build tool will add the string into +// the resource section. Thus the application can use '-?' option to show help message in +// Shell. +// +GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mDpStrEngHelpTokenId = STRING_TOKEN (STR_DP_HELP_INFORMATION); + // /// Module-Global Variables ///@{ 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; +BOOLEAN mShowId = FALSE; PERF_SUMMARY_DATA SummaryData = { 0 }; ///< Create the SummaryData structure and init. to ZERO. @@ -79,25 +92,14 @@ PARAM_ITEM_LIST ParamList[] = { {STRING_TOKEN (STR_DP_OPTION_UT), TypeFlag}, // -T Dump Trace Data #endif {STRING_TOKEN (STR_DP_OPTION_LX), TypeFlag}, // -x eXclude Cumulative Items + {STRING_TOKEN (STR_DP_OPTION_LI), TypeFlag}, // -i Display Identifier + {STRING_TOKEN (STR_DP_OPTION_LC), TypeValue}, // -c Display cumulative data. {STRING_TOKEN (STR_DP_OPTION_LN), TypeValue}, // -n # Number of records to display for A and R {STRING_TOKEN (STR_DP_OPTION_LT), TypeValue} // -t # Threshold of interest }; ///@} -/** - Wrap original FreePool to check NULL pointer first. -**/ -VOID -SafeFreePool ( - IN VOID *Buffer - ) -{ - if (Buffer != NULL) { - FreePool (Buffer); - } -} - /** Transfer the param list value and get the command line parse. @@ -111,7 +113,7 @@ InitialShellParamList( void ) // // Allocate one more for the end tag. // - ListLength = sizeof (ParamList) / sizeof (ParamList[0]) + 1; + ListLength = ARRAY_SIZE (ParamList) + 1; DpParamList = AllocatePool (sizeof (SHELL_PARAM_ITEM) * ListLength); ASSERT (DpParamList != NULL); @@ -148,6 +150,8 @@ ShowHelp( void ) #endif // PROFILING_IMPLEMENTED PrintToken (STRING_TOKEN (STR_DP_HELP_THRESHOLD)); PrintToken (STRING_TOKEN (STR_DP_HELP_COUNT)); + PrintToken (STRING_TOKEN (STR_DP_HELP_ID)); + PrintToken (STRING_TOKEN (STR_DP_HELP_CUM_DATA)); PrintToken (STRING_TOKEN (STR_DP_HELP_HELP)); Print(L"\n"); } @@ -178,16 +182,16 @@ DumpStatistics( void ) FreePool (StringPtrUnknown); } -/** +/** Dump performance data. @param[in] ImageHandle The image handle. @param[in] SystemTable The system table. - + @retval EFI_SUCCESS Command completed successfully. @retval EFI_INVALID_PARAMETER Command usage error. + @retval EFI_ABORTED The user aborts the operation. @retval value Unknown error. - **/ EFI_STATUS EFIAPI @@ -196,23 +200,27 @@ InitializeDp ( IN EFI_SYSTEM_TABLE *SystemTable ) { - UINT64 Freq; - UINT64 Ticker; - UINT32 ListIndex; - - LIST_ENTRY *ParamPackage; - CONST CHAR16 *CmdLineArg; - EFI_STRING StringPtr; - UINTN Number2Display; - - EFI_STATUS Status; - BOOLEAN SummaryMode; - BOOLEAN VerboseMode; - BOOLEAN AllMode; - BOOLEAN RawMode; - BOOLEAN TraceMode; - BOOLEAN ProfileMode; - BOOLEAN ExcludeMode; + PERFORMANCE_PROPERTY *PerformanceProperty; + UINT32 ListIndex; + + LIST_ENTRY *ParamPackage; + CONST CHAR16 *CmdLineArg; + EFI_STRING StringPtr; + UINTN Number2Display; + + EFI_STATUS Status; + BOOLEAN SummaryMode; + BOOLEAN VerboseMode; + BOOLEAN AllMode; + BOOLEAN RawMode; + BOOLEAN TraceMode; + BOOLEAN ProfileMode; + BOOLEAN ExcludeMode; + BOOLEAN CumulativeMode; + CONST CHAR16 *CustomCumulativeToken; + PERF_CUM_DATA *CustomCumulativeData; + UINTN NameSize; + EFI_HII_PACKAGE_LIST_HEADER *PackageList; EFI_STRING StringDpOptionQh; EFI_STRING StringDpOptionLh; @@ -227,6 +235,8 @@ InitializeDp ( EFI_STRING StringDpOptionLx; EFI_STRING StringDpOptionLn; EFI_STRING StringDpOptionLt; + EFI_STRING StringDpOptionLi; + EFI_STRING StringDpOptionLc; SummaryMode = FALSE; VerboseMode = FALSE; @@ -235,6 +245,8 @@ InitializeDp ( TraceMode = FALSE; ProfileMode = FALSE; ExcludeMode = FALSE; + CumulativeMode = FALSE; + CustomCumulativeData = NULL; StringDpOptionQh = NULL; StringDpOptionLh = NULL; @@ -249,17 +261,39 @@ InitializeDp ( StringDpOptionLx = NULL; StringDpOptionLn = NULL; StringDpOptionLt = NULL; + StringDpOptionLi = NULL; + StringDpOptionLc = NULL; StringPtr = NULL; - // Get DP's entry time as soon as possible. - // This is used as the Shell-Phase end time. // - Ticker = GetPerformanceCounter (); + // Retrieve HII package list from ImageHandle + // + Status = gBS->OpenProtocol ( + ImageHandle, + &gEfiHiiPackageListProtocolGuid, + (VOID **) &PackageList, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return Status; + } - // Register our string package with HII and return the handle to it. // - gHiiHandle = HiiAddPackages (&gEfiCallerIdGuid, ImageHandle, DPStrings, NULL); + // Publish HII package list to HII Database. + // + Status = gHiiDatabase->NewPackageList ( + gHiiDatabase, + PackageList, + NULL, + &gHiiHandle + ); + if (EFI_ERROR (Status)) { + return Status; + } ASSERT (gHiiHandle != NULL); + // Initial the command list // @@ -296,6 +330,8 @@ InitializeDp ( StringDpOptionLx = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LX), NULL); StringDpOptionLn = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LN), NULL); StringDpOptionLt = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LT), NULL); + StringDpOptionLi = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LI), NULL); + StringDpOptionLc = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LC), NULL); // Boolean Options // @@ -309,6 +345,8 @@ InitializeDp ( ProfileMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUp); #endif // PROFILING_IMPLEMENTED ExcludeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLx); + mShowId = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLi); + CumulativeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLc); // Options with Values CmdLineArg = ShellCommandLineGetValue (ParamPackage, StringDpOptionLn); @@ -337,6 +375,22 @@ InitializeDp ( #endif // PROFILING_IMPLEMENTED } + // + // Init the custom cumulative data. + // + CustomCumulativeToken = ShellCommandLineGetValue (ParamPackage, StringDpOptionLc); + if (CustomCumulativeToken != NULL) { + CustomCumulativeData = AllocateZeroPool (sizeof (PERF_CUM_DATA)); + ASSERT (CustomCumulativeData != NULL); + CustomCumulativeData->MinDur = 0; + CustomCumulativeData->MaxDur = 0; + CustomCumulativeData->Count = 0; + CustomCumulativeData->Duration = 0; + NameSize = StrLen (CustomCumulativeToken) + 1; + CustomCumulativeData->Name = AllocateZeroPool (NameSize); + UnicodeStrToAsciiStrS (CustomCumulativeToken, CustomCumulativeData->Name, NameSize); + } + /**************************************************************************** **** Timer specific processing **** ****************************************************************************/ @@ -345,10 +399,16 @@ InitializeDp ( // StartCount = Value loaded into the counter when it starts counting // EndCount = Value counter counts to before it needs to be reset // - Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount); + Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty); + if (EFI_ERROR (Status) || (PerformanceProperty == NULL)) { + PrintToken (STRING_TOKEN (STR_PERF_PROPERTY_NOT_FOUND)); + goto Done; + } // Convert the Frequency from Hz to KHz - TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000); + TimerInfo.Frequency = (UINT32)DivU64x32 (PerformanceProperty->Frequency, 1000); + TimerInfo.StartCount = PerformanceProperty->TimerStartValue; + TimerInfo.EndCount = PerformanceProperty->TimerEndValue; // Determine in which direction the performance counter counts. TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount); @@ -398,10 +458,15 @@ InitializeDp ( **** !T && P := (2) Only Profile records are displayed **** T && P := (3) Same as Default, both are displayed ****************************************************************************/ - GatherStatistics(); - if (AllMode) { + GatherStatistics (CustomCumulativeData); + if (CumulativeMode) { + ProcessCumulative (CustomCumulativeData); + } else if (AllMode) { if (TraceMode) { - DumpAllTrace( Number2Display, ExcludeMode); + Status = DumpAllTrace( Number2Display, ExcludeMode); + if (Status == EFI_ABORTED) { + goto Done; + } } if (ProfileMode) { DumpAllProfile( Number2Display, ExcludeMode); @@ -409,7 +474,10 @@ InitializeDp ( } else if (RawMode) { if (TraceMode) { - DumpRawTrace( Number2Display, ExcludeMode); + Status = DumpRawTrace( Number2Display, ExcludeMode); + if (Status == EFI_ABORTED) { + goto Done; + } } if (ProfileMode) { DumpRawProfile( Number2Display, ExcludeMode); @@ -418,14 +486,24 @@ InitializeDp ( else { //------------- Begin Cooked Mode Processing if (TraceMode) { - ProcessPhases ( Ticker ); + ProcessPhases (); if ( ! SummaryMode) { Status = ProcessHandles ( ExcludeMode); - if ( ! EFI_ERROR( Status)) { - ProcessPeims ( ); - ProcessGlobal ( ); - ProcessCumulative (); + if (Status == EFI_ABORTED) { + goto Done; } + + Status = ProcessPeims (); + if (Status == EFI_ABORTED) { + goto Done; + } + + Status = ProcessGlobal (); + if (Status == EFI_ABORTED) { + goto Done; + } + + ProcessCumulative (NULL); } } if (ProfileMode) { @@ -438,6 +516,9 @@ InitializeDp ( } } +Done: + + // // Free the memory allocate from HiiGetString // ListIndex = 0; @@ -460,9 +541,19 @@ InitializeDp ( SafeFreePool (StringDpOptionLx); SafeFreePool (StringDpOptionLn); SafeFreePool (StringDpOptionLt); + SafeFreePool (StringDpOptionLi); + SafeFreePool (StringDpOptionLc); SafeFreePool (StringPtr); SafeFreePool (mPrintTokenBuffer); + if (ParamPackage != NULL) { + ShellCommandLineFreeVarList (ParamPackage); + } + if (CustomCumulativeData != NULL) { + SafeFreePool (CustomCumulativeData->Name); + } + SafeFreePool (CustomCumulativeData); + HiiRemovePackages (gHiiHandle); return Status; }