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
> (PeiPerformanceLogEntries
* PEI_MAX_RECORD_SIZE
)) {
81 (*PeiPerformanceLogHeader
)->HobIsFull
= TRUE
;
83 if (!(*PeiPerformanceLogHeader
)->HobIsFull
&& (*PeiPerformanceLogHeader
)->SizeOfAllEntries
+ RecordSize
<= (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
|| Guid
== NULL
) {
427 return EFI_INVALID_PARAMETER
;
430 if (AsciiStrLen (String
) == 0) {
431 StringPtr
= "unknown name";
433 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
434 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Type
= FPDT_DUAL_GUID_STRING_EVENT_TYPE
;
435 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
= sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD
);
436 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
437 FpdtRecordPtr
.DualGuidStringEvent
->ProgressID
= PerfId
;
438 FpdtRecordPtr
.DualGuidStringEvent
->Timestamp
= TimeStamp
;
439 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid1
, ModuleGuid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid1
));
440 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid2
, Guid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid2
));
441 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DualGuidStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
);
446 case PERF_FUNCTION_START_ID
:
447 case PERF_FUNCTION_END_ID
:
448 case PERF_INMODULE_START_ID
:
449 case PERF_INMODULE_END_ID
:
450 case PERF_CROSSMODULE_START_ID
:
451 case PERF_CROSSMODULE_END_ID
:
452 if (String
!= NULL
&& AsciiStrLen (String
) != 0) {
455 StringPtr
= "unknown name";
457 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
458 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
459 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
460 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
461 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
462 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
463 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
464 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
469 if (Attribute
!= PerfEntry
) {
470 if (String
!= NULL
&& AsciiStrLen (String
) != 0) {
473 StringPtr
= "unknown name";
475 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
476 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
477 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
478 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
479 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
480 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
481 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
482 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
485 return EFI_INVALID_PARAMETER
;
491 // 5.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
493 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
494 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
495 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
496 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
497 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
498 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
501 // Cache the event guid in string event record.
503 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, Guid
, sizeof (EFI_GUID
));
505 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, ModuleGuid
, sizeof (EFI_GUID
));
507 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
511 // 6. Update the length of the used buffer after fill in the record.
513 PeiPerformanceLogHeader
->SizeOfAllEntries
+= FpdtRecordPtr
.RecordHeader
->Length
;
519 Creates a record for the beginning of a performance measurement.
521 If TimeStamp is zero, then this function reads the current time stamp
522 and adds that time stamp value to the record as the start time.
524 If TimeStamp is one, then this function reads 0 as the start time.
526 If TimeStamp is other value, then TimeStamp is added to the record as the start time.
528 @param Handle Pointer to environment specific context used
529 to identify the component being measured.
530 @param Token Pointer to a Null-terminated ASCII string
531 that identifies the component being measured.
532 @param Module Pointer to a Null-terminated ASCII string
533 that identifies the module being measured.
534 @param TimeStamp 64-bit time stamp.
535 @param Identifier 32-bit identifier. If the value is 0, the created record
536 is same as the one created by StartPerformanceMeasurement.
538 @retval RETURN_SUCCESS The start of the measurement was recorded.
539 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
544 StartPerformanceMeasurementEx (
545 IN CONST VOID
*Handle
, OPTIONAL
546 IN CONST CHAR8
*Token
, OPTIONAL
547 IN CONST CHAR8
*Module
, OPTIONAL
556 } else if (Module
!= NULL
) {
562 return (RETURN_STATUS
)InsertFpdtRecord (Handle
, NULL
, String
, TimeStamp
, 0, (UINT16
)Identifier
, PerfStartEntry
);
568 Creates a record for the end of a performance measurement.
570 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.
571 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.
572 If the TimeStamp is one, then this function reads 0 as the end time.
574 @param Handle Pointer to environment specific context used
575 to identify the component being measured.
576 @param Token Pointer to a Null-terminated ASCII string
577 that identifies the component being measured.
578 @param Module Pointer to a Null-terminated ASCII string
579 that identifies the module being measured.
580 @param TimeStamp 64-bit time stamp.
581 @param Identifier 32-bit identifier. If the value is 0, the found record
582 is same as the one found by EndPerformanceMeasurement.
584 @retval RETURN_SUCCESS The end of the measurement was recorded.
585 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
590 EndPerformanceMeasurementEx (
591 IN CONST VOID
*Handle
, OPTIONAL
592 IN CONST CHAR8
*Token
, OPTIONAL
593 IN CONST CHAR8
*Module
, OPTIONAL
602 } else if (Module
!= NULL
) {
608 return (RETURN_STATUS
)InsertFpdtRecord (Handle
, NULL
, String
, TimeStamp
, 0, (UINT16
)Identifier
, PerfEndEntry
);
612 Attempts to retrieve a performance measurement log entry from the performance measurement log.
613 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
614 and then assign the Identifier with 0.
616 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
617 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
618 and the key for the second entry in the log is returned. If the performance log is empty,
619 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
620 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
621 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
622 retrieved and an implementation specific non-zero key value that specifies the end of the performance
623 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
624 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
625 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
626 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
627 If Handle is NULL, then ASSERT().
628 If Token is NULL, then ASSERT().
629 If Module is NULL, then ASSERT().
630 If StartTimeStamp is NULL, then ASSERT().
631 If EndTimeStamp is NULL, then ASSERT().
632 If Identifier is NULL, then ASSERT().
634 !!!NOT Support yet!!!
636 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
637 0, then the first performance measurement log entry is retrieved.
638 On exit, the key of the next performance of entry entry.
639 @param Handle Pointer to environment specific context used to identify the component
641 @param Token Pointer to a Null-terminated ASCII string that identifies the component
643 @param Module Pointer to a Null-terminated ASCII string that identifies the module
645 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
647 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
649 @param Identifier Pointer to the 32-bit identifier that was recorded.
651 @return The key for the next performance log entry (in general case).
656 GetPerformanceMeasurementEx (
657 IN UINTN LogEntryKey
,
658 OUT CONST VOID
**Handle
,
659 OUT CONST CHAR8
**Token
,
660 OUT CONST CHAR8
**Module
,
661 OUT UINT64
*StartTimeStamp
,
662 OUT UINT64
*EndTimeStamp
,
663 OUT UINT32
*Identifier
670 Creates a record for the beginning of a performance measurement.
672 If TimeStamp is zero, then this function reads the current time stamp
673 and adds that time stamp value to the record as the start time.
675 If TimeStamp is one, then this function reads 0 as the start time.
677 If TimeStamp is other value, then TimeStamp is added to the record as the start time.
680 @param Handle Pointer to environment specific context used
681 to identify the component being measured.
682 @param Token Pointer to a Null-terminated ASCII string
683 that identifies the component being measured.
684 @param Module Pointer to a Null-terminated ASCII string
685 that identifies the module being measured.
686 @param TimeStamp 64-bit time stamp.
688 @retval RETURN_SUCCESS The start of the measurement was recorded.
689 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
694 StartPerformanceMeasurement (
695 IN CONST VOID
*Handle
, OPTIONAL
696 IN CONST CHAR8
*Token
, OPTIONAL
697 IN CONST CHAR8
*Module
, OPTIONAL
701 return StartPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
706 Creates a record for the end of a performance measurement.
708 If the TimeStamp is not zero or one, then TimeStamp is added to the record as the end time.
709 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.
710 If the TimeStamp is one, then this function reads 0 as the end time.
712 @param Handle Pointer to environment specific context used
713 to identify the component being measured.
714 @param Token Pointer to a Null-terminated ASCII string
715 that identifies the component being measured.
716 @param Module Pointer to a Null-terminated ASCII string
717 that identifies the module being measured.
718 @param TimeStamp 64-bit time stamp.
720 @retval RETURN_SUCCESS The end of the measurement was recorded.
721 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
726 EndPerformanceMeasurement (
727 IN CONST VOID
*Handle
, OPTIONAL
728 IN CONST CHAR8
*Token
, OPTIONAL
729 IN CONST CHAR8
*Module
, OPTIONAL
733 return EndPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
737 Attempts to retrieve a performance measurement log entry from the performance measurement log.
738 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
739 and then eliminate the Identifier.
741 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
742 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
743 and the key for the second entry in the log is returned. If the performance log is empty,
744 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
745 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
746 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
747 retrieved and an implementation specific non-zero key value that specifies the end of the performance
748 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
749 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
750 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
751 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
752 If Handle is NULL, then ASSERT().
753 If Token is NULL, then ASSERT().
754 If Module is NULL, then ASSERT().
755 If StartTimeStamp is NULL, then ASSERT().
756 If EndTimeStamp is NULL, then ASSERT().
760 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
761 0, then the first performance measurement log entry is retrieved.
762 On exit, the key of the next performance of entry entry.
763 @param Handle Pointer to environment specific context used to identify the component
765 @param Token Pointer to a Null-terminated ASCII string that identifies the component
767 @param Module Pointer to a Null-terminated ASCII string that identifies the module
769 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
771 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
774 @return The key for the next performance log entry (in general case).
779 GetPerformanceMeasurement (
780 IN UINTN LogEntryKey
,
781 OUT CONST VOID
**Handle
,
782 OUT CONST CHAR8
**Token
,
783 OUT CONST CHAR8
**Module
,
784 OUT UINT64
*StartTimeStamp
,
785 OUT UINT64
*EndTimeStamp
792 Returns TRUE if the performance measurement macros are enabled.
794 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
795 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
797 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
798 PcdPerformanceLibraryPropertyMask is set.
799 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
800 PcdPerformanceLibraryPropertyMask is clear.
805 PerformanceMeasurementEnabled (
809 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);
813 Create performance record with event description and a timestamp.
815 @param CallerIdentifier - Image handle or pointer to caller ID GUID
816 @param Guid - Pointer to a GUID
817 @param String - Pointer to a string describing the measurement
818 @param Address - Pointer to a location in memory relevant to the measurement
819 @param Identifier - Performance identifier describing the type of measurement
821 @retval RETURN_SUCCESS - Successfully created performance record
822 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
823 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
824 pointer or invalid PerfId
829 LogPerformanceMeasurement (
830 IN CONST VOID
*CallerIdentifier
,
831 IN CONST VOID
*Guid
, OPTIONAL
832 IN CONST CHAR8
*String
, OPTIONAL
833 IN UINT64 Address
, OPTIONAL
837 return (RETURN_STATUS
)InsertFpdtRecord (CallerIdentifier
, Guid
, String
, 0, Address
, (UINT16
)Identifier
, PerfEntry
);
841 Check whether the specified performance measurement can be logged.
843 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
844 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
846 @param Type - Type of the performance measurement entry.
848 @retval TRUE The performance measurement can be logged.
849 @retval FALSE The performance measurement can NOT be logged.
854 LogPerformanceMeasurementEnabled (
859 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
861 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask
) & Type
) == 0) {