2 * Shell application for Displaying Performance Metrics.
4 * The Dp application reads performance data and presents it in several
5 * different formats depending upon the needs of the user. Both
6 * Trace and Measured Profiling information is processed and presented.
8 * Dp uses the "PerformanceLib" to read the measurement records.
9 * The "TimerLib" provides information about the timer, such as frequency,
10 * beginning, and ending counter values.
11 * Measurement records contain identifying information (Handle, Token, Module)
12 * and start and end time values.
13 * Dp uses this information to group records in different ways. It also uses
14 * timer information to calculate elapsed time for each measurement.
16 * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
17 * This program and the accompanying materials
18 * are licensed and made available under the terms and conditions of the BSD License
19 * which accompanies this distribution. The full text of the license may be found at
20 * http://opensource.org/licenses/bsd-license.php
22 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 #include <Library/UefiApplicationEntryPoint.h>
27 #include <Library/ShellLib.h>
28 #include <Library/BaseLib.h>
29 #include <Library/MemoryAllocationLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/TimerLib.h>
32 #include <Library/UefiLib.h>
33 #include <Library/HiiLib.h>
34 #include <Library/PcdLib.h>
36 #include <Guid/Performance.h>
38 #include <PerformanceTokens.h>
41 #include "DpInternal.h"
44 /// Module-Global Variables
46 EFI_HII_HANDLE gHiiHandle
;
47 CHAR16
*mPrintTokenBuffer
= NULL
;
48 CHAR16 mGaugeString
[DXE_PERFORMANCE_STRING_SIZE
];
49 CHAR16 mUnicodeToken
[PERF_TOKEN_LENGTH
+ 1];
50 UINT64 mInterestThreshold
;
52 PERF_SUMMARY_DATA SummaryData
= { 0 }; ///< Create the SummaryData structure and init. to ZERO.
54 /// Timer Specific Information.
57 /// Items for which to gather cumulative statistics.
58 PERF_CUM_DATA CumData
[] = {
59 PERF_INIT_CUM_DATA (LOAD_IMAGE_TOK
),
60 PERF_INIT_CUM_DATA (START_IMAGE_TOK
),
61 PERF_INIT_CUM_DATA (DRIVERBINDING_START_TOK
),
62 PERF_INIT_CUM_DATA (DRIVERBINDING_SUPPORT_TOK
)
65 /// Number of items for which we are gathering cumulative statistics.
66 UINT32
const NumCum
= sizeof(CumData
) / sizeof(PERF_CUM_DATA
);
68 SHELL_PARAM_ITEM DpParamList
[] = {
69 {STR_DP_OPTION_QH
, TypeFlag
}, // -? Help
70 {STR_DP_OPTION_LH
, TypeFlag
}, // -h Help
71 {STR_DP_OPTION_UH
, TypeFlag
}, // -H Help
72 {STR_DP_OPTION_LV
, TypeFlag
}, // -v Verbose Mode
73 {STR_DP_OPTION_UA
, TypeFlag
}, // -A All, Cooked
74 {STR_DP_OPTION_UR
, TypeFlag
}, // -R RAW All
75 {STR_DP_OPTION_LS
, TypeFlag
}, // -s Summary
76 #if PROFILING_IMPLEMENTED
77 {STR_DP_OPTION_UP
, TypeFlag
}, // -P Dump Profile Data
78 {STR_DP_OPTION_UT
, TypeFlag
}, // -T Dump Trace Data
80 {STR_DP_OPTION_LX
, TypeFlag
}, // -x eXclude Cumulative Items
81 {STR_DP_OPTION_LN
, TypeValue
}, // -n # Number of records to display for A and R
82 {STR_DP_OPTION_LT
, TypeValue
}, // -t # Threshold of interest
89 Display Usage and Help information.
94 PrintToken (STRING_TOKEN (STR_DP_HELP_HEAD
));
95 #if PROFILING_IMPLEMENTED
96 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS
));
98 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS_2
));
99 #endif // PROFILING_IMPLEMENTED
100 PrintToken (STRING_TOKEN (STR_DP_HELP_PAGINATE
));
101 PrintToken (STRING_TOKEN (STR_DP_HELP_VERBOSE
));
102 PrintToken (STRING_TOKEN (STR_DP_HELP_EXCLUDE
));
103 PrintToken (STRING_TOKEN (STR_DP_HELP_STAT
));
104 PrintToken (STRING_TOKEN (STR_DP_HELP_ALL
));
105 PrintToken (STRING_TOKEN (STR_DP_HELP_RAW
));
106 #if PROFILING_IMPLEMENTED
107 PrintToken (STRING_TOKEN (STR_DP_HELP_TRACE
));
108 PrintToken (STRING_TOKEN (STR_DP_HELP_PROFILE
));
109 #endif // PROFILING_IMPLEMENTED
110 PrintToken (STRING_TOKEN (STR_DP_HELP_THRESHOLD
));
111 PrintToken (STRING_TOKEN (STR_DP_HELP_COUNT
));
112 PrintToken (STRING_TOKEN (STR_DP_HELP_HELP
));
117 Display the trailing Verbose information.
120 DumpStatistics( void )
122 EFI_STRING StringPtr
;
124 StringPtr
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_SECTION_STATISTICS
), NULL
);
125 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER
),
126 (StringPtr
== NULL
) ? ALit_UNKNOWN
: StringPtr
);
128 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMTRACE
), SummaryData
.NumTrace
);
129 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE
), SummaryData
.NumIncomplete
);
130 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPHASES
), SummaryData
.NumSummary
);
131 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMHANDLES
), SummaryData
.NumHandles
, SummaryData
.NumTrace
- SummaryData
.NumHandles
);
132 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPEIMS
), SummaryData
.NumPEIMs
);
133 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMGLOBALS
), SummaryData
.NumGlobal
);
134 #if PROFILING_IMPLEMENTED
135 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPROFILE
), SummaryData
.NumProfile
);
136 #endif // PROFILING_IMPLEMENTED
140 Dump performance data.
142 @param[in] ImageHandle The image handle.
143 @param[in] SystemTable The system table.
145 @retval EFI_SUCCESS Command completed successfully.
146 @retval EFI_INVALID_PARAMETER Command usage error.
147 @retval value Unknown error.
153 IN EFI_HANDLE ImageHandle
,
154 IN EFI_SYSTEM_TABLE
*SystemTable
160 LIST_ENTRY
*ParamPackage
;
161 CONST CHAR16
*CmdLineArg
;
162 EFI_STRING StringPtr
;
163 UINTN Number2Display
;
181 // Get DP's entry time as soon as possible.
182 // This is used as the Shell-Phase end time.
184 Ticker
= GetPerformanceCounter ();
186 // Register our string package with HII and return the handle to it.
188 gHiiHandle
= HiiAddPackages (&gEfiCallerIdGuid
, ImageHandle
, DPStrings
, NULL
);
189 ASSERT (gHiiHandle
!= NULL
);
191 /****************************************************************************
192 **** Process Command Line arguments ****
193 ****************************************************************************/
194 Status
= ShellCommandLineParse (DpParamList
, &ParamPackage
, NULL
, TRUE
);
196 if (EFI_ERROR(Status
)) {
197 PrintToken (STRING_TOKEN (STR_DP_INVALID_ARG
));
201 if (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_QH
) ||
202 ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_LH
) ||
203 ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UH
))
209 VerboseMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_LV
));
210 SummaryMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_US
) ||
211 ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_LS
));
212 AllMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UA
));
213 RawMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UR
));
214 #if PROFILING_IMPLEMENTED
215 TraceMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UT
));
216 ProfileMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UP
));
217 #endif // PROFILING_IMPLEMENTED
218 ExcludeMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_LX
));
220 // Options with Values
221 CmdLineArg
= ( ShellCommandLineGetValue (ParamPackage
, STR_DP_OPTION_LN
));
222 if (CmdLineArg
== NULL
) {
223 Number2Display
= DEFAULT_DISPLAYCOUNT
;
226 Number2Display
= StrDecimalToUintn(CmdLineArg
);
227 if (Number2Display
== 0) {
228 Number2Display
= MAXIMUM_DISPLAYCOUNT
;
231 CmdLineArg
= (ShellCommandLineGetValue (ParamPackage
, STR_DP_OPTION_LT
));
232 if (CmdLineArg
== NULL
) {
233 mInterestThreshold
= DEFAULT_THRESHOLD
; // 1ms := 1,000 us
236 mInterestThreshold
= StrDecimalToUint64(CmdLineArg
);
238 // Handle Flag combinations and default behaviors
239 // If both TraceMode and ProfileMode are FALSE, set them both to TRUE
240 if ((! TraceMode
) && (! ProfileMode
)) {
242 #if PROFILING_IMPLEMENTED
244 #endif // PROFILING_IMPLEMENTED
247 /****************************************************************************
248 **** Timer specific processing ****
249 ****************************************************************************/
250 // Get the Performance counter characteristics:
251 // Freq = Frequency in Hz
252 // StartCount = Value loaded into the counter when it starts counting
253 // EndCount = Value counter counts to before it needs to be reset
255 Freq
= GetPerformanceCounterProperties (&TimerInfo
.StartCount
, &TimerInfo
.EndCount
);
257 // Convert the Frequency from Hz to KHz
258 TimerInfo
.Frequency
= (UINT32
)DivU64x32 (Freq
, 1000);
260 // Determine in which direction the performance counter counts.
261 TimerInfo
.CountUp
= (BOOLEAN
) (TimerInfo
.EndCount
>= TimerInfo
.StartCount
);
263 /****************************************************************************
264 **** Print heading ****
265 ****************************************************************************/
266 // print DP's build version
267 PrintToken (STRING_TOKEN (STR_DP_BUILD_REVISION
), DP_MAJOR_VERSION
, DP_MINOR_VERSION
);
269 // print performance timer characteristics
270 PrintToken (STRING_TOKEN (STR_DP_KHZ
), TimerInfo
.Frequency
); // Print Timer frequency in KHz
275 StringPtr
= HiiGetString (gHiiHandle
,
276 TimerInfo
.CountUp
? STRING_TOKEN (STR_DP_UP
) : STRING_TOKEN (STR_DP_DOWN
),
278 ASSERT (StringPtr
!= NULL
);
279 PrintToken (STRING_TOKEN (STR_DP_TIMER_PROPERTIES
), // Print Timer count range and direction
281 TimerInfo
.StartCount
,
284 PrintToken (STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD
), mInterestThreshold
);
287 /* **************************************************************************
288 **** Print Sections based on command line options
290 **** Option modes have the following priority:
291 **** v Verbose -- Valid in combination with any other options
292 **** t Threshold -- Modifies All, Raw, and Cooked output
293 **** Default is 0 for All and Raw mode
294 **** Default is DEFAULT_THRESHOLD for "Cooked" mode
295 **** n Number2Display Used by All and Raw mode. Otherwise ignored.
296 **** A All -- R and S options are ignored
297 **** R Raw -- S option is ignored
298 **** s Summary -- Modifies "Cooked" output only
299 **** Cooked (Default)
301 **** The All, Raw, and Cooked modes are modified by the Trace and Profile
303 **** !T && !P := (0) Default, Both are displayed
304 **** T && !P := (1) Only Trace records are displayed
305 **** !T && P := (2) Only Profile records are displayed
306 **** T && P := (3) Same as Default, both are displayed
307 ****************************************************************************/
311 DumpAllTrace( Number2Display
, ExcludeMode
);
314 DumpAllProfile( Number2Display
, ExcludeMode
);
319 DumpRawTrace( Number2Display
, ExcludeMode
);
322 DumpRawProfile( Number2Display
, ExcludeMode
);
326 //------------- Begin Cooked Mode Processing
328 ProcessPhases ( Ticker
);
329 if ( ! SummaryMode
) {
330 Status
= ProcessHandles ( ExcludeMode
);
331 if ( ! EFI_ERROR( Status
)) {
334 ProcessCumulative ();
339 DumpAllProfile( Number2Display
, ExcludeMode
);
341 } //------------- End of Cooked Mode Processing
342 if ( VerboseMode
|| SummaryMode
) {
347 (void) FreePool (mPrintTokenBuffer
);
348 HiiRemovePackages (gHiiHandle
);