VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiDpLib/Dp.c@ 58466

Last change on this file since 58466 was 58466, checked in by vboxsync, 9 years ago

EFI/Firmware: Merged in the svn:eol-style, svn:mime-type and trailing whitespace cleanup that was done after the initial UDK2014.SP1 import: svn merge /vendor/edk2/UDK2014.SP1 /vendor/edk2/current .

  • Property svn:eol-style set to native
File size: 11.2 KB
Line 
1/** @file
2 Shell command for Displaying Performance Metrics.
3
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.
7
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.
15
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
21
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.
24**/
25
26#include "UefiDpLib.h"
27#include <Guid/GlobalVariable.h>
28#include <Library/PrintLib.h>
29#include <Library/HandleParsingLib.h>
30#include <Library/DevicePathLib.h>
31
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>
38
39#include <Guid/Performance.h>
40
41#include "PerformanceTokens.h"
42#include "Dp.h"
43#include "Literals.h"
44#include "DpInternal.h"
45
46//
47/// Module-Global Variables
48///@{
49CHAR16 mGaugeString[DP_GAUGE_STRING_LENGTH + 1];
50CHAR16 mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE];
51UINT64 mInterestThreshold;
52BOOLEAN mShowId = FALSE;
53
54PERF_SUMMARY_DATA SummaryData = { 0 }; ///< Create the SummaryData structure and init. to ZERO.
55
56/// Timer Specific Information.
57TIMER_INFO TimerInfo;
58
59/// Items for which to gather cumulative statistics.
60PERF_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)
65};
66
67/// Number of items for which we are gathering cumulative statistics.
68UINT32 const NumCum = sizeof(CumData) / sizeof(PERF_CUM_DATA);
69
70STATIC 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
83 {NULL, TypeMax}
84 };
85
86///@}
87
88/**
89 Display the trailing Verbose information.
90**/
91VOID
92DumpStatistics( void )
93{
94 EFI_STRING StringPtr;
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);
111}
112
113/**
114 Dump performance data.
115
116 @param[in] ImageHandle The image handle.
117 @param[in] SystemTable The system table.
118
119 @retval EFI_SUCCESS Command completed successfully.
120 @retval EFI_INVALID_PARAMETER Command usage error.
121 @retval value Unknown error.
122
123**/
124SHELL_STATUS
125EFIAPI
126ShellCommandRunDp (
127 IN EFI_HANDLE ImageHandle,
128 IN EFI_SYSTEM_TABLE *SystemTable
129 )
130{
131 LIST_ENTRY *ParamPackage;
132 CONST CHAR16 *CmdLineArg;
133 EFI_STATUS Status;
134
135 UINT64 Freq;
136 UINT64 Ticker;
137 UINTN Number2Display;
138
139 EFI_STRING StringPtr;
140 BOOLEAN SummaryMode;
141 BOOLEAN VerboseMode;
142 BOOLEAN AllMode;
143 BOOLEAN RawMode;
144 BOOLEAN TraceMode;
145 BOOLEAN ProfileMode;
146 BOOLEAN ExcludeMode;
147
148 StringPtr = NULL;
149 SummaryMode = FALSE;
150 VerboseMode = FALSE;
151 AllMode = FALSE;
152 RawMode = FALSE;
153 TraceMode = FALSE;
154 ProfileMode = FALSE;
155 ExcludeMode = FALSE;
156
157 // Get DP's entry time as soon as possible.
158 // This is used as the Shell-Phase end time.
159 //
160 Ticker = GetPerformanceCounter ();
161
162 //
163 // initialize the shell lib (we must be in non-auto-init...)
164 //
165 Status = ShellInitialize();
166 ASSERT_EFI_ERROR(Status);
167
168 Status = CommandInit();
169 ASSERT_EFI_ERROR(Status);
170
171 //
172 // Process Command Line arguments
173 //
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;
178 }
179
180 //
181 // Boolean options
182 //
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");
193
194 // Options with Values
195 CmdLineArg = ShellCommandLineGetValue (ParamPackage, L"-n");
196 if (CmdLineArg == NULL) {
197 Number2Display = DEFAULT_DISPLAYCOUNT;
198 } else {
199 Number2Display = StrDecimalToUintn(CmdLineArg);
200 if (Number2Display == 0) {
201 Number2Display = MAXIMUM_DISPLAYCOUNT;
202 }
203 }
204
205 CmdLineArg = ShellCommandLineGetValue (ParamPackage, L"-t");
206 if (CmdLineArg == NULL) {
207 mInterestThreshold = DEFAULT_THRESHOLD; // 1ms := 1,000 us
208 } else {
209 mInterestThreshold = StrDecimalToUint64(CmdLineArg);
210 }
211
212 // Handle Flag combinations and default behaviors
213 // If both TraceMode and ProfileMode are FALSE, set them both to TRUE
214 if ((! TraceMode) && (! ProfileMode)) {
215 TraceMode = TRUE;
216#if PROFILING_IMPLEMENTED
217 ProfileMode = TRUE;
218#endif // PROFILING_IMPLEMENTED
219 }
220
221 //
222 // Timer specific processing
223 //
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
228 //
229 Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount);
230
231 // Convert the Frequency from Hz to KHz
232 TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000);
233
234 // Determine in which direction the performance counter counts.
235 TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount);
236
237 //
238 // Print header
239 //
240 // print DP's build version
241 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_BUILD_REVISION), gDpHiiHandle, DP_MAJOR_VERSION, DP_MINOR_VERSION);
242
243 // print performance timer characteristics
244 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_KHZ), gDpHiiHandle, TimerInfo.Frequency);
245
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,
252 StringPtr,
253 TimerInfo.StartCount,
254 TimerInfo.EndCount
255 );
256 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), gDpHiiHandle, mInterestThreshold);
257 }
258
259/****************************************************************************
260**** Print Sections based on command line options
261****
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)
272****
273**** The All, Raw, and Cooked modes are modified by the Trace and Profile
274**** options.
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****************************************************************************/
280 GatherStatistics();
281 if (AllMode) {
282 if (TraceMode) {
283 DumpAllTrace( Number2Display, ExcludeMode);
284 }
285 if (ProfileMode) {
286 DumpAllProfile( Number2Display, ExcludeMode);
287 }
288 } else if (RawMode) {
289 if (TraceMode) {
290 DumpRawTrace( Number2Display, ExcludeMode);
291 }
292 if (ProfileMode) {
293 DumpRawProfile( Number2Display, ExcludeMode);
294 }
295 } else {
296 //------------- Begin Cooked Mode Processing
297 if (TraceMode) {
298 ProcessPhases ( Ticker );
299 if ( ! SummaryMode) {
300 Status = ProcessHandles ( ExcludeMode);
301 if ( ! EFI_ERROR( Status)) {
302 ProcessPeims ();
303 ProcessGlobal ();
304 ProcessCumulative ();
305 }
306 }
307 }
308 if (ProfileMode) {
309 DumpAllProfile( Number2Display, ExcludeMode);
310 }
311 } //------------- End of Cooked Mode Processing
312 if ( VerboseMode || SummaryMode) {
313 DumpStatistics();
314 }
315
316 SHELL_FREE_NON_NULL (StringPtr);
317
318 return SHELL_SUCCESS;
319}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette