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
88 /// Display Usage and Help information.
92 PrintToken (STRING_TOKEN (STR_DP_HELP_HEAD
));
93 #if PROFILING_IMPLEMENTED
94 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS
));
96 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS_2
));
97 #endif // PROFILING_IMPLEMENTED
98 PrintToken (STRING_TOKEN (STR_DP_HELP_PAGINATE
));
99 PrintToken (STRING_TOKEN (STR_DP_HELP_VERBOSE
));
100 PrintToken (STRING_TOKEN (STR_DP_HELP_EXCLUDE
));
101 PrintToken (STRING_TOKEN (STR_DP_HELP_STAT
));
102 PrintToken (STRING_TOKEN (STR_DP_HELP_ALL
));
103 PrintToken (STRING_TOKEN (STR_DP_HELP_RAW
));
104 #if PROFILING_IMPLEMENTED
105 PrintToken (STRING_TOKEN (STR_DP_HELP_TRACE
));
106 PrintToken (STRING_TOKEN (STR_DP_HELP_PROFILE
));
107 #endif // PROFILING_IMPLEMENTED
108 PrintToken (STRING_TOKEN (STR_DP_HELP_THRESHOLD
));
109 PrintToken (STRING_TOKEN (STR_DP_HELP_COUNT
));
110 PrintToken (STRING_TOKEN (STR_DP_HELP_HELP
));
114 /// Display the trailing Verbose information.
116 DumpStatistics( void )
118 EFI_STRING StringPtr
;
120 StringPtr
= HiiGetString (gHiiHandle
, STRING_TOKEN (STR_DP_SECTION_STATISTICS
), NULL
);
121 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER
),
122 (StringPtr
== NULL
) ? ALit_UNKNOWN
: StringPtr
);
124 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMTRACE
), SummaryData
.NumTrace
);
125 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE
), SummaryData
.NumIncomplete
);
126 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPHASES
), SummaryData
.NumSummary
);
127 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMHANDLES
), SummaryData
.NumHandles
, SummaryData
.NumTrace
- SummaryData
.NumHandles
);
128 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPEIMS
), SummaryData
.NumPEIMs
);
129 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMGLOBALS
), SummaryData
.NumGlobal
);
130 #if PROFILING_IMPLEMENTED
131 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPROFILE
), SummaryData
.NumProfile
);
132 #endif // PROFILING_IMPLEMENTED
135 /** Dump performance data.
137 * @param[in] ImageHandle The image handle.
138 * @param[in] SystemTable The system table.
140 * @retval EFI_SUCCESS Command completed successfully.
141 * @retval EFI_INVALID_PARAMETER Command usage error.
142 * @retval value Unknown error.
148 IN EFI_HANDLE ImageHandle
,
149 IN EFI_SYSTEM_TABLE
*SystemTable
155 LIST_ENTRY
*ParamPackage
;
156 CONST CHAR16
*CmdLineArg
;
157 EFI_STRING StringPtr
;
158 UINTN Number2Display
;
161 BOOLEAN SummaryMode
= FALSE
;
162 BOOLEAN VerboseMode
= FALSE
;
163 BOOLEAN AllMode
= FALSE
;
164 BOOLEAN RawMode
= FALSE
;
165 BOOLEAN TraceMode
= FALSE
;
166 BOOLEAN ProfileMode
= FALSE
;
167 BOOLEAN ExcludeMode
= FALSE
;
170 // Get DP's entry time as soon as possible.
171 // This is used as the Shell-Phase end time.
173 Ticker
= GetPerformanceCounter ();
175 // Register our string package with HII and return the handle to it.
177 gHiiHandle
= HiiAddPackages (&gEfiCallerIdGuid
, ImageHandle
, DPStrings
, NULL
);
178 ASSERT (gHiiHandle
!= NULL
);
180 /****************************************************************************
181 **** Process Command Line arguments ****
182 ****************************************************************************/
183 Status
= ShellCommandLineParse (DpParamList
, &ParamPackage
, NULL
, TRUE
);
185 if (EFI_ERROR(Status
)) {
186 PrintToken (STRING_TOKEN (STR_DP_INVALID_ARG
));
190 if (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_QH
) ||
191 ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_LH
) ||
192 ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UH
))
198 VerboseMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_LV
));
199 SummaryMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_US
) ||
200 ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_LS
));
201 AllMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UA
));
202 RawMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UR
));
203 #if PROFILING_IMPLEMENTED
204 TraceMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UT
));
205 ProfileMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_UP
));
206 #endif // PROFILING_IMPLEMENTED
207 ExcludeMode
= (ShellCommandLineGetFlag (ParamPackage
, STR_DP_OPTION_LX
));
209 // Options with Values
210 CmdLineArg
= ( ShellCommandLineGetValue (ParamPackage
, STR_DP_OPTION_LN
));
211 if (CmdLineArg
== NULL
) {
212 Number2Display
= DEFAULT_DISPLAYCOUNT
;
215 Number2Display
= StrDecimalToUintn(CmdLineArg
);
216 if (Number2Display
== 0) {
217 Number2Display
= MAXIMUM_DISPLAYCOUNT
;
220 CmdLineArg
= (ShellCommandLineGetValue (ParamPackage
, STR_DP_OPTION_LT
));
221 if (CmdLineArg
== NULL
) {
222 mInterestThreshold
= DEFAULT_THRESHOLD
; // 1ms := 1,000 us
225 mInterestThreshold
= StrDecimalToUint64(CmdLineArg
);
227 // Handle Flag combinations and default behaviors
228 // If both TraceMode and ProfileMode are FALSE, set them both to TRUE
229 if ((! TraceMode
) && (! ProfileMode
)) {
231 #if PROFILING_IMPLEMENTED
233 #endif // PROFILING_IMPLEMENTED
236 /****************************************************************************
237 **** Timer specific processing ****
238 ****************************************************************************/
239 // Get the Performance counter characteristics:
240 // Freq = Frequency in Hz
241 // StartCount = Value loaded into the counter when it starts counting
242 // EndCount = Value counter counts to before it needs to be reset
244 Freq
= GetPerformanceCounterProperties (&TimerInfo
.StartCount
, &TimerInfo
.EndCount
);
246 // Convert the Frequency from Hz to KHz
247 TimerInfo
.Frequency
= (UINT32
)DivU64x32 (Freq
, 1000);
249 // Determine in which direction the performance counter counts.
250 TimerInfo
.CountUp
= (BOOLEAN
) (TimerInfo
.EndCount
>= TimerInfo
.StartCount
);
252 /****************************************************************************
253 **** Print heading ****
254 ****************************************************************************/
255 // print DP's build version
256 PrintToken (STRING_TOKEN (STR_DP_BUILD_REVISION
), DP_MAJOR_VERSION
, DP_MINOR_VERSION
);
258 // print performance timer characteristics
259 PrintToken (STRING_TOKEN (STR_DP_KHZ
), TimerInfo
.Frequency
); // Print Timer frequency in KHz
264 StringPtr
= HiiGetString (gHiiHandle
,
265 TimerInfo
.CountUp
? STRING_TOKEN (STR_DP_UP
) : STRING_TOKEN (STR_DP_DOWN
),
267 ASSERT (StringPtr
!= NULL
);
268 PrintToken (STRING_TOKEN (STR_DP_TIMER_PROPERTIES
), // Print Timer count range and direction
270 TimerInfo
.StartCount
,
273 PrintToken (STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD
), mInterestThreshold
);
276 /* **************************************************************************
277 **** Print Sections based on command line options
279 **** Option modes have the following priority:
280 **** v Verbose -- Valid in combination with any other options
281 **** t Threshold -- Modifies All, Raw, and Cooked output
282 **** Default is 0 for All and Raw mode
283 **** Default is DEFAULT_THRESHOLD for "Cooked" mode
284 **** n Number2Display Used by All and Raw mode. Otherwise ignored.
285 **** A All -- R and S options are ignored
286 **** R Raw -- S option is ignored
287 **** s Summary -- Modifies "Cooked" output only
288 **** Cooked (Default)
290 **** The All, Raw, and Cooked modes are modified by the Trace and Profile
292 **** !T && !P := (0) Default, Both are displayed
293 **** T && !P := (1) Only Trace records are displayed
294 **** !T && P := (2) Only Profile records are displayed
295 **** T && P := (3) Same as Default, both are displayed
296 ****************************************************************************/
300 DumpAllTrace( Number2Display
, ExcludeMode
);
303 DumpAllProfile( Number2Display
, ExcludeMode
);
308 DumpRawTrace( Number2Display
, ExcludeMode
);
311 DumpRawProfile( Number2Display
, ExcludeMode
);
315 //------------- Begin Cooked Mode Processing
317 ProcessPhases ( Ticker
);
318 if ( ! SummaryMode
) {
319 Status
= ProcessHandles ( ExcludeMode
);
320 if ( ! EFI_ERROR( Status
)) {
323 ProcessCumulative ();
328 DumpAllProfile( Number2Display
, ExcludeMode
);
330 } //------------- End of Cooked Mode Processing
331 if ( VerboseMode
|| SummaryMode
) {
336 (void) FreePool (mPrintTokenBuffer
);
337 HiiRemovePackages (gHiiHandle
);