2 Trace reporting for the Dp utility.
4 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
5 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/BaseLib.h>
10 #include <Library/BaseMemoryLib.h>
11 #include <Library/MemoryAllocationLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/UefiBootServicesTableLib.h>
14 #include <Library/PeCoffGetEntryPointLib.h>
15 #include <Library/PerformanceLib.h>
16 #include <Library/PrintLib.h>
17 #include <Library/HiiLib.h>
18 #include <Library/PcdLib.h>
22 #include "DpInternal.h"
25 Attempts to retrieve a performance measurement log entry from the performance measurement log.
28 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
29 0, then the first performance measurement log entry is retrieved.
30 On exit, the key of the next performance log entry.
31 @param Handle Pointer to environment specific context used to identify the component
33 @param Token Pointer to a Null-terminated ASCII string that identifies the component
35 @param Module Pointer to a Null-terminated ASCII string that identifies the module
37 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
39 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
41 @param Identifier Pointer to the 32-bit identifier that was recorded when the measurement
44 @return The key for the next performance log entry (in general case).
48 GetPerformanceMeasurementRecord (
50 OUT CONST VOID
**Handle
,
51 OUT CONST CHAR8
**Token
,
52 OUT CONST CHAR8
**Module
,
53 OUT UINT64
*StartTimeStamp
,
54 OUT UINT64
*EndTimeStamp
,
55 OUT UINT32
*Identifier
58 if (LogEntryKey
== mMeasurementNum
) {
62 *Handle
= (VOID
*) (UINTN
) mMeasurementList
[LogEntryKey
].Handle
;
63 *Token
= mMeasurementList
[LogEntryKey
].Token
;
64 *Module
= mMeasurementList
[LogEntryKey
].Module
;
65 *StartTimeStamp
= mMeasurementList
[LogEntryKey
].StartTimeStamp
;
66 *EndTimeStamp
= mMeasurementList
[LogEntryKey
].EndTimeStamp
;
67 *Identifier
= mMeasurementList
[LogEntryKey
].Identifier
;
75 Collect verbose statistics about the logged performance measurements.
77 General Summary information for all Trace measurements is gathered and
78 stored within the SummaryData structure. This information is both
79 used internally by subsequent reporting functions, and displayed
80 at the end of verbose reports.
82 @pre The SummaryData and CumData structures must be initialized
83 prior to calling this function.
85 @post The SummaryData and CumData structures contain statistics for the
86 current performance logs.
88 @param[in, out] CustomCumulativeData A pointer to the cumtom cumulative data.
93 IN OUT PERF_CUM_DATA
*CustomCumulativeData OPTIONAL
96 MEASUREMENT_RECORD Measurement
;
102 while ((LogEntryKey
= GetPerformanceMeasurementRecord (
107 &Measurement
.StartTimeStamp
,
108 &Measurement
.EndTimeStamp
,
109 &Measurement
.Identifier
)) != 0)
111 ++SummaryData
.NumTrace
; // Count the number of TRACE Measurement records
112 if (Measurement
.EndTimeStamp
== 0) {
113 ++SummaryData
.NumIncomplete
; // Count the incomplete records
117 if (Measurement
.Handle
!= NULL
) {
118 ++SummaryData
.NumHandles
; // Count the number of measurements with non-NULL handles
121 if (IsPhase( &Measurement
)) {
122 ++SummaryData
.NumSummary
; // Count the number of major phases
125 if(Measurement
.Handle
== NULL
) {
126 ++SummaryData
.NumGlobal
;
130 if (AsciiStrCmp (Measurement
.Token
, ALit_PEIM
) == 0) {
131 ++SummaryData
.NumPEIMs
; // Count PEIM measurements
134 Duration
= GetDuration (&Measurement
);
135 TIndex
= GetCumulativeItem (&Measurement
);
137 CumData
[TIndex
].Duration
+= Duration
;
138 CumData
[TIndex
].Count
++;
139 if ( Duration
< CumData
[TIndex
].MinDur
) {
140 CumData
[TIndex
].MinDur
= Duration
;
142 if ( Duration
> CumData
[TIndex
].MaxDur
) {
143 CumData
[TIndex
].MaxDur
= Duration
;
148 // Collect the data for custom cumulative data.
150 if ((CustomCumulativeData
!= NULL
) && (AsciiStrCmp (Measurement
.Token
, CustomCumulativeData
->Name
) == 0)) {
151 CustomCumulativeData
->Duration
+= Duration
;
152 CustomCumulativeData
->Count
++;
153 if (Duration
< CustomCumulativeData
->MinDur
) {
154 CustomCumulativeData
->MinDur
= Duration
;
156 if (Duration
> CustomCumulativeData
->MaxDur
) {
157 CustomCumulativeData
->MaxDur
= Duration
;
164 Gather and print ALL Trace Records.
166 Displays all "interesting" Trace measurements in order.<BR>
167 The number of records displayed is controlled by:
168 - records with a duration less than mInterestThreshold microseconds are not displayed.
169 - No more than Limit records are displayed. A Limit of zero will not limit the output.
170 - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
173 @pre The mInterestThreshold global variable is set to the shortest duration to be printed.
174 The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.
175 They must not be in use by a calling function.
177 @param[in] Limit The number of records to print. Zero is ALL.
178 @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.
180 @retval EFI_SUCCESS The operation was successful.
181 @retval EFI_ABORTED The user aborts the operation.
182 @return Others from a call to gBS->LocateHandleBuffer().
187 IN BOOLEAN ExcludeFlag
190 MEASUREMENT_RECORD Measurement
;
199 EFI_HANDLE
*HandleBuffer
;
202 EFI_STRING StringPtrUnknown
;
204 StringPtrUnknown
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
205 IncFlag
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_DP_SECTION_ALL
), NULL
);
206 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_SECTION_HEADER
), mDpHiiHandle
,
207 (IncFlag
== NULL
) ? StringPtrUnknown
: IncFlag
);
208 FreePool (StringPtrUnknown
);
210 // Get Handle information
212 Status
= gBS
->LocateHandleBuffer (AllHandles
, NULL
, NULL
, &HandleCount
, &HandleBuffer
);
213 if (EFI_ERROR (Status
)) {
214 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_HANDLES_ERROR
), mDpHiiHandle
, Status
);
217 // We have successfully populated the HandleBuffer
218 // Display ALL Measurement Records
219 // Up to Limit lines displayed
220 // Display only records with Elapsed times >= mInterestThreshold
221 // Display driver names in Module field for records with Handles.
224 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_ALL_HEADR2
), mDpHiiHandle
);
225 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_ALL_DASHES2
), mDpHiiHandle
);
227 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_ALL_HEADR
), mDpHiiHandle
);
228 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_DASHES
), mDpHiiHandle
);
234 while ( WITHIN_LIMIT(Count
, Limit
) &&
235 ((LogEntryKey
= GetPerformanceMeasurementRecord (
240 &Measurement
.StartTimeStamp
,
241 &Measurement
.EndTimeStamp
,
242 &Measurement
.Identifier
)) != 0)
245 ++Index
; // Count every record. First record is 1.
247 SHELL_FREE_NON_NULL (IncFlag
);
248 if (Measurement
.EndTimeStamp
!= 0) {
249 Duration
= GetDuration (&Measurement
);
250 ElapsedTime
= DurationInMicroSeconds ( Duration
);
251 IncFlag
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_DP_COMPLETE
), NULL
);
254 IncFlag
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_DP_INCOMPLETE
), NULL
); // Mark incomplete records
256 if (((Measurement
.EndTimeStamp
!= 0) && (ElapsedTime
< mInterestThreshold
)) ||
257 ((ExcludeFlag
) && (GetCumulativeItem(&Measurement
) >= 0))
258 ) { // Ignore "uninteresting" or excluded records
261 ++Count
; // Count the number of records printed
263 // If Handle is non-zero, see if we can determine a name for the driver
264 AsciiStrToUnicodeStrS (Measurement
.Module
, mGaugeString
, ARRAY_SIZE (mGaugeString
)); // Use Module by default
265 AsciiStrToUnicodeStrS (Measurement
.Token
, mUnicodeToken
, ARRAY_SIZE (mUnicodeToken
));
266 if (Measurement
.Handle
!= NULL
) {
267 // See if the Handle is in the HandleBuffer
268 for (TIndex
= 0; TIndex
< HandleCount
; TIndex
++) {
269 if (Measurement
.Handle
== HandleBuffer
[TIndex
]) {
270 DpGetNameFromHandle (HandleBuffer
[TIndex
]);
276 if (AsciiStrCmp (Measurement
.Token
, ALit_PEIM
) == 0) {
277 UnicodeSPrint (mGaugeString
, sizeof (mGaugeString
), L
"%g", Measurement
.Handle
);
280 // Ensure that the argument strings are not too long.
281 mGaugeString
[DP_GAUGE_STRING_LENGTH
] = 0;
282 mUnicodeToken
[13] = 0;
285 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_ALL_VARS2
), mDpHiiHandle
,
286 Index
, // 1 based, Which measurement record is being printed
292 Measurement
.Identifier
295 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_ALL_VARS
), mDpHiiHandle
,
296 Index
, // 1 based, Which measurement record is being printed
304 if (ShellGetExecutionBreakFlag ()) {
305 Status
= EFI_ABORTED
;
310 if (HandleBuffer
!= NULL
) {
311 FreePool (HandleBuffer
);
313 SHELL_FREE_NON_NULL (IncFlag
);
319 Gather and print Raw Trace Records.
321 All Trace measurements with a duration greater than or equal to
322 mInterestThreshold are printed without interpretation.
324 The number of records displayed is controlled by:
325 - records with a duration less than mInterestThreshold microseconds are not displayed.
326 - No more than Limit records are displayed. A Limit of zero will not limit the output.
327 - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
330 @pre The mInterestThreshold global variable is set to the shortest duration to be printed.
332 @param[in] Limit The number of records to print. Zero is ALL.
333 @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.
335 @retval EFI_SUCCESS The operation was successful.
336 @retval EFI_ABORTED The user aborts the operation.
341 IN BOOLEAN ExcludeFlag
344 MEASUREMENT_RECORD Measurement
;
351 EFI_STRING StringPtr
;
352 EFI_STRING StringPtrUnknown
;
355 Status
= EFI_SUCCESS
;
357 StringPtrUnknown
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
358 StringPtr
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_DP_SECTION_RAWTRACE
), NULL
);
359 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_SECTION_HEADER
), mDpHiiHandle
,
360 (StringPtr
== NULL
) ? StringPtrUnknown
: StringPtr
);
361 FreePool (StringPtr
);
362 FreePool (StringPtrUnknown
);
365 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_RAW_HEADR2
), mDpHiiHandle
);
366 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_RAW_DASHES2
), mDpHiiHandle
);
368 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_RAW_HEADR
), mDpHiiHandle
);
369 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_RAW_DASHES
), mDpHiiHandle
);
375 while ( WITHIN_LIMIT(Count
, Limit
) &&
376 ((LogEntryKey
= GetPerformanceMeasurementRecord (
381 &Measurement
.StartTimeStamp
,
382 &Measurement
.EndTimeStamp
,
383 &Measurement
.Identifier
)) != 0)
386 ++Index
; // Count every record. First record is 1.
388 if (Measurement
.EndTimeStamp
!= 0) {
389 Duration
= GetDuration (&Measurement
);
390 ElapsedTime
= DurationInMicroSeconds ( Duration
);
392 if ((ElapsedTime
< mInterestThreshold
) ||
393 ((ExcludeFlag
) && (GetCumulativeItem(&Measurement
) >= 0))
394 ) { // Ignore "uninteresting" or Excluded records
397 ++Count
; // Count the number of records printed
400 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_RAW_VARS2
), mDpHiiHandle
,
401 Index
, // 1 based, Which measurement record is being printed
403 Measurement
.StartTimeStamp
,
404 Measurement
.EndTimeStamp
,
407 Measurement
.Identifier
410 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_RAW_VARS
), mDpHiiHandle
,
411 Index
, // 1 based, Which measurement record is being printed
413 Measurement
.StartTimeStamp
,
414 Measurement
.EndTimeStamp
,
419 if (ShellGetExecutionBreakFlag ()) {
420 Status
= EFI_ABORTED
;
428 Gather and print Major Phase metrics.
436 MEASUREMENT_RECORD Measurement
;
437 UINT64 BdsTimeoutValue
;
445 EFI_STRING StringPtr
;
447 EFI_STRING StringPtrUnknown
;
455 // Get Execution Phase Statistics
457 StringPtrUnknown
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
458 StringPtr
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_DP_SECTION_PHASES
), NULL
);
459 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_SECTION_HEADER
), mDpHiiHandle
,
460 (StringPtr
== NULL
) ? StringPtrUnknown
: StringPtr
);
461 FreePool (StringPtr
);
462 FreePool (StringPtrUnknown
);
465 while ((LogEntryKey
= GetPerformanceMeasurementRecord (
470 &Measurement
.StartTimeStamp
,
471 &Measurement
.EndTimeStamp
,
472 &Measurement
.Identifier
)) != 0)
474 if (Measurement
.EndTimeStamp
== 0) { // Skip "incomplete" records
477 Duration
= GetDuration (&Measurement
);
478 if ( Measurement
.Handle
!= NULL
479 && (AsciiStrCmp (Measurement
.Token
, ALit_BdsTO
) == 0)
482 BdsTimeoutValue
= Duration
;
483 } else if (AsciiStrCmp (Measurement
.Token
, ALit_SEC
) == 0) {
485 } else if (AsciiStrCmp (Measurement
.Token
, ALit_PEI
) == 0) {
487 } else if (AsciiStrCmp (Measurement
.Token
, ALit_DXE
) == 0) {
489 } else if (AsciiStrCmp (Measurement
.Token
, ALit_BDS
) == 0) {
496 // print SEC phase duration time
499 ElapsedTime
= DurationInMicroSeconds ( SecTime
); // Calculate elapsed time in microseconds
500 Total
+= DivU64x32 (ElapsedTime
, 1000); // Accumulate time in milliseconds
501 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_SEC_PHASE
), mDpHiiHandle
, ElapsedTime
);
504 // print PEI phase duration time
507 ElapsedTime
= DivU64x32 (PeiTime
, 1000000);
508 Total
+= ElapsedTime
;
509 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_PHASE_DURATION
), mDpHiiHandle
, ALit_PEI
, ElapsedTime
);
512 // print DXE phase duration time
515 ElapsedTime
= DivU64x32 (DxeTime
, 1000000);
516 Total
+= ElapsedTime
;
517 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_PHASE_DURATION
), mDpHiiHandle
, ALit_DXE
, ElapsedTime
);
520 // print BDS phase duration time
523 ElapsedTime
= DivU64x32 (BdsTime
, 1000000);
524 Total
+= ElapsedTime
;
525 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_PHASE_DURATION
), mDpHiiHandle
, ALit_BDS
, ElapsedTime
);
528 if (BdsTimeoutValue
> 0) {
529 ElapsedTime
= DivU64x32 (BdsTimeoutValue
, 1000000);
530 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_PHASE_BDSTO
), mDpHiiHandle
, ALit_BdsTO
, ElapsedTime
);
533 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_TOTAL_DURATION
), mDpHiiHandle
, Total
);
537 Gather and print Handle data.
539 @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.
541 @retval EFI_SUCCESS The operation was successful.
542 @retval EFI_ABORTED The user aborts the operation.
543 @return Others from a call to gBS->LocateHandleBuffer().
547 IN BOOLEAN ExcludeFlag
550 MEASUREMENT_RECORD Measurement
;
553 EFI_HANDLE
*HandleBuffer
;
554 EFI_STRING StringPtr
;
560 EFI_STRING StringPtrUnknown
;
562 StringPtrUnknown
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
563 StringPtr
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_DP_SECTION_DRIVERS
), NULL
);
564 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_SECTION_HEADER
), mDpHiiHandle
,
565 (StringPtr
== NULL
) ? StringPtrUnknown
: StringPtr
);
566 FreePool (StringPtr
);
567 FreePool (StringPtrUnknown
);
569 Status
= gBS
->LocateHandleBuffer (AllHandles
, NULL
, NULL
, &HandleCount
, &HandleBuffer
);
570 if (EFI_ERROR (Status
)) {
571 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_HANDLES_ERROR
), mDpHiiHandle
, Status
);
575 Print (L
"There are %,d Handles defined.\n", (Size
/ sizeof(HandleBuffer
[0])));
579 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_HANDLE_SECTION2
), mDpHiiHandle
);
581 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_HANDLE_SECTION
), mDpHiiHandle
);
583 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_DASHES
), mDpHiiHandle
);
587 while ((LogEntryKey
= GetPerformanceMeasurementRecord (
592 &Measurement
.StartTimeStamp
,
593 &Measurement
.EndTimeStamp
,
594 &Measurement
.Identifier
)) != 0)
597 Duration
= GetDuration (&Measurement
);
598 ElapsedTime
= DurationInMicroSeconds ( Duration
);
599 if ((ElapsedTime
< mInterestThreshold
) ||
600 (Measurement
.EndTimeStamp
== 0) ||
601 (!IsCorePerf (&Measurement
)) ||
602 ((ExcludeFlag
) && (GetCumulativeItem(&Measurement
) >= 0))
603 ) { // Ignore "uninteresting" or excluded records
606 mGaugeString
[0] = 0; // Empty driver name by default
607 AsciiStrToUnicodeStrS (Measurement
.Token
, mUnicodeToken
, ARRAY_SIZE (mUnicodeToken
));
608 // See if the Handle is in the HandleBuffer
609 for (Index
= 0; Index
< HandleCount
; Index
++) {
610 if (Measurement
.Handle
== HandleBuffer
[Index
]) {
611 DpGetNameFromHandle (HandleBuffer
[Index
]); // Name is put into mGaugeString
615 // Ensure that the argument strings are not too long.
616 mGaugeString
[DP_GAUGE_STRING_LENGTH
] = 0;
617 mUnicodeToken
[11] = 0;
618 if (mGaugeString
[0] != 0) {
619 // Display the record if it has a valid handle.
621 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_HANDLE_VARS2
), mDpHiiHandle
,
622 Count
, // 1 based, Which measurement record is being printed
623 Index
+ 1, // 1 based, Which handle is being printed
627 Measurement
.Identifier
630 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_HANDLE_VARS
), mDpHiiHandle
,
631 Count
, // 1 based, Which measurement record is being printed
632 Index
+ 1, // 1 based, Which handle is being printed
639 if (ShellGetExecutionBreakFlag ()) {
640 Status
= EFI_ABORTED
;
645 if (HandleBuffer
!= NULL
) {
646 FreePool (HandleBuffer
);
652 Gather and print PEIM data.
654 Only prints complete PEIM records
656 @retval EFI_SUCCESS The operation was successful.
657 @retval EFI_ABORTED The user aborts the operation.
664 MEASUREMENT_RECORD Measurement
;
667 EFI_STRING StringPtr
;
670 EFI_STRING StringPtrUnknown
;
673 Status
= EFI_SUCCESS
;
675 StringPtrUnknown
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
676 StringPtr
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_DP_SECTION_PEIMS
), NULL
);
677 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_SECTION_HEADER
), mDpHiiHandle
,
678 (StringPtr
== NULL
) ? StringPtrUnknown
: StringPtr
);
679 FreePool (StringPtr
);
680 FreePool (StringPtrUnknown
);
683 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_PEIM_SECTION2
), mDpHiiHandle
);
685 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_PEIM_SECTION
), mDpHiiHandle
);
687 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_DASHES
), mDpHiiHandle
);
690 while ((LogEntryKey
= GetPerformanceMeasurementRecord (
695 &Measurement
.StartTimeStamp
,
696 &Measurement
.EndTimeStamp
,
697 &Measurement
.Identifier
)) != 0)
700 if ((Measurement
.EndTimeStamp
== 0) ||
701 (AsciiStrCmp (Measurement
.Token
, ALit_PEIM
) != 0)
706 Duration
= GetDuration (&Measurement
);
707 ElapsedTime
= DurationInMicroSeconds ( Duration
); // Calculate elapsed time in microseconds
708 if (ElapsedTime
>= mInterestThreshold
) {
709 // PEIM FILE Handle is the start address of its FFS file that contains its file guid.
711 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_PEIM_VARS2
), mDpHiiHandle
,
712 TIndex
, // 1 based, Which measurement record is being printed
713 Measurement
.Handle
, // file guid
715 Measurement
.Identifier
718 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_PEIM_VARS
), mDpHiiHandle
,
719 TIndex
, // 1 based, Which measurement record is being printed
720 Measurement
.Handle
, // file guid
725 if (ShellGetExecutionBreakFlag ()) {
726 Status
= EFI_ABORTED
;
734 Gather and print global data.
736 Strips out incomplete or "Execution Phase" records
737 Only prints records where Handle is NULL
738 Increment TIndex for every record, even skipped ones, so that we have an
739 indication of every measurement record taken.
741 @retval EFI_SUCCESS The operation was successful.
742 @retval EFI_ABORTED The user aborts the operation.
749 MEASUREMENT_RECORD Measurement
;
752 EFI_STRING StringPtr
;
754 UINTN Index
; // Index, or number, of the measurement record being processed
755 EFI_STRING StringPtrUnknown
;
758 Status
= EFI_SUCCESS
;
760 StringPtrUnknown
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
761 StringPtr
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_DP_SECTION_GENERAL
), NULL
);
762 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_SECTION_HEADER
), mDpHiiHandle
,
763 (StringPtr
== NULL
) ? StringPtrUnknown
: StringPtr
);
764 FreePool (StringPtr
);
765 FreePool (StringPtrUnknown
);
768 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_GLOBAL_SECTION2
), mDpHiiHandle
);
770 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_GLOBAL_SECTION
), mDpHiiHandle
);
772 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_DASHES
), mDpHiiHandle
);
777 while ((LogEntryKey
= GetPerformanceMeasurementRecord (
782 &Measurement
.StartTimeStamp
,
783 &Measurement
.EndTimeStamp
,
784 &Measurement
.Identifier
)) != 0)
786 AsciiStrToUnicodeStrS (Measurement
.Module
, mGaugeString
, ARRAY_SIZE (mGaugeString
));
787 AsciiStrToUnicodeStrS (Measurement
.Token
, mUnicodeToken
, ARRAY_SIZE (mUnicodeToken
));
788 mGaugeString
[25] = 0;
789 mUnicodeToken
[31] = 0;
790 if ( ! ( IsPhase( &Measurement
) ||
791 IsCorePerf (&Measurement
) ||
792 (Measurement
.EndTimeStamp
== 0)
795 Duration
= GetDuration (&Measurement
);
796 ElapsedTime
= DurationInMicroSeconds ( Duration
);
797 if (ElapsedTime
>= mInterestThreshold
) {
799 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_GLOBAL_VARS2
), mDpHiiHandle
,
804 Measurement
.Identifier
807 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_GLOBAL_VARS
), mDpHiiHandle
,
816 if (ShellGetExecutionBreakFlag ()) {
817 Status
= EFI_ABORTED
;
826 Gather and print cumulative data.
828 Traverse the measurement records and:<BR>
829 For each record with a Token listed in the CumData array:<BR>
830 - Update the instance count and the total, minimum, and maximum durations.
831 Finally, print the gathered cumulative statistics.
833 @param[in] CustomCumulativeData A pointer to the cumtom cumulative data.
838 IN PERF_CUM_DATA
*CustomCumulativeData OPTIONAL
841 UINT64 AvgDur
; // the computed average duration
845 EFI_STRING StringPtr
;
847 EFI_STRING StringPtrUnknown
;
849 StringPtrUnknown
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_ALIT_UNKNOWN
), NULL
);
850 StringPtr
= HiiGetString (mDpHiiHandle
, STRING_TOKEN (STR_DP_SECTION_CUMULATIVE
), NULL
);
851 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_SECTION_HEADER
), mDpHiiHandle
,
852 (StringPtr
== NULL
) ? StringPtrUnknown
: StringPtr
);
853 FreePool (StringPtr
);
854 FreePool (StringPtrUnknown
);
856 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_1
), mDpHiiHandle
);
857 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_2
), mDpHiiHandle
);
858 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_DASHES
), mDpHiiHandle
);
860 for ( TIndex
= 0; TIndex
< NumCum
; ++TIndex
) {
861 if (CumData
[TIndex
].Count
!= 0) {
862 AvgDur
= DivU64x32 (CumData
[TIndex
].Duration
, CumData
[TIndex
].Count
);
863 AvgDur
= DurationInMicroSeconds(AvgDur
);
864 Dur
= DurationInMicroSeconds(CumData
[TIndex
].Duration
);
865 MaxDur
= DurationInMicroSeconds(CumData
[TIndex
].MaxDur
);
866 MinDur
= DurationInMicroSeconds(CumData
[TIndex
].MinDur
);
868 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_CUMULATIVE_STATS
), mDpHiiHandle
,
869 CumData
[TIndex
].Name
,
870 CumData
[TIndex
].Count
,
880 // Print the custom cumulative data.
882 if (CustomCumulativeData
!= NULL
) {
883 if (CustomCumulativeData
->Count
!= 0) {
884 AvgDur
= DivU64x32 (CustomCumulativeData
->Duration
, CustomCumulativeData
->Count
);
885 AvgDur
= DurationInMicroSeconds (AvgDur
);
886 Dur
= DurationInMicroSeconds (CustomCumulativeData
->Duration
);
887 MaxDur
= DurationInMicroSeconds (CustomCumulativeData
->MaxDur
);
888 MinDur
= DurationInMicroSeconds (CustomCumulativeData
->MinDur
);
895 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_DP_CUMULATIVE_STATS
), mDpHiiHandle
,
896 CustomCumulativeData
->Name
,
897 CustomCumulativeData
->Count
,