]> git.proxmox.com Git - mirror_edk2.git/blame - PerformancePkg/Dp_App/DpTrace.c
Clean up DEC files:
[mirror_edk2.git] / PerformancePkg / Dp_App / DpTrace.c
CommitLineData
c06ad33e 1/** @file\r
2 * Trace reporting for the Dp utility.\r
3 *\r
92ea1df8 4 * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
c06ad33e 5 * This program and the accompanying materials\r
6 * are licensed and made available under the terms and conditions of the BSD License\r
7 * which accompanies this distribution. The full text of the license may be found at\r
8 * http://opensource.org/licenses/bsd-license.php\r
9 *\r
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12**/\r
13\r
14#include <Library/BaseLib.h>\r
15#include <Library/BaseMemoryLib.h>\r
16#include <Library/MemoryAllocationLib.h>\r
17#include <Library/DebugLib.h>\r
18#include <Library/UefiBootServicesTableLib.h>\r
19#include <Library/TimerLib.h>\r
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
c06ad33e 45**/\r
46VOID\r
47GatherStatistics(\r
48 VOID\r
49)\r
50{\r
51 MEASUREMENT_RECORD Measurement;\r
52 UINT64 Duration;\r
53 UINTN LogEntryKey;\r
fc48db0d 54 INTN TIndex;\r
c06ad33e 55\r
56 LogEntryKey = 0;\r
57 while ((LogEntryKey = GetPerformanceMeasurement (\r
58 LogEntryKey,\r
59 &Measurement.Handle,\r
60 &Measurement.Token,\r
61 &Measurement.Module,\r
62 &Measurement.StartTimeStamp,\r
63 &Measurement.EndTimeStamp)) != 0)\r
64 {\r
65 ++SummaryData.NumTrace; // Count the number of TRACE Measurement records\r
66 if (Measurement.EndTimeStamp == 0) {\r
67 ++SummaryData.NumIncomplete; // Count the incomplete records\r
68 continue;\r
69 }\r
70\r
71 if (Measurement.Handle != NULL) {\r
72 ++SummaryData.NumHandles; // Count the number of measurements with non-NULL handles\r
73 }\r
74\r
75 if (IsPhase( &Measurement)) {\r
76 ++SummaryData.NumSummary; // Count the number of major phases\r
77 }\r
78 else { // !IsPhase(...\r
79 if(Measurement.Handle == NULL) {\r
80 ++SummaryData.NumGlobal;\r
81 }\r
82 }\r
83\r
84 if (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) == 0) {\r
85 ++SummaryData.NumPEIMs; // Count PEIM measurements\r
86 }\r
87\r
88 Duration = GetDuration (&Measurement);\r
89 TIndex = GetCumulativeItem (&Measurement);\r
90 if (TIndex >= 0) {\r
91 CumData[TIndex].Duration += Duration;\r
92 CumData[TIndex].Count++;\r
93 if ( Duration < CumData[TIndex].MinDur ) {\r
94 CumData[TIndex].MinDur = Duration;\r
95 }\r
96 if ( Duration > CumData[TIndex].MaxDur ) {\r
97 CumData[TIndex].MaxDur = Duration;\r
98 }\r
99 }\r
100 }\r
101}\r
102\r
9dd74618
ED
103/** \r
104 Gather and print ALL Trace Records.\r
105 \r
106 Displays all "interesting" Trace measurements in order.<BR>\r
107 The number of records displayed is controlled by:\r
108 - records with a duration less than mInterestThreshold microseconds are not displayed.\r
109 - No more than Limit records are displayed. A Limit of zero will not limit the output.\r
110 - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r
111 displayed.\r
112 \r
113 @pre The mInterestThreshold global variable is set to the shortest duration to be printed.\r
114 The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.\r
115 They must not be in use by a calling function.\r
116 \r
117 @param[in] Limit The number of records to print. Zero is ALL.\r
118 @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.\r
119 \r
c06ad33e 120**/\r
121VOID\r
122DumpAllTrace(\r
123 IN UINTN Limit,\r
124 IN BOOLEAN ExcludeFlag\r
125 )\r
126{\r
127 MEASUREMENT_RECORD Measurement;\r
128 UINT64 ElapsedTime;\r
129 UINT64 Duration;\r
130 const CHAR16 *IncFlag;\r
131 UINTN LogEntryKey;\r
132 UINTN Count;\r
133 UINTN Index;\r
134 UINTN TIndex;\r
135\r
136 EFI_HANDLE *HandleBuffer;\r
137 UINTN Size;\r
138 EFI_HANDLE TempHandle;\r
139 EFI_STATUS Status;\r
88359546 140 EFI_STRING StringPtrUnknown;\r
c06ad33e 141\r
88359546 142 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 143 IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_ALL), NULL);\r
144 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
145 (IncFlag == NULL) ? StringPtrUnknown : IncFlag);\r
146 FreePool (StringPtrUnknown);\r
c06ad33e 147\r
148 // Get Handle information\r
149 //\r
150 Size = 0;\r
fc48db0d 151 HandleBuffer = &TempHandle;\r
c06ad33e 152 Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, &TempHandle);\r
153 if (Status == EFI_BUFFER_TOO_SMALL) {\r
154 HandleBuffer = AllocatePool (Size);\r
155 ASSERT (HandleBuffer != NULL);\r
fc48db0d
ED
156 if (HandleBuffer == NULL) {\r
157 return;\r
158 }\r
c06ad33e 159 Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, HandleBuffer);\r
160 }\r
161 if (EFI_ERROR (Status)) {\r
162 PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);\r
163 }\r
164 else {\r
165 // We have successfully populated the HandleBuffer\r
166 // Display ALL Measurement Records\r
167 // Up to Limit lines displayed\r
168 // Display only records with Elapsed times >= mInterestThreshold\r
169 // Display driver names in Module field for records with Handles.\r
170 //\r
171 PrintToken (STRING_TOKEN (STR_DP_ALL_HEADR) );\r
172 PrintToken (STRING_TOKEN (STR_DP_DASHES) );\r
173\r
174 LogEntryKey = 0;\r
175 Count = 0;\r
176 Index = 0;\r
177 while ( WITHIN_LIMIT(Count, Limit) &&\r
178 ((LogEntryKey = GetPerformanceMeasurement (\r
179 LogEntryKey,\r
180 &Measurement.Handle,\r
181 &Measurement.Token,\r
182 &Measurement.Module,\r
183 &Measurement.StartTimeStamp,\r
184 &Measurement.EndTimeStamp)) != 0)\r
185 )\r
186 {\r
187 ++Index; // Count every record. First record is 1.\r
188 ElapsedTime = 0;\r
88359546
ED
189 if (IncFlag != NULL) {\r
190 FreePool ((void *)IncFlag);\r
191 }\r
c06ad33e 192 if (Measurement.EndTimeStamp != 0) {\r
193 Duration = GetDuration (&Measurement);\r
194 ElapsedTime = DurationInMicroSeconds ( Duration );\r
88359546 195 IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_COMPLETE), NULL);\r
c06ad33e 196 }\r
197 else {\r
88359546 198 IncFlag = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL); // Mark incomplete records\r
c06ad33e 199 }\r
200 if ((ElapsedTime < mInterestThreshold) ||\r
201 ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))\r
202 ) { // Ignore "uninteresting" or excluded records\r
203 continue;\r
204 }\r
205 if (Measurement.EndTimeStamp == 0) {\r
206 ElapsedTime = Measurement.StartTimeStamp;\r
207 }\r
208 ++Count; // Count the number of records printed\r
209\r
210 // If Handle is non-zero, see if we can determine a name for the driver\r
211 AsciiStrToUnicodeStr (Measurement.Module, mGaugeString); // Use Module by default\r
212 AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);\r
213 if (Measurement.Handle != NULL) {\r
214 // See if the Handle is in the HandleBuffer\r
215 for (TIndex = 0; TIndex < (Size / sizeof(HandleBuffer[0])); TIndex++) {\r
216 if (Measurement.Handle == HandleBuffer[TIndex]) {\r
217 GetNameFromHandle (HandleBuffer[TIndex]);\r
218 break;\r
219 }\r
220 }\r
221 }\r
222 // Ensure that the argument strings are not too long.\r
223 mGaugeString[31] = 0;\r
224 mUnicodeToken[18] = 0;\r
225\r
226 PrintToken( STRING_TOKEN (STR_DP_ALL_STATS),\r
227 Index, // 1 based, Which measurement record is being printed\r
228 IncFlag,\r
229 Measurement.Handle,\r
230 mGaugeString,\r
231 mUnicodeToken,\r
232 ElapsedTime\r
233 );\r
234 }\r
235 }\r
fc48db0d
ED
236 if (HandleBuffer != &TempHandle) {\r
237 FreePool (HandleBuffer);\r
238 }\r
88359546 239 FreePool ((void *)IncFlag);\r
c06ad33e 240}\r
241\r
9dd74618
ED
242/** \r
243 Gather and print Raw Trace Records.\r
244 \r
245 All Trace measurements with a duration greater than or equal to\r
246 mInterestThreshold are printed without interpretation.\r
247 \r
248 The number of records displayed is controlled by:\r
249 - records with a duration less than mInterestThreshold microseconds are not displayed.\r
250 - No more than Limit records are displayed. A Limit of zero will not limit the output.\r
251 - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r
252 displayed.\r
253 \r
254 @pre The mInterestThreshold global variable is set to the shortest duration to be printed.\r
255 \r
256 @param[in] Limit The number of records to print. Zero is ALL.\r
257 @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.\r
258 \r
c06ad33e 259**/\r
260VOID\r
261DumpRawTrace(\r
262 IN UINTN Limit,\r
263 IN BOOLEAN ExcludeFlag\r
264 )\r
265{\r
266 MEASUREMENT_RECORD Measurement;\r
267 UINT64 ElapsedTime;\r
268 UINT64 Duration;\r
269 UINTN LogEntryKey;\r
270 UINTN Count;\r
271 UINTN Index;\r
272\r
273 EFI_STRING StringPtr;\r
88359546 274 EFI_STRING StringPtrUnknown;\r
c06ad33e 275\r
88359546 276 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 277 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWTRACE), NULL);\r
278 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
279 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
280 FreePool (StringPtr);\r
281 FreePool (StringPtrUnknown);\r
c06ad33e 282\r
283 PrintToken (STRING_TOKEN (STR_DP_RAW_HEADR) );\r
284 PrintToken (STRING_TOKEN (STR_DP_RAW_DASHES) );\r
285\r
286 LogEntryKey = 0;\r
287 Count = 0;\r
288 Index = 0;\r
289 while ( WITHIN_LIMIT(Count, Limit) &&\r
290 ((LogEntryKey = GetPerformanceMeasurement (\r
291 LogEntryKey,\r
292 &Measurement.Handle,\r
293 &Measurement.Token,\r
294 &Measurement.Module,\r
295 &Measurement.StartTimeStamp,\r
296 &Measurement.EndTimeStamp)) != 0)\r
297 )\r
298 {\r
299 ++Index; // Count every record. First record is 1.\r
300 ElapsedTime = 0;\r
301 if (Measurement.EndTimeStamp != 0) {\r
302 Duration = GetDuration (&Measurement);\r
303 ElapsedTime = DurationInMicroSeconds ( Duration );\r
304 }\r
305 if ((ElapsedTime < mInterestThreshold) ||\r
306 ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))\r
307 ) { // Ignore "uninteresting" or Excluded records\r
308 continue;\r
309 }\r
310 ++Count; // Count the number of records printed\r
311 PrintToken (STRING_TOKEN (STR_DP_RAW_VARS),\r
312 Index, // 1 based, Which measurement record is being printed\r
313 Measurement.Handle,\r
314 Measurement.StartTimeStamp,\r
315 Measurement.EndTimeStamp,\r
316 Measurement.Token,\r
317 Measurement.Module\r
318 );\r
319 }\r
320}\r
321\r
9dd74618
ED
322/** \r
323 Gather and print Major Phase metrics.\r
324 \r
325 @param[in] Ticker The timer value for the END of Shell phase\r
326 \r
c06ad33e 327**/\r
328VOID\r
329ProcessPhases(\r
cbdf19a5 330 IN UINT64 Ticker\r
c06ad33e 331 )\r
332{\r
333 MEASUREMENT_RECORD Measurement;\r
9dd74618
ED
334 UINT64 BdsTimeoutValue;\r
335 UINT64 SecTime;\r
336 UINT64 PeiTime;\r
337 UINT64 DxeTime;\r
338 UINT64 BdsTime;\r
339 UINT64 ShellTime;\r
c06ad33e 340 UINT64 ElapsedTime;\r
341 UINT64 Duration;\r
342 UINT64 Total;\r
343 EFI_STRING StringPtr;\r
344 UINTN LogEntryKey;\r
88359546 345 EFI_STRING StringPtrUnknown;\r
c06ad33e 346\r
9dd74618
ED
347 BdsTimeoutValue = 0;\r
348 SecTime = 0;\r
349 PeiTime = 0;\r
350 DxeTime = 0;\r
351 BdsTime = 0;\r
352 ShellTime = 0; \r
c06ad33e 353 //\r
354 // Get Execution Phase Statistics\r
355 //\r
88359546 356 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 357 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_PHASES), NULL);\r
358 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
359 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
360 FreePool (StringPtr);\r
361 FreePool (StringPtrUnknown);\r
c06ad33e 362\r
363 LogEntryKey = 0;\r
364 while ((LogEntryKey = GetPerformanceMeasurement (\r
365 LogEntryKey,\r
366 &Measurement.Handle,\r
367 &Measurement.Token,\r
368 &Measurement.Module,\r
369 &Measurement.StartTimeStamp,\r
370 &Measurement.EndTimeStamp)) != 0)\r
371 {\r
372 if (AsciiStrnCmp (Measurement.Token, ALit_SHELL, PERF_TOKEN_LENGTH) == 0) {\r
373 Measurement.EndTimeStamp = Ticker;\r
374 }\r
375 if (Measurement.EndTimeStamp == 0) { // Skip "incomplete" records\r
376 continue;\r
377 }\r
378 Duration = GetDuration (&Measurement);\r
379 if ( Measurement.Handle != NULL\r
380 && (AsciiStrnCmp (Measurement.Token, ALit_BdsTO, PERF_TOKEN_LENGTH) == 0)\r
381 )\r
382 {\r
383 BdsTimeoutValue = Duration;\r
384 } else if (AsciiStrnCmp (Measurement.Token, ALit_SEC, PERF_TOKEN_LENGTH) == 0) {\r
385 SecTime = Duration;\r
386 } else if (AsciiStrnCmp (Measurement.Token, ALit_PEI, PERF_TOKEN_LENGTH) == 0) {\r
387 PeiTime = Duration;\r
388 } else if (AsciiStrnCmp (Measurement.Token, ALit_DXE, PERF_TOKEN_LENGTH) == 0) {\r
389 DxeTime = Duration;\r
390 } else if (AsciiStrnCmp (Measurement.Token, ALit_BDS, PERF_TOKEN_LENGTH) == 0) {\r
391 BdsTime = Duration;\r
392 } else if (AsciiStrnCmp (Measurement.Token, ALit_SHELL, PERF_TOKEN_LENGTH) == 0) {\r
393 ShellTime = Duration;\r
394 }\r
395 }\r
396\r
397 Total = 0;\r
398\r
399 // print SEC phase duration time\r
400 //\r
401 if (SecTime > 0) {\r
402 ElapsedTime = DurationInMicroSeconds ( SecTime ); // Calculate elapsed time in microseconds\r
403 Total += DivU64x32 (ElapsedTime, 1000); // Accumulate time in milliseconds\r
404 PrintToken (STRING_TOKEN (STR_DP_SEC_PHASE), ElapsedTime);\r
405 }\r
406\r
407 // print PEI phase duration time\r
408 //\r
409 if (PeiTime > 0) {\r
410 ElapsedTime = DivU64x32 (\r
411 PeiTime,\r
412 (UINT32)TimerInfo.Frequency\r
413 );\r
414 Total += ElapsedTime;\r
415 PrintToken (STRING_TOKEN (STR_DP_PHASE_DURATION), ALit_PEI, ElapsedTime);\r
416 }\r
417\r
418 // print DXE phase duration time\r
419 //\r
420 if (DxeTime > 0) {\r
421 ElapsedTime = DivU64x32 (\r
422 DxeTime,\r
423 (UINT32)TimerInfo.Frequency\r
424 );\r
425 Total += ElapsedTime;\r
426 PrintToken (STRING_TOKEN (STR_DP_PHASE_DURATION), ALit_DXE, ElapsedTime);\r
427 }\r
428\r
429 // print BDS phase duration time\r
430 //\r
431 if (BdsTime > 0) {\r
432 ElapsedTime = DivU64x32 (\r
433 BdsTime,\r
434 (UINT32)TimerInfo.Frequency\r
435 );\r
436 Total += ElapsedTime;\r
437 PrintToken (STRING_TOKEN (STR_DP_PHASE_DURATION), ALit_BDS, ElapsedTime);\r
438 }\r
439\r
440 if (BdsTimeoutValue > 0) {\r
441 ElapsedTime = DivU64x32 (\r
442 BdsTimeoutValue,\r
443 (UINT32)TimerInfo.Frequency\r
444 );\r
445 PrintToken (STRING_TOKEN (STR_DP_PHASE_BDSTO), ALit_BdsTO, ElapsedTime);\r
446 }\r
447\r
448 // print SHELL phase duration time\r
449 //\r
450 if (ShellTime > 0) {\r
451 ElapsedTime = DivU64x32 (\r
452 ShellTime,\r
453 (UINT32)TimerInfo.Frequency\r
454 );\r
455 Total += ElapsedTime;\r
456 PrintToken (STRING_TOKEN (STR_DP_PHASE_DURATION), ALit_SHELL, ElapsedTime);\r
457 }\r
458\r
459 PrintToken (STRING_TOKEN (STR_DP_TOTAL_DURATION), Total);\r
460}\r
461\r
9dd74618
ED
462/** \r
463 Gather and print Handle data.\r
464 \r
465 @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.\r
466 \r
467 @return Status from a call to gBS->LocateHandle().\r
c06ad33e 468**/\r
469EFI_STATUS\r
470ProcessHandles(\r
471 IN BOOLEAN ExcludeFlag\r
472 )\r
473{\r
474 MEASUREMENT_RECORD Measurement;\r
475 UINT64 ElapsedTime;\r
476 UINT64 Duration;\r
477 EFI_HANDLE *HandleBuffer;\r
478 EFI_STRING StringPtr;\r
479 UINTN Index;\r
480 UINTN LogEntryKey;\r
481 UINTN Count;\r
482 UINTN Size;\r
483 EFI_HANDLE TempHandle;\r
484 EFI_STATUS Status;\r
88359546 485 EFI_STRING StringPtrUnknown;\r
c06ad33e 486\r
88359546 487 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 488 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_DRIVERS), NULL);\r
489 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
490 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
491 FreePool (StringPtr);\r
492 FreePool (StringPtrUnknown);\r
c06ad33e 493\r
494 Size = 0;\r
fc48db0d 495 HandleBuffer = &TempHandle;\r
c06ad33e 496 Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, &TempHandle);\r
497 if (Status == EFI_BUFFER_TOO_SMALL) {\r
498 HandleBuffer = AllocatePool (Size);\r
499 ASSERT (HandleBuffer != NULL);\r
fc48db0d 500 if (HandleBuffer == NULL) {\r
224beee0 501 return Status;\r
fc48db0d 502 }\r
c06ad33e 503 Status = gBS->LocateHandle (AllHandles, NULL, NULL, &Size, HandleBuffer);\r
504 }\r
505 if (EFI_ERROR (Status)) {\r
506 PrintToken (STRING_TOKEN (STR_DP_HANDLES_ERROR), Status);\r
507 }\r
508 else {\r
509#if DP_DEBUG == 2\r
510 Print (L"There are %,d Handles defined.\n", (Size / sizeof(HandleBuffer[0])));\r
511#endif\r
512\r
513 PrintToken (STRING_TOKEN (STR_DP_HANDLE_GUID) );\r
514 PrintToken (STRING_TOKEN (STR_DP_DASHES) );\r
515\r
516 LogEntryKey = 0;\r
517 Count = 0;\r
518 while ((LogEntryKey = GetPerformanceMeasurement (\r
519 LogEntryKey,\r
520 &Measurement.Handle,\r
521 &Measurement.Token,\r
522 &Measurement.Module,\r
523 &Measurement.StartTimeStamp,\r
524 &Measurement.EndTimeStamp)) != 0)\r
525 {\r
526 Count++;\r
527 Duration = GetDuration (&Measurement);\r
528 ElapsedTime = DurationInMicroSeconds ( Duration );\r
529 if ((ElapsedTime < mInterestThreshold) ||\r
530 (Measurement.EndTimeStamp == 0) ||\r
531 (Measurement.Handle == NULL) ||\r
532 ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))\r
533 ) { // Ignore "uninteresting" or excluded records\r
534 continue;\r
535 }\r
536 mGaugeString[0] = 0; // Empty driver name by default\r
537 AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);\r
538 // See if the Handle is in the HandleBuffer\r
539 for (Index = 0; Index < (Size / sizeof(HandleBuffer[0])); Index++) {\r
540 if (Measurement.Handle == HandleBuffer[Index]) {\r
541 GetNameFromHandle (HandleBuffer[Index]); // Name is put into mGaugeString\r
542 break;\r
543 }\r
544 }\r
545 // Ensure that the argument strings are not too long.\r
546 mGaugeString[31] = 0;\r
547 mUnicodeToken[18] = 0;\r
548 if (mGaugeString[0] != 0) {\r
549 // Display the record if it has a valid handle.\r
550 PrintToken (\r
551 STRING_TOKEN (STR_DP_HANDLE_VARS),\r
552 Count, // 1 based, Which measurement record is being printed\r
553 Index + 1, // 1 based, Which handle is being printed\r
554 mGaugeString,\r
555 mUnicodeToken,\r
556 ElapsedTime\r
557 );\r
558 }\r
559 }\r
560 }\r
fc48db0d
ED
561 if (HandleBuffer != &TempHandle) {\r
562 FreePool (HandleBuffer);\r
563 }\r
c06ad33e 564 return Status;\r
565}\r
566\r
9dd74618
ED
567/** \r
568 Gather and print PEIM data.\r
569 \r
570 Only prints complete PEIM records\r
571 \r
c06ad33e 572**/\r
573VOID\r
574ProcessPeims(\r
575 VOID\r
576)\r
577{\r
578 MEASUREMENT_RECORD Measurement;\r
579 UINT64 Duration;\r
580 UINT64 ElapsedTime;\r
581 EFI_STRING StringPtr;\r
582 UINTN LogEntryKey;\r
583 UINTN TIndex;\r
88359546 584 EFI_STRING StringPtrUnknown;\r
c06ad33e 585\r
88359546 586 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 587 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_PEIMS), NULL);\r
588 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
589 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
590 FreePool (StringPtr);\r
591 FreePool (StringPtrUnknown);\r
c06ad33e 592\r
593 PrintToken (STRING_TOKEN (STR_DP_PEIM_SECTION));\r
594 PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
595 TIndex = 0;\r
596 LogEntryKey = 0;\r
597 while ((LogEntryKey = GetPerformanceMeasurement (\r
598 LogEntryKey,\r
599 &Measurement.Handle,\r
600 &Measurement.Token,\r
601 &Measurement.Module,\r
602 &Measurement.StartTimeStamp,\r
603 &Measurement.EndTimeStamp)) != 0)\r
604 {\r
605 TIndex++;\r
606 if ((Measurement.EndTimeStamp == 0) ||\r
607 (AsciiStrnCmp (Measurement.Token, ALit_PEIM, PERF_TOKEN_LENGTH) != 0)\r
608 ) {\r
609 continue;\r
610 }\r
611\r
612 Duration = GetDuration (&Measurement);\r
613 ElapsedTime = DurationInMicroSeconds ( Duration ); // Calculate elapsed time in microseconds\r
614 if (ElapsedTime >= mInterestThreshold) {\r
c3522526 615 // PEIM FILE Handle is the start address of its FFS file that contains its file guid.\r
c06ad33e 616 PrintToken (STRING_TOKEN (STR_DP_PEIM_STAT2),\r
617 TIndex, // 1 based, Which measurement record is being printed\r
c3522526
LG
618 Measurement.Handle, // base address\r
619 Measurement.Handle, // file guid\r
c06ad33e 620 ElapsedTime\r
621 );\r
622 }\r
623 }\r
624}\r
625\r
9dd74618
ED
626/** \r
627 Gather and print global data.\r
628 \r
629 Strips out incomplete or "Execution Phase" records\r
630 Only prints records where Handle is NULL\r
631 Increment TIndex for every record, even skipped ones, so that we have an\r
632 indication of every measurement record taken.\r
633 \r
c06ad33e 634**/\r
635VOID\r
636ProcessGlobal(\r
637 VOID\r
638)\r
639{\r
640 MEASUREMENT_RECORD Measurement;\r
641 UINT64 Duration;\r
642 UINT64 ElapsedTime;\r
643 EFI_STRING StringPtr;\r
644 UINTN LogEntryKey;\r
645 UINTN Index; // Index, or number, of the measurement record being processed\r
88359546 646 EFI_STRING StringPtrUnknown;\r
c06ad33e 647\r
88359546 648 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 649 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_GENERAL), NULL);\r
650 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
651 (StringPtr == NULL) ? StringPtrUnknown: StringPtr);\r
652 FreePool (StringPtr);\r
653 FreePool (StringPtrUnknown);\r
c06ad33e 654\r
655 PrintToken (STRING_TOKEN (STR_DP_GLOBAL_SECTION));\r
656 PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
657\r
658 Index = 1;\r
659 LogEntryKey = 0;\r
660\r
661 while ((LogEntryKey = GetPerformanceMeasurement (\r
662 LogEntryKey,\r
663 &Measurement.Handle,\r
664 &Measurement.Token,\r
665 &Measurement.Module,\r
666 &Measurement.StartTimeStamp,\r
667 &Measurement.EndTimeStamp)) != 0)\r
668 {\r
669 AsciiStrToUnicodeStr (Measurement.Module, mGaugeString);\r
670 AsciiStrToUnicodeStr (Measurement.Token, mUnicodeToken);\r
671 if ( ! ( IsPhase( &Measurement) ||\r
672 (Measurement.Handle != NULL) ||\r
673 (Measurement.EndTimeStamp == 0)\r
674 ))\r
675 {\r
676 Duration = GetDuration (&Measurement);\r
677 ElapsedTime = DurationInMicroSeconds ( Duration );\r
678 if (ElapsedTime >= mInterestThreshold) {\r
679 PrintToken (\r
680 STRING_TOKEN (STR_DP_FOUR_VARS_2),\r
681 Index,\r
682 mGaugeString,\r
683 mUnicodeToken,\r
684 ElapsedTime\r
685 );\r
686 }\r
687 }\r
688 Index++;\r
689 }\r
690}\r
691\r
9dd74618
ED
692/** \r
693 Gather and print cumulative data.\r
694 \r
695 Traverse the measurement records and:<BR>\r
696 For each record with a Token listed in the CumData array:<BR>\r
697 - Update the instance count and the total, minimum, and maximum durations.\r
698 Finally, print the gathered cumulative statistics.\r
699 \r
c06ad33e 700**/\r
701VOID\r
702ProcessCumulative(\r
703 VOID\r
704)\r
705{\r
5460c4bb
ED
706 UINT64 AvgDur; // the computed average duration\r
707 UINT64 Dur;\r
708 UINT64 MinDur;\r
709 UINT64 MaxDur;\r
c06ad33e 710 EFI_STRING StringPtr;\r
711 UINTN TIndex;\r
88359546 712 EFI_STRING StringPtrUnknown;\r
c06ad33e 713\r
88359546 714 StringPtrUnknown = HiiGetString (gHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL); \r
c06ad33e 715 StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_CUMULATIVE), NULL);\r
716 PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r
88359546
ED
717 (StringPtr == NULL) ? StringPtrUnknown: StringPtr);\r
718 FreePool (StringPtr);\r
719 FreePool (StringPtrUnknown);\r
c06ad33e 720\r
721 PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_SECT_1));\r
722 PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_SECT_2));\r
723 PrintToken (STRING_TOKEN (STR_DP_DASHES));\r
724\r
725 for ( TIndex = 0; TIndex < NumCum; ++TIndex) {\r
0d70a709
SZ
726 if (CumData[TIndex].Count != 0) {\r
727 AvgDur = DivU64x32 (CumData[TIndex].Duration, CumData[TIndex].Count);\r
728 AvgDur = DurationInMicroSeconds(AvgDur);\r
729 Dur = DurationInMicroSeconds(CumData[TIndex].Duration);\r
730 MaxDur = DurationInMicroSeconds(CumData[TIndex].MaxDur);\r
731 MinDur = DurationInMicroSeconds(CumData[TIndex].MinDur);\r
5460c4bb 732 \r
0d70a709
SZ
733 PrintToken (STRING_TOKEN (STR_DP_CUMULATIVE_STATS),\r
734 CumData[TIndex].Name,\r
735 CumData[TIndex].Count,\r
736 Dur,\r
737 AvgDur,\r
738 MinDur,\r
739 MaxDur\r
740 );\r
741 }\r
c06ad33e 742 }\r
743}\r