]> git.proxmox.com Git - mirror_edk2.git/blame - PerformancePkg/Dp_App/DpTrace.c
BaseTools: Update Python Makefile to include the new added python files
[mirror_edk2.git] / PerformancePkg / Dp_App / DpTrace.c
CommitLineData
c06ad33e 1/** @file\r
86da563d
ED
2 Trace reporting for the Dp utility.\r
3\r
13935109 4 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
aae1a875 5 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
86da563d
ED
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
c06ad33e 13**/\r
14\r
15#include <Library/BaseLib.h>\r
16#include <Library/BaseMemoryLib.h>\r
17#include <Library/MemoryAllocationLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/UefiBootServicesTableLib.h>\r
c06ad33e 20#include <Library/PeCoffGetEntryPointLib.h>\r
21#include <Library/PerformanceLib.h>\r
22#include <Library/PrintLib.h>\r
23#include <Library/HiiLib.h>\r
24#include <Library/PcdLib.h>\r
25\r
26#include <Guid/Performance.h>\r
27\r
28#include "Dp.h"\r
29#include "Literals.h"\r
30#include "DpInternal.h"\r
31\r
9dd74618
ED
32/** \r
33 Collect verbose statistics about the logged performance measurements.\r
34 \r
35 General Summary information for all Trace measurements is gathered and\r
36 stored within the SummaryData structure. This information is both\r
37 used internally by subsequent reporting functions, and displayed\r
38 at the end of verbose reports.\r
39 \r
40 @pre The SummaryData and CumData structures must be initialized\r
41 prior to calling this function.\r
42 \r
43 @post The SummaryData and CumData structures contain statistics for the\r
44 current performance logs.\r
d28f77df
CS
45\r
46 @param[in, out] CustomCumulativeData A pointer to the cumtom cumulative data.\r
47\r
c06ad33e 48**/\r
49VOID\r
50GatherStatistics(\r
d28f77df
CS
51 IN OUT PERF_CUM_DATA *CustomCumulativeData OPTIONAL\r
52 )\r
c06ad33e 53{\r
54 MEASUREMENT_RECORD Measurement;\r
55 UINT64 Duration;\r
56 UINTN LogEntryKey;\r
fc48db0d 57 INTN TIndex;\r
c06ad33e 58\r
59 LogEntryKey = 0;\r
0b84f444 60 while ((LogEntryKey = GetPerformanceMeasurementEx (\r
c06ad33e 61 LogEntryKey,\r
62 &Measurement.Handle,\r
63 &Measurement.Token,\r
64 &Measurement.Module,\r
65 &Measurement.StartTimeStamp,\r
0b84f444
SZ
66 &Measurement.EndTimeStamp,\r
67 &Measurement.Identifier)) != 0)\r
c06ad33e 68 {\r
69 ++SummaryData.NumTrace; // Count the number of TRACE Measurement records\r
70 if (Measurement.EndTimeStamp == 0) {\r
71 ++SummaryData.NumIncomplete; // Count the incomplete records\r
72 continue;\r
73 }\r
74\r
75 if (Measurement.Handle != NULL) {\r
76 ++SummaryData.NumHandles; // Count the number of measurements with non-NULL handles\r
77 }\r
78\r
79 if (IsPhase( &Measurement)) {\r
80 ++SummaryData.NumSummary; // Count the number of major phases\r
81 }\r
82 else { // !IsPhase(...\r
83 if(Measurement.Handle == NULL) {\r
84 ++SummaryData.NumGlobal;\r
85 }\r
86 }\r
87\r
88 if (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) == 0) {\r
89 ++SummaryData.NumPEIMs; // Count PEIM measurements\r
90 }\r
91\r
92 Duration = GetDuration (&Measurement);\r
93 TIndex = GetCumulativeItem (&Measurement);\r
94 if (TIndex >= 0) {\r
95 CumData[TIndex].Duration += Duration;\r
96 CumData[TIndex].Count++;\r
97 if ( Duration < CumData[TIndex].MinDur ) {\r
98 CumData[TIndex].MinDur = Duration;\r
99 }\r
100 if ( Duration > CumData[TIndex].MaxDur ) {\r
101 CumData[TIndex].MaxDur = Duration;\r
102 }\r
103 }\r
d28f77df
CS
104\r
105 //\r
106 // Collect the data for custom cumulative data.\r
107 //\r
108 if ((CustomCumulativeData != NULL) && (AsciiStrCmp (Measurement.Token, CustomCumulativeData->Name) == 0)) {\r
109 CustomCumulativeData->Duration += Duration;\r
110 CustomCumulativeData->Count++;\r
111 if (Duration < CustomCumulativeData->MinDur) {\r
112 CustomCumulativeData->MinDur = Duration;\r
113 }\r
114 if (Duration > CustomCumulativeData->MaxDur) {\r
115 CustomCumulativeData->MaxDur = Duration;\r
116 }\r
117 }\r
c06ad33e 118 }\r
119}\r
120\r
9dd74618
ED
121/** \r
122 Gather and print ALL Trace Records.\r
123 \r
124 Displays all "interesting" Trace measurements in order.<BR>\r
125 The number of records displayed is controlled by:\r
126 - records with a duration less than mInterestThreshold microseconds are not displayed.\r
127 - No more than Limit records are displayed. A Limit of zero will not limit the output.\r
128 - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r
129 displayed.\r
130 \r
131 @pre The mInterestThreshold global variable is set to the shortest duration to be printed.\r
132 The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.\r
133 They must not be in use by a calling function.\r
134 \r
135 @param[in] Limit The number of records to print. Zero is ALL.\r
136 @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.\r
137 \r
3e9de670
CS
138 @retval EFI_SUCCESS The operation was successful.\r
139 @retval EFI_ABORTED The user aborts the operation.\r
140 @return Others from a call to gBS->LocateHandleBuffer().\r
c06ad33e 141**/\r
3e9de670 142EFI_STATUS\r
c06ad33e 143DumpAllTrace(\r
144 IN UINTN Limit,\r
145 IN BOOLEAN ExcludeFlag\r
146 )\r
147{\r
148 MEASUREMENT_RECORD Measurement;\r
149 UINT64 ElapsedTime;\r
150 UINT64 Duration;\r
151 const CHAR16 *IncFlag;\r
152 UINTN LogEntryKey;\r
153 UINTN Count;\r
154 UINTN Index;\r
155 UINTN TIndex;\r
156\r
157 EFI_HANDLE *HandleBuffer;\r
aae1a875 158 UINTN HandleCount;\r
c06ad33e 159 EFI_STATUS Status;\r
88359546 160 EFI_STRING StringPtrUnknown;\r
c06ad33e 161\r
88359546 162 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 163 IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_ALL), NULL);\r
164 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
165 (IncFlag == NULL) ? StringPtrUnknown : IncFlag);\r
166 FreePool (StringPtrUnknown);\r
c06ad33e 167\r
168 // Get Handle information\r
169 //\r
aae1a875 170 Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);\r
c06ad33e 171 if (EFI_ERROR (Status)) {\r
172 PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);\r
173 }\r
174 else {\r
175 // We have successfully populated the HandleBuffer\r
176 // Display ALL Measurement Records\r
177 // Up to Limit lines displayed\r
178 // Display only records with Elapsed times >= mInterestThreshold\r
179 // Display driver names in Module field for records with Handles.\r
180 //\r
0b84f444
SZ
181 if (mShowId) {\r
182 PrintToken (STRING_TOKEN (STR_DP_ALL_HEADR2) );\r
183 PrintToken (STRING_TOKEN (STR_DP_ALL_DASHES2) );\r
184 } else {\r
185 PrintToken (STRING_TOKEN (STR_DP_ALL_HEADR) );\r
186 PrintToken (STRING_TOKEN (STR_DP_DASHES) );\r
187 }\r
c06ad33e 188\r
189 LogEntryKey = 0;\r
190 Count = 0;\r
191 Index = 0;\r
192 while ( WITHIN_LIMIT(Count, Limit) &&\r
0b84f444 193 ((LogEntryKey = GetPerformanceMeasurementEx (\r
c06ad33e 194 LogEntryKey,\r
195 &Measurement.Handle,\r
196 &Measurement.Token,\r
197 &Measurement.Module,\r
198 &Measurement.StartTimeStamp,\r
0b84f444
SZ
199 &Measurement.EndTimeStamp,\r
200 &Measurement.Identifier)) != 0)\r
c06ad33e 201 )\r
202 {\r
203 ++Index; // Count every record. First record is 1.\r
204 ElapsedTime = 0;\r
0b84f444 205 SafeFreePool ((VOID *) IncFlag);\r
c06ad33e 206 if (Measurement.EndTimeStamp != 0) {\r
207 Duration = GetDuration (&Measurement);\r
208 ElapsedTime = DurationInMicroSeconds ( Duration );\r
88359546 209 IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_COMPLETE), NULL);\r
c06ad33e 210 }\r
211 else {\r
88359546 212 IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL); // Mark incomplete records\r
c06ad33e 213 }\r
a2daf8db 214 if (((Measurement.EndTimeStamp != 0) && (ElapsedTime < mInterestThreshold)) ||\r
c06ad33e 215 ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))\r
216 ) { // Ignore "uninteresting" or excluded records\r
217 continue;\r
218 }\r
c06ad33e 219 ++Count; // Count the number of records printed\r
220\r
221 // If Handle is non-zero, see if we can determine a name for the driver\r
fcfba04a
LE
222 AsciiStrToUnicodeStrS (Measurement.Module, mGaugeString, ARRAY_SIZE (mGaugeString)); // Use Module by default\r
223 AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));\r
c06ad33e 224 if (Measurement.Handle != NULL) {\r
225 // See if the Handle is in the HandleBuffer\r
aae1a875 226 for (TIndex = 0; TIndex < HandleCount; TIndex++) {\r
c06ad33e 227 if (Measurement.Handle == HandleBuffer[TIndex]) {\r
228 GetNameFromHandle (HandleBuffer[TIndex]);\r
229 break;\r
230 }\r
231 }\r
232 }\r
a2daf8db
SZ
233\r
234 if (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) == 0) {\r
235 UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", Measurement.Handle);\r
236 }\r
237\r
c06ad33e 238 // Ensure that the argument strings are not too long.\r
a2daf8db
SZ
239 mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
240 mUnicodeToken[13] = 0;\r
c06ad33e 241\r
0b84f444
SZ
242 if (mShowId) {\r
243 PrintToken( STRING_TOKEN (STR_DP_ALL_VARS2),\r
244 Index, // 1 based, Which measurement record is being printed\r
245 IncFlag,\r
246 Measurement.Handle,\r
247 mGaugeString,\r
248 mUnicodeToken,\r
249 ElapsedTime,\r
250 Measurement.Identifier\r
251 );\r
252 } else {\r
253 PrintToken( STRING_TOKEN (STR_DP_ALL_VARS),\r
254 Index, // 1 based, Which measurement record is being printed\r
255 IncFlag,\r
256 Measurement.Handle,\r
257 mGaugeString,\r
258 mUnicodeToken,\r
259 ElapsedTime\r
260 );\r
261 }\r
3e9de670
CS
262 if (ShellGetExecutionBreakFlag ()) {\r
263 Status = EFI_ABORTED;\r
264 break;\r
265 }\r
c06ad33e 266 }\r
267 }\r
aae1a875 268 if (HandleBuffer != NULL) {\r
fc48db0d
ED
269 FreePool (HandleBuffer);\r
270 }\r
0b84f444 271 SafeFreePool ((VOID *) IncFlag);\r
3e9de670 272 return Status;\r
c06ad33e 273}\r
274\r
9dd74618
ED
275/** \r
276 Gather and print Raw Trace Records.\r
277 \r
278 All Trace measurements with a duration greater than or equal to\r
279 mInterestThreshold are printed without interpretation.\r
280 \r
281 The number of records displayed is controlled by:\r
282 - records with a duration less than mInterestThreshold microseconds are not displayed.\r
283 - No more than Limit records are displayed. A Limit of zero will not limit the output.\r
284 - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r
285 displayed.\r
286 \r
287 @pre The mInterestThreshold global variable is set to the shortest duration to be printed.\r
288 \r
289 @param[in] Limit The number of records to print. Zero is ALL.\r
290 @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.\r
3e9de670
CS
291\r
292 @retval EFI_SUCCESS The operation was successful.\r
293 @retval EFI_ABORTED The user aborts the operation.\r
c06ad33e 294**/\r
3e9de670 295EFI_STATUS\r
c06ad33e 296DumpRawTrace(\r
297 IN UINTN Limit,\r
298 IN BOOLEAN ExcludeFlag\r
299 )\r
300{\r
301 MEASUREMENT_RECORD Measurement;\r
302 UINT64 ElapsedTime;\r
303 UINT64 Duration;\r
304 UINTN LogEntryKey;\r
305 UINTN Count;\r
306 UINTN Index;\r
307\r
308 EFI_STRING StringPtr;\r
88359546 309 EFI_STRING StringPtrUnknown;\r
3e9de670
CS
310 EFI_STATUS Status;\r
311\r
312 Status = EFI_SUCCESS;\r
c06ad33e 313\r
88359546 314 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 315 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWTRACE), NULL);\r
316 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
317 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
318 FreePool (StringPtr);\r
319 FreePool (StringPtrUnknown);\r
c06ad33e 320\r
0b84f444
SZ
321 if (mShowId) {\r
322 PrintToken (STRING_TOKEN (STR_DP_RAW_HEADR2) );\r
323 PrintToken (STRING_TOKEN (STR_DP_RAW_DASHES2) );\r
324 } else {\r
325 PrintToken (STRING_TOKEN (STR_DP_RAW_HEADR) );\r
326 PrintToken (STRING_TOKEN (STR_DP_RAW_DASHES) );\r
327 }\r
c06ad33e 328\r
329 LogEntryKey = 0;\r
330 Count = 0;\r
331 Index = 0;\r
332 while ( WITHIN_LIMIT(Count, Limit) &&\r
0b84f444 333 ((LogEntryKey = GetPerformanceMeasurementEx (\r
c06ad33e 334 LogEntryKey,\r
335 &Measurement.Handle,\r
336 &Measurement.Token,\r
337 &Measurement.Module,\r
338 &Measurement.StartTimeStamp,\r
0b84f444
SZ
339 &Measurement.EndTimeStamp,\r
340 &Measurement.Identifier)) != 0)\r
c06ad33e 341 )\r
342 {\r
343 ++Index; // Count every record. First record is 1.\r
344 ElapsedTime = 0;\r
345 if (Measurement.EndTimeStamp != 0) {\r
346 Duration = GetDuration (&Measurement);\r
347 ElapsedTime = DurationInMicroSeconds ( Duration );\r
348 }\r
349 if ((ElapsedTime < mInterestThreshold) ||\r
350 ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))\r
351 ) { // Ignore "uninteresting" or Excluded records\r
352 continue;\r
353 }\r
354 ++Count; // Count the number of records printed\r
0b84f444
SZ
355\r
356 if (mShowId) {\r
357 PrintToken (STRING_TOKEN (STR_DP_RAW_VARS2),\r
358 Index, // 1 based, Which measurement record is being printed\r
359 Measurement.Handle,\r
360 Measurement.StartTimeStamp,\r
361 Measurement.EndTimeStamp,\r
362 Measurement.Token,\r
363 Measurement.Module,\r
364 Measurement.Identifier\r
365 );\r
366 } else {\r
367 PrintToken (STRING_TOKEN (STR_DP_RAW_VARS),\r
368 Index, // 1 based, Which measurement record is being printed\r
369 Measurement.Handle,\r
370 Measurement.StartTimeStamp,\r
371 Measurement.EndTimeStamp,\r
372 Measurement.Token,\r
373 Measurement.Module\r
374 );\r
375 }\r
3e9de670
CS
376 if (ShellGetExecutionBreakFlag ()) {\r
377 Status = EFI_ABORTED;\r
378 break;\r
379 }\r
c06ad33e 380 }\r
3e9de670 381 return Status;\r
c06ad33e 382}\r
383\r
9dd74618
ED
384/** \r
385 Gather and print Major Phase metrics.\r
386 \r
c06ad33e 387**/\r
388VOID\r
389ProcessPhases(\r
13935109 390 VOID\r
c06ad33e 391 )\r
392{\r
393 MEASUREMENT_RECORD Measurement;\r
9dd74618
ED
394 UINT64 BdsTimeoutValue;\r
395 UINT64 SecTime;\r
396 UINT64 PeiTime;\r
397 UINT64 DxeTime;\r
398 UINT64 BdsTime;\r
c06ad33e 399 UINT64 ElapsedTime;\r
400 UINT64 Duration;\r
401 UINT64 Total;\r
402 EFI_STRING StringPtr;\r
403 UINTN LogEntryKey;\r
88359546 404 EFI_STRING StringPtrUnknown;\r
c06ad33e 405\r
9dd74618
ED
406 BdsTimeoutValue = 0;\r
407 SecTime = 0;\r
408 PeiTime = 0;\r
409 DxeTime = 0;\r
410 BdsTime = 0;\r
c06ad33e 411 //\r
412 // Get Execution Phase Statistics\r
413 //\r
88359546 414 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 415 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_PHASES), NULL);\r
416 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
417 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
418 FreePool (StringPtr);\r
419 FreePool (StringPtrUnknown);\r
c06ad33e 420\r
421 LogEntryKey = 0;\r
0b84f444 422 while ((LogEntryKey = GetPerformanceMeasurementEx (\r
c06ad33e 423 LogEntryKey,\r
424 &Measurement.Handle,\r
425 &Measurement.Token,\r
426 &Measurement.Module,\r
427 &Measurement.StartTimeStamp,\r
0b84f444
SZ
428 &Measurement.EndTimeStamp,\r
429 &Measurement.Identifier)) != 0)\r
c06ad33e 430 {\r
c06ad33e 431 if (Measurement.EndTimeStamp == 0) { // Skip "incomplete" records\r
432 continue;\r
433 }\r
434 Duration = GetDuration (&Measurement);\r
435 if ( Measurement.Handle != NULL\r
436 && (AsciiStrnCmp (Measurement.Token, ALit_BdsTO, PERF_TOKEN_LENGTH) == 0)\r
437 )\r
438 {\r
439 BdsTimeoutValue = Duration;\r
440 } else if (AsciiStrnCmp (Measurement.Token, ALit_SEC, PERF_TOKEN_LENGTH) == 0) {\r
441 SecTime = Duration;\r
442 } else if (AsciiStrnCmp (Measurement.Token, ALit_PEI, PERF_TOKEN_LENGTH) == 0) {\r
443 PeiTime = Duration;\r
444 } else if (AsciiStrnCmp (Measurement.Token, ALit_DXE, PERF_TOKEN_LENGTH) == 0) {\r
445 DxeTime = Duration;\r
446 } else if (AsciiStrnCmp (Measurement.Token, ALit_BDS, PERF_TOKEN_LENGTH) == 0) {\r
447 BdsTime = Duration;\r
c06ad33e 448 }\r
449 }\r
450\r
451 Total = 0;\r
452\r
453 // print SEC phase duration time\r
454 //\r
455 if (SecTime > 0) {\r
456 ElapsedTime = DurationInMicroSeconds ( SecTime ); // Calculate elapsed time in microseconds\r
457 Total += DivU64x32 (ElapsedTime, 1000); // Accumulate time in milliseconds\r
458 PrintToken (STRING_TOKEN (STR_DP_SEC_PHASE), ElapsedTime);\r
459 }\r
460\r
461 // print PEI phase duration time\r
462 //\r
463 if (PeiTime > 0) {\r
464 ElapsedTime = DivU64x32 (\r
465 PeiTime,\r
466 (UINT32)TimerInfo.Frequency\r
467 );\r
468 Total += ElapsedTime;\r
469 PrintToken (STRING_TOKEN (STR_DP_PHASE_DURATION), ALit_PEI, ElapsedTime);\r
470 }\r
471\r
472 // print DXE phase duration time\r
473 //\r
474 if (DxeTime > 0) {\r
475 ElapsedTime = DivU64x32 (\r
476 DxeTime,\r
477 (UINT32)TimerInfo.Frequency\r
478 );\r
479 Total += ElapsedTime;\r
480 PrintToken (STRING_TOKEN (STR_DP_PHASE_DURATION), ALit_DXE, ElapsedTime);\r
481 }\r
482\r
483 // print BDS phase duration time\r
484 //\r
485 if (BdsTime > 0) {\r
486 ElapsedTime = DivU64x32 (\r
487 BdsTime,\r
488 (UINT32)TimerInfo.Frequency\r
489 );\r
490 Total += ElapsedTime;\r
491 PrintToken (STRING_TOKEN (STR_DP_PHASE_DURATION), ALit_BDS, ElapsedTime);\r
492 }\r
493\r
494 if (BdsTimeoutValue > 0) {\r
495 ElapsedTime = DivU64x32 (\r
496 BdsTimeoutValue,\r
497 (UINT32)TimerInfo.Frequency\r
498 );\r
499 PrintToken (STRING_TOKEN (STR_DP_PHASE_BDSTO), ALit_BdsTO, ElapsedTime);\r
500 }\r
501\r
c06ad33e 502 PrintToken (STRING_TOKEN (STR_DP_TOTAL_DURATION), Total);\r
503}\r
504\r
9dd74618
ED
505/** \r
506 Gather and print Handle data.\r
507 \r
508 @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.\r
3e9de670
CS
509\r
510 @retval EFI_SUCCESS The operation was successful.\r
511 @retval EFI_ABORTED The user aborts the operation.\r
512 @return Others from a call to gBS->LocateHandleBuffer().\r
c06ad33e 513**/\r
514EFI_STATUS\r
515ProcessHandles(\r
516 IN BOOLEAN ExcludeFlag\r
517 )\r
518{\r
519 MEASUREMENT_RECORD Measurement;\r
520 UINT64 ElapsedTime;\r
521 UINT64 Duration;\r
522 EFI_HANDLE *HandleBuffer;\r
523 EFI_STRING StringPtr;\r
524 UINTN Index;\r
525 UINTN LogEntryKey;\r
526 UINTN Count;\r
aae1a875 527 UINTN HandleCount;\r
c06ad33e 528 EFI_STATUS Status;\r
88359546 529 EFI_STRING StringPtrUnknown;\r
c06ad33e 530\r
88359546 531 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 532 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_DRIVERS), NULL);\r
533 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
534 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
535 FreePool (StringPtr);\r
536 FreePool (StringPtrUnknown);\r
c06ad33e 537\r
aae1a875 538 Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);\r
c06ad33e 539 if (EFI_ERROR (Status)) {\r
540 PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);\r
541 }\r
542 else {\r
543#if DP_DEBUG == 2\r
544 Print (L"There are %,d Handles defined.\n", (Size / sizeof(HandleBuffer[0])));\r
545#endif\r
546\r
0b84f444
SZ
547 if (mShowId) {\r
548 PrintToken (STRING_TOKEN (STR_DP_HANDLE_SECTION2) );\r
549 } else {\r
550 PrintToken (STRING_TOKEN (STR_DP_HANDLE_SECTION) );\r
551 }\r
c06ad33e 552 PrintToken (STRING_TOKEN (STR_DP_DASHES) );\r
553\r
554 LogEntryKey = 0;\r
555 Count = 0;\r
0b84f444 556 while ((LogEntryKey = GetPerformanceMeasurementEx (\r
c06ad33e 557 LogEntryKey,\r
558 &Measurement.Handle,\r
559 &Measurement.Token,\r
560 &Measurement.Module,\r
561 &Measurement.StartTimeStamp,\r
0b84f444
SZ
562 &Measurement.EndTimeStamp,\r
563 &Measurement.Identifier)) != 0)\r
c06ad33e 564 {\r
565 Count++;\r
566 Duration = GetDuration (&Measurement);\r
567 ElapsedTime = DurationInMicroSeconds ( Duration );\r
568 if ((ElapsedTime < mInterestThreshold) ||\r
569 (Measurement.EndTimeStamp == 0) ||\r
570 (Measurement.Handle == NULL) ||\r
571 ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))\r
572 ) { // Ignore "uninteresting" or excluded records\r
573 continue;\r
574 }\r
575 mGaugeString[0] = 0; // Empty driver name by default\r
fcfba04a 576 AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));\r
c06ad33e 577 // See if the Handle is in the HandleBuffer\r
aae1a875 578 for (Index = 0; Index < HandleCount; Index++) {\r
c06ad33e 579 if (Measurement.Handle == HandleBuffer[Index]) {\r
580 GetNameFromHandle (HandleBuffer[Index]); // Name is put into mGaugeString\r
581 break;\r
582 }\r
583 }\r
584 // Ensure that the argument strings are not too long.\r
a2daf8db
SZ
585 mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
586 mUnicodeToken[11] = 0;\r
c06ad33e 587 if (mGaugeString[0] != 0) {\r
588 // Display the record if it has a valid handle.\r
0b84f444
SZ
589 if (mShowId) {\r
590 PrintToken (\r
591 STRING_TOKEN (STR_DP_HANDLE_VARS2),\r
592 Count, // 1 based, Which measurement record is being printed\r
593 Index + 1, // 1 based, Which handle is being printed\r
594 mGaugeString,\r
595 mUnicodeToken,\r
596 ElapsedTime,\r
597 Measurement.Identifier\r
598 );\r
599 } else {\r
600 PrintToken (\r
601 STRING_TOKEN (STR_DP_HANDLE_VARS),\r
602 Count, // 1 based, Which measurement record is being printed\r
603 Index + 1, // 1 based, Which handle is being printed\r
604 mGaugeString,\r
605 mUnicodeToken,\r
606 ElapsedTime\r
607 );\r
608 }\r
c06ad33e 609 }\r
3e9de670
CS
610 if (ShellGetExecutionBreakFlag ()) {\r
611 Status = EFI_ABORTED;\r
612 break;\r
613 }\r
c06ad33e 614 }\r
615 }\r
aae1a875 616 if (HandleBuffer != NULL) {\r
fc48db0d
ED
617 FreePool (HandleBuffer);\r
618 }\r
c06ad33e 619 return Status;\r
620}\r
621\r
9dd74618
ED
622/** \r
623 Gather and print PEIM data.\r
624 \r
625 Only prints complete PEIM records\r
3e9de670
CS
626\r
627 @retval EFI_SUCCESS The operation was successful.\r
628 @retval EFI_ABORTED The user aborts the operation.\r
c06ad33e 629**/\r
3e9de670 630EFI_STATUS\r
c06ad33e 631ProcessPeims(\r
632 VOID\r
633)\r
634{\r
635 MEASUREMENT_RECORD Measurement;\r
636 UINT64 Duration;\r
637 UINT64 ElapsedTime;\r
638 EFI_STRING StringPtr;\r
639 UINTN LogEntryKey;\r
640 UINTN TIndex;\r
88359546 641 EFI_STRING StringPtrUnknown;\r
3e9de670
CS
642 EFI_STATUS Status;\r
643\r
644 Status = EFI_SUCCESS;\r
c06ad33e 645\r
88359546 646 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 647 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_PEIMS), NULL);\r
648 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
649 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
650 FreePool (StringPtr);\r
651 FreePool (StringPtrUnknown);\r
c06ad33e 652\r
0b84f444
SZ
653 if (mShowId) {\r
654 PrintToken (STRING_TOKEN (STR_DP_PEIM_SECTION2));\r
655 } else {\r
656 PrintToken (STRING_TOKEN (STR_DP_PEIM_SECTION));\r
657 }\r
c06ad33e 658 PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
659 TIndex = 0;\r
660 LogEntryKey = 0;\r
0b84f444 661 while ((LogEntryKey = GetPerformanceMeasurementEx (\r
c06ad33e 662 LogEntryKey,\r
663 &Measurement.Handle,\r
664 &Measurement.Token,\r
665 &Measurement.Module,\r
666 &Measurement.StartTimeStamp,\r
0b84f444
SZ
667 &Measurement.EndTimeStamp,\r
668 &Measurement.Identifier)) != 0)\r
c06ad33e 669 {\r
670 TIndex++;\r
671 if ((Measurement.EndTimeStamp == 0) ||\r
672 (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) != 0)\r
673 ) {\r
674 continue;\r
675 }\r
676\r
677 Duration = GetDuration (&Measurement);\r
678 ElapsedTime = DurationInMicroSeconds ( Duration ); // Calculate elapsed time in microseconds\r
679 if (ElapsedTime >= mInterestThreshold) {\r
c3522526 680 // PEIM FILE Handle is the start address of its FFS file that contains its file guid.\r
0b84f444
SZ
681 if (mShowId) {\r
682 PrintToken (STRING_TOKEN (STR_DP_PEIM_VARS2),\r
683 TIndex, // 1 based, Which measurement record is being printed\r
684 Measurement.Handle, // base address\r
685 Measurement.Handle, // file guid\r
686 ElapsedTime,\r
687 Measurement.Identifier\r
688 );\r
689 } else {\r
690 PrintToken (STRING_TOKEN (STR_DP_PEIM_VARS),\r
691 TIndex, // 1 based, Which measurement record is being printed\r
692 Measurement.Handle, // base address\r
693 Measurement.Handle, // file guid\r
694 ElapsedTime\r
695 );\r
696 }\r
c06ad33e 697 }\r
3e9de670
CS
698 if (ShellGetExecutionBreakFlag ()) {\r
699 Status = EFI_ABORTED;\r
700 break;\r
701 }\r
c06ad33e 702 }\r
3e9de670 703 return Status;\r
c06ad33e 704}\r
705\r
9dd74618
ED
706/** \r
707 Gather and print global data.\r
708 \r
709 Strips out incomplete or "Execution Phase" records\r
710 Only prints records where Handle is NULL\r
711 Increment TIndex for every record, even skipped ones, so that we have an\r
712 indication of every measurement record taken.\r
3e9de670
CS
713\r
714 @retval EFI_SUCCESS The operation was successful.\r
715 @retval EFI_ABORTED The user aborts the operation.\r
c06ad33e 716**/\r
3e9de670 717EFI_STATUS\r
c06ad33e 718ProcessGlobal(\r
719 VOID\r
720)\r
721{\r
722 MEASUREMENT_RECORD Measurement;\r
723 UINT64 Duration;\r
724 UINT64 ElapsedTime;\r
725 EFI_STRING StringPtr;\r
726 UINTN LogEntryKey;\r
727 UINTN Index; // Index, or number, of the measurement record being processed\r
88359546 728 EFI_STRING StringPtrUnknown;\r
3e9de670
CS
729 EFI_STATUS Status;\r
730\r
731 Status = EFI_SUCCESS;\r
c06ad33e 732\r
88359546 733 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 734 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_GENERAL), NULL);\r
735 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
736 (StringPtr == NULL) ? StringPtrUnknown: StringPtr);\r
737 FreePool (StringPtr);\r
738 FreePool (StringPtrUnknown);\r
c06ad33e 739\r
0b84f444
SZ
740 if (mShowId) {\r
741 PrintToken (STRING_TOKEN (STR_DP_GLOBAL_SECTION2));\r
742 } else {\r
743 PrintToken (STRING_TOKEN (STR_DP_GLOBAL_SECTION));\r
744 }\r
c06ad33e 745 PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
746\r
747 Index = 1;\r
748 LogEntryKey = 0;\r
749\r
0b84f444 750 while ((LogEntryKey = GetPerformanceMeasurementEx (\r
c06ad33e 751 LogEntryKey,\r
752 &Measurement.Handle,\r
753 &Measurement.Token,\r
754 &Measurement.Module,\r
755 &Measurement.StartTimeStamp,\r
0b84f444
SZ
756 &Measurement.EndTimeStamp,\r
757 &Measurement.Identifier)) != 0)\r
c06ad33e 758 {\r
fcfba04a
LE
759 AsciiStrToUnicodeStrS (Measurement.Module, mGaugeString, ARRAY_SIZE (mGaugeString));\r
760 AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));\r
0b84f444 761 mGaugeString[25] = 0;\r
a2daf8db 762 mUnicodeToken[31] = 0;\r
c06ad33e 763 if ( ! ( IsPhase( &Measurement) ||\r
764 (Measurement.Handle != NULL) ||\r
765 (Measurement.EndTimeStamp == 0)\r
766 ))\r
767 {\r
768 Duration = GetDuration (&Measurement);\r
769 ElapsedTime = DurationInMicroSeconds ( Duration );\r
770 if (ElapsedTime >= mInterestThreshold) {\r
0b84f444
SZ
771 if (mShowId) {\r
772 PrintToken (\r
773 STRING_TOKEN (STR_DP_GLOBAL_VARS2),\r
774 Index,\r
775 mGaugeString,\r
776 mUnicodeToken,\r
777 ElapsedTime,\r
778 Measurement.Identifier\r
779 );\r
780 } else {\r
781 PrintToken (\r
782 STRING_TOKEN (STR_DP_GLOBAL_VARS),\r
783 Index,\r
784 mGaugeString,\r
785 mUnicodeToken,\r
786 ElapsedTime\r
787 );\r
788 }\r
c06ad33e 789 }\r
790 }\r
3e9de670
CS
791 if (ShellGetExecutionBreakFlag ()) {\r
792 Status = EFI_ABORTED;\r
793 break;\r
794 }\r
c06ad33e 795 Index++;\r
796 }\r
3e9de670 797 return Status;\r
c06ad33e 798}\r
799\r
9dd74618
ED
800/** \r
801 Gather and print cumulative data.\r
802 \r
803 Traverse the measurement records and:<BR>\r
804 For each record with a Token listed in the CumData array:<BR>\r
805 - Update the instance count and the total, minimum, and maximum durations.\r
806 Finally, print the gathered cumulative statistics.\r
d28f77df
CS
807\r
808 @param[in] CustomCumulativeData A pointer to the cumtom cumulative data.\r
809\r
c06ad33e 810**/\r
811VOID\r
812ProcessCumulative(\r
d28f77df
CS
813 IN PERF_CUM_DATA *CustomCumulativeData OPTIONAL\r
814 )\r
c06ad33e 815{\r
5460c4bb
ED
816 UINT64 AvgDur; // the computed average duration\r
817 UINT64 Dur;\r
818 UINT64 MinDur;\r
819 UINT64 MaxDur;\r
c06ad33e 820 EFI_STRING StringPtr;\r
821 UINTN TIndex;\r
88359546 822 EFI_STRING StringPtrUnknown;\r
c06ad33e 823\r
88359546 824 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 825 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_CUMULATIVE), NULL);\r
826 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
827 (StringPtr == NULL) ? StringPtrUnknown: StringPtr);\r
828 FreePool (StringPtr);\r
829 FreePool (StringPtrUnknown);\r
c06ad33e 830\r
831 PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_SECT_1));\r
832 PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_SECT_2));\r
833 PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
834\r
835 for ( TIndex = 0; TIndex < NumCum; ++TIndex) {\r
0d70a709
SZ
836 if (CumData[TIndex].Count != 0) {\r
837 AvgDur = DivU64x32 (CumData[TIndex].Duration, CumData[TIndex].Count);\r
838 AvgDur = DurationInMicroSeconds(AvgDur);\r
839 Dur = DurationInMicroSeconds(CumData[TIndex].Duration);\r
840 MaxDur = DurationInMicroSeconds(CumData[TIndex].MaxDur);\r
841 MinDur = DurationInMicroSeconds(CumData[TIndex].MinDur);\r
5460c4bb 842 \r
0d70a709
SZ
843 PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_STATS),\r
844 CumData[TIndex].Name,\r
845 CumData[TIndex].Count,\r
846 Dur,\r
847 AvgDur,\r
848 MinDur,\r
849 MaxDur\r
850 );\r
851 }\r
c06ad33e 852 }\r
d28f77df
CS
853\r
854 //\r
855 // Print the custom cumulative data.\r
856 //\r
857 if (CustomCumulativeData != NULL) {\r
858 if (CustomCumulativeData->Count != 0) {\r
859 AvgDur = DivU64x32 (CustomCumulativeData->Duration, CustomCumulativeData->Count);\r
860 AvgDur = DurationInMicroSeconds (AvgDur);\r
861 Dur = DurationInMicroSeconds (CustomCumulativeData->Duration);\r
862 MaxDur = DurationInMicroSeconds (CustomCumulativeData->MaxDur);\r
863 MinDur = DurationInMicroSeconds (CustomCumulativeData->MinDur);\r
864 } else {\r
865 AvgDur = 0;\r
866 Dur = 0;\r
867 MaxDur = 0;\r
868 MinDur = 0;\r
869 }\r
870 PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_STATS),\r
871 CustomCumulativeData->Name,\r
872 CustomCumulativeData->Count,\r
873 Dur,\r
874 AvgDur,\r
875 MinDur,\r
876 MaxDur\r
877 );\r
878 }\r
c06ad33e 879}\r