TianoCore EDK2 master
Loading...
Searching...
No Matches
DpTrace.c
Go to the documentation of this file.
1
9#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
16#include <Library/PrintLib.h>
17#include <Library/HiiLib.h>
18#include <Library/PcdLib.h>
19
20#include "Dp.h"
21#include "Literals.h"
22#include "DpInternal.h"
23
49 IN UINTN LogEntryKey,
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
56 )
57{
58 if (LogEntryKey == mMeasurementNum) {
59 return 0;
60 }
61
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;
68
69 LogEntryKey++;
70
71 return LogEntryKey;
72}
73
91VOID
93 IN OUT PERF_CUM_DATA *CustomCumulativeData OPTIONAL
94 )
95{
96 MEASUREMENT_RECORD Measurement;
97 UINT64 Duration;
98 UINTN LogEntryKey;
99 INTN TIndex;
100
101 LogEntryKey = 0;
102 while ((LogEntryKey = GetPerformanceMeasurementRecord (
103 LogEntryKey,
104 &Measurement.Handle,
105 &Measurement.Token,
106 &Measurement.Module,
107 &Measurement.StartTimeStamp,
108 &Measurement.EndTimeStamp,
109 &Measurement.Identifier
110 )) != 0)
111 {
112 ++SummaryData.NumTrace; // Count the number of TRACE Measurement records
113 if (Measurement.EndTimeStamp == 0) {
114 ++SummaryData.NumIncomplete; // Count the incomplete records
115 continue;
116 }
117
118 if (Measurement.Handle != NULL) {
119 ++SummaryData.NumHandles; // Count the number of measurements with non-NULL handles
120 }
121
122 if (IsPhase (&Measurement)) {
123 ++SummaryData.NumSummary; // Count the number of major phases
124 } else {
125 // !IsPhase
126 if (Measurement.Handle == NULL) {
128 }
129 }
130
131 if (AsciiStrCmp (Measurement.Token, ALit_PEIM) == 0) {
132 ++SummaryData.NumPEIMs; // Count PEIM measurements
133 }
134
135 Duration = GetDuration (&Measurement);
136 TIndex = GetCumulativeItem (&Measurement);
137 if (TIndex >= 0) {
138 CumData[TIndex].Duration += Duration;
139 CumData[TIndex].Count++;
140 if ( Duration < CumData[TIndex].MinDur ) {
141 CumData[TIndex].MinDur = Duration;
142 }
143
144 if ( Duration > CumData[TIndex].MaxDur ) {
145 CumData[TIndex].MaxDur = Duration;
146 }
147 }
148
149 //
150 // Collect the data for custom cumulative data.
151 //
152 if ((CustomCumulativeData != NULL) && (AsciiStrCmp (Measurement.Token, CustomCumulativeData->Name) == 0)) {
153 CustomCumulativeData->Duration += Duration;
154 CustomCumulativeData->Count++;
155 if (Duration < CustomCumulativeData->MinDur) {
156 CustomCumulativeData->MinDur = Duration;
157 }
158
159 if (Duration > CustomCumulativeData->MaxDur) {
160 CustomCumulativeData->MaxDur = Duration;
161 }
162 }
163 }
164}
165
189 IN UINTN Limit,
190 IN BOOLEAN ExcludeFlag
191 )
192{
193 MEASUREMENT_RECORD Measurement;
194 UINT64 ElapsedTime;
195 UINT64 Duration;
196 CHAR16 *IncFlag;
197 UINTN LogEntryKey;
198 UINTN Count;
199 UINTN Index;
200 UINTN TIndex;
201
202 EFI_HANDLE *HandleBuffer;
203 UINTN HandleCount;
204 EFI_STATUS Status;
205 EFI_STRING StringPtrUnknown;
206
207 StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
208 IncFlag = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_ALL), NULL);
210 -1,
211 -1,
212 NULL,
213 STRING_TOKEN (STR_DP_SECTION_HEADER),
215 (IncFlag == NULL) ? StringPtrUnknown : IncFlag
216 );
217 FreePool (StringPtrUnknown);
218
219 // Get Handle information
220 //
221 Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);
222 if (EFI_ERROR (Status)) {
223 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), mDpHiiHandle, Status);
224 } else {
225 // We have successfully populated the HandleBuffer
226 // Display ALL Measurement Records
227 // Up to Limit lines displayed
228 // Display only records with Elapsed times >= mInterestThreshold
229 // Display driver names in Module field for records with Handles.
230 //
231 if (mShowId) {
232 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_HEADR2), mDpHiiHandle);
233 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_DASHES2), mDpHiiHandle);
234 } else {
235 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_HEADR), mDpHiiHandle);
236 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
237 }
238
239 LogEntryKey = 0;
240 Count = 0;
241 Index = 0;
242 while ( WITHIN_LIMIT (Count, Limit) &&
243 ((LogEntryKey = GetPerformanceMeasurementRecord (
244 LogEntryKey,
245 &Measurement.Handle,
246 &Measurement.Token,
247 &Measurement.Module,
248 &Measurement.StartTimeStamp,
249 &Measurement.EndTimeStamp,
250 &Measurement.Identifier
251 )) != 0)
252 )
253 {
254 ++Index; // Count every record. First record is 1.
255 ElapsedTime = 0;
256 SHELL_FREE_NON_NULL (IncFlag);
257 if (Measurement.EndTimeStamp != 0) {
258 Duration = GetDuration (&Measurement);
259 ElapsedTime = DurationInMicroSeconds (Duration);
260 IncFlag = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_COMPLETE), NULL);
261 } else {
262 IncFlag = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL); // Mark incomplete records
263 }
264
265 if (((Measurement.EndTimeStamp != 0) && (ElapsedTime < mInterestThreshold)) ||
266 ((ExcludeFlag) && (GetCumulativeItem (&Measurement) >= 0))
267 ) // Ignore "uninteresting" or excluded records
268 {
269 continue;
270 }
271
272 ++Count; // Count the number of records printed
273
274 // If Handle is non-zero, see if we can determine a name for the driver
275 AsciiStrToUnicodeStrS (Measurement.Module, mGaugeString, ARRAY_SIZE (mGaugeString)); // Use Module by default
276 AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));
277 if (Measurement.Handle != NULL) {
278 // See if the Handle is in the HandleBuffer
279 for (TIndex = 0; TIndex < HandleCount; TIndex++) {
280 if (Measurement.Handle == HandleBuffer[TIndex]) {
281 DpGetNameFromHandle (HandleBuffer[TIndex]);
282 break;
283 }
284 }
285 }
286
287 if (AsciiStrCmp (Measurement.Token, ALit_PEIM) == 0) {
288 UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", Measurement.Handle);
289 }
290
291 // Ensure that the argument strings are not too long.
292 mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;
293 mUnicodeToken[13] = 0;
294
295 if (mShowId) {
297 -1,
298 -1,
299 NULL,
300 STRING_TOKEN (STR_DP_ALL_VARS2),
302 Index, // 1 based, Which measurement record is being printed
303 IncFlag,
304 Measurement.Handle,
306 mUnicodeToken,
307 ElapsedTime,
308 Measurement.Identifier
309 );
310 } else {
312 -1,
313 -1,
314 NULL,
315 STRING_TOKEN (STR_DP_ALL_VARS),
317 Index, // 1 based, Which measurement record is being printed
318 IncFlag,
319 Measurement.Handle,
321 mUnicodeToken,
322 ElapsedTime
323 );
324 }
325
327 Status = EFI_ABORTED;
328 break;
329 }
330 }
331 }
332
333 if (HandleBuffer != NULL) {
334 FreePool (HandleBuffer);
335 }
336
337 SHELL_FREE_NON_NULL (IncFlag);
338
339 return Status;
340}
341
364 IN UINTN Limit,
365 IN BOOLEAN ExcludeFlag
366 )
367{
368 MEASUREMENT_RECORD Measurement;
369 UINT64 ElapsedTime;
370 UINT64 Duration;
371 UINTN LogEntryKey;
372 UINTN Count;
373 UINTN Index;
374
375 EFI_STRING StringPtr;
376 EFI_STRING StringPtrUnknown;
377 EFI_STATUS Status;
378
379 Status = EFI_SUCCESS;
380
381 StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
382 StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWTRACE), NULL);
384 -1,
385 -1,
386 NULL,
387 STRING_TOKEN (STR_DP_SECTION_HEADER),
389 (StringPtr == NULL) ? StringPtrUnknown : StringPtr
390 );
391 FreePool (StringPtr);
392 FreePool (StringPtrUnknown);
393
394 if (mShowId) {
395 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_HEADR2), mDpHiiHandle);
396 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_DASHES2), mDpHiiHandle);
397 } else {
398 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_HEADR), mDpHiiHandle);
399 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_DASHES), mDpHiiHandle);
400 }
401
402 LogEntryKey = 0;
403 Count = 0;
404 Index = 0;
405 while ( WITHIN_LIMIT (Count, Limit) &&
406 ((LogEntryKey = GetPerformanceMeasurementRecord (
407 LogEntryKey,
408 &Measurement.Handle,
409 &Measurement.Token,
410 &Measurement.Module,
411 &Measurement.StartTimeStamp,
412 &Measurement.EndTimeStamp,
413 &Measurement.Identifier
414 )) != 0)
415 )
416 {
417 ++Index; // Count every record. First record is 1.
418 ElapsedTime = 0;
419 if (Measurement.EndTimeStamp != 0) {
420 Duration = GetDuration (&Measurement);
421 ElapsedTime = DurationInMicroSeconds (Duration);
422 }
423
424 if ((ElapsedTime < mInterestThreshold) ||
425 ((ExcludeFlag) && (GetCumulativeItem (&Measurement) >= 0))
426 ) // Ignore "uninteresting" or Excluded records
427 {
428 continue;
429 }
430
431 ++Count; // Count the number of records printed
432
433 if (mShowId) {
435 -1,
436 -1,
437 NULL,
438 STRING_TOKEN (STR_DP_RAW_VARS2),
440 Index, // 1 based, Which measurement record is being printed
441 Measurement.Handle,
442 Measurement.StartTimeStamp,
443 Measurement.EndTimeStamp,
444 Measurement.Token,
445 Measurement.Module,
446 Measurement.Identifier
447 );
448 } else {
450 -1,
451 -1,
452 NULL,
453 STRING_TOKEN (STR_DP_RAW_VARS),
455 Index, // 1 based, Which measurement record is being printed
456 Measurement.Handle,
457 Measurement.StartTimeStamp,
458 Measurement.EndTimeStamp,
459 Measurement.Token,
460 Measurement.Module
461 );
462 }
463
465 Status = EFI_ABORTED;
466 break;
467 }
468 }
469
470 return Status;
471}
472
477VOID
479 VOID
480 )
481{
482 MEASUREMENT_RECORD Measurement;
483 UINT64 BdsTimeoutValue;
484 UINT64 SecTime;
485 UINT64 PeiTime;
486 UINT64 DxeTime;
487 UINT64 BdsTime;
488 UINT64 ElapsedTime;
489 UINT64 Duration;
490 UINT64 Total;
491 EFI_STRING StringPtr;
492 UINTN LogEntryKey;
493 EFI_STRING StringPtrUnknown;
494
495 BdsTimeoutValue = 0;
496 SecTime = 0;
497 PeiTime = 0;
498 DxeTime = 0;
499 BdsTime = 0;
500 //
501 // Get Execution Phase Statistics
502 //
503 StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
504 StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PHASES), NULL);
506 -1,
507 -1,
508 NULL,
509 STRING_TOKEN (STR_DP_SECTION_HEADER),
511 (StringPtr == NULL) ? StringPtrUnknown : StringPtr
512 );
513 FreePool (StringPtr);
514 FreePool (StringPtrUnknown);
515
516 LogEntryKey = 0;
517 while ((LogEntryKey = GetPerformanceMeasurementRecord (
518 LogEntryKey,
519 &Measurement.Handle,
520 &Measurement.Token,
521 &Measurement.Module,
522 &Measurement.StartTimeStamp,
523 &Measurement.EndTimeStamp,
524 &Measurement.Identifier
525 )) != 0)
526 {
527 if (Measurement.EndTimeStamp == 0) {
528 // Skip "incomplete" records
529 continue;
530 }
531
532 Duration = GetDuration (&Measurement);
533 if ( (Measurement.Handle != NULL)
534 && (AsciiStrCmp (Measurement.Token, ALit_BdsTO) == 0)
535 )
536 {
537 BdsTimeoutValue = Duration;
538 } else if (AsciiStrCmp (Measurement.Token, ALit_SEC) == 0) {
539 SecTime = Duration;
540 } else if (AsciiStrCmp (Measurement.Token, ALit_PEI) == 0) {
541 PeiTime = Duration;
542 } else if (AsciiStrCmp (Measurement.Token, ALit_DXE) == 0) {
543 DxeTime = Duration;
544 } else if (AsciiStrCmp (Measurement.Token, ALit_BDS) == 0) {
545 BdsTime = Duration;
546 }
547 }
548
549 Total = 0;
550
551 // print Reset End if it's valid
552 //
553 if (SecTime > mResetEnd) {
554 SecTime = SecTime - mResetEnd; // Calculate sec time duration start from the beginning of firmware image execution
555 ElapsedTime = DurationInMicroSeconds (mResetEnd); // Calculate elapsed time in microseconds
556 Total += DivU64x32 (ElapsedTime, 1000); // Accumulate time in milliseconds
557 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RESET_END), mDpHiiHandle, ElapsedTime);
558 }
559
560 // print SEC phase duration time
561 //
562 if (SecTime > 0) {
563 ElapsedTime = DurationInMicroSeconds (SecTime); // Calculate elapsed time in microseconds
564 Total += DivU64x32 (ElapsedTime, 1000); // Accumulate time in milliseconds
565 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SEC_PHASE), mDpHiiHandle, ElapsedTime);
566 }
567
568 // print PEI phase duration time
569 //
570 if (PeiTime > 0) {
571 ElapsedTime = DivU64x32 (PeiTime, 1000000);
572 Total += ElapsedTime;
573 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_PEI, ElapsedTime);
574 }
575
576 // print DXE phase duration time
577 //
578 if (DxeTime > 0) {
579 ElapsedTime = DivU64x32 (DxeTime, 1000000);
580 Total += ElapsedTime;
581 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_DXE, ElapsedTime);
582 }
583
584 // print BDS phase duration time
585 //
586 if (BdsTime > 0) {
587 ElapsedTime = DivU64x32 (BdsTime, 1000000);
588 Total += ElapsedTime;
589 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_BDS, ElapsedTime);
590 }
591
592 if (BdsTimeoutValue > 0) {
593 ElapsedTime = DivU64x32 (BdsTimeoutValue, 1000000);
594 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_BDSTO), mDpHiiHandle, ALit_BdsTO, ElapsedTime);
595 }
596
597 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TOTAL_DURATION), mDpHiiHandle, Total);
598}
599
611 IN BOOLEAN ExcludeFlag
612 )
613{
614 MEASUREMENT_RECORD Measurement;
615 UINT64 ElapsedTime;
616 UINT64 Duration;
617 EFI_HANDLE *HandleBuffer;
618 EFI_STRING StringPtr;
619 UINTN Index;
620 UINTN LogEntryKey;
621 UINTN Count;
622 UINTN HandleCount;
623 EFI_STATUS Status;
624 EFI_STRING StringPtrUnknown;
625
626 StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
627 StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_DRIVERS), NULL);
629 -1,
630 -1,
631 NULL,
632 STRING_TOKEN (STR_DP_SECTION_HEADER),
634 (StringPtr == NULL) ? StringPtrUnknown : StringPtr
635 );
636 FreePool (StringPtr);
637 FreePool (StringPtrUnknown);
638
639 Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);
640 if (EFI_ERROR (Status)) {
641 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), mDpHiiHandle, Status);
642 } else {
643 #if DP_DEBUG == 2
644 Print (L"There are %,d Handles defined.\n", (Size / sizeof (HandleBuffer[0])));
645 #endif
646
647 if (mShowId) {
648 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_SECTION2), mDpHiiHandle);
649 } else {
650 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_SECTION), mDpHiiHandle);
651 }
652
653 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
654
655 LogEntryKey = 0;
656 Count = 0;
657 while ((LogEntryKey = GetPerformanceMeasurementRecord (
658 LogEntryKey,
659 &Measurement.Handle,
660 &Measurement.Token,
661 &Measurement.Module,
662 &Measurement.StartTimeStamp,
663 &Measurement.EndTimeStamp,
664 &Measurement.Identifier
665 )) != 0)
666 {
667 Count++;
668 Duration = GetDuration (&Measurement);
669 ElapsedTime = DurationInMicroSeconds (Duration);
670 if ((ElapsedTime < mInterestThreshold) ||
671 (Measurement.EndTimeStamp == 0) ||
672 (!IsCorePerf (&Measurement)) ||
673 ((ExcludeFlag) && (GetCumulativeItem (&Measurement) >= 0))
674 ) // Ignore "uninteresting" or excluded records
675 {
676 continue;
677 }
678
679 mGaugeString[0] = 0; // Empty driver name by default
680 AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));
681 // See if the Handle is in the HandleBuffer
682 for (Index = 0; Index < HandleCount; Index++) {
683 if (Measurement.Handle == HandleBuffer[Index]) {
684 DpGetNameFromHandle (HandleBuffer[Index]); // Name is put into mGaugeString
685 break;
686 }
687 }
688
689 // Ensure that the argument strings are not too long.
690 mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;
691 mUnicodeToken[11] = 0;
692 if (mGaugeString[0] != 0) {
693 // Display the record if it has a valid handle.
694 if (mShowId) {
696 -1,
697 -1,
698 NULL,
699 STRING_TOKEN (STR_DP_HANDLE_VARS2),
701 Count, // 1 based, Which measurement record is being printed
702 Index + 1, // 1 based, Which handle is being printed
704 mUnicodeToken,
705 ElapsedTime,
706 Measurement.Identifier
707 );
708 } else {
710 -1,
711 -1,
712 NULL,
713 STRING_TOKEN (STR_DP_HANDLE_VARS),
715 Count, // 1 based, Which measurement record is being printed
716 Index + 1, // 1 based, Which handle is being printed
718 mUnicodeToken,
719 ElapsedTime
720 );
721 }
722 }
723
725 Status = EFI_ABORTED;
726 break;
727 }
728 }
729 }
730
731 if (HandleBuffer != NULL) {
732 FreePool (HandleBuffer);
733 }
734
735 return Status;
736}
737
748 VOID
749 )
750{
751 MEASUREMENT_RECORD Measurement;
752 UINT64 Duration;
753 UINT64 ElapsedTime;
754 EFI_STRING StringPtr;
755 UINTN LogEntryKey;
756 UINTN TIndex;
757 EFI_STRING StringPtrUnknown;
758 EFI_STATUS Status;
759
760 Status = EFI_SUCCESS;
761
762 StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
763 StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PEIMS), NULL);
765 -1,
766 -1,
767 NULL,
768 STRING_TOKEN (STR_DP_SECTION_HEADER),
770 (StringPtr == NULL) ? StringPtrUnknown : StringPtr
771 );
772 FreePool (StringPtr);
773 FreePool (StringPtrUnknown);
774
775 if (mShowId) {
776 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_SECTION2), mDpHiiHandle);
777 } else {
778 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_SECTION), mDpHiiHandle);
779 }
780
781 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
782 TIndex = 0;
783 LogEntryKey = 0;
784 while ((LogEntryKey = GetPerformanceMeasurementRecord (
785 LogEntryKey,
786 &Measurement.Handle,
787 &Measurement.Token,
788 &Measurement.Module,
789 &Measurement.StartTimeStamp,
790 &Measurement.EndTimeStamp,
791 &Measurement.Identifier
792 )) != 0)
793 {
794 TIndex++;
795 if ((Measurement.EndTimeStamp == 0) ||
796 (AsciiStrCmp (Measurement.Token, ALit_PEIM) != 0)
797 )
798 {
799 continue;
800 }
801
802 Duration = GetDuration (&Measurement);
803 ElapsedTime = DurationInMicroSeconds (Duration); // Calculate elapsed time in microseconds
804 if (ElapsedTime >= mInterestThreshold) {
805 // PEIM FILE Handle is the start address of its FFS file that contains its file guid.
806 if (mShowId) {
808 -1,
809 -1,
810 NULL,
811 STRING_TOKEN (STR_DP_PEIM_VARS2),
813 TIndex, // 1 based, Which measurement record is being printed
814 Measurement.Handle, // file guid
815 ElapsedTime,
816 Measurement.Identifier
817 );
818 } else {
820 -1,
821 -1,
822 NULL,
823 STRING_TOKEN (STR_DP_PEIM_VARS),
825 TIndex, // 1 based, Which measurement record is being printed
826 Measurement.Handle, // file guid
827 ElapsedTime
828 );
829 }
830 }
831
833 Status = EFI_ABORTED;
834 break;
835 }
836 }
837
838 return Status;
839}
840
854 VOID
855 )
856{
857 MEASUREMENT_RECORD Measurement;
858 UINT64 Duration;
859 UINT64 ElapsedTime;
860 EFI_STRING StringPtr;
861 UINTN LogEntryKey;
862 UINTN Index; // Index, or number, of the measurement record being processed
863 EFI_STRING StringPtrUnknown;
864 EFI_STATUS Status;
865
866 Status = EFI_SUCCESS;
867
868 StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
869 StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_GENERAL), NULL);
871 -1,
872 -1,
873 NULL,
874 STRING_TOKEN (STR_DP_SECTION_HEADER),
876 (StringPtr == NULL) ? StringPtrUnknown : StringPtr
877 );
878 FreePool (StringPtr);
879 FreePool (StringPtrUnknown);
880
881 if (mShowId) {
882 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_SECTION2), mDpHiiHandle);
883 } else {
884 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_SECTION), mDpHiiHandle);
885 }
886
887 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
888
889 Index = 1;
890 LogEntryKey = 0;
891
892 while ((LogEntryKey = GetPerformanceMeasurementRecord (
893 LogEntryKey,
894 &Measurement.Handle,
895 &Measurement.Token,
896 &Measurement.Module,
897 &Measurement.StartTimeStamp,
898 &Measurement.EndTimeStamp,
899 &Measurement.Identifier
900 )) != 0)
901 {
903 AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));
904 mGaugeString[25] = 0;
905 mUnicodeToken[31] = 0;
906 if ( !(IsPhase (&Measurement) ||
907 IsCorePerf (&Measurement) ||
908 (Measurement.EndTimeStamp == 0)
909 ))
910 {
911 Duration = GetDuration (&Measurement);
912 ElapsedTime = DurationInMicroSeconds (Duration);
913 if (ElapsedTime >= mInterestThreshold) {
914 if (mShowId) {
916 -1,
917 -1,
918 NULL,
919 STRING_TOKEN (STR_DP_GLOBAL_VARS2),
921 Index,
923 mUnicodeToken,
924 ElapsedTime,
925 Measurement.Identifier
926 );
927 } else {
929 -1,
930 -1,
931 NULL,
932 STRING_TOKEN (STR_DP_GLOBAL_VARS),
934 Index,
936 mUnicodeToken,
937 ElapsedTime
938 );
939 }
940 }
941 }
942
944 Status = EFI_ABORTED;
945 break;
946 }
947
948 Index++;
949 }
950
951 return Status;
952}
953
965VOID
967 IN PERF_CUM_DATA *CustomCumulativeData OPTIONAL
968 )
969{
970 UINT64 AvgDur; // the computed average duration
971 UINT64 Dur;
972 UINT64 MinDur;
973 UINT64 MaxDur;
974 EFI_STRING StringPtr;
975 UINTN TIndex;
976 EFI_STRING StringPtrUnknown;
977
978 StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
979 StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_CUMULATIVE), NULL);
981 -1,
982 -1,
983 NULL,
984 STRING_TOKEN (STR_DP_SECTION_HEADER),
986 (StringPtr == NULL) ? StringPtrUnknown : StringPtr
987 );
988 FreePool (StringPtr);
989 FreePool (StringPtrUnknown);
990
991 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_1), mDpHiiHandle);
992 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_2), mDpHiiHandle);
993 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
994
995 for ( TIndex = 0; TIndex < NumCum; ++TIndex) {
996 if (CumData[TIndex].Count != 0) {
997 AvgDur = DivU64x32 (CumData[TIndex].Duration, CumData[TIndex].Count);
998 AvgDur = DurationInMicroSeconds (AvgDur);
999 Dur = DurationInMicroSeconds (CumData[TIndex].Duration);
1000 MaxDur = DurationInMicroSeconds (CumData[TIndex].MaxDur);
1001 MinDur = DurationInMicroSeconds (CumData[TIndex].MinDur);
1002
1004 -1,
1005 -1,
1006 NULL,
1007 STRING_TOKEN (STR_DP_CUMULATIVE_STATS),
1009 CumData[TIndex].Name,
1010 CumData[TIndex].Count,
1011 Dur,
1012 AvgDur,
1013 MinDur,
1014 MaxDur
1015 );
1016 }
1017 }
1018
1019 //
1020 // Print the custom cumulative data.
1021 //
1022 if (CustomCumulativeData != NULL) {
1023 if (CustomCumulativeData->Count != 0) {
1024 AvgDur = DivU64x32 (CustomCumulativeData->Duration, CustomCumulativeData->Count);
1025 AvgDur = DurationInMicroSeconds (AvgDur);
1026 Dur = DurationInMicroSeconds (CustomCumulativeData->Duration);
1027 MaxDur = DurationInMicroSeconds (CustomCumulativeData->MaxDur);
1028 MinDur = DurationInMicroSeconds (CustomCumulativeData->MinDur);
1029 } else {
1030 AvgDur = 0;
1031 Dur = 0;
1032 MaxDur = 0;
1033 MinDur = 0;
1034 }
1035
1037 -1,
1038 -1,
1039 NULL,
1040 STRING_TOKEN (STR_DP_CUMULATIVE_STATS),
1042 CustomCumulativeData->Name,
1043 CustomCumulativeData->Count,
1044 Dur,
1045 AvgDur,
1046 MinDur,
1047 MaxDur
1048 );
1049 }
1050}
UINT64 UINTN
INT64 INTN
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
Definition: String.c:716
RETURN_STATUS EFIAPI AsciiStrToUnicodeStrS(IN CONST CHAR8 *Source, OUT CHAR16 *Destination, IN UINTN DestMax)
Definition: SafeString.c:2873
PERF_CUM_DATA CumData[]
Items for which to gather cumulative statistics.
Definition: Dp.c:67
PERF_SUMMARY_DATA SummaryData
Create the SummaryData structure and init. to ZERO.
Definition: Dp.c:62
CHAR16 mGaugeString[DP_GAUGE_STRING_LENGTH+1]
Definition: Dp.c:52
UINT32 const NumCum
Number of items for which we are gathering cumulative statistics.
Definition: Dp.c:76
EFI_HII_HANDLE mDpHiiHandle
Definition: Dp.c:39
#define WITHIN_LIMIT(C, L)
Determine whether 0 <= C < L. If L == 0, return true regardless of C.
Definition: Dp.h:56
INTN GetCumulativeItem(IN MEASUREMENT_RECORD *Measurement)
Definition: DpUtilities.c:413
BOOLEAN IsPhase(IN MEASUREMENT_RECORD *Measurement)
Definition: DpUtilities.c:91
VOID DpGetNameFromHandle(IN EFI_HANDLE Handle)
Definition: DpUtilities.c:208
UINT64 GetDuration(IN OUT MEASUREMENT_RECORD *Measurement)
Definition: DpUtilities.c:57
BOOLEAN IsCorePerf(IN MEASUREMENT_RECORD *Measurement)
Definition: DpUtilities.c:116
UINT64 DurationInMicroSeconds(IN UINT64 Duration)
Definition: DpUtilities.c:392
UINTN GetPerformanceMeasurementRecord(IN UINTN LogEntryKey, OUT CONST VOID **Handle, OUT CONST CHAR8 **Token, OUT CONST CHAR8 **Module, OUT UINT64 *StartTimeStamp, OUT UINT64 *EndTimeStamp, OUT UINT32 *Identifier)
Definition: DpTrace.c:48
VOID GatherStatistics(IN OUT PERF_CUM_DATA *CustomCumulativeData OPTIONAL)
Definition: DpTrace.c:92
EFI_STATUS ProcessGlobal(VOID)
Definition: DpTrace.c:853
EFI_STATUS DumpRawTrace(IN UINTN Limit, IN BOOLEAN ExcludeFlag)
Definition: DpTrace.c:363
EFI_STATUS ProcessPeims(VOID)
Definition: DpTrace.c:747
EFI_STATUS DumpAllTrace(IN UINTN Limit, IN BOOLEAN ExcludeFlag)
Definition: DpTrace.c:188
VOID ProcessPhases(VOID)
Definition: DpTrace.c:478
EFI_STATUS ProcessHandles(IN BOOLEAN ExcludeFlag)
Definition: DpTrace.c:610
VOID ProcessCumulative(IN PERF_CUM_DATA *CustomCumulativeData OPTIONAL)
Definition: DpTrace.c:966
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STRING EFIAPI HiiGetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:211
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
BOOLEAN EFIAPI ShellGetExecutionBreakFlag(VOID)
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:113
@ AllHandles
Definition: UefiSpec.h:1509
UINT32 Identifier
Identifier.
Definition: Dp.h:100
CONST CHAR8 * Module
Module string name.
Definition: Dp.h:97
UINT64 StartTimeStamp
Start time point.
Definition: Dp.h:98
CONST CHAR8 * Token
Measured token string name.
Definition: Dp.h:96
UINT64 EndTimeStamp
End time point.
Definition: Dp.h:99
UINT64 MaxDur
Largest duration encountered.
Definition: Dp.h:80
UINT64 MinDur
Smallest duration encountered.
Definition: Dp.h:79
UINT64 Duration
Cumulative duration for this item.
Definition: Dp.h:78
UINT32 Count
Total number of measurements accumulated.
Definition: Dp.h:82
UINT32 NumSummary
Number of summary section measurements.
Definition: Dp.h:88
UINT32 NumHandles
Number of measurements with handles.
Definition: Dp.h:89
UINT32 NumPEIMs
Number of measurements of PEIMs.
Definition: Dp.h:90
UINT32 NumTrace
Number of recorded TRACE performance measurements.
Definition: Dp.h:86
UINT32 NumGlobal
Number of measurements with END value and NULL handle.
Definition: Dp.h:91
UINT32 NumIncomplete
Number of measurements with no END value.
Definition: Dp.h:87