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 - 2011, 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 SHELL_PARAM_ITEM
*DpParamList
= NULL
;
48 CHAR16
*mPrintTokenBuffer
= NULL
;
49 CHAR16 mGaugeString
[DXE_PERFORMANCE_STRING_SIZE
];
50 CHAR16 mUnicodeToken
[PERF_TOKEN_LENGTH
+ 1];
51 UINT64 mInterestThreshold
;
53 PERF_SUMMARY_DATA SummaryData
= { 0 }; ///< Create the SummaryData structure and init. to ZERO.
55 /// Timer Specific Information.
58 /// Items for which to gather cumulative statistics.
59 PERF_CUM_DATA CumData
[] = {
60 PERF_INIT_CUM_DATA (LOAD_IMAGE_TOK
),
61 PERF_INIT_CUM_DATA (START_IMAGE_TOK
),
62 PERF_INIT_CUM_DATA (DRIVERBINDING_START_TOK
),
63 PERF_INIT_CUM_DATA (DRIVERBINDING_SUPPORT_TOK
)
66 /// Number of items for which we are gathering cumulative statistics.
67 UINT32
const NumCum
= sizeof(CumData
) / sizeof(PERF_CUM_DATA
);
69 PARAM_ITEM_LIST ParamList
[] = {
70 {STRING_TOKEN (STR_DP_OPTION_QH
), TypeFlag
}, // -? Help
71 {STRING_TOKEN (STR_DP_OPTION_LH
), TypeFlag
}, // -h Help
72 {STRING_TOKEN (STR_DP_OPTION_UH
), TypeFlag
}, // -H Help
73 {STRING_TOKEN (STR_DP_OPTION_LV
), TypeFlag
}, // -v Verbose Mode
74 {STRING_TOKEN (STR_DP_OPTION_UA
), TypeFlag
}, // -A All, Cooked
75 {STRING_TOKEN (STR_DP_OPTION_UR
), TypeFlag
}, // -R RAW All
76 {STRING_TOKEN (STR_DP_OPTION_LS
), TypeFlag
}, // -s Summary
77 #if PROFILING_IMPLEMENTED
78 {STRING_TOKEN (STR_DP_OPTION_UP
), TypeFlag
}, // -P Dump Profile Data
79 {STRING_TOKEN (STR_DP_OPTION_UT
), TypeFlag
}, // -T Dump Trace Data
81 {STRING_TOKEN (STR_DP_OPTION_LX
), TypeFlag
}, // -x eXclude Cumulative Items
82 {STRING_TOKEN (STR_DP_OPTION_LN
), TypeValue
}, // -n # Number of records to display for A and R
83 {STRING_TOKEN (STR_DP_OPTION_LT
), TypeValue
} // -t # Threshold of interest
89 Wrap original FreePool to check NULL pointer first.
102 Transfer the param list value and get the command line parse.
106 InitialShellParamList( void )
112 // Allocate one more for the end tag.
114 ListLength
= sizeof (ParamList
) / sizeof (ParamList
[0]) + 1;
115 DpParamList
= AllocatePool (sizeof (SHELL_PARAM_ITEM
) * ListLength
);
116 ASSERT (DpParamList
!= NULL
);
118 for (ListIndex
= 0; ListIndex
< ListLength
- 1; ListIndex
++)
120 DpParamList
[ListIndex
].Name
= HiiGetString (gHiiHandle
, ParamList
[ListIndex
].Token
, NULL
);
121 DpParamList
[ListIndex
].Type
= ParamList
[ListIndex
].Type
;
123 DpParamList
[ListIndex
].Name
= NULL
;
124 DpParamList
[ListIndex
].Type
= TypeMax
;
128 Display Usage and Help information.
133 PrintToken (STRING_TOKEN (STR_DP_HELP_HEAD
));
134 #if PROFILING_IMPLEMENTED
135 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS
));
137 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS_2
));
138 #endif // PROFILING_IMPLEMENTED
139 PrintToken (STRING_TOKEN (STR_DP_HELP_PAGINATE
));
140 PrintToken (STRING_TOKEN (STR_DP_HELP_VERBOSE
));
141 PrintToken (STRING_TOKEN (STR_DP_HELP_EXCLUDE
));
142 PrintToken (STRING_TOKEN (STR_DP_HELP_STAT
));
143 PrintToken (STRING_TOKEN (STR_DP_HELP_ALL
));
144 PrintToken (STRING_TOKEN (STR_DP_HELP_RAW
));
145 #if PROFILING_IMPLEMENTED
146 PrintToken (STRING_TOKEN (STR_DP_HELP_TRACE
));
147 PrintToken (STRING_TOKEN (STR_DP_HELP_PROFILE
));
148 #endif // PROFILING_IMPLEMENTED
149 PrintToken (STRING_TOKEN (STR_DP_HELP_THRESHOLD
));
150 PrintToken (STRING_TOKEN (STR_DP_HELP_COUNT
));
151 PrintToken (STRING_TOKEN (STR_DP_HELP_HELP
));
156 Display the trailing Verbose information.
159 DumpStatistics( void )
161 EFI_STRING StringPtr
;
162 EFI_STRING StringPtrUnknown
;
163 StringPtr
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_SECTION_STATISTICS
), NULL
);
164 StringPtrUnknown
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
165 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER
),
166 (StringPtr
== NULL
) ? StringPtrUnknown
: StringPtr
);
168 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMTRACE
), SummaryData
.NumTrace
);
169 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE
), SummaryData
.NumIncomplete
);
170 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPHASES
), SummaryData
.NumSummary
);
171 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMHANDLES
), SummaryData
.NumHandles
, SummaryData
.NumTrace
- SummaryData
.NumHandles
);
172 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPEIMS
), SummaryData
.NumPEIMs
);
173 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMGLOBALS
), SummaryData
.NumGlobal
);
174 #if PROFILING_IMPLEMENTED
175 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPROFILE
), SummaryData
.NumProfile
);
176 #endif // PROFILING_IMPLEMENTED
177 FreePool (StringPtr
);
178 FreePool (StringPtrUnknown
);
182 Dump performance data.
184 @param[in] ImageHandle The image handle.
185 @param[in] SystemTable The system table.
187 @retval EFI_SUCCESS Command completed successfully.
188 @retval EFI_INVALID_PARAMETER Command usage error.
189 @retval value Unknown error.
195 IN EFI_HANDLE ImageHandle
,
196 IN EFI_SYSTEM_TABLE
*SystemTable
203 LIST_ENTRY
*ParamPackage
;
204 CONST CHAR16
*CmdLineArg
;
205 EFI_STRING StringPtr
;
206 UINTN Number2Display
;
217 EFI_STRING StringDpOptionQh
;
218 EFI_STRING StringDpOptionLh
;
219 EFI_STRING StringDpOptionUh
;
220 EFI_STRING StringDpOptionLv
;
221 EFI_STRING StringDpOptionUs
;
222 EFI_STRING StringDpOptionLs
;
223 EFI_STRING StringDpOptionUa
;
224 EFI_STRING StringDpOptionUr
;
225 EFI_STRING StringDpOptionUt
;
226 EFI_STRING StringDpOptionUp
;
227 EFI_STRING StringDpOptionLx
;
228 EFI_STRING StringDpOptionLn
;
229 EFI_STRING StringDpOptionLt
;
239 StringDpOptionQh
= NULL
;
240 StringDpOptionLh
= NULL
;
241 StringDpOptionUh
= NULL
;
242 StringDpOptionLv
= NULL
;
243 StringDpOptionUs
= NULL
;
244 StringDpOptionLs
= NULL
;
245 StringDpOptionUa
= NULL
;
246 StringDpOptionUr
= NULL
;
247 StringDpOptionUt
= NULL
;
248 StringDpOptionUp
= NULL
;
249 StringDpOptionLx
= NULL
;
250 StringDpOptionLn
= NULL
;
251 StringDpOptionLt
= NULL
;
254 // Get DP's entry time as soon as possible.
255 // This is used as the Shell-Phase end time.
257 Ticker
= GetPerformanceCounter ();
259 // Register our string package with HII and return the handle to it.
261 gHiiHandle
= HiiAddPackages (&gEfiCallerIdGuid
, ImageHandle
, DPStrings
, NULL
);
262 ASSERT (gHiiHandle
!= NULL
);
264 // Initial the command list
266 InitialShellParamList ();
268 /****************************************************************************
269 **** Process Command Line arguments ****
270 ****************************************************************************/
271 Status
= ShellCommandLineParse (DpParamList
, &ParamPackage
, NULL
, TRUE
);
273 if (EFI_ERROR(Status
)) {
274 PrintToken (STRING_TOKEN (STR_DP_INVALID_ARG
));
278 StringDpOptionQh
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_QH
), NULL
);
279 StringDpOptionLh
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LH
), NULL
);
280 StringDpOptionUh
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UH
), NULL
);
282 if (ShellCommandLineGetFlag (ParamPackage
, StringDpOptionQh
) ||
283 ShellCommandLineGetFlag (ParamPackage
, StringDpOptionLh
) ||
284 ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUh
))
289 StringDpOptionLv
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LV
), NULL
);
290 StringDpOptionUs
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_US
), NULL
);
291 StringDpOptionLs
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LS
), NULL
);
292 StringDpOptionUa
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UA
), NULL
);
293 StringDpOptionUr
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UR
), NULL
);
294 StringDpOptionUt
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UT
), NULL
);
295 StringDpOptionUp
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UP
), NULL
);
296 StringDpOptionLx
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LX
), NULL
);
297 StringDpOptionLn
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LN
), NULL
);
298 StringDpOptionLt
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LT
), NULL
);
302 VerboseMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionLv
);
303 SummaryMode
= (BOOLEAN
) (ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUs
) ||
304 ShellCommandLineGetFlag (ParamPackage
, StringDpOptionLs
));
305 AllMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUa
);
306 RawMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUr
);
307 #if PROFILING_IMPLEMENTED
308 TraceMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUt
);
309 ProfileMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUp
);
310 #endif // PROFILING_IMPLEMENTED
311 ExcludeMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionLx
);
313 // Options with Values
314 CmdLineArg
= ShellCommandLineGetValue (ParamPackage
, StringDpOptionLn
);
315 if (CmdLineArg
== NULL
) {
316 Number2Display
= DEFAULT_DISPLAYCOUNT
;
319 Number2Display
= StrDecimalToUintn(CmdLineArg
);
320 if (Number2Display
== 0) {
321 Number2Display
= MAXIMUM_DISPLAYCOUNT
;
324 CmdLineArg
= ShellCommandLineGetValue (ParamPackage
, StringDpOptionLt
);
325 if (CmdLineArg
== NULL
) {
326 mInterestThreshold
= DEFAULT_THRESHOLD
; // 1ms := 1,000 us
329 mInterestThreshold
= StrDecimalToUint64(CmdLineArg
);
331 // Handle Flag combinations and default behaviors
332 // If both TraceMode and ProfileMode are FALSE, set them both to TRUE
333 if ((! TraceMode
) && (! ProfileMode
)) {
335 #if PROFILING_IMPLEMENTED
337 #endif // PROFILING_IMPLEMENTED
340 /****************************************************************************
341 **** Timer specific processing ****
342 ****************************************************************************/
343 // Get the Performance counter characteristics:
344 // Freq = Frequency in Hz
345 // StartCount = Value loaded into the counter when it starts counting
346 // EndCount = Value counter counts to before it needs to be reset
348 Freq
= GetPerformanceCounterProperties (&TimerInfo
.StartCount
, &TimerInfo
.EndCount
);
350 // Convert the Frequency from Hz to KHz
351 TimerInfo
.Frequency
= (UINT32
)DivU64x32 (Freq
, 1000);
353 // Determine in which direction the performance counter counts.
354 TimerInfo
.CountUp
= (BOOLEAN
) (TimerInfo
.EndCount
>= TimerInfo
.StartCount
);
356 /****************************************************************************
357 **** Print heading ****
358 ****************************************************************************/
359 // print DP's build version
360 PrintToken (STRING_TOKEN (STR_DP_BUILD_REVISION
), DP_MAJOR_VERSION
, DP_MINOR_VERSION
);
362 // print performance timer characteristics
363 PrintToken (STRING_TOKEN (STR_DP_KHZ
), TimerInfo
.Frequency
); // Print Timer frequency in KHz
368 StringPtr
= HiiGetString (gHiiHandle
,
369 (EFI_STRING_ID
) (TimerInfo
.CountUp
? STRING_TOKEN (STR_DP_UP
) : STRING_TOKEN (STR_DP_DOWN
)),
371 ASSERT (StringPtr
!= NULL
);
372 PrintToken (STRING_TOKEN (STR_DP_TIMER_PROPERTIES
), // Print Timer count range and direction
374 TimerInfo
.StartCount
,
377 PrintToken (STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD
), mInterestThreshold
);
380 /* **************************************************************************
381 **** Print Sections based on command line options
383 **** Option modes have the following priority:
384 **** v Verbose -- Valid in combination with any other options
385 **** t Threshold -- Modifies All, Raw, and Cooked output
386 **** Default is 0 for All and Raw mode
387 **** Default is DEFAULT_THRESHOLD for "Cooked" mode
388 **** n Number2Display Used by All and Raw mode. Otherwise ignored.
389 **** A All -- R and S options are ignored
390 **** R Raw -- S option is ignored
391 **** s Summary -- Modifies "Cooked" output only
392 **** Cooked (Default)
394 **** The All, Raw, and Cooked modes are modified by the Trace and Profile
396 **** !T && !P := (0) Default, Both are displayed
397 **** T && !P := (1) Only Trace records are displayed
398 **** !T && P := (2) Only Profile records are displayed
399 **** T && P := (3) Same as Default, both are displayed
400 ****************************************************************************/
404 DumpAllTrace( Number2Display
, ExcludeMode
);
407 DumpAllProfile( Number2Display
, ExcludeMode
);
412 DumpRawTrace( Number2Display
, ExcludeMode
);
415 DumpRawProfile( Number2Display
, ExcludeMode
);
419 //------------- Begin Cooked Mode Processing
421 ProcessPhases ( Ticker
);
422 if ( ! SummaryMode
) {
423 Status
= ProcessHandles ( ExcludeMode
);
424 if ( ! EFI_ERROR( Status
)) {
427 ProcessCumulative ();
432 DumpAllProfile( Number2Display
, ExcludeMode
);
434 } //------------- End of Cooked Mode Processing
435 if ( VerboseMode
|| SummaryMode
) {
441 // Free the memory allocate from HiiGetString
444 while (DpParamList
[ListIndex
].Name
!= NULL
) {
445 FreePool (DpParamList
[ListIndex
].Name
);
448 FreePool (DpParamList
);
450 SafeFreePool (StringDpOptionQh
);
451 SafeFreePool (StringDpOptionLh
);
452 SafeFreePool (StringDpOptionUh
);
453 SafeFreePool (StringDpOptionLv
);
454 SafeFreePool (StringDpOptionUs
);
455 SafeFreePool (StringDpOptionLs
);
456 SafeFreePool (StringDpOptionUa
);
457 SafeFreePool (StringDpOptionUr
);
458 SafeFreePool (StringDpOptionUt
);
459 SafeFreePool (StringDpOptionUp
);
460 SafeFreePool (StringDpOptionLx
);
461 SafeFreePool (StringDpOptionLn
);
462 SafeFreePool (StringDpOptionLt
);
463 SafeFreePool (StringPtr
);
464 SafeFreePool (mPrintTokenBuffer
);
466 HiiRemovePackages (gHiiHandle
);