PerformancePkg/Dp_App: Add check to avoid NULL pointer deference
[mirror_edk2.git] / PerformancePkg / Dp_App / Dp.c
CommitLineData
c06ad33e 1/** @file\r
86da563d
ED
2 Shell application for Displaying Performance Metrics.\r
3\r
4 The Dp application reads performance data and presents it in several\r
5 different formats depending upon the needs of the user. Both\r
6 Trace and Measured Profiling information is processed and presented.\r
7\r
8 Dp uses the "PerformanceLib" to read the measurement records.\r
9 The "TimerLib" provides information about the timer, such as frequency,\r
10 beginning, and ending counter values.\r
11 Measurement records contain identifying information (Handle, Token, Module)\r
12 and start and end time values.\r
13 Dp uses this information to group records in different ways. It also uses\r
14 timer information to calculate elapsed time for each measurement.\r
15 \r
13935109 16 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
3e9de670 17 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
86da563d
ED
18 This program and the accompanying materials\r
19 are licensed and made available under the terms and conditions of the BSD License\r
20 which accompanies this distribution. The full text of the license may be found at\r
21 http://opensource.org/licenses/bsd-license.php\r
22 \r
23 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
24 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
c06ad33e 25**/\r
26\r
27#include <Library/UefiApplicationEntryPoint.h>\r
b7b2b3c8 28#include <Library/UefiBootServicesTableLib.h>\r
c06ad33e 29#include <Library/ShellLib.h>\r
30#include <Library/BaseLib.h>\r
31#include <Library/MemoryAllocationLib.h>\r
32#include <Library/DebugLib.h>\r
c06ad33e 33#include <Library/UefiLib.h>\r
b7b2b3c8 34#include <Library/UefiHiiServicesLib.h>\r
c06ad33e 35#include <Library/HiiLib.h>\r
36#include <Library/PcdLib.h>\r
37\r
38#include <Guid/Performance.h>\r
39\r
40#include <PerformanceTokens.h>\r
41#include "Dp.h"\r
42#include "Literals.h"\r
43#include "DpInternal.h"\r
44\r
b7b2b3c8
QS
45//\r
46// String token ID of help message text.\r
47// Shell supports to find help message in the resource section of an application image if\r
48// .MAN file is not found. This global variable is added to make build tool recognizes\r
49// that the help string is consumed by user and then build tool will add the string into\r
50// the resource section. Thus the application can use '-?' option to show help message in\r
51// Shell.\r
52//\r
53GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mDpStrEngHelpTokenId = STRING_TOKEN (STR_DP_HELP_INFORMATION);\r
54\r
c06ad33e 55//\r
56/// Module-Global Variables\r
9dd74618 57///@{\r
c06ad33e 58EFI_HII_HANDLE gHiiHandle;\r
88359546 59SHELL_PARAM_ITEM *DpParamList = NULL;\r
c06ad33e 60CHAR16 *mPrintTokenBuffer = NULL;\r
a2daf8db
SZ
61CHAR16 mGaugeString[DP_GAUGE_STRING_LENGTH + 1];\r
62CHAR16 mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE];\r
c06ad33e 63UINT64 mInterestThreshold;\r
0b84f444 64BOOLEAN mShowId = FALSE;\r
c06ad33e 65\r
66PERF_SUMMARY_DATA SummaryData = { 0 }; ///< Create the SummaryData structure and init. to ZERO.\r
67\r
68/// Timer Specific Information.\r
69TIMER_INFO TimerInfo;\r
70\r
71/// Items for which to gather cumulative statistics.\r
72PERF_CUM_DATA CumData[] = {\r
73 PERF_INIT_CUM_DATA (LOAD_IMAGE_TOK),\r
74 PERF_INIT_CUM_DATA (START_IMAGE_TOK),\r
75 PERF_INIT_CUM_DATA (DRIVERBINDING_START_TOK),\r
76 PERF_INIT_CUM_DATA (DRIVERBINDING_SUPPORT_TOK)\r
77};\r
78\r
79/// Number of items for which we are gathering cumulative statistics.\r
80UINT32 const NumCum = sizeof(CumData) / sizeof(PERF_CUM_DATA);\r
81\r
88359546
ED
82PARAM_ITEM_LIST ParamList[] = {\r
83 {STRING_TOKEN (STR_DP_OPTION_QH), TypeFlag}, // -? Help\r
84 {STRING_TOKEN (STR_DP_OPTION_LH), TypeFlag}, // -h Help\r
85 {STRING_TOKEN (STR_DP_OPTION_UH), TypeFlag}, // -H Help\r
86 {STRING_TOKEN (STR_DP_OPTION_LV), TypeFlag}, // -v Verbose Mode\r
87 {STRING_TOKEN (STR_DP_OPTION_UA), TypeFlag}, // -A All, Cooked\r
88 {STRING_TOKEN (STR_DP_OPTION_UR), TypeFlag}, // -R RAW All\r
89 {STRING_TOKEN (STR_DP_OPTION_LS), TypeFlag}, // -s Summary\r
c06ad33e 90#if PROFILING_IMPLEMENTED\r
88359546
ED
91 {STRING_TOKEN (STR_DP_OPTION_UP), TypeFlag}, // -P Dump Profile Data\r
92 {STRING_TOKEN (STR_DP_OPTION_UT), TypeFlag}, // -T Dump Trace Data\r
c06ad33e 93#endif\r
88359546 94 {STRING_TOKEN (STR_DP_OPTION_LX), TypeFlag}, // -x eXclude Cumulative Items\r
0b84f444 95 {STRING_TOKEN (STR_DP_OPTION_LI), TypeFlag}, // -i Display Identifier\r
d28f77df 96 {STRING_TOKEN (STR_DP_OPTION_LC), TypeValue}, // -c Display cumulative data.\r
88359546
ED
97 {STRING_TOKEN (STR_DP_OPTION_LN), TypeValue}, // -n # Number of records to display for A and R\r
98 {STRING_TOKEN (STR_DP_OPTION_LT), TypeValue} // -t # Threshold of interest\r
c06ad33e 99 };\r
100\r
9dd74618 101///@}\r
c06ad33e 102\r
88359546
ED
103/**\r
104 Transfer the param list value and get the command line parse.\r
105\r
106**/\r
107VOID\r
108InitialShellParamList( void )\r
109{\r
110 UINT32 ListIndex;\r
111 UINT32 ListLength; \r
112\r
113 //\r
114 // Allocate one more for the end tag.\r
115 //\r
fcfba04a 116 ListLength = ARRAY_SIZE (ParamList) + 1; \r
88359546
ED
117 DpParamList = AllocatePool (sizeof (SHELL_PARAM_ITEM) * ListLength);\r
118 ASSERT (DpParamList != NULL);\r
119 \r
120 for (ListIndex = 0; ListIndex < ListLength - 1; ListIndex ++)\r
121 { \r
122 DpParamList[ListIndex].Name = HiiGetString (gHiiHandle, ParamList[ListIndex].Token, NULL); \r
123 DpParamList[ListIndex].Type = ParamList[ListIndex].Type;\r
124 }\r
125 DpParamList[ListIndex].Name = NULL;\r
126 DpParamList[ListIndex].Type = TypeMax;\r
127}\r
128\r
9dd74618
ED
129/**\r
130 Display Usage and Help information.\r
131**/\r
c06ad33e 132VOID\r
133ShowHelp( void )\r
134{\r
135 PrintToken (STRING_TOKEN (STR_DP_HELP_HEAD));\r
136#if PROFILING_IMPLEMENTED\r
137 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS));\r
138#else\r
139 PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS_2));\r
140#endif // PROFILING_IMPLEMENTED\r
141 PrintToken (STRING_TOKEN (STR_DP_HELP_PAGINATE));\r
142 PrintToken (STRING_TOKEN (STR_DP_HELP_VERBOSE));\r
143 PrintToken (STRING_TOKEN (STR_DP_HELP_EXCLUDE));\r
144 PrintToken (STRING_TOKEN (STR_DP_HELP_STAT));\r
145 PrintToken (STRING_TOKEN (STR_DP_HELP_ALL));\r
146 PrintToken (STRING_TOKEN (STR_DP_HELP_RAW));\r
147#if PROFILING_IMPLEMENTED\r
148 PrintToken (STRING_TOKEN (STR_DP_HELP_TRACE));\r
149 PrintToken (STRING_TOKEN (STR_DP_HELP_PROFILE));\r
150#endif // PROFILING_IMPLEMENTED\r
151 PrintToken (STRING_TOKEN (STR_DP_HELP_THRESHOLD));\r
152 PrintToken (STRING_TOKEN (STR_DP_HELP_COUNT));\r
0b84f444 153 PrintToken (STRING_TOKEN (STR_DP_HELP_ID));\r
d28f77df 154 PrintToken (STRING_TOKEN (STR_DP_HELP_CUM_DATA));\r
c06ad33e 155 PrintToken (STRING_TOKEN (STR_DP_HELP_HELP));\r
156 Print(L"\n");\r
157}\r
158\r
9dd74618
ED
159/**\r
160 Display the trailing Verbose information.\r
161**/\r
c06ad33e 162VOID\r
163DumpStatistics( void )\r
164{\r
165 EFI_STRING StringPtr;\r
88359546
ED
166 EFI_STRING StringPtrUnknown;\r
167 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_STATISTICS), NULL);\r
168 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 169 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546 170 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
c06ad33e 171\r
172 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMTRACE), SummaryData.NumTrace);\r
173 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE), SummaryData.NumIncomplete);\r
174 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPHASES), SummaryData.NumSummary);\r
175 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMHANDLES), SummaryData.NumHandles, SummaryData.NumTrace - SummaryData.NumHandles);\r
176 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPEIMS), SummaryData.NumPEIMs);\r
177 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMGLOBALS), SummaryData.NumGlobal);\r
178#if PROFILING_IMPLEMENTED\r
179 PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPROFILE), SummaryData.NumProfile);\r
180#endif // PROFILING_IMPLEMENTED\r
88359546
ED
181 FreePool (StringPtr);\r
182 FreePool (StringPtrUnknown);\r
c06ad33e 183}\r
184\r
d28f77df 185/**\r
9dd74618
ED
186 Dump performance data.\r
187 \r
188 @param[in] ImageHandle The image handle.\r
189 @param[in] SystemTable The system table.\r
3e9de670 190\r
9dd74618
ED
191 @retval EFI_SUCCESS Command completed successfully.\r
192 @retval EFI_INVALID_PARAMETER Command usage error.\r
3e9de670 193 @retval EFI_ABORTED The user aborts the operation.\r
9dd74618 194 @retval value Unknown error.\r
c06ad33e 195**/\r
196EFI_STATUS\r
197EFIAPI\r
198InitializeDp (\r
199 IN EFI_HANDLE ImageHandle,\r
200 IN EFI_SYSTEM_TABLE *SystemTable\r
201 )\r
202{\r
13935109
SZ
203 PERFORMANCE_PROPERTY *PerformanceProperty;\r
204 UINT32 ListIndex;\r
205\r
206 LIST_ENTRY *ParamPackage;\r
207 CONST CHAR16 *CmdLineArg;\r
208 EFI_STRING StringPtr;\r
209 UINTN Number2Display;\r
c06ad33e 210\r
b7b2b3c8
QS
211 EFI_STATUS Status;\r
212 BOOLEAN SummaryMode;\r
213 BOOLEAN VerboseMode;\r
214 BOOLEAN AllMode;\r
215 BOOLEAN RawMode;\r
216 BOOLEAN TraceMode;\r
217 BOOLEAN ProfileMode;\r
218 BOOLEAN ExcludeMode;\r
219 BOOLEAN CumulativeMode;\r
220 CONST CHAR16 *CustomCumulativeToken;\r
221 PERF_CUM_DATA *CustomCumulativeData;\r
23cfa2b9 222 UINTN NameSize;\r
b7b2b3c8 223 EFI_HII_PACKAGE_LIST_HEADER *PackageList;\r
9dd74618 224\r
88359546
ED
225 EFI_STRING StringDpOptionQh;\r
226 EFI_STRING StringDpOptionLh;\r
227 EFI_STRING StringDpOptionUh;\r
228 EFI_STRING StringDpOptionLv;\r
229 EFI_STRING StringDpOptionUs;\r
230 EFI_STRING StringDpOptionLs;\r
231 EFI_STRING StringDpOptionUa;\r
232 EFI_STRING StringDpOptionUr;\r
233 EFI_STRING StringDpOptionUt;\r
234 EFI_STRING StringDpOptionUp;\r
235 EFI_STRING StringDpOptionLx;\r
236 EFI_STRING StringDpOptionLn;\r
237 EFI_STRING StringDpOptionLt;\r
0b84f444 238 EFI_STRING StringDpOptionLi;\r
d28f77df 239 EFI_STRING StringDpOptionLc;\r
88359546 240 \r
9dd74618
ED
241 SummaryMode = FALSE;\r
242 VerboseMode = FALSE;\r
243 AllMode = FALSE;\r
244 RawMode = FALSE;\r
245 TraceMode = FALSE;\r
246 ProfileMode = FALSE;\r
247 ExcludeMode = FALSE;\r
d28f77df
CS
248 CumulativeMode = FALSE;\r
249 CustomCumulativeData = NULL;\r
88359546
ED
250\r
251 StringDpOptionQh = NULL;\r
252 StringDpOptionLh = NULL;\r
253 StringDpOptionUh = NULL;\r
254 StringDpOptionLv = NULL;\r
255 StringDpOptionUs = NULL;\r
256 StringDpOptionLs = NULL;\r
257 StringDpOptionUa = NULL;\r
258 StringDpOptionUr = NULL;\r
259 StringDpOptionUt = NULL;\r
260 StringDpOptionUp = NULL;\r
261 StringDpOptionLx = NULL;\r
262 StringDpOptionLn = NULL;\r
263 StringDpOptionLt = NULL;\r
0b84f444 264 StringDpOptionLi = NULL;\r
d28f77df 265 StringDpOptionLc = NULL;\r
88359546
ED
266 StringPtr = NULL;\r
267\r
c06ad33e 268 //\r
b7b2b3c8
QS
269 // Retrieve HII package list from ImageHandle\r
270 //\r
271 Status = gBS->OpenProtocol (\r
272 ImageHandle,\r
273 &gEfiHiiPackageListProtocolGuid,\r
274 (VOID **) &PackageList,\r
275 ImageHandle,\r
276 NULL,\r
277 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
278 );\r
279 if (EFI_ERROR (Status)) {\r
280 return Status;\r
281 }\r
282\r
283 //\r
284 // Publish HII package list to HII Database.\r
285 //\r
286 Status = gHiiDatabase->NewPackageList (\r
287 gHiiDatabase,\r
288 PackageList,\r
289 NULL,\r
290 &gHiiHandle\r
291 );\r
292 if (EFI_ERROR (Status)) {\r
293 return Status;\r
294 }\r
c06ad33e 295 ASSERT (gHiiHandle != NULL);\r
b7b2b3c8 296 \r
c06ad33e 297\r
88359546
ED
298 // Initial the command list\r
299 //\r
300 InitialShellParamList ();\r
301 \r
c06ad33e 302/****************************************************************************\r
303**** Process Command Line arguments ****\r
304****************************************************************************/\r
305 Status = ShellCommandLineParse (DpParamList, &ParamPackage, NULL, TRUE);\r
306\r
307 if (EFI_ERROR(Status)) {\r
308 PrintToken (STRING_TOKEN (STR_DP_INVALID_ARG));\r
309 ShowHelp();\r
310 }\r
311 else {\r
88359546
ED
312 StringDpOptionQh = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_QH), NULL);\r
313 StringDpOptionLh = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LH), NULL);\r
314 StringDpOptionUh = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UH), NULL);\r
315 \r
316 if (ShellCommandLineGetFlag (ParamPackage, StringDpOptionQh) ||\r
317 ShellCommandLineGetFlag (ParamPackage, StringDpOptionLh) ||\r
318 ShellCommandLineGetFlag (ParamPackage, StringDpOptionUh))\r
c06ad33e 319 {\r
320 ShowHelp();\r
321 }\r
322 else {\r
88359546
ED
323 StringDpOptionLv = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LV), NULL);\r
324 StringDpOptionUs = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_US), NULL);\r
325 StringDpOptionLs = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LS), NULL);\r
326 StringDpOptionUa = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UA), NULL);\r
327 StringDpOptionUr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UR), NULL);\r
328 StringDpOptionUt = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UT), NULL);\r
329 StringDpOptionUp = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UP), NULL);\r
330 StringDpOptionLx = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LX), NULL);\r
331 StringDpOptionLn = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LN), NULL);\r
332 StringDpOptionLt = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LT), NULL);\r
0b84f444 333 StringDpOptionLi = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LI), NULL);\r
d28f77df 334 StringDpOptionLc = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LC), NULL);\r
88359546 335 \r
c06ad33e 336 // Boolean Options\r
88359546
ED
337 // \r
338 VerboseMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLv);\r
aec905b7
ED
339 SummaryMode = (BOOLEAN) (ShellCommandLineGetFlag (ParamPackage, StringDpOptionUs) ||\r
340 ShellCommandLineGetFlag (ParamPackage, StringDpOptionLs));\r
88359546
ED
341 AllMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUa);\r
342 RawMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUr);\r
c06ad33e 343#if PROFILING_IMPLEMENTED\r
88359546
ED
344 TraceMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUt);\r
345 ProfileMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUp);\r
c06ad33e 346#endif // PROFILING_IMPLEMENTED\r
88359546 347 ExcludeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLx);\r
0b84f444 348 mShowId = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLi);\r
d28f77df 349 CumulativeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLc);\r
c06ad33e 350\r
351 // Options with Values\r
88359546 352 CmdLineArg = ShellCommandLineGetValue (ParamPackage, StringDpOptionLn);\r
c06ad33e 353 if (CmdLineArg == NULL) {\r
354 Number2Display = DEFAULT_DISPLAYCOUNT;\r
355 }\r
356 else {\r
357 Number2Display = StrDecimalToUintn(CmdLineArg);\r
358 if (Number2Display == 0) {\r
359 Number2Display = MAXIMUM_DISPLAYCOUNT;\r
360 }\r
361 }\r
88359546 362 CmdLineArg = ShellCommandLineGetValue (ParamPackage, StringDpOptionLt);\r
c06ad33e 363 if (CmdLineArg == NULL) {\r
364 mInterestThreshold = DEFAULT_THRESHOLD; // 1ms := 1,000 us\r
365 }\r
366 else {\r
367 mInterestThreshold = StrDecimalToUint64(CmdLineArg);\r
368 }\r
369 // Handle Flag combinations and default behaviors\r
370 // If both TraceMode and ProfileMode are FALSE, set them both to TRUE\r
371 if ((! TraceMode) && (! ProfileMode)) {\r
372 TraceMode = TRUE;\r
373#if PROFILING_IMPLEMENTED\r
374 ProfileMode = TRUE;\r
375#endif // PROFILING_IMPLEMENTED\r
376 }\r
377\r
d28f77df
CS
378 //\r
379 // Init the custom cumulative data.\r
380 //\r
381 CustomCumulativeToken = ShellCommandLineGetValue (ParamPackage, StringDpOptionLc);\r
382 if (CustomCumulativeToken != NULL) {\r
383 CustomCumulativeData = AllocateZeroPool (sizeof (PERF_CUM_DATA));\r
c4ace582 384 ASSERT (CustomCumulativeData != NULL);\r
d28f77df
CS
385 CustomCumulativeData->MinDur = 0;\r
386 CustomCumulativeData->MaxDur = 0;\r
387 CustomCumulativeData->Count = 0;\r
388 CustomCumulativeData->Duration = 0;\r
23cfa2b9
SZ
389 NameSize = StrLen (CustomCumulativeToken) + 1;\r
390 CustomCumulativeData->Name = AllocateZeroPool (NameSize);\r
391 UnicodeStrToAsciiStrS (CustomCumulativeToken, CustomCumulativeData->Name, NameSize);\r
d28f77df
CS
392 }\r
393\r
c06ad33e 394/****************************************************************************\r
395**** Timer specific processing ****\r
396****************************************************************************/\r
397 // Get the Performance counter characteristics:\r
398 // Freq = Frequency in Hz\r
399 // StartCount = Value loaded into the counter when it starts counting\r
400 // EndCount = Value counter counts to before it needs to be reset\r
401 //\r
e0850230 402 Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty);\r
9555c097 403 if (EFI_ERROR (Status) || (PerformanceProperty == NULL)) {\r
13935109
SZ
404 PrintToken (STRING_TOKEN (STR_PERF_PROPERTY_NOT_FOUND));\r
405 goto Done;\r
406 }\r
c06ad33e 407\r
408 // Convert the Frequency from Hz to KHz\r
13935109
SZ
409 TimerInfo.Frequency = (UINT32)DivU64x32 (PerformanceProperty->Frequency, 1000);\r
410 TimerInfo.StartCount = PerformanceProperty->TimerStartValue;\r
411 TimerInfo.EndCount = PerformanceProperty->TimerEndValue;\r
c06ad33e 412\r
413 // Determine in which direction the performance counter counts.\r
414 TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount);\r
415\r
416/****************************************************************************\r
417**** Print heading ****\r
418****************************************************************************/\r
419 // print DP's build version\r
420 PrintToken (STRING_TOKEN (STR_DP_BUILD_REVISION), DP_MAJOR_VERSION, DP_MINOR_VERSION);\r
421\r
422 // print performance timer characteristics\r
423 PrintToken (STRING_TOKEN (STR_DP_KHZ), TimerInfo.Frequency); // Print Timer frequency in KHz\r
424\r
425 if ((VerboseMode) &&\r
426 (! RawMode)\r
427 ) {\r
428 StringPtr = HiiGetString (gHiiHandle,\r
aec905b7 429 (EFI_STRING_ID) (TimerInfo.CountUp ? STRING_TOKEN (STR_DP_UP) : STRING_TOKEN (STR_DP_DOWN)),\r
c06ad33e 430 NULL);\r
431 ASSERT (StringPtr != NULL);\r
432 PrintToken (STRING_TOKEN (STR_DP_TIMER_PROPERTIES), // Print Timer count range and direction\r
433 StringPtr,\r
434 TimerInfo.StartCount,\r
435 TimerInfo.EndCount\r
436 );\r
437 PrintToken (STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), mInterestThreshold);\r
438 }\r
439\r
440/* **************************************************************************\r
441**** Print Sections based on command line options\r
442****\r
443**** Option modes have the following priority:\r
444**** v Verbose -- Valid in combination with any other options\r
445**** t Threshold -- Modifies All, Raw, and Cooked output\r
446**** Default is 0 for All and Raw mode\r
447**** Default is DEFAULT_THRESHOLD for "Cooked" mode\r
448**** n Number2Display Used by All and Raw mode. Otherwise ignored.\r
449**** A All -- R and S options are ignored\r
450**** R Raw -- S option is ignored\r
451**** s Summary -- Modifies "Cooked" output only\r
452**** Cooked (Default)\r
453****\r
454**** The All, Raw, and Cooked modes are modified by the Trace and Profile\r
455**** options.\r
456**** !T && !P := (0) Default, Both are displayed\r
457**** T && !P := (1) Only Trace records are displayed\r
458**** !T && P := (2) Only Profile records are displayed\r
459**** T && P := (3) Same as Default, both are displayed\r
460****************************************************************************/\r
d28f77df
CS
461 GatherStatistics (CustomCumulativeData);\r
462 if (CumulativeMode) { \r
463 ProcessCumulative (CustomCumulativeData);\r
464 } else if (AllMode) {\r
c06ad33e 465 if (TraceMode) {\r
3e9de670
CS
466 Status = DumpAllTrace( Number2Display, ExcludeMode);\r
467 if (Status == EFI_ABORTED) {\r
468 goto Done;\r
469 }\r
c06ad33e 470 }\r
471 if (ProfileMode) {\r
472 DumpAllProfile( Number2Display, ExcludeMode);\r
473 }\r
474 }\r
475 else if (RawMode) {\r
476 if (TraceMode) {\r
3e9de670
CS
477 Status = DumpRawTrace( Number2Display, ExcludeMode);\r
478 if (Status == EFI_ABORTED) {\r
479 goto Done;\r
480 }\r
c06ad33e 481 }\r
482 if (ProfileMode) {\r
483 DumpRawProfile( Number2Display, ExcludeMode);\r
484 }\r
485 }\r
486 else {\r
487 //------------- Begin Cooked Mode Processing\r
488 if (TraceMode) {\r
13935109 489 ProcessPhases ();\r
c06ad33e 490 if ( ! SummaryMode) {\r
491 Status = ProcessHandles ( ExcludeMode);\r
3e9de670
CS
492 if (Status == EFI_ABORTED) {\r
493 goto Done;\r
c06ad33e 494 }\r
3e9de670
CS
495\r
496 Status = ProcessPeims ();\r
497 if (Status == EFI_ABORTED) {\r
498 goto Done;\r
499 }\r
500\r
501 Status = ProcessGlobal ();\r
502 if (Status == EFI_ABORTED) {\r
503 goto Done;\r
504 }\r
505\r
506 ProcessCumulative (NULL);\r
c06ad33e 507 }\r
508 }\r
509 if (ProfileMode) {\r
510 DumpAllProfile( Number2Display, ExcludeMode);\r
511 }\r
512 } //------------- End of Cooked Mode Processing\r
513 if ( VerboseMode || SummaryMode) {\r
514 DumpStatistics();\r
515 }\r
516 }\r
517 }\r
88359546 518\r
3e9de670
CS
519Done:\r
520\r
d28f77df 521 //\r
88359546
ED
522 // Free the memory allocate from HiiGetString\r
523 //\r
524 ListIndex = 0;\r
525 while (DpParamList[ListIndex].Name != NULL) {\r
526 FreePool (DpParamList[ListIndex].Name);\r
527 ListIndex ++;\r
528 } \r
529 FreePool (DpParamList);\r
cdd95292
SZ
530\r
531 SafeFreePool (StringDpOptionQh);\r
532 SafeFreePool (StringDpOptionLh);\r
533 SafeFreePool (StringDpOptionUh);\r
534 SafeFreePool (StringDpOptionLv);\r
535 SafeFreePool (StringDpOptionUs);\r
536 SafeFreePool (StringDpOptionLs);\r
537 SafeFreePool (StringDpOptionUa);\r
538 SafeFreePool (StringDpOptionUr);\r
539 SafeFreePool (StringDpOptionUt);\r
540 SafeFreePool (StringDpOptionUp);\r
541 SafeFreePool (StringDpOptionLx);\r
542 SafeFreePool (StringDpOptionLn);\r
543 SafeFreePool (StringDpOptionLt);\r
0b84f444 544 SafeFreePool (StringDpOptionLi);\r
d28f77df 545 SafeFreePool (StringDpOptionLc);\r
cdd95292
SZ
546 SafeFreePool (StringPtr);\r
547 SafeFreePool (mPrintTokenBuffer);\r
548\r
38ac6bf1
CS
549 if (ParamPackage != NULL) {\r
550 ShellCommandLineFreeVarList (ParamPackage);\r
551 }\r
d28f77df
CS
552 if (CustomCumulativeData != NULL) {\r
553 SafeFreePool (CustomCumulativeData->Name);\r
554 }\r
555 SafeFreePool (CustomCumulativeData);\r
556\r
c06ad33e 557 HiiRemovePackages (gHiiHandle);\r
558 return Status;\r
559}\r