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 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 Transfer the param list value and get the command line parse.
93 InitialShellParamList( void )
99 // Allocate one more for the end tag.
101 ListLength
= sizeof (ParamList
) / sizeof (ParamList
[0]) + 1;
102 DpParamList
= AllocatePool (sizeof (SHELL_PARAM_ITEM
) * ListLength
);
103 ASSERT (DpParamList
!= NULL
);
105 for (ListIndex
= 0; ListIndex
< ListLength
- 1; ListIndex
++)
107 DpParamList
[ListIndex
].Name
= HiiGetString (gHiiHandle
, ParamList
[ListIndex
].Token
, NULL
);
108 DpParamList
[ListIndex
].Type
= ParamList
[ListIndex
].Type
;
110 DpParamList
[ListIndex
].Name
= NULL
;
111 DpParamList
[ListIndex
].Type
= TypeMax
;
115 Display Usage and Help information.
120 PrintToken (STRING_TOKEN (STR_DP_HELP_HEAD
));
121 #if PROFILING_IMPLEMENTED
122 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS
));
124 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS_2
));
125 #endif // PROFILING_IMPLEMENTED
126 PrintToken (STRING_TOKEN (STR_DP_HELP_PAGINATE
));
127 PrintToken (STRING_TOKEN (STR_DP_HELP_VERBOSE
));
128 PrintToken (STRING_TOKEN (STR_DP_HELP_EXCLUDE
));
129 PrintToken (STRING_TOKEN (STR_DP_HELP_STAT
));
130 PrintToken (STRING_TOKEN (STR_DP_HELP_ALL
));
131 PrintToken (STRING_TOKEN (STR_DP_HELP_RAW
));
132 #if PROFILING_IMPLEMENTED
133 PrintToken (STRING_TOKEN (STR_DP_HELP_TRACE
));
134 PrintToken (STRING_TOKEN (STR_DP_HELP_PROFILE
));
135 #endif // PROFILING_IMPLEMENTED
136 PrintToken (STRING_TOKEN (STR_DP_HELP_THRESHOLD
));
137 PrintToken (STRING_TOKEN (STR_DP_HELP_COUNT
));
138 PrintToken (STRING_TOKEN (STR_DP_HELP_HELP
));
143 Display the trailing Verbose information.
146 DumpStatistics( void )
148 EFI_STRING StringPtr
;
149 EFI_STRING StringPtrUnknown
;
150 StringPtr
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_SECTION_STATISTICS
), NULL
);
151 StringPtrUnknown
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
152 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER
),
153 (StringPtr
== NULL
) ? StringPtrUnknown
: StringPtr
);
155 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMTRACE
), SummaryData
.NumTrace
);
156 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE
), SummaryData
.NumIncomplete
);
157 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPHASES
), SummaryData
.NumSummary
);
158 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMHANDLES
), SummaryData
.NumHandles
, SummaryData
.NumTrace
- SummaryData
.NumHandles
);
159 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPEIMS
), SummaryData
.NumPEIMs
);
160 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMGLOBALS
), SummaryData
.NumGlobal
);
161 #if PROFILING_IMPLEMENTED
162 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPROFILE
), SummaryData
.NumProfile
);
163 #endif // PROFILING_IMPLEMENTED
164 FreePool (StringPtr
);
165 FreePool (StringPtrUnknown
);
169 Dump performance data.
171 @param[in] ImageHandle The image handle.
172 @param[in] SystemTable The system table.
174 @retval EFI_SUCCESS Command completed successfully.
175 @retval EFI_INVALID_PARAMETER Command usage error.
176 @retval value Unknown error.
182 IN EFI_HANDLE ImageHandle
,
183 IN EFI_SYSTEM_TABLE
*SystemTable
190 LIST_ENTRY
*ParamPackage
;
191 CONST CHAR16
*CmdLineArg
;
192 EFI_STRING StringPtr
;
193 UINTN Number2Display
;
204 EFI_STRING StringDpOptionQh
;
205 EFI_STRING StringDpOptionLh
;
206 EFI_STRING StringDpOptionUh
;
207 EFI_STRING StringDpOptionLv
;
208 EFI_STRING StringDpOptionUs
;
209 EFI_STRING StringDpOptionLs
;
210 EFI_STRING StringDpOptionUa
;
211 EFI_STRING StringDpOptionUr
;
212 EFI_STRING StringDpOptionUt
;
213 EFI_STRING StringDpOptionUp
;
214 EFI_STRING StringDpOptionLx
;
215 EFI_STRING StringDpOptionLn
;
216 EFI_STRING StringDpOptionLt
;
226 StringDpOptionQh
= NULL
;
227 StringDpOptionLh
= NULL
;
228 StringDpOptionUh
= NULL
;
229 StringDpOptionLv
= NULL
;
230 StringDpOptionUs
= NULL
;
231 StringDpOptionLs
= NULL
;
232 StringDpOptionUa
= NULL
;
233 StringDpOptionUr
= NULL
;
234 StringDpOptionUt
= NULL
;
235 StringDpOptionUp
= NULL
;
236 StringDpOptionLx
= NULL
;
237 StringDpOptionLn
= NULL
;
238 StringDpOptionLt
= NULL
;
241 // Get DP's entry time as soon as possible.
242 // This is used as the Shell-Phase end time.
244 Ticker
= GetPerformanceCounter ();
246 // Register our string package with HII and return the handle to it.
248 gHiiHandle
= HiiAddPackages (&gEfiCallerIdGuid
, ImageHandle
, DPStrings
, NULL
);
249 ASSERT (gHiiHandle
!= NULL
);
251 // Initial the command list
253 InitialShellParamList ();
255 /****************************************************************************
256 **** Process Command Line arguments ****
257 ****************************************************************************/
258 Status
= ShellCommandLineParse (DpParamList
, &ParamPackage
, NULL
, TRUE
);
260 if (EFI_ERROR(Status
)) {
261 PrintToken (STRING_TOKEN (STR_DP_INVALID_ARG
));
265 StringDpOptionQh
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_QH
), NULL
);
266 StringDpOptionLh
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LH
), NULL
);
267 StringDpOptionUh
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UH
), NULL
);
269 if (ShellCommandLineGetFlag (ParamPackage
, StringDpOptionQh
) ||
270 ShellCommandLineGetFlag (ParamPackage
, StringDpOptionLh
) ||
271 ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUh
))
276 StringDpOptionLv
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LV
), NULL
);
277 StringDpOptionUs
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_US
), NULL
);
278 StringDpOptionLs
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LS
), NULL
);
279 StringDpOptionUa
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UA
), NULL
);
280 StringDpOptionUr
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UR
), NULL
);
281 StringDpOptionUt
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UT
), NULL
);
282 StringDpOptionUp
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_UP
), NULL
);
283 StringDpOptionLx
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LX
), NULL
);
284 StringDpOptionLn
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LN
), NULL
);
285 StringDpOptionLt
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_OPTION_LT
), NULL
);
289 VerboseMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionLv
);
290 SummaryMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUs
) ||
291 ShellCommandLineGetFlag (ParamPackage
, StringDpOptionLs
);
292 AllMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUa
);
293 RawMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUr
);
294 #if PROFILING_IMPLEMENTED
295 TraceMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUt
);
296 ProfileMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionUp
);
297 #endif // PROFILING_IMPLEMENTED
298 ExcludeMode
= ShellCommandLineGetFlag (ParamPackage
, StringDpOptionLx
);
300 // Options with Values
301 CmdLineArg
= ShellCommandLineGetValue (ParamPackage
, StringDpOptionLn
);
302 if (CmdLineArg
== NULL
) {
303 Number2Display
= DEFAULT_DISPLAYCOUNT
;
306 Number2Display
= StrDecimalToUintn(CmdLineArg
);
307 if (Number2Display
== 0) {
308 Number2Display
= MAXIMUM_DISPLAYCOUNT
;
311 CmdLineArg
= ShellCommandLineGetValue (ParamPackage
, StringDpOptionLt
);
312 if (CmdLineArg
== NULL
) {
313 mInterestThreshold
= DEFAULT_THRESHOLD
; // 1ms := 1,000 us
316 mInterestThreshold
= StrDecimalToUint64(CmdLineArg
);
318 // Handle Flag combinations and default behaviors
319 // If both TraceMode and ProfileMode are FALSE, set them both to TRUE
320 if ((! TraceMode
) && (! ProfileMode
)) {
322 #if PROFILING_IMPLEMENTED
324 #endif // PROFILING_IMPLEMENTED
327 /****************************************************************************
328 **** Timer specific processing ****
329 ****************************************************************************/
330 // Get the Performance counter characteristics:
331 // Freq = Frequency in Hz
332 // StartCount = Value loaded into the counter when it starts counting
333 // EndCount = Value counter counts to before it needs to be reset
335 Freq
= GetPerformanceCounterProperties (&TimerInfo
.StartCount
, &TimerInfo
.EndCount
);
337 // Convert the Frequency from Hz to KHz
338 TimerInfo
.Frequency
= (UINT32
)DivU64x32 (Freq
, 1000);
340 // Determine in which direction the performance counter counts.
341 TimerInfo
.CountUp
= (BOOLEAN
) (TimerInfo
.EndCount
>= TimerInfo
.StartCount
);
343 /****************************************************************************
344 **** Print heading ****
345 ****************************************************************************/
346 // print DP's build version
347 PrintToken (STRING_TOKEN (STR_DP_BUILD_REVISION
), DP_MAJOR_VERSION
, DP_MINOR_VERSION
);
349 // print performance timer characteristics
350 PrintToken (STRING_TOKEN (STR_DP_KHZ
), TimerInfo
.Frequency
); // Print Timer frequency in KHz
355 StringPtr
= HiiGetString (gHiiHandle
,
356 TimerInfo
.CountUp
? STRING_TOKEN (STR_DP_UP
) : STRING_TOKEN (STR_DP_DOWN
),
358 ASSERT (StringPtr
!= NULL
);
359 PrintToken (STRING_TOKEN (STR_DP_TIMER_PROPERTIES
), // Print Timer count range and direction
361 TimerInfo
.StartCount
,
364 PrintToken (STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD
), mInterestThreshold
);
367 /* **************************************************************************
368 **** Print Sections based on command line options
370 **** Option modes have the following priority:
371 **** v Verbose -- Valid in combination with any other options
372 **** t Threshold -- Modifies All, Raw, and Cooked output
373 **** Default is 0 for All and Raw mode
374 **** Default is DEFAULT_THRESHOLD for "Cooked" mode
375 **** n Number2Display Used by All and Raw mode. Otherwise ignored.
376 **** A All -- R and S options are ignored
377 **** R Raw -- S option is ignored
378 **** s Summary -- Modifies "Cooked" output only
379 **** Cooked (Default)
381 **** The All, Raw, and Cooked modes are modified by the Trace and Profile
383 **** !T && !P := (0) Default, Both are displayed
384 **** T && !P := (1) Only Trace records are displayed
385 **** !T && P := (2) Only Profile records are displayed
386 **** T && P := (3) Same as Default, both are displayed
387 ****************************************************************************/
391 DumpAllTrace( Number2Display
, ExcludeMode
);
394 DumpAllProfile( Number2Display
, ExcludeMode
);
399 DumpRawTrace( Number2Display
, ExcludeMode
);
402 DumpRawProfile( Number2Display
, ExcludeMode
);
406 //------------- Begin Cooked Mode Processing
408 ProcessPhases ( Ticker
);
409 if ( ! SummaryMode
) {
410 Status
= ProcessHandles ( ExcludeMode
);
411 if ( ! EFI_ERROR( Status
)) {
414 ProcessCumulative ();
419 DumpAllProfile( Number2Display
, ExcludeMode
);
421 } //------------- End of Cooked Mode Processing
422 if ( VerboseMode
|| SummaryMode
) {
428 // Free the memory allocate from HiiGetString
431 while (DpParamList
[ListIndex
].Name
!= NULL
) {
432 FreePool (DpParamList
[ListIndex
].Name
);
435 FreePool (DpParamList
);
437 FreePool (StringDpOptionQh
);
438 FreePool (StringDpOptionLh
);
439 FreePool (StringDpOptionUh
);
440 FreePool (StringDpOptionLv
);
441 FreePool (StringDpOptionUs
);
442 FreePool (StringDpOptionLs
);
443 FreePool (StringDpOptionUa
);
444 FreePool (StringDpOptionUr
);
445 FreePool (StringDpOptionUt
);
446 FreePool (StringDpOptionUp
);
447 FreePool (StringDpOptionLx
);
448 FreePool (StringDpOptionLn
);
449 FreePool (StringDpOptionLt
);
450 FreePool (StringPtr
);
451 FreePool (mPrintTokenBuffer
);
453 HiiRemovePackages (gHiiHandle
);