2 Performance library instance used in PEI phase.
4 This file implements all APIs in Performance Library class in MdePkg. It creates
5 performance logging GUIDed HOB on the first performance logging and then logs the
6 performance data to the GUIDed HOB. Due to the limitation of temporary RAM, the maximum
7 number of performance logging entry is specified by PcdMaxPeiPerformanceLogEntries or
8 PcdMaxPeiPerformanceLogEntries16.
10 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
11 (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
12 SPDX-License-Identifier: BSD-2-Clause-Patent
19 #include <Guid/ExtendedFirmwarePerformance.h>
20 #include <Guid/PerformanceMeasurement.h>
22 #include <Library/PerformanceLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/HobLib.h>
25 #include <Library/BaseLib.h>
26 #include <Library/TimerLib.h>
27 #include <Library/PcdLib.h>
28 #include <Library/BaseMemoryLib.h>
30 #define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
31 #define PEI_MAX_RECORD_SIZE (sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD) + STRING_SIZE)
35 Return the pointer to the FPDT record in the allocated memory.
37 @param RecordSize The size of FPDT record.
38 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.
39 @param PeiPerformanceLogHeader Pointer to the header of the PEI Performance records in the GUID Hob.
41 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.
42 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.
47 IN OUT FPDT_RECORD_PTR
*FpdtRecordPtr
,
48 IN OUT FPDT_PEI_EXT_PERF_HEADER
**PeiPerformanceLogHeader
51 UINT16 PeiPerformanceLogEntries
;
52 UINTN PeiPerformanceSize
;
53 UINT8
*PeiFirmwarePerformance
;
54 EFI_HOB_GUID_TYPE
*GuidHob
;
57 // Get the number of PeiPerformanceLogEntries form PCD.
59 PeiPerformanceLogEntries
= (UINT16
) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16
) != 0 ?
60 PcdGet16 (PcdMaxPeiPerformanceLogEntries16
) :
61 PcdGet8 (PcdMaxPeiPerformanceLogEntries
));
64 // Create GUID HOB Data.
66 GuidHob
= GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
);
67 PeiFirmwarePerformance
= NULL
;
68 while (GuidHob
!= NULL
) {
70 // PEI Performance HOB was found, then return the existing one.
72 PeiFirmwarePerformance
= (UINT8
*)GET_GUID_HOB_DATA (GuidHob
);
73 *PeiPerformanceLogHeader
= (FPDT_PEI_EXT_PERF_HEADER
*)PeiFirmwarePerformance
;
74 if (!(*PeiPerformanceLogHeader
)->HobIsFull
&& (*PeiPerformanceLogHeader
)->SizeOfAllEntries
+ RecordSize
> (PeiPerformanceLogEntries
* PEI_MAX_RECORD_SIZE
)) {
75 (*PeiPerformanceLogHeader
)->HobIsFull
= TRUE
;
77 if (!(*PeiPerformanceLogHeader
)->HobIsFull
&& (*PeiPerformanceLogHeader
)->SizeOfAllEntries
+ RecordSize
<= (PeiPerformanceLogEntries
* PEI_MAX_RECORD_SIZE
)) {
78 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(PeiFirmwarePerformance
+ sizeof (FPDT_PEI_EXT_PERF_HEADER
) + (*PeiPerformanceLogHeader
)->SizeOfAllEntries
);
82 // Previous HOB is used, then find next one.
84 GuidHob
= GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, GET_NEXT_HOB (GuidHob
));
87 if (GuidHob
== NULL
) {
89 // PEI Performance HOB was not found, then build one.
91 PeiPerformanceSize
= sizeof (FPDT_PEI_EXT_PERF_HEADER
) +
92 PEI_MAX_RECORD_SIZE
* PeiPerformanceLogEntries
;
93 PeiFirmwarePerformance
= (UINT8
*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, PeiPerformanceSize
);
94 if (PeiFirmwarePerformance
!= NULL
) {
95 ZeroMem (PeiFirmwarePerformance
, PeiPerformanceSize
);
96 (*PeiPerformanceLogHeader
) = (FPDT_PEI_EXT_PERF_HEADER
*)PeiFirmwarePerformance
;
97 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(PeiFirmwarePerformance
+ sizeof (FPDT_PEI_EXT_PERF_HEADER
));
101 if (PeiFirmwarePerformance
== NULL
) {
103 // there is no enough resource to store performance data
105 return EFI_OUT_OF_RESOURCES
;
112 Check whether the Token is a known one which is uesed by core.
114 @param Token Pointer to a Null-terminated ASCII string
116 @retval TRUE Is a known one used by core.
117 @retval FALSE Not a known one.
122 IN CONST CHAR8
*Token
129 if (AsciiStrCmp (Token
, SEC_TOK
) == 0 ||
130 AsciiStrCmp (Token
, PEI_TOK
) == 0 ||
131 AsciiStrCmp (Token
, DXE_TOK
) == 0 ||
132 AsciiStrCmp (Token
, BDS_TOK
) == 0 ||
133 AsciiStrCmp (Token
, DRIVERBINDING_START_TOK
) == 0 ||
134 AsciiStrCmp (Token
, DRIVERBINDING_SUPPORT_TOK
) == 0 ||
135 AsciiStrCmp (Token
, DRIVERBINDING_STOP_TOK
) == 0 ||
136 AsciiStrCmp (Token
, LOAD_IMAGE_TOK
) == 0 ||
137 AsciiStrCmp (Token
, START_IMAGE_TOK
) == 0 ||
138 AsciiStrCmp (Token
, PEIM_TOK
) == 0) {
146 Check whether the ID is a known one which map to the known Token.
148 @param Identifier 32-bit identifier.
150 @retval TRUE Is a known one used by core.
151 @retval FALSE Not a known one.
159 if (Identifier
== MODULE_START_ID
||
160 Identifier
== MODULE_END_ID
||
161 Identifier
== MODULE_LOADIMAGE_START_ID
||
162 Identifier
== MODULE_LOADIMAGE_END_ID
||
163 Identifier
== MODULE_DB_START_ID
||
164 Identifier
== MODULE_DB_END_ID
||
165 Identifier
== MODULE_DB_SUPPORT_START_ID
||
166 Identifier
== MODULE_DB_SUPPORT_END_ID
||
167 Identifier
== MODULE_DB_STOP_START_ID
||
168 Identifier
== MODULE_DB_STOP_END_ID
) {
176 Get the FPDT record identifier.
178 @param Attribute The attribute of the Record.
179 PerfStartEntry: Start Record.
180 PerfEndEntry: End Record.
181 @param Handle Pointer to environment specific context used to identify the component being measured.
182 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.
183 @param ProgressID On return, pointer to the ProgressID.
185 @retval EFI_SUCCESS Get record info successfully.
186 @retval EFI_INVALID_PARAMETER No matched FPDT record.
191 IN BOOLEAN Attribute
,
192 IN CONST VOID
*Handle
,
193 IN CONST CHAR8
*String
,
194 OUT UINT16
*ProgressID
198 // Get the ProgressID based on the Token.
199 // When PcdEdkiiFpdtStringRecordEnableOnly is TRUE, all records are with type of FPDT_DYNAMIC_STRING_EVENT_TYPE.
201 if (String
!= NULL
) {
202 if (AsciiStrCmp (String
, LOAD_IMAGE_TOK
) == 0) { // "LoadImage:"
203 if (Attribute
== PerfStartEntry
) {
204 *ProgressID
= MODULE_LOADIMAGE_START_ID
;
206 *ProgressID
= MODULE_LOADIMAGE_END_ID
;
208 } else if (AsciiStrCmp (String
, SEC_TOK
) == 0 || // "SEC"
209 AsciiStrCmp (String
, PEI_TOK
) == 0) { // "PEI"
210 if (Attribute
== PerfStartEntry
) {
211 *ProgressID
= PERF_CROSSMODULE_START_ID
;
213 *ProgressID
= PERF_CROSSMODULE_END_ID
;
215 } else if (AsciiStrCmp (String
, PEIM_TOK
) == 0) { // "PEIM"
216 if (Attribute
== PerfStartEntry
) {
217 *ProgressID
= MODULE_START_ID
;
219 *ProgressID
= MODULE_END_ID
;
221 } else { //Pref used in Modules.
222 if (Attribute
== PerfStartEntry
) {
223 *ProgressID
= PERF_INMODULE_START_ID
;
225 *ProgressID
= PERF_INMODULE_END_ID
;
228 } else if (Handle
!= NULL
) { //Pref used in Modules.
229 if (Attribute
== PerfStartEntry
) {
230 *ProgressID
= PERF_INMODULE_START_ID
;
232 *ProgressID
= PERF_INMODULE_END_ID
;
235 return EFI_INVALID_PARAMETER
;
242 Copies the string from Source into Destination and updates Length with the
245 @param Destination - destination of the string copy
246 @param Source - pointer to the source string which will get copied
247 @param Length - pointer to a length variable to be updated
251 CopyStringIntoPerfRecordAndUpdateLength (
252 IN OUT CHAR8
*Destination
,
253 IN CONST CHAR8
*Source
,
260 ASSERT (Source
!= NULL
);
262 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
263 DestMax
= STRING_SIZE
;
265 DestMax
= AsciiStrSize (Source
);
266 if (DestMax
> STRING_SIZE
) {
267 DestMax
= STRING_SIZE
;
270 StringLen
= AsciiStrLen (Source
);
271 if (StringLen
>= DestMax
) {
272 StringLen
= DestMax
-1;
275 AsciiStrnCpyS(Destination
, DestMax
, Source
, StringLen
);
276 *Length
+= (UINT8
)DestMax
;
283 Convert PEI performance log to FPDT String boot record.
285 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
286 @param Guid - Pointer to a GUID.
287 @param String - Pointer to a string describing the measurement.
288 @param Ticker - 64-bit time stamp.
289 @param Address - Pointer to a location in memory relevant to the measurement.
290 @param PerfId - Performance identifier describing the type of measurement.
291 @param Attribute - The attribute of the measurement. According to attribute can create a start
292 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
293 or a general record for other Perf macros.
295 @retval EFI_SUCCESS - Successfully created performance record.
296 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
297 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
298 pointer or invalid PerfId.
303 IN CONST VOID
*CallerIdentifier OPTIONAL
,
304 IN CONST VOID
*Guid OPTIONAL
,
305 IN CONST CHAR8
*String OPTIONAL
,
307 IN UINT64 Address OPTIONAL
,
309 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
312 FPDT_RECORD_PTR FpdtRecordPtr
;
313 CONST VOID
*ModuleGuid
;
314 CONST CHAR8
*StringPtr
;
317 FPDT_PEI_EXT_PERF_HEADER
*PeiPerformanceLogHeader
;
320 FpdtRecordPtr
.RecordHeader
= NULL
;
321 PeiPerformanceLogHeader
= NULL
;
324 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
325 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
327 if (Attribute
!= PerfEntry
) {
329 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
330 // !!! Note: If the Perf is not the known Token used in the core but have same
331 // ID with the core Token, this case will not be supported.
332 // And in currtnt usage mode, for the unkown ID, there is a general rule:
333 // If it is start pref: the lower 4 bits of the ID should be 0.
334 // If it is end pref: the lower 4 bits of the ID should not be 0.
335 // If input ID doesn't follow the rule, we will adjust it.
337 if ((PerfId
!= 0) && (IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
338 return EFI_UNSUPPORTED
;
339 } else if ((PerfId
!= 0) && (!IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
340 if (Attribute
== PerfStartEntry
&& ((PerfId
& 0x000F) != 0)) {
342 } else if ((Attribute
== PerfEndEntry
) && ((PerfId
& 0x000F) == 0)) {
345 } else if (PerfId
== 0) {
346 Status
= GetFpdtRecordId (Attribute
, CallerIdentifier
, String
, &PerfId
);
347 if (EFI_ERROR (Status
)) {
354 // 2. Get the buffer to store the FPDT record.
356 Status
= GetFpdtRecordPtr (PEI_MAX_RECORD_SIZE
, &FpdtRecordPtr
, &PeiPerformanceLogHeader
);
357 if (EFI_ERROR (Status
)) {
362 // 3 Get the TimeStamp.
365 Ticker
= GetPerformanceCounter ();
366 TimeStamp
= GetTimeInNanoSecond (Ticker
);
367 } else if (Ticker
== 1) {
370 TimeStamp
= GetTimeInNanoSecond (Ticker
);
374 // 4.Get the ModuleGuid.
376 if (CallerIdentifier
!= NULL
) {
377 ModuleGuid
= CallerIdentifier
;
379 ModuleGuid
= &gEfiCallerIdGuid
;
383 // 5. Fill in the FPDT record according to different Performance Identifier.
386 case MODULE_START_ID
:
388 StringPtr
= PEIM_TOK
;
389 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
390 FpdtRecordPtr
.GuidEvent
->Header
.Type
= FPDT_GUID_EVENT_TYPE
;
391 FpdtRecordPtr
.GuidEvent
->Header
.Length
= sizeof (FPDT_GUID_EVENT_RECORD
);
392 FpdtRecordPtr
.GuidEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
393 FpdtRecordPtr
.GuidEvent
->ProgressID
= PerfId
;
394 FpdtRecordPtr
.GuidEvent
->Timestamp
= TimeStamp
;
395 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
399 case MODULE_LOADIMAGE_START_ID
:
400 case MODULE_LOADIMAGE_END_ID
:
401 StringPtr
= LOAD_IMAGE_TOK
;
402 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
403 FpdtRecordPtr
.GuidQwordEvent
->Header
.Type
= FPDT_GUID_QWORD_EVENT_TYPE
;
404 FpdtRecordPtr
.GuidQwordEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_EVENT_RECORD
);
405 FpdtRecordPtr
.GuidQwordEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
406 FpdtRecordPtr
.GuidQwordEvent
->ProgressID
= PerfId
;
407 FpdtRecordPtr
.GuidQwordEvent
->Timestamp
= TimeStamp
;
408 if (PerfId
== MODULE_LOADIMAGE_START_ID
) {
409 PeiPerformanceLogHeader
->LoadImageCount
++;
411 FpdtRecordPtr
.GuidQwordEvent
->Qword
= PeiPerformanceLogHeader
->LoadImageCount
;
412 CopyMem (&FpdtRecordPtr
.GuidQwordEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
416 case PERF_EVENTSIGNAL_START_ID
:
417 case PERF_EVENTSIGNAL_END_ID
:
418 case PERF_CALLBACK_START_ID
:
419 case PERF_CALLBACK_END_ID
:
420 if (String
== NULL
|| Guid
== NULL
) {
421 return EFI_INVALID_PARAMETER
;
424 if (AsciiStrLen (String
) == 0) {
425 StringPtr
= "unknown name";
427 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
428 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Type
= FPDT_DUAL_GUID_STRING_EVENT_TYPE
;
429 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
= sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD
);
430 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
431 FpdtRecordPtr
.DualGuidStringEvent
->ProgressID
= PerfId
;
432 FpdtRecordPtr
.DualGuidStringEvent
->Timestamp
= TimeStamp
;
433 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid1
, ModuleGuid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid1
));
434 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid2
, Guid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid2
));
435 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DualGuidStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
);
440 case PERF_FUNCTION_START_ID
:
441 case PERF_FUNCTION_END_ID
:
442 case PERF_INMODULE_START_ID
:
443 case PERF_INMODULE_END_ID
:
444 case PERF_CROSSMODULE_START_ID
:
445 case PERF_CROSSMODULE_END_ID
:
446 if (String
!= NULL
&& AsciiStrLen (String
) != 0) {
449 StringPtr
= "unknown name";
451 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
452 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
453 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
454 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
455 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
456 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
457 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
458 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
463 if (Attribute
!= PerfEntry
) {
464 if (String
!= NULL
&& AsciiStrLen (String
) != 0) {
467 StringPtr
= "unknown name";
469 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
470 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
471 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
472 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
473 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
474 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
475 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
476 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
479 return EFI_INVALID_PARAMETER
;
485 // 5.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
487 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
488 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
489 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
490 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
491 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
492 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
495 // Cache the event guid in string event record.
497 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, Guid
, sizeof (EFI_GUID
));
499 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
501 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
505 // 6. Update the length of the used buffer after fill in the record.
507 PeiPerformanceLogHeader
->SizeOfAllEntries
+= FpdtRecordPtr
.RecordHeader
->Length
;
513 Creates a record for the beginning of a performance measurement.
515 If TimeStamp is zero, then this function reads the current time stamp
516 and adds that time stamp value to the record as the start time.
518 If TimeStamp is one, then this function reads 0 as the start time.
520 If TimeStamp is other value, then TimeStamp is added to the record as the start time.
522 @param Handle Pointer to environment specific context used
523 to identify the component being measured.
524 @param Token Pointer to a Null-terminated ASCII string
525 that identifies the component being measured.
526 @param Module Pointer to a Null-terminated ASCII string
527 that identifies the module being measured.
528 @param TimeStamp 64-bit time stamp.
529 @param Identifier 32-bit identifier. If the value is 0, the created record
530 is same as the one created by StartPerformanceMeasurement.
532 @retval RETURN_SUCCESS The start of the measurement was recorded.
533 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
538 StartPerformanceMeasurementEx (
539 IN CONST VOID
*Handle OPTIONAL
,
540 IN CONST CHAR8
*Token OPTIONAL
,
541 IN CONST CHAR8
*Module OPTIONAL
,
550 } else if (Module
!= NULL
) {
556 return (RETURN_STATUS
)InsertFpdtRecord (Handle
, NULL
, String
, TimeStamp
, 0, (UINT16
)Identifier
, PerfStartEntry
);
562 Creates a record for the end of a performance measurement.
564 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.
565 If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.
566 If the TimeStamp is one, then this function reads 0 as the end time.
568 @param Handle Pointer to environment specific context used
569 to identify the component being measured.
570 @param Token Pointer to a Null-terminated ASCII string
571 that identifies the component being measured.
572 @param Module Pointer to a Null-terminated ASCII string
573 that identifies the module being measured.
574 @param TimeStamp 64-bit time stamp.
575 @param Identifier 32-bit identifier. If the value is 0, the found record
576 is same as the one found by EndPerformanceMeasurement.
578 @retval RETURN_SUCCESS The end of the measurement was recorded.
579 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
584 EndPerformanceMeasurementEx (
585 IN CONST VOID
*Handle OPTIONAL
,
586 IN CONST CHAR8
*Token OPTIONAL
,
587 IN CONST CHAR8
*Module OPTIONAL
,
596 } else if (Module
!= NULL
) {
602 return (RETURN_STATUS
)InsertFpdtRecord (Handle
, NULL
, String
, TimeStamp
, 0, (UINT16
)Identifier
, PerfEndEntry
);
606 Attempts to retrieve a performance measurement log entry from the performance measurement log.
607 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
608 and then assign the Identifier with 0.
610 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
611 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
612 and the key for the second entry in the log is returned. If the performance log is empty,
613 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
614 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
615 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
616 retrieved and an implementation specific non-zero key value that specifies the end of the performance
617 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
618 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
619 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
620 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
621 If Handle is NULL, then ASSERT().
622 If Token is NULL, then ASSERT().
623 If Module is NULL, then ASSERT().
624 If StartTimeStamp is NULL, then ASSERT().
625 If EndTimeStamp is NULL, then ASSERT().
626 If Identifier is NULL, then ASSERT().
628 !!!NOT Support yet!!!
630 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
631 0, then the first performance measurement log entry is retrieved.
632 On exit, the key of the next performance of entry entry.
633 @param Handle Pointer to environment specific context used to identify the component
635 @param Token Pointer to a Null-terminated ASCII string that identifies the component
637 @param Module Pointer to a Null-terminated ASCII string that identifies the module
639 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
641 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
643 @param Identifier Pointer to the 32-bit identifier that was recorded.
645 @return The key for the next performance log entry (in general case).
650 GetPerformanceMeasurementEx (
651 IN UINTN LogEntryKey
,
652 OUT CONST VOID
**Handle
,
653 OUT CONST CHAR8
**Token
,
654 OUT CONST CHAR8
**Module
,
655 OUT UINT64
*StartTimeStamp
,
656 OUT UINT64
*EndTimeStamp
,
657 OUT UINT32
*Identifier
664 Creates a record for the beginning of a performance measurement.
666 If TimeStamp is zero, then this function reads the current time stamp
667 and adds that time stamp value to the record as the start time.
669 If TimeStamp is one, then this function reads 0 as the start time.
671 If TimeStamp is other value, then TimeStamp is added to the record as the start time.
674 @param Handle Pointer to environment specific context used
675 to identify the component being measured.
676 @param Token Pointer to a Null-terminated ASCII string
677 that identifies the component being measured.
678 @param Module Pointer to a Null-terminated ASCII string
679 that identifies the module being measured.
680 @param TimeStamp 64-bit time stamp.
682 @retval RETURN_SUCCESS The start of the measurement was recorded.
683 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
688 StartPerformanceMeasurement (
689 IN CONST VOID
*Handle OPTIONAL
,
690 IN CONST CHAR8
*Token OPTIONAL
,
691 IN CONST CHAR8
*Module OPTIONAL
,
695 return StartPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
700 Creates a record for the end of a performance measurement.
702 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.
703 If the TimeStamp is zero, then this function reads the current time stamp and adds that time stamp value to the record as the end time.
704 If the TimeStamp is one, then this function reads 0 as the end time.
706 @param Handle Pointer to environment specific context used
707 to identify the component being measured.
708 @param Token Pointer to a Null-terminated ASCII string
709 that identifies the component being measured.
710 @param Module Pointer to a Null-terminated ASCII string
711 that identifies the module being measured.
712 @param TimeStamp 64-bit time stamp.
714 @retval RETURN_SUCCESS The end of the measurement was recorded.
715 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
720 EndPerformanceMeasurement (
721 IN CONST VOID
*Handle OPTIONAL
,
722 IN CONST CHAR8
*Token OPTIONAL
,
723 IN CONST CHAR8
*Module OPTIONAL
,
727 return EndPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
731 Attempts to retrieve a performance measurement log entry from the performance measurement log.
732 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
733 and then eliminate the Identifier.
735 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
736 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
737 and the key for the second entry in the log is returned. If the performance log is empty,
738 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
739 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
740 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
741 retrieved and an implementation specific non-zero key value that specifies the end of the performance
742 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
743 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
744 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
745 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
746 If Handle is NULL, then ASSERT().
747 If Token is NULL, then ASSERT().
748 If Module is NULL, then ASSERT().
749 If StartTimeStamp is NULL, then ASSERT().
750 If EndTimeStamp is NULL, then ASSERT().
754 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
755 0, then the first performance measurement log entry is retrieved.
756 On exit, the key of the next performance of entry entry.
757 @param Handle Pointer to environment specific context used to identify the component
759 @param Token Pointer to a Null-terminated ASCII string that identifies the component
761 @param Module Pointer to a Null-terminated ASCII string that identifies the module
763 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
765 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
768 @return The key for the next performance log entry (in general case).
773 GetPerformanceMeasurement (
774 IN UINTN LogEntryKey
,
775 OUT CONST VOID
**Handle
,
776 OUT CONST CHAR8
**Token
,
777 OUT CONST CHAR8
**Module
,
778 OUT UINT64
*StartTimeStamp
,
779 OUT UINT64
*EndTimeStamp
786 Returns TRUE if the performance measurement macros are enabled.
788 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
789 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
791 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
792 PcdPerformanceLibraryPropertyMask is set.
793 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
794 PcdPerformanceLibraryPropertyMask is clear.
799 PerformanceMeasurementEnabled (
803 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);
807 Create performance record with event description and a timestamp.
809 @param CallerIdentifier - Image handle or pointer to caller ID GUID
810 @param Guid - Pointer to a GUID
811 @param String - Pointer to a string describing the measurement
812 @param Address - Pointer to a location in memory relevant to the measurement
813 @param Identifier - Performance identifier describing the type of measurement
815 @retval RETURN_SUCCESS - Successfully created performance record
816 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
817 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
818 pointer or invalid PerfId
823 LogPerformanceMeasurement (
824 IN CONST VOID
*CallerIdentifier
,
825 IN CONST VOID
*Guid OPTIONAL
,
826 IN CONST CHAR8
*String OPTIONAL
,
827 IN UINT64 Address OPTIONAL
,
831 return (RETURN_STATUS
)InsertFpdtRecord (CallerIdentifier
, Guid
, String
, 0, Address
, (UINT16
)Identifier
, PerfEntry
);
835 Check whether the specified performance measurement can be logged.
837 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
838 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
840 @param Type - Type of the performance measurement entry.
842 @retval TRUE The performance measurement can be logged.
843 @retval FALSE The performance measurement can NOT be logged.
848 LogPerformanceMeasurementEnabled (
853 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
855 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask
) & Type
) == 0) {