2 Shell command for Displaying Performance Metrics.
4 The Dp command 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 - 2013, Intel Corporation. All rights reserved.
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 "UefiDpLib.h"
27 #include <Guid/GlobalVariable.h>
28 #include <Library/PrintLib.h>
29 #include <Library/HandleParsingLib.h>
30 #include <Library/DevicePathLib.h>
32 #include <Library/ShellLib.h>
33 #include <Library/BaseLib.h>
34 #include <Library/MemoryAllocationLib.h>
35 #include <Library/DebugLib.h>
36 #include <Library/TimerLib.h>
37 #include <Library/UefiLib.h>
39 #include <Guid/Performance.h>
41 #include "PerformanceTokens.h"
44 #include "DpInternal.h"
47 /// Module-Global Variables
49 CHAR16 mGaugeString
[DP_GAUGE_STRING_LENGTH
+ 1];
50 CHAR16 mUnicodeToken
[DXE_PERFORMANCE_STRING_SIZE
];
51 UINT64 mInterestThreshold
;
52 BOOLEAN mShowId
= FALSE
;
54 PERF_SUMMARY_DATA SummaryData
= { 0 }; ///< Create the SummaryData structure and init. to ZERO.
56 /// Timer Specific Information.
59 /// Items for which to gather cumulative statistics.
60 PERF_CUM_DATA CumData
[] = {
61 PERF_INIT_CUM_DATA (LOAD_IMAGE_TOK
),
62 PERF_INIT_CUM_DATA (START_IMAGE_TOK
),
63 PERF_INIT_CUM_DATA (DRIVERBINDING_START_TOK
),
64 PERF_INIT_CUM_DATA (DRIVERBINDING_SUPPORT_TOK
)
67 /// Number of items for which we are gathering cumulative statistics.
68 UINT32
const NumCum
= sizeof(CumData
) / sizeof(PERF_CUM_DATA
);
70 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
71 {L
"-v", TypeFlag
}, // -v Verbose Mode
72 {L
"-A", TypeFlag
}, // -A All, Cooked
73 {L
"-R", TypeFlag
}, // -R RAW All
74 {L
"-s", TypeFlag
}, // -s Summary
75 #if PROFILING_IMPLEMENTED
76 {L
"-P", TypeFlag
}, // -P Dump Profile Data
77 {L
"-T", TypeFlag
}, // -T Dump Trace Data
78 #endif // PROFILING_IMPLEMENTED
79 {L
"-x", TypeFlag
}, // -x eXclude Cumulative Items
80 {L
"-i", TypeFlag
}, // -i Display Identifier
81 {L
"-n", TypeValue
}, // -n # Number of records to display for A and R
82 {L
"-t", TypeValue
}, // -t # Threshold of interest
89 Display the trailing Verbose information.
92 DumpStatistics( void )
95 EFI_STRING StringPtrUnknown
;
96 StringPtr
= HiiGetString (gDpHiiHandle
, STRING_TOKEN (STR_DP_SECTION_STATISTICS
), NULL
);
97 StringPtrUnknown
= HiiGetString (gDpHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
98 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_SECTION_HEADER
), gDpHiiHandle
,
99 (StringPtr
== NULL
) ? StringPtrUnknown
: StringPtr
);
100 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_STATS_NUMTRACE
), gDpHiiHandle
, SummaryData
.NumTrace
);
101 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE
), gDpHiiHandle
, SummaryData
.NumIncomplete
);
102 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_STATS_NUMPHASES
), gDpHiiHandle
, SummaryData
.NumSummary
);
103 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_STATS_NUMHANDLES
), gDpHiiHandle
, SummaryData
.NumHandles
, SummaryData
.NumTrace
- SummaryData
.NumHandles
);
104 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_STATS_NUMPEIMS
), gDpHiiHandle
, SummaryData
.NumPEIMs
);
105 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_STATS_NUMGLOBALS
), gDpHiiHandle
, SummaryData
.NumGlobal
);
106 #if PROFILING_IMPLEMENTED
107 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_STATS_NUMPROFILE
), gDpHiiHandle
, SummaryData
.NumProfile
);
108 #endif // PROFILING_IMPLEMENTED
109 SHELL_FREE_NON_NULL (StringPtr
);
110 SHELL_FREE_NON_NULL (StringPtrUnknown
);
114 Dump performance data.
116 @param[in] ImageHandle The image handle.
117 @param[in] SystemTable The system table.
119 @retval EFI_SUCCESS Command completed successfully.
120 @retval EFI_INVALID_PARAMETER Command usage error.
121 @retval value Unknown error.
127 IN EFI_HANDLE ImageHandle
,
128 IN EFI_SYSTEM_TABLE
*SystemTable
131 LIST_ENTRY
*ParamPackage
;
132 CONST CHAR16
*CmdLineArg
;
137 UINTN Number2Display
;
139 EFI_STRING StringPtr
;
157 // Get DP's entry time as soon as possible.
158 // This is used as the Shell-Phase end time.
160 Ticker
= GetPerformanceCounter ();
163 // initialize the shell lib (we must be in non-auto-init...)
165 Status
= ShellInitialize();
166 ASSERT_EFI_ERROR(Status
);
168 Status
= CommandInit();
169 ASSERT_EFI_ERROR(Status
);
172 // Process Command Line arguments
174 Status
= ShellCommandLineParse (ParamList
, &ParamPackage
, NULL
, TRUE
);
175 if (EFI_ERROR(Status
)) {
176 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_INVALID_ARG
), gDpHiiHandle
);
177 return SHELL_INVALID_PARAMETER
;
183 VerboseMode
= ShellCommandLineGetFlag (ParamPackage
, L
"-v");
184 SummaryMode
= (BOOLEAN
) (ShellCommandLineGetFlag (ParamPackage
, L
"-S") || ShellCommandLineGetFlag (ParamPackage
, L
"-s"));
185 AllMode
= ShellCommandLineGetFlag (ParamPackage
, L
"-A");
186 RawMode
= ShellCommandLineGetFlag (ParamPackage
, L
"-R");
187 #if PROFILING_IMPLEMENTED
188 TraceMode
= ShellCommandLineGetFlag (ParamPackage
, L
"-T");
189 ProfileMode
= ShellCommandLineGetFlag (ParamPackage
, L
"-P");
190 #endif // PROFILING_IMPLEMENTED
191 ExcludeMode
= ShellCommandLineGetFlag (ParamPackage
, L
"-x");
192 mShowId
= ShellCommandLineGetFlag (ParamPackage
, L
"-i");
194 // Options with Values
195 CmdLineArg
= ShellCommandLineGetValue (ParamPackage
, L
"-n");
196 if (CmdLineArg
== NULL
) {
197 Number2Display
= DEFAULT_DISPLAYCOUNT
;
199 Number2Display
= StrDecimalToUintn(CmdLineArg
);
200 if (Number2Display
== 0) {
201 Number2Display
= MAXIMUM_DISPLAYCOUNT
;
205 CmdLineArg
= ShellCommandLineGetValue (ParamPackage
, L
"-t");
206 if (CmdLineArg
== NULL
) {
207 mInterestThreshold
= DEFAULT_THRESHOLD
; // 1ms := 1,000 us
209 mInterestThreshold
= StrDecimalToUint64(CmdLineArg
);
212 // Handle Flag combinations and default behaviors
213 // If both TraceMode and ProfileMode are FALSE, set them both to TRUE
214 if ((! TraceMode
) && (! ProfileMode
)) {
216 #if PROFILING_IMPLEMENTED
218 #endif // PROFILING_IMPLEMENTED
222 // Timer specific processing
224 // Get the Performance counter characteristics:
225 // Freq = Frequency in Hz
226 // StartCount = Value loaded into the counter when it starts counting
227 // EndCount = Value counter counts to before it needs to be reset
229 Freq
= GetPerformanceCounterProperties (&TimerInfo
.StartCount
, &TimerInfo
.EndCount
);
231 // Convert the Frequency from Hz to KHz
232 TimerInfo
.Frequency
= (UINT32
)DivU64x32 (Freq
, 1000);
234 // Determine in which direction the performance counter counts.
235 TimerInfo
.CountUp
= (BOOLEAN
) (TimerInfo
.EndCount
>= TimerInfo
.StartCount
);
240 // print DP's build version
241 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_BUILD_REVISION
), gDpHiiHandle
, DP_MAJOR_VERSION
, DP_MINOR_VERSION
);
243 // print performance timer characteristics
244 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_KHZ
), gDpHiiHandle
, TimerInfo
.Frequency
);
246 if (VerboseMode
&& !RawMode
) {
247 StringPtr
= HiiGetString (gDpHiiHandle
,
248 (EFI_STRING_ID
) (TimerInfo
.CountUp
? STRING_TOKEN (STR_DP_UP
) : STRING_TOKEN (STR_DP_DOWN
)), NULL
);
249 ASSERT (StringPtr
!= NULL
);
250 // Print Timer count range and direction
251 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_TIMER_PROPERTIES
), gDpHiiHandle
,
253 TimerInfo
.StartCount
,
256 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD
), gDpHiiHandle
, mInterestThreshold
);
259 /****************************************************************************
260 **** Print Sections based on command line options
262 **** Option modes have the following priority:
263 **** v Verbose -- Valid in combination with any other options
264 **** t Threshold -- Modifies All, Raw, and Cooked output
265 **** Default is 0 for All and Raw mode
266 **** Default is DEFAULT_THRESHOLD for "Cooked" mode
267 **** n Number2Display Used by All and Raw mode. Otherwise ignored.
268 **** A All -- R and S options are ignored
269 **** R Raw -- S option is ignored
270 **** s Summary -- Modifies "Cooked" output only
271 **** Cooked (Default)
273 **** The All, Raw, and Cooked modes are modified by the Trace and Profile
275 **** !T && !P := (0) Default, Both are displayed
276 **** T && !P := (1) Only Trace records are displayed
277 **** !T && P := (2) Only Profile records are displayed
278 **** T && P := (3) Same as Default, both are displayed
279 ****************************************************************************/
283 DumpAllTrace( Number2Display
, ExcludeMode
);
286 DumpAllProfile( Number2Display
, ExcludeMode
);
288 } else if (RawMode
) {
290 DumpRawTrace( Number2Display
, ExcludeMode
);
293 DumpRawProfile( Number2Display
, ExcludeMode
);
296 //------------- Begin Cooked Mode Processing
298 ProcessPhases ( Ticker
);
299 if ( ! SummaryMode
) {
300 Status
= ProcessHandles ( ExcludeMode
);
301 if ( ! EFI_ERROR( Status
)) {
304 ProcessCumulative ();
309 DumpAllProfile( Number2Display
, ExcludeMode
);
311 } //------------- End of Cooked Mode Processing
312 if ( VerboseMode
|| SummaryMode
) {
316 SHELL_FREE_NON_NULL (StringPtr
);
318 return SHELL_SUCCESS
;