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 This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 #include <Guid/ExtendedFirmwarePerformance.h>
26 #include <Guid/PerformanceMeasurement.h>
28 #include <Library/PerformanceLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/HobLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/TimerLib.h>
33 #include <Library/PcdLib.h>
34 #include <Library/BaseMemoryLib.h>
36 #define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
37 #define PEI_MAX_RECORD_SIZE (sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD) + STRING_SIZE)
41 Return the pointer to the FPDT record in the allocated memory.
43 @param RecordSize The size of FPDT record.
44 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.
45 @param PeiPerformanceLogHeader Pointer to the header of the PEI Performance records in the GUID Hob.
47 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.
48 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.
53 IN OUT FPDT_RECORD_PTR
*FpdtRecordPtr
,
54 IN OUT FPDT_PEI_EXT_PERF_HEADER
**PeiPerformanceLogHeader
57 UINT16 PeiPerformanceLogEntries
;
58 UINTN PeiPerformanceSize
;
59 UINT8
*PeiFirmwarePerformance
;
60 EFI_HOB_GUID_TYPE
*GuidHob
;
63 // Get the number of PeiPerformanceLogEntries form PCD.
65 PeiPerformanceLogEntries
= (UINT16
) (PcdGet16 (PcdMaxPeiPerformanceLogEntries16
) != 0 ?
66 PcdGet16 (PcdMaxPeiPerformanceLogEntries16
) :
67 PcdGet8 (PcdMaxPeiPerformanceLogEntries
));
70 // Create GUID HOB Data.
72 GuidHob
= GetFirstGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
);
73 PeiFirmwarePerformance
= NULL
;
74 while (GuidHob
!= NULL
) {
76 // PEI Performance HOB was found, then return the existing one.
78 PeiFirmwarePerformance
= (UINT8
*)GET_GUID_HOB_DATA (GuidHob
);
79 *PeiPerformanceLogHeader
= (FPDT_PEI_EXT_PERF_HEADER
*)PeiFirmwarePerformance
;
80 if (!(*PeiPerformanceLogHeader
)->HobIsFull
&& (*PeiPerformanceLogHeader
)->SizeOfAllEntries
+ RecordSize
> (UINTN
)(PeiPerformanceLogEntries
* PEI_MAX_RECORD_SIZE
)) {
81 (*PeiPerformanceLogHeader
)->HobIsFull
= TRUE
;
83 if (!(*PeiPerformanceLogHeader
)->HobIsFull
&& (*PeiPerformanceLogHeader
)->SizeOfAllEntries
+ RecordSize
<= (UINTN
)(PeiPerformanceLogEntries
* PEI_MAX_RECORD_SIZE
)) {
84 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(PeiFirmwarePerformance
+ sizeof (FPDT_PEI_EXT_PERF_HEADER
) + (*PeiPerformanceLogHeader
)->SizeOfAllEntries
);
88 // Previous HOB is used, then find next one.
90 GuidHob
= GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, GET_NEXT_HOB (GuidHob
));
93 if (GuidHob
== NULL
) {
95 // PEI Performance HOB was not found, then build one.
97 PeiPerformanceSize
= sizeof (FPDT_PEI_EXT_PERF_HEADER
) +
98 PEI_MAX_RECORD_SIZE
* PeiPerformanceLogEntries
;
99 PeiFirmwarePerformance
= (UINT8
*)BuildGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, PeiPerformanceSize
);
100 if (PeiFirmwarePerformance
!= NULL
) {
101 ZeroMem (PeiFirmwarePerformance
, PeiPerformanceSize
);
102 (*PeiPerformanceLogHeader
) = (FPDT_PEI_EXT_PERF_HEADER
*)PeiFirmwarePerformance
;
103 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(PeiFirmwarePerformance
+ sizeof (FPDT_PEI_EXT_PERF_HEADER
));
107 if (PeiFirmwarePerformance
== NULL
) {
109 // there is no enough resource to store performance data
111 return EFI_OUT_OF_RESOURCES
;
118 Check whether the Token is a known one which is uesed by core.
120 @param Token Pointer to a Null-terminated ASCII string
122 @retval TRUE Is a known one used by core.
123 @retval FALSE Not a known one.
128 IN CONST CHAR8
*Token
135 if (AsciiStrCmp (Token
, SEC_TOK
) == 0 ||
136 AsciiStrCmp (Token
, PEI_TOK
) == 0 ||
137 AsciiStrCmp (Token
, DXE_TOK
) == 0 ||
138 AsciiStrCmp (Token
, BDS_TOK
) == 0 ||
139 AsciiStrCmp (Token
, DRIVERBINDING_START_TOK
) == 0 ||
140 AsciiStrCmp (Token
, DRIVERBINDING_SUPPORT_TOK
) == 0 ||
141 AsciiStrCmp (Token
, DRIVERBINDING_STOP_TOK
) == 0 ||
142 AsciiStrCmp (Token
, LOAD_IMAGE_TOK
) == 0 ||
143 AsciiStrCmp (Token
, START_IMAGE_TOK
) == 0 ||
144 AsciiStrCmp (Token
, PEIM_TOK
) == 0) {
152 Check whether the ID is a known one which map to the known Token.
154 @param Identifier 32-bit identifier.
156 @retval TRUE Is a known one used by core.
157 @retval FALSE Not a known one.
165 if (Identifier
== MODULE_START_ID
||
166 Identifier
== MODULE_END_ID
||
167 Identifier
== MODULE_LOADIMAGE_START_ID
||
168 Identifier
== MODULE_LOADIMAGE_END_ID
||
169 Identifier
== MODULE_DB_START_ID
||
170 Identifier
== MODULE_DB_END_ID
||
171 Identifier
== MODULE_DB_SUPPORT_START_ID
||
172 Identifier
== MODULE_DB_SUPPORT_END_ID
||
173 Identifier
== MODULE_DB_STOP_START_ID
||
174 Identifier
== MODULE_DB_STOP_END_ID
) {
182 Get the FPDT record identifier.
184 @param Attribute The attribute of the Record.
185 PerfStartEntry: Start Record.
186 PerfEndEntry: End Record.
187 @param Handle Pointer to environment specific context used to identify the component being measured.
188 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.
189 @param ProgressID On return, pointer to the ProgressID.
191 @retval EFI_SUCCESS Get record info successfully.
192 @retval EFI_INVALID_PARAMETER No matched FPDT record.
197 IN BOOLEAN Attribute
,
198 IN CONST VOID
*Handle
,
199 IN CONST CHAR8
*String
,
200 OUT UINT16
*ProgressID
204 // Get the ProgressID based on the Token.
205 // When PcdEdkiiFpdtStringRecordEnableOnly is TRUE, all records are with type of FPDT_DYNAMIC_STRING_EVENT_TYPE.
207 if (String
!= NULL
) {
208 if (AsciiStrCmp (String
, LOAD_IMAGE_TOK
) == 0) { // "LoadImage:"
209 if (Attribute
== PerfStartEntry
) {
210 *ProgressID
= MODULE_LOADIMAGE_START_ID
;
212 *ProgressID
= MODULE_LOADIMAGE_END_ID
;
214 } else if (AsciiStrCmp (String
, SEC_TOK
) == 0 || // "SEC"
215 AsciiStrCmp (String
, PEI_TOK
) == 0) { // "PEI"
216 if (Attribute
== PerfStartEntry
) {
217 *ProgressID
= PERF_CROSSMODULE_START_ID
;
219 *ProgressID
= PERF_CROSSMODULE_END_ID
;
221 } else if (AsciiStrCmp (String
, PEIM_TOK
) == 0) { // "PEIM"
222 if (Attribute
== PerfStartEntry
) {
223 *ProgressID
= MODULE_START_ID
;
225 *ProgressID
= MODULE_END_ID
;
227 } else { //Pref used in Modules.
228 if (Attribute
== PerfStartEntry
) {
229 *ProgressID
= PERF_INMODULE_START_ID
;
231 *ProgressID
= PERF_INMODULE_END_ID
;
234 } else if (Handle
!= NULL
) { //Pref used in Modules.
235 if (Attribute
== PerfStartEntry
) {
236 *ProgressID
= PERF_INMODULE_START_ID
;
238 *ProgressID
= PERF_INMODULE_END_ID
;
241 return EFI_INVALID_PARAMETER
;
248 Copies the string from Source into Destination and updates Length with the
251 @param Destination - destination of the string copy
252 @param Source - pointer to the source string which will get copied
253 @param Length - pointer to a length variable to be updated
257 CopyStringIntoPerfRecordAndUpdateLength (
258 IN OUT CHAR8
*Destination
,
259 IN CONST CHAR8
*Source
,
266 ASSERT (Source
!= NULL
);
268 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
269 DestMax
= STRING_SIZE
;
271 DestMax
= AsciiStrSize (Source
);
272 if (DestMax
> STRING_SIZE
) {
273 DestMax
= STRING_SIZE
;
276 StringLen
= AsciiStrLen (Source
);
277 if (StringLen
>= DestMax
) {
278 StringLen
= DestMax
-1;
281 AsciiStrnCpyS(Destination
, DestMax
, Source
, StringLen
);
282 *Length
+= (UINT8
)DestMax
;
289 Convert PEI performance log to FPDT String boot record.
291 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
292 @param Guid - Pointer to a GUID.
293 @param String - Pointer to a string describing the measurement.
294 @param Ticker - 64-bit time stamp.
295 @param Address - Pointer to a location in memory relevant to the measurement.
296 @param PerfId - Performance identifier describing the type of measurement.
297 @param Attribute - The attribute of the measurement. According to attribute can create a start
298 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
299 or a general record for other Perf macros.
301 @retval EFI_SUCCESS - Successfully created performance record.
302 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
303 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
304 pointer or invalid PerfId.
309 IN CONST VOID
*CallerIdentifier
, OPTIONAL
310 IN CONST VOID
*Guid
, OPTIONAL
311 IN CONST CHAR8
*String
, OPTIONAL
313 IN UINT64 Address
, OPTIONAL
315 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
318 FPDT_RECORD_PTR FpdtRecordPtr
;
319 CONST VOID
*ModuleGuid
;
320 CONST CHAR8
*StringPtr
;
323 FPDT_PEI_EXT_PERF_HEADER
*PeiPerformanceLogHeader
;
326 FpdtRecordPtr
.RecordHeader
= NULL
;
327 PeiPerformanceLogHeader
= NULL
;
330 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
331 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
333 if (Attribute
!= PerfEntry
) {
335 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
336 // !!! Note: If the Perf is not the known Token used in the core but have same
337 // ID with the core Token, this case will not be supported.
338 // And in currtnt usage mode, for the unkown ID, there is a general rule:
339 // If it is start pref: the lower 4 bits of the ID should be 0.
340 // If it is end pref: the lower 4 bits of the ID should not be 0.
341 // If input ID doesn't follow the rule, we will adjust it.
343 if ((PerfId
!= 0) && (IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
344 return EFI_UNSUPPORTED
;
345 } else if ((PerfId
!= 0) && (!IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
346 if (Attribute
== PerfStartEntry
&& ((PerfId
& 0x000F) != 0)) {
348 } else if ((Attribute
== PerfEndEntry
) && ((PerfId
& 0x000F) == 0)) {
351 } else if (PerfId
== 0) {
352 Status
= GetFpdtRecordId (Attribute
, CallerIdentifier
, String
, &PerfId
);
353 if (EFI_ERROR (Status
)) {
360 // 2. Get the buffer to store the FPDT record.
362 Status
= GetFpdtRecordPtr (PEI_MAX_RECORD_SIZE
, &FpdtRecordPtr
, &PeiPerformanceLogHeader
);
363 if (EFI_ERROR (Status
)) {
368 // 3 Get the TimeStamp.
371 Ticker
= GetPerformanceCounter ();
372 TimeStamp
= GetTimeInNanoSecond (Ticker
);
373 } else if (Ticker
== 1) {
376 TimeStamp
= GetTimeInNanoSecond (Ticker
);
380 // 4.Get the ModuleGuid.
382 if (CallerIdentifier
!= NULL
) {
383 ModuleGuid
= CallerIdentifier
;
385 ModuleGuid
= &gEfiCallerIdGuid
;
389 // 5. Fill in the FPDT record according to different Performance Identifier.
392 case MODULE_START_ID
:
394 StringPtr
= PEIM_TOK
;
395 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
396 FpdtRecordPtr
.GuidEvent
->Header
.Type
= FPDT_GUID_EVENT_TYPE
;
397 FpdtRecordPtr
.GuidEvent
->Header
.Length
= sizeof (FPDT_GUID_EVENT_RECORD
);
398 FpdtRecordPtr
.GuidEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
399 FpdtRecordPtr
.GuidEvent
->ProgressID
= PerfId
;
400 FpdtRecordPtr
.GuidEvent
->Timestamp
= TimeStamp
;
401 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
405 case MODULE_LOADIMAGE_START_ID
:
406 case MODULE_LOADIMAGE_END_ID
:
407 StringPtr
= LOAD_IMAGE_TOK
;
408 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
409 FpdtRecordPtr
.GuidQwordEvent
->Header
.Type
= FPDT_GUID_QWORD_EVENT_TYPE
;
410 FpdtRecordPtr
.GuidQwordEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_EVENT_RECORD
);
411 FpdtRecordPtr
.GuidQwordEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
412 FpdtRecordPtr
.GuidQwordEvent
->ProgressID
= PerfId
;
413 FpdtRecordPtr
.GuidQwordEvent
->Timestamp
= TimeStamp
;
414 if (PerfId
== MODULE_LOADIMAGE_START_ID
) {
415 PeiPerformanceLogHeader
->LoadImageCount
++;
417 FpdtRecordPtr
.GuidQwordEvent
->Qword
= PeiPerformanceLogHeader
->LoadImageCount
;
418 CopyMem (&FpdtRecordPtr
.GuidQwordEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
422 case PERF_EVENTSIGNAL_START_ID
:
423 case PERF_EVENTSIGNAL_END_ID
:
424 case PERF_CALLBACK_START_ID
:
425 case PERF_CALLBACK_END_ID
:
426 if (String
!= NULL
&& AsciiStrLen (String
) != 0) {
429 StringPtr
= "unknown name";
431 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
432 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Type
= FPDT_DUAL_GUID_STRING_EVENT_TYPE
;
433 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
= sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD
);
434 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
435 FpdtRecordPtr
.DualGuidStringEvent
->ProgressID
= PerfId
;
436 FpdtRecordPtr
.DualGuidStringEvent
->Timestamp
= TimeStamp
;
437 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid1
, ModuleGuid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid1
));
438 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid2
, Guid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid2
));
443 case PERF_FUNCTION_START_ID
:
444 case PERF_FUNCTION_END_ID
:
445 case PERF_INMODULE_START_ID
:
446 case PERF_INMODULE_END_ID
:
447 case PERF_CROSSMODULE_START_ID
:
448 case PERF_CROSSMODULE_END_ID
:
449 if (String
!= NULL
&& AsciiStrLen (String
) != 0) {
452 StringPtr
= "unknown name";
454 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
455 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
456 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
457 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
458 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
459 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
460 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
461 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
466 if (Attribute
!= PerfEntry
) {
467 if (String
!= NULL
&& AsciiStrLen (String
) != 0) {
470 StringPtr
= "unknown name";
472 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
473 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
474 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
475 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
476 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
477 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
478 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
479 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
482 return EFI_INVALID_PARAMETER
;
488 // 5.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
490 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
491 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
492 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
493 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
494 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
495 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
498 // Cache the event guid in string event record.
500 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, Guid
, sizeof (EFI_GUID
));
502 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
504 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
508 // 6. Update the length of the used buffer after fill in the record.
510 PeiPerformanceLogHeader
->SizeOfAllEntries
+= FpdtRecordPtr
.RecordHeader
->Length
;
516 Creates a record for the beginning of a performance measurement.
518 If TimeStamp is zero, then this function reads the current time stamp
519 and adds that time stamp value to the record as the start time.
521 If TimeStamp is one, then this function reads 0 as the start time.
523 If TimeStamp is other value, then TimeStamp is added to the record as the start time.
525 @param Handle Pointer to environment specific context used
526 to identify the component being measured.
527 @param Token Pointer to a Null-terminated ASCII string
528 that identifies the component being measured.
529 @param Module Pointer to a Null-terminated ASCII string
530 that identifies the module being measured.
531 @param TimeStamp 64-bit time stamp.
532 @param Identifier 32-bit identifier. If the value is 0, the created record
533 is same as the one created by StartPerformanceMeasurement.
535 @retval RETURN_SUCCESS The start of the measurement was recorded.
536 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
541 StartPerformanceMeasurementEx (
542 IN CONST VOID
*Handle
, OPTIONAL
543 IN CONST CHAR8
*Token
, OPTIONAL
544 IN CONST CHAR8
*Module
, OPTIONAL
553 } else if (Module
!= NULL
) {
559 return (RETURN_STATUS
)InsertFpdtRecord (Handle
, NULL
, String
, TimeStamp
, 0, (UINT16
)Identifier
, PerfStartEntry
);
565 Creates a record for the end of a performance measurement.
567 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.
568 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.
569 If the TimeStamp is one, then this function reads 0 as the end time.
571 @param Handle Pointer to environment specific context used
572 to identify the component being measured.
573 @param Token Pointer to a Null-terminated ASCII string
574 that identifies the component being measured.
575 @param Module Pointer to a Null-terminated ASCII string
576 that identifies the module being measured.
577 @param TimeStamp 64-bit time stamp.
578 @param Identifier 32-bit identifier. If the value is 0, the found record
579 is same as the one found by EndPerformanceMeasurement.
581 @retval RETURN_SUCCESS The end of the measurement was recorded.
582 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
587 EndPerformanceMeasurementEx (
588 IN CONST VOID
*Handle
, OPTIONAL
589 IN CONST CHAR8
*Token
, OPTIONAL
590 IN CONST CHAR8
*Module
, OPTIONAL
599 } else if (Module
!= NULL
) {
605 return (RETURN_STATUS
)InsertFpdtRecord (Handle
, NULL
, String
, TimeStamp
, 0, (UINT16
)Identifier
, PerfEndEntry
);
609 Attempts to retrieve a performance measurement log entry from the performance measurement log.
610 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
611 and then assign the Identifier with 0.
613 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
614 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
615 and the key for the second entry in the log is returned. If the performance log is empty,
616 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
617 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
618 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
619 retrieved and an implementation specific non-zero key value that specifies the end of the performance
620 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
621 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
622 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
623 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
624 If Handle is NULL, then ASSERT().
625 If Token is NULL, then ASSERT().
626 If Module is NULL, then ASSERT().
627 If StartTimeStamp is NULL, then ASSERT().
628 If EndTimeStamp is NULL, then ASSERT().
629 If Identifier is NULL, then ASSERT().
631 !!!NOT Support yet!!!
633 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
634 0, then the first performance measurement log entry is retrieved.
635 On exit, the key of the next performance of entry entry.
636 @param Handle Pointer to environment specific context used to identify the component
638 @param Token Pointer to a Null-terminated ASCII string that identifies the component
640 @param Module Pointer to a Null-terminated ASCII string that identifies the module
642 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
644 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
646 @param Identifier Pointer to the 32-bit identifier that was recorded.
648 @return The key for the next performance log entry (in general case).
653 GetPerformanceMeasurementEx (
654 IN UINTN LogEntryKey
,
655 OUT CONST VOID
**Handle
,
656 OUT CONST CHAR8
**Token
,
657 OUT CONST CHAR8
**Module
,
658 OUT UINT64
*StartTimeStamp
,
659 OUT UINT64
*EndTimeStamp
,
660 OUT UINT32
*Identifier
667 Creates a record for the beginning of a performance measurement.
669 If TimeStamp is zero, then this function reads the current time stamp
670 and adds that time stamp value to the record as the start time.
672 If TimeStamp is one, then this function reads 0 as the start time.
674 If TimeStamp is other value, then TimeStamp is added to the record as the start time.
677 @param Handle Pointer to environment specific context used
678 to identify the component being measured.
679 @param Token Pointer to a Null-terminated ASCII string
680 that identifies the component being measured.
681 @param Module Pointer to a Null-terminated ASCII string
682 that identifies the module being measured.
683 @param TimeStamp 64-bit time stamp.
685 @retval RETURN_SUCCESS The start of the measurement was recorded.
686 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
691 StartPerformanceMeasurement (
692 IN CONST VOID
*Handle
, OPTIONAL
693 IN CONST CHAR8
*Token
, OPTIONAL
694 IN CONST CHAR8
*Module
, OPTIONAL
698 return StartPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
703 Creates a record for the end of a performance measurement.
705 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.
706 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.
707 If the TimeStamp is one, then this function reads 0 as the end time.
709 @param Handle Pointer to environment specific context used
710 to identify the component being measured.
711 @param Token Pointer to a Null-terminated ASCII string
712 that identifies the component being measured.
713 @param Module Pointer to a Null-terminated ASCII string
714 that identifies the module being measured.
715 @param TimeStamp 64-bit time stamp.
717 @retval RETURN_SUCCESS The end of the measurement was recorded.
718 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
723 EndPerformanceMeasurement (
724 IN CONST VOID
*Handle
, OPTIONAL
725 IN CONST CHAR8
*Token
, OPTIONAL
726 IN CONST CHAR8
*Module
, OPTIONAL
730 return EndPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
734 Attempts to retrieve a performance measurement log entry from the performance measurement log.
735 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
736 and then eliminate the Identifier.
738 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
739 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
740 and the key for the second entry in the log is returned. If the performance log is empty,
741 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
742 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
743 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
744 retrieved and an implementation specific non-zero key value that specifies the end of the performance
745 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
746 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
747 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
748 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
749 If Handle is NULL, then ASSERT().
750 If Token is NULL, then ASSERT().
751 If Module is NULL, then ASSERT().
752 If StartTimeStamp is NULL, then ASSERT().
753 If EndTimeStamp is NULL, then ASSERT().
757 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
758 0, then the first performance measurement log entry is retrieved.
759 On exit, the key of the next performance of entry entry.
760 @param Handle Pointer to environment specific context used to identify the component
762 @param Token Pointer to a Null-terminated ASCII string that identifies the component
764 @param Module Pointer to a Null-terminated ASCII string that identifies the module
766 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
768 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
771 @return The key for the next performance log entry (in general case).
776 GetPerformanceMeasurement (
777 IN UINTN LogEntryKey
,
778 OUT CONST VOID
**Handle
,
779 OUT CONST CHAR8
**Token
,
780 OUT CONST CHAR8
**Module
,
781 OUT UINT64
*StartTimeStamp
,
782 OUT UINT64
*EndTimeStamp
789 Returns TRUE if the performance measurement macros are enabled.
791 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
792 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
794 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
795 PcdPerformanceLibraryPropertyMask is set.
796 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
797 PcdPerformanceLibraryPropertyMask is clear.
802 PerformanceMeasurementEnabled (
806 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);
810 Create performance record with event description and a timestamp.
812 @param CallerIdentifier - Image handle or pointer to caller ID GUID
813 @param Guid - Pointer to a GUID
814 @param String - Pointer to a string describing the measurement
815 @param Address - Pointer to a location in memory relevant to the measurement
816 @param Identifier - Performance identifier describing the type of measurement
818 @retval RETURN_SUCCESS - Successfully created performance record
819 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
820 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
821 pointer or invalid PerfId
826 LogPerformanceMeasurement (
827 IN CONST VOID
*CallerIdentifier
,
828 IN CONST VOID
*Guid
, OPTIONAL
829 IN CONST CHAR8
*String
, OPTIONAL
830 IN UINT64 Address
, OPTIONAL
834 return (RETURN_STATUS
)InsertFpdtRecord (CallerIdentifier
, Guid
, String
, 0, Address
, (UINT16
)Identifier
, PerfEntry
);
838 Check whether the specified performance measurement can be logged.
840 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
841 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
843 @param Type - Type of the performance measurement entry.
845 @retval TRUE The performance measurement can be logged.
846 @retval FALSE The performance measurement can NOT be logged.
851 LogPerformanceMeasurementEnabled (
856 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
858 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask
) & Type
) == 0) {