2 Performance library instance mainly used by DxeCore.
4 This library provides the performance measurement interfaces and initializes performance
5 logging for DXE phase. It first initializes its private global data structure for
6 performance logging and saves the performance GUIDed HOB passed from PEI phase.
7 It initializes DXE phase performance logging by publishing the Performance and PerformanceEx Protocol,
8 which are consumed by DxePerformanceLib to logging performance data in DXE phase.
10 This library is mainly used by DxeCore to start performance logging to ensure that
11 Performance Protocol is installed at the very beginning of DXE phase.
13 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
14 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
15 This program and the accompanying materials
16 are licensed and made available under the terms and conditions of the BSD License
17 which accompanies this distribution. The full text of the license may be found at
18 http://opensource.org/licenses/bsd-license.php
20 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
21 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 #include "DxeCorePerformanceLibInternal.h"
29 // Data for FPDT performance records.
31 #define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))
32 #define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
33 #define FIRMWARE_RECORD_BUFFER 0x10000
34 #define CACHE_HANDLE_GUID_COUNT 0x800
36 BOOT_PERFORMANCE_TABLE
*mAcpiBootPerformanceTable
= NULL
;
37 BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate
= {
39 EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE
,
40 sizeof (BOOT_PERFORMANCE_TABLE
)
44 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT
, // Type
45 sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD
), // Length
46 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT
// Revision
50 // These values will be updated at runtime.
53 0, // OsLoaderLoadImageStart
54 0, // OsLoaderStartImageStart
55 0, // ExitBootServicesEntry
56 0 // ExitBootServicesExit
62 CHAR8 NameString
[FPDT_STRING_EVENT_RECORD_NAME_LENGTH
];
66 HANDLE_GUID_MAP mCacheHandleGuidTable
[CACHE_HANDLE_GUID_COUNT
];
67 UINTN mCachePairCount
= 0;
69 UINT32 mLoadImageCount
= 0;
70 UINT32 mPerformanceLength
= 0;
71 UINT32 mMaxPerformanceLength
= 0;
72 UINT32 mBootRecordSize
= 0;
73 UINT32 mBootRecordMaxSize
= 0;
74 UINT32 mCachedLength
= 0;
76 BOOLEAN mFpdtBufferIsReported
= FALSE
;
77 BOOLEAN mLackSpaceIsReported
= FALSE
;
78 CHAR8
*mPlatformLanguage
= NULL
;
79 UINT8
*mPerformancePointer
= NULL
;
80 UINT8
*mBootRecordBuffer
= NULL
;
81 BOOLEAN mLockInsertRecord
= FALSE
;
82 CHAR8
*mDevicePathString
= NULL
;
84 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*mDevicePathToText
= NULL
;
87 // Interfaces for PerformanceMeasurement Protocol.
89 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface
= {
90 CreatePerformanceMeasurement
,
93 PERFORMANCE_PROPERTY mPerformanceProperty
;
96 Return the pointer to the FPDT record in the allocated memory.
98 @param RecordSize The size of FPDT record.
99 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.
101 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.
102 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.
107 IN OUT FPDT_RECORD_PTR
*FpdtRecordPtr
110 if (mFpdtBufferIsReported
) {
112 // Append Boot records to the boot performance table.
114 if (mBootRecordSize
+ RecordSize
> mBootRecordMaxSize
) {
115 if (!mLackSpaceIsReported
) {
116 DEBUG ((DEBUG_INFO
, "DxeCorePerformanceLib: No enough space to save boot records\n"));
117 mLackSpaceIsReported
= TRUE
;
119 return EFI_OUT_OF_RESOURCES
;
122 // Save boot record into BootPerformance table
124 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mBootRecordSize
);
128 // Check if pre-allocated buffer is full
130 if (mPerformanceLength
+ RecordSize
> mMaxPerformanceLength
) {
131 mPerformancePointer
= ReallocatePool (
133 mPerformanceLength
+ RecordSize
+ FIRMWARE_RECORD_BUFFER
,
136 if (mPerformancePointer
== NULL
) {
137 return EFI_OUT_OF_RESOURCES
;
139 mMaxPerformanceLength
= mPerformanceLength
+ RecordSize
+ FIRMWARE_RECORD_BUFFER
;
142 // Covert buffer to FPDT Ptr Union type.
144 FpdtRecordPtr
->RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mPerformanceLength
);
150 Check whether the Token is a known one which is uesed by core.
152 @param Token Pointer to a Null-terminated ASCII string
154 @retval TRUE Is a known one used by core.
155 @retval FALSE Not a known one.
160 IN CONST CHAR8
*Token
167 if (AsciiStrCmp (Token
, SEC_TOK
) == 0 ||
168 AsciiStrCmp (Token
, PEI_TOK
) == 0 ||
169 AsciiStrCmp (Token
, DXE_TOK
) == 0 ||
170 AsciiStrCmp (Token
, BDS_TOK
) == 0 ||
171 AsciiStrCmp (Token
, DRIVERBINDING_START_TOK
) == 0 ||
172 AsciiStrCmp (Token
, DRIVERBINDING_SUPPORT_TOK
) == 0 ||
173 AsciiStrCmp (Token
, DRIVERBINDING_STOP_TOK
) == 0 ||
174 AsciiStrCmp (Token
, LOAD_IMAGE_TOK
) == 0 ||
175 AsciiStrCmp (Token
, START_IMAGE_TOK
) == 0 ||
176 AsciiStrCmp (Token
, PEIM_TOK
) == 0) {
184 Check whether the ID is a known one which map to the known Token.
186 @param Identifier 32-bit identifier.
188 @retval TRUE Is a known one used by core.
189 @retval FALSE Not a known one.
197 if (Identifier
== MODULE_START_ID
||
198 Identifier
== MODULE_END_ID
||
199 Identifier
== MODULE_LOADIMAGE_START_ID
||
200 Identifier
== MODULE_LOADIMAGE_END_ID
||
201 Identifier
== MODULE_DB_START_ID
||
202 Identifier
== MODULE_DB_END_ID
||
203 Identifier
== MODULE_DB_SUPPORT_START_ID
||
204 Identifier
== MODULE_DB_SUPPORT_END_ID
||
205 Identifier
== MODULE_DB_STOP_START_ID
||
206 Identifier
== MODULE_DB_STOP_END_ID
) {
214 Allocate buffer for Boot Performance table.
220 AllocateBootPerformanceTable (
225 UINT8
*SmmBootRecordCommBuffer
;
226 EFI_SMM_COMMUNICATE_HEADER
*SmmCommBufferHeader
;
227 SMM_BOOT_RECORD_COMMUNICATE
*SmmCommData
;
229 UINTN BootPerformanceDataSize
;
230 UINT8
*BootPerformanceData
;
231 EFI_SMM_COMMUNICATION_PROTOCOL
*Communication
;
232 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable
;
233 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE
*SmmCommRegionTable
;
234 EFI_MEMORY_DESCRIPTOR
*SmmCommMemRegion
;
236 VOID
*SmmBootRecordData
;
237 UINTN SmmBootRecordDataSize
;
238 UINTN ReservedMemSize
;
241 // Collect boot records from SMM drivers.
243 SmmBootRecordCommBuffer
= NULL
;
245 SmmBootRecordData
= NULL
;
246 SmmBootRecordDataSize
= 0;
248 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &Communication
);
249 if (!EFI_ERROR (Status
)) {
251 // Initialize communicate buffer
252 // Get the prepared Reserved Memory Range
254 Status
= EfiGetSystemConfigurationTable (
255 &gEdkiiPiSmmCommunicationRegionTableGuid
,
256 (VOID
**) &SmmCommRegionTable
258 if (!EFI_ERROR (Status
)) {
259 ASSERT (SmmCommRegionTable
!= NULL
);
260 SmmCommMemRegion
= (EFI_MEMORY_DESCRIPTOR
*) (SmmCommRegionTable
+ 1);
261 for (Index
= 0; Index
< SmmCommRegionTable
->NumberOfEntries
; Index
++) {
262 if (SmmCommMemRegion
->Type
== EfiConventionalMemory
) {
265 SmmCommMemRegion
= (EFI_MEMORY_DESCRIPTOR
*) ((UINT8
*) SmmCommMemRegion
+ SmmCommRegionTable
->DescriptorSize
);
267 ASSERT (Index
< SmmCommRegionTable
->NumberOfEntries
);
268 ASSERT (SmmCommMemRegion
->PhysicalStart
> 0);
269 ASSERT (SmmCommMemRegion
->NumberOfPages
> 0);
270 ReservedMemSize
= (UINTN
) SmmCommMemRegion
->NumberOfPages
* EFI_PAGE_SIZE
;
273 // Check enough reserved memory space
275 if (ReservedMemSize
> SMM_BOOT_RECORD_COMM_SIZE
) {
276 SmmBootRecordCommBuffer
= (VOID
*) (UINTN
) SmmCommMemRegion
->PhysicalStart
;
277 SmmCommBufferHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)SmmBootRecordCommBuffer
;
278 SmmCommData
= (SMM_BOOT_RECORD_COMMUNICATE
*)SmmCommBufferHeader
->Data
;
279 ZeroMem((UINT8
*)SmmCommData
, sizeof(SMM_BOOT_RECORD_COMMUNICATE
));
281 CopyGuid (&SmmCommBufferHeader
->HeaderGuid
, &gEfiFirmwarePerformanceGuid
);
282 SmmCommBufferHeader
->MessageLength
= sizeof(SMM_BOOT_RECORD_COMMUNICATE
);
283 CommSize
= SMM_BOOT_RECORD_COMM_SIZE
;
286 // Get the size of boot records.
288 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE
;
289 SmmCommData
->BootRecordData
= NULL
;
290 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
292 if (!EFI_ERROR (Status
) && !EFI_ERROR (SmmCommData
->ReturnStatus
) && SmmCommData
->BootRecordSize
!= 0) {
294 // Get all boot records
296 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET
;
297 SmmBootRecordDataSize
= SmmCommData
->BootRecordSize
;
298 SmmBootRecordData
= AllocateZeroPool(SmmBootRecordDataSize
);
299 ASSERT (SmmBootRecordData
!= NULL
);
300 SmmCommData
->BootRecordOffset
= 0;
301 SmmCommData
->BootRecordData
= (VOID
*) ((UINTN
) SmmCommMemRegion
->PhysicalStart
+ SMM_BOOT_RECORD_COMM_SIZE
);
302 SmmCommData
->BootRecordSize
= ReservedMemSize
- SMM_BOOT_RECORD_COMM_SIZE
;
303 while (SmmCommData
->BootRecordOffset
< SmmBootRecordDataSize
) {
304 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
305 ASSERT_EFI_ERROR (Status
);
306 ASSERT_EFI_ERROR(SmmCommData
->ReturnStatus
);
307 if (SmmCommData
->BootRecordOffset
+ SmmCommData
->BootRecordSize
> SmmBootRecordDataSize
) {
308 CopyMem ((UINT8
*) SmmBootRecordData
+ SmmCommData
->BootRecordOffset
, SmmCommData
->BootRecordData
, SmmBootRecordDataSize
- SmmCommData
->BootRecordOffset
);
310 CopyMem ((UINT8
*) SmmBootRecordData
+ SmmCommData
->BootRecordOffset
, SmmCommData
->BootRecordData
, SmmCommData
->BootRecordSize
);
312 SmmCommData
->BootRecordOffset
= SmmCommData
->BootRecordOffset
+ SmmCommData
->BootRecordSize
;
320 // Prepare memory for Boot Performance table.
321 // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.
323 BootPerformanceDataSize
= sizeof (BOOT_PERFORMANCE_TABLE
) + mPerformanceLength
+ PcdGet32 (PcdExtFpdtBootRecordPadSize
);
324 if (SmmCommData
!= NULL
&& SmmBootRecordData
!= NULL
) {
325 BootPerformanceDataSize
+= SmmBootRecordDataSize
;
329 // Try to allocate the same runtime buffer as last time boot.
331 ZeroMem (&PerformanceVariable
, sizeof (PerformanceVariable
));
332 Size
= sizeof (PerformanceVariable
);
333 Status
= gRT
->GetVariable (
334 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
335 &gEfiFirmwarePerformanceGuid
,
340 if (!EFI_ERROR (Status
)) {
341 Status
= gBS
->AllocatePages (
343 EfiReservedMemoryType
,
344 EFI_SIZE_TO_PAGES (BootPerformanceDataSize
),
345 &PerformanceVariable
.BootPerformanceTablePointer
347 if (!EFI_ERROR (Status
)) {
348 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*) (UINTN
) PerformanceVariable
.BootPerformanceTablePointer
;
352 if (mAcpiBootPerformanceTable
== NULL
) {
354 // Fail to allocate at specified address, continue to allocate at any address.
356 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*) AllocatePeiAccessiblePages (
357 EfiReservedMemoryType
,
358 EFI_SIZE_TO_PAGES (BootPerformanceDataSize
)
360 if (mAcpiBootPerformanceTable
!= NULL
) {
361 ZeroMem (mAcpiBootPerformanceTable
, BootPerformanceDataSize
);
364 DEBUG ((DEBUG_INFO
, "DxeCorePerformanceLib: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable
));
366 if (mAcpiBootPerformanceTable
== NULL
) {
367 if (SmmCommData
!= NULL
&& SmmBootRecordData
!= NULL
) {
368 FreePool (SmmBootRecordData
);
370 return EFI_OUT_OF_RESOURCES
;
374 // Prepare Boot Performance Table.
376 BootPerformanceData
= (UINT8
*) mAcpiBootPerformanceTable
;
378 // Fill Basic Boot record to Boot Performance Table.
380 CopyMem (mAcpiBootPerformanceTable
, &mBootPerformanceTableTemplate
, sizeof (mBootPerformanceTableTemplate
));
381 BootPerformanceData
= BootPerformanceData
+ mAcpiBootPerformanceTable
->Header
.Length
;
383 // Fill Boot records from boot drivers.
385 if (mPerformancePointer
!= NULL
) {
386 CopyMem (BootPerformanceData
, mPerformancePointer
, mPerformanceLength
);
387 mAcpiBootPerformanceTable
->Header
.Length
+= mPerformanceLength
;
388 BootPerformanceData
= BootPerformanceData
+ mPerformanceLength
;
389 FreePool (mPerformancePointer
);
390 mPerformancePointer
= NULL
;
391 mPerformanceLength
= 0;
392 mMaxPerformanceLength
= 0;
394 if (SmmCommData
!= NULL
&& SmmBootRecordData
!= NULL
) {
396 // Fill Boot records from SMM drivers.
398 CopyMem (BootPerformanceData
, SmmBootRecordData
, SmmBootRecordDataSize
);
399 FreePool (SmmBootRecordData
);
400 mAcpiBootPerformanceTable
->Header
.Length
= (UINT32
) (mAcpiBootPerformanceTable
->Header
.Length
+ SmmBootRecordDataSize
);
401 BootPerformanceData
= BootPerformanceData
+ SmmBootRecordDataSize
;
404 mBootRecordBuffer
= (UINT8
*) mAcpiBootPerformanceTable
;
405 mBootRecordSize
= mAcpiBootPerformanceTable
->Header
.Length
;
406 mBootRecordMaxSize
= mBootRecordSize
+ PcdGet32 (PcdExtFpdtBootRecordPadSize
);
412 Get a human readable module name and module guid for the given image handle.
413 If module name can't be found, "" string will return.
414 If module guid can't be found, Zero Guid will return.
416 @param Handle Image handle or Controller handle.
417 @param NameString The ascii string will be filled into it. If not found, null string will return.
418 @param BufferSize Size of the input NameString buffer.
419 @param ModuleGuid Point to the guid buffer to store the got module guid value.
421 @retval EFI_SUCCESS Successfully get module name and guid.
422 @retval EFI_INVALID_PARAMETER The input parameter NameString is NULL.
423 @retval other value Module Name can't be got.
426 GetModuleInfoFromHandle (
427 IN EFI_HANDLE Handle
,
428 OUT CHAR8
*NameString
,
430 OUT EFI_GUID
*ModuleGuid OPTIONAL
434 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
435 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
441 BOOLEAN ModuleGuidIsGet
;
444 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
445 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*FvFilePath
;
447 if (NameString
== NULL
|| BufferSize
== 0) {
448 return EFI_INVALID_PARAMETER
;
451 // Try to get the ModuleGuid and name string form the caached array.
453 if (mCachePairCount
> 0) {
454 for (Count
= mCachePairCount
-1; Count
>= 0; Count
--) {
455 if (Handle
== mCacheHandleGuidTable
[Count
].Handle
) {
456 CopyGuid (ModuleGuid
, &mCacheHandleGuidTable
[Count
].ModuleGuid
);
457 AsciiStrCpyS (NameString
, FPDT_STRING_EVENT_RECORD_NAME_LENGTH
, mCacheHandleGuidTable
[Count
].NameString
);
463 Status
= EFI_INVALID_PARAMETER
;
465 ModuleGuidIsGet
= FALSE
;
468 // Initialize GUID as zero value.
470 TempGuid
= &gZeroGuid
;
472 // Initialize it as "" string.
476 if (Handle
!= NULL
) {
478 // Try Handle as ImageHandle.
480 Status
= gBS
->HandleProtocol (
482 &gEfiLoadedImageProtocolGuid
,
483 (VOID
**) &LoadedImage
486 if (EFI_ERROR (Status
)) {
488 // Try Handle as Controller Handle
490 Status
= gBS
->OpenProtocol (
492 &gEfiDriverBindingProtocolGuid
,
493 (VOID
**) &DriverBinding
,
496 EFI_OPEN_PROTOCOL_GET_PROTOCOL
498 if (!EFI_ERROR (Status
)) {
500 // Get Image protocol from ImageHandle
502 Status
= gBS
->HandleProtocol (
503 DriverBinding
->ImageHandle
,
504 &gEfiLoadedImageProtocolGuid
,
505 (VOID
**) &LoadedImage
511 if (!EFI_ERROR (Status
) && LoadedImage
!= NULL
) {
513 // Get Module Guid from DevicePath.
515 if (LoadedImage
->FilePath
!= NULL
&&
516 LoadedImage
->FilePath
->Type
== MEDIA_DEVICE_PATH
&&
517 LoadedImage
->FilePath
->SubType
== MEDIA_PIWG_FW_FILE_DP
520 // Determine GUID associated with module logging performance
522 ModuleGuidIsGet
= TRUE
;
523 FvFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) LoadedImage
->FilePath
;
524 TempGuid
= &FvFilePath
->FvFileName
;
528 // Method 1 Get Module Name from PDB string.
530 PdbFileName
= PeCoffLoaderGetPdbPointer (LoadedImage
->ImageBase
);
531 if (PdbFileName
!= NULL
&& BufferSize
> 0) {
533 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
534 if ((PdbFileName
[Index
] == '\\') || (PdbFileName
[Index
] == '/')) {
535 StartIndex
= Index
+ 1;
539 // Copy the PDB file name to our temporary string.
540 // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.
542 for (Index
= 0; Index
< BufferSize
- 1; Index
++) {
543 NameString
[Index
] = PdbFileName
[Index
+ StartIndex
];
544 if (NameString
[Index
] == 0 || NameString
[Index
] == '.') {
545 NameString
[Index
] = 0;
550 if (Index
== BufferSize
- 1) {
551 NameString
[Index
] = 0;
554 // Module Name is got.
561 // Method 2: Get the name string from ComponentName2 protocol
563 Status
= gBS
->HandleProtocol (
565 &gEfiComponentName2ProtocolGuid
,
566 (VOID
**) &ComponentName2
568 if (!EFI_ERROR (Status
)) {
570 // Get the current platform language setting
572 if (mPlatformLanguage
== NULL
) {
573 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**) &mPlatformLanguage
, NULL
);
575 if (mPlatformLanguage
!= NULL
) {
576 Status
= ComponentName2
->GetDriverName (
578 mPlatformLanguage
!= NULL
? mPlatformLanguage
: "en-US",
581 if (!EFI_ERROR (Status
)) {
582 for (Index
= 0; Index
< BufferSize
- 1 && StringPtr
[Index
] != 0; Index
++) {
583 NameString
[Index
] = (CHAR8
) StringPtr
[Index
];
585 NameString
[Index
] = 0;
587 // Module Name is got.
594 if (ModuleGuidIsGet
) {
596 // Method 3 Try to get the image's FFS UI section by image GUID
600 Status
= GetSectionFromAnyFv (
602 EFI_SECTION_USER_INTERFACE
,
604 (VOID
**) &StringPtr
,
608 if (!EFI_ERROR (Status
)) {
610 // Method 3. Get the name string from FFS UI section
612 for (Index
= 0; Index
< BufferSize
- 1 && StringPtr
[Index
] != 0; Index
++) {
613 NameString
[Index
] = (CHAR8
) StringPtr
[Index
];
615 NameString
[Index
] = 0;
616 FreePool (StringPtr
);
624 if (ModuleGuid
!= NULL
) {
625 CopyGuid (ModuleGuid
, TempGuid
);
626 if (IsZeroGuid(TempGuid
) && (Handle
!= NULL
) && !ModuleGuidIsGet
) {
628 CopyGuid (ModuleGuid
, (EFI_GUID
*) Handle
);
633 // Cache the Handle and Guid pairs.
635 if (mCachePairCount
< CACHE_HANDLE_GUID_COUNT
) {
636 mCacheHandleGuidTable
[mCachePairCount
].Handle
= Handle
;
637 CopyGuid (&mCacheHandleGuidTable
[mCachePairCount
].ModuleGuid
, ModuleGuid
);
638 AsciiStrCpyS (mCacheHandleGuidTable
[mCachePairCount
].NameString
, FPDT_STRING_EVENT_RECORD_NAME_LENGTH
, NameString
);
646 Get the FPDT record identifier.
648 @param Attribute The attribute of the Record.
649 PerfStartEntry: Start Record.
650 PerfEndEntry: End Record.
651 @param Handle Pointer to environment specific context used to identify the component being measured.
652 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.
653 @param ProgressID On return, pointer to the ProgressID.
655 @retval EFI_SUCCESS Get record info successfully.
656 @retval EFI_INVALID_PARAMETER No matched FPDT record.
661 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
,
662 IN CONST VOID
*Handle
,
663 IN CONST CHAR8
*String
,
664 OUT UINT16
*ProgressID
670 if (String
!= NULL
) {
671 if (AsciiStrCmp (String
, START_IMAGE_TOK
) == 0) { // "StartImage:"
672 if (Attribute
== PerfStartEntry
) {
673 *ProgressID
= MODULE_START_ID
;
675 *ProgressID
= MODULE_END_ID
;
677 } else if (AsciiStrCmp (String
, LOAD_IMAGE_TOK
) == 0) { // "LoadImage:"
678 if (Attribute
== PerfStartEntry
) {
679 *ProgressID
= MODULE_LOADIMAGE_START_ID
;
681 *ProgressID
= MODULE_LOADIMAGE_END_ID
;
683 } else if (AsciiStrCmp (String
, DRIVERBINDING_START_TOK
) == 0) { // "DB:Start:"
684 if (Attribute
== PerfStartEntry
) {
685 *ProgressID
= MODULE_DB_START_ID
;
687 *ProgressID
= MODULE_DB_END_ID
;
689 } else if (AsciiStrCmp (String
, DRIVERBINDING_SUPPORT_TOK
) == 0) { // "DB:Support:"
690 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
691 return RETURN_UNSUPPORTED
;
693 if (Attribute
== PerfStartEntry
) {
694 *ProgressID
= MODULE_DB_SUPPORT_START_ID
;
696 *ProgressID
= MODULE_DB_SUPPORT_END_ID
;
698 } else if (AsciiStrCmp (String
, DRIVERBINDING_STOP_TOK
) == 0) { // "DB:Stop:"
699 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
700 return RETURN_UNSUPPORTED
;
702 if (Attribute
== PerfStartEntry
) {
703 *ProgressID
= MODULE_DB_STOP_START_ID
;
705 *ProgressID
= MODULE_DB_STOP_END_ID
;
707 } else if (AsciiStrCmp (String
, PEI_TOK
) == 0 || // "PEI"
708 AsciiStrCmp (String
, DXE_TOK
) == 0 || // "DXE"
709 AsciiStrCmp (String
, BDS_TOK
) == 0) { // "BDS"
710 if (Attribute
== PerfStartEntry
) {
711 *ProgressID
= PERF_CROSSMODULE_START_ID
;
713 *ProgressID
= PERF_CROSSMODULE_END_ID
;
715 } else { // Pref used in Modules.
716 if (Attribute
== PerfStartEntry
) {
717 *ProgressID
= PERF_INMODULE_START_ID
;
719 *ProgressID
= PERF_INMODULE_END_ID
;
722 } else if (Handle
!= NULL
) { // Pref used in Modules.
723 if (Attribute
== PerfStartEntry
) {
724 *ProgressID
= PERF_INMODULE_START_ID
;
726 *ProgressID
= PERF_INMODULE_END_ID
;
729 return EFI_INVALID_PARAMETER
;
735 Copies the string from Source into Destination and updates Length with the
738 @param Destination - destination of the string copy
739 @param Source - pointer to the source string which will get copied
740 @param Length - pointer to a length variable to be updated
744 CopyStringIntoPerfRecordAndUpdateLength (
745 IN OUT CHAR8
*Destination
,
746 IN CONST CHAR8
*Source
,
753 ASSERT (Source
!= NULL
);
755 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
756 DestMax
= STRING_SIZE
;
758 DestMax
= AsciiStrSize (Source
);
759 if (DestMax
> STRING_SIZE
) {
760 DestMax
= STRING_SIZE
;
763 StringLen
= AsciiStrLen (Source
);
764 if (StringLen
>= DestMax
) {
765 StringLen
= DestMax
-1;
768 AsciiStrnCpyS(Destination
, DestMax
, Source
, StringLen
);
769 *Length
+= (UINT8
)DestMax
;
775 Get a string description for device for the given controller handle and update record
776 length. If ComponentName2 GetControllerName is supported, the value is included in the string,
777 followed by device path, otherwise just device path.
779 @param Handle - Image handle
780 @param ControllerHandle - Controller handle.
781 @param ComponentNameString - Pointer to a location where the string will be saved
782 @param Length - Pointer to record length to be updated
784 @retval EFI_SUCCESS - Successfully got string description for device
785 @retval EFI_UNSUPPORTED - Neither ComponentName2 ControllerName nor DevicePath were found
789 GetDeviceInfoFromHandleAndUpdateLength (
790 IN CONST VOID
*Handle
,
791 IN EFI_HANDLE ControllerHandle
,
792 OUT CHAR8
*ComponentNameString
,
796 EFI_DEVICE_PATH_PROTOCOL
*DevicePathProtocol
;
797 EFI_COMPONENT_NAME2_PROTOCOL
*ComponentName2
;
800 CHAR8
*AsciiStringPtr
;
801 UINTN ControllerNameStringSize
;
802 UINTN DevicePathStringSize
;
804 ControllerNameStringSize
= 0;
806 Status
= gBS
->HandleProtocol (
808 &gEfiComponentName2ProtocolGuid
,
809 (VOID
**) &ComponentName2
812 if (!EFI_ERROR(Status
)) {
814 // Get the current platform language setting
816 if (mPlatformLanguage
== NULL
) {
817 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&mPlatformLanguage
, NULL
);
820 Status
= ComponentName2
->GetControllerName (
824 mPlatformLanguage
!= NULL
? mPlatformLanguage
: "en-US",
829 if (!EFI_ERROR (Status
)) {
831 // This will produce the size of the unicode string, which is twice as large as the ASCII one
832 // This must be an even number, so ok to divide by 2
834 ControllerNameStringSize
= StrSize(StringPtr
) / 2;
837 // The + 1 is because we want to add a space between the ControllerName and the device path
839 if ((ControllerNameStringSize
+ (*Length
) + 1) > FPDT_MAX_PERF_RECORD_SIZE
) {
841 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
843 ControllerNameStringSize
= FPDT_MAX_PERF_RECORD_SIZE
- (*Length
) - 1;
846 UnicodeStrToAsciiStrS(StringPtr
, ComponentNameString
, ControllerNameStringSize
);
849 // Add a space in the end of the ControllerName
851 AsciiStringPtr
= ComponentNameString
+ ControllerNameStringSize
- 1;
852 *AsciiStringPtr
= 0x20;
855 ControllerNameStringSize
++;
857 *Length
+= (UINT8
)ControllerNameStringSize
;
861 // This function returns the device path protocol from the handle specified by Handle. If Handle is
862 // NULL or Handle does not contain a device path protocol, then NULL is returned.
864 DevicePathProtocol
= DevicePathFromHandle(ControllerHandle
);
866 if (DevicePathProtocol
!= NULL
) {
867 StringPtr
= ConvertDevicePathToText (DevicePathProtocol
, TRUE
, FALSE
);
868 if (StringPtr
!= NULL
) {
870 // This will produce the size of the unicode string, which is twice as large as the ASCII one
871 // This must be an even number, so ok to divide by 2
873 DevicePathStringSize
= StrSize(StringPtr
) / 2;
875 if ((DevicePathStringSize
+ (*Length
)) > FPDT_MAX_PERF_RECORD_SIZE
) {
877 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record
879 DevicePathStringSize
= FPDT_MAX_PERF_RECORD_SIZE
- (*Length
);
882 if (ControllerNameStringSize
!= 0) {
883 AsciiStringPtr
= ComponentNameString
+ ControllerNameStringSize
- 1;
885 AsciiStringPtr
= ComponentNameString
;
888 UnicodeStrToAsciiStrS(StringPtr
, AsciiStringPtr
, DevicePathStringSize
);
889 *Length
+= (UINT8
)DevicePathStringSize
;
894 return EFI_UNSUPPORTED
;
898 Create performance record with event description and a timestamp.
900 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
901 @param Guid - Pointer to a GUID.
902 @param String - Pointer to a string describing the measurement.
903 @param Ticker - 64-bit time stamp.
904 @param Address - Pointer to a location in memory relevant to the measurement.
905 @param PerfId - Performance identifier describing the type of measurement.
906 @param Attribute - The attribute of the measurement. According to attribute can create a start
907 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
908 or a general record for other Perf macros.
910 @retval EFI_SUCCESS - Successfully created performance record.
911 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
912 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
913 pointer or invalid PerfId.
915 @retval EFI_SUCCESS - Successfully created performance record
916 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records
917 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
918 pointer or invalid PerfId
923 IN CONST VOID
*CallerIdentifier
, OPTIONAL
924 IN CONST VOID
*Guid
, OPTIONAL
925 IN CONST CHAR8
*String
, OPTIONAL
927 IN UINT64 Address
, OPTIONAL
929 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
933 CHAR8 ModuleName
[FPDT_STRING_EVENT_RECORD_NAME_LENGTH
];
934 FPDT_RECORD_PTR FpdtRecordPtr
;
935 FPDT_RECORD_PTR CachedFpdtRecordPtr
;
937 CONST CHAR8
*StringPtr
;
945 ZeroMem (ModuleName
, sizeof (ModuleName
));
948 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.
949 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.
951 if (Attribute
!= PerfEntry
) {
953 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.
954 // !!! Note: If the Perf is not the known Token used in the core but have same
955 // ID with the core Token, this case will not be supported.
956 // And in currtnt usage mode, for the unkown ID, there is a general rule:
957 // If it is start pref: the lower 4 bits of the ID should be 0.
958 // If it is end pref: the lower 4 bits of the ID should not be 0.
959 // If input ID doesn't follow the rule, we will adjust it.
961 if ((PerfId
!= 0) && (IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
962 return EFI_INVALID_PARAMETER
;
963 } else if ((PerfId
!= 0) && (!IsKnownID (PerfId
)) && (!IsKnownTokens (String
))) {
964 if ((Attribute
== PerfStartEntry
) && ((PerfId
& 0x000F) != 0)) {
966 } else if ((Attribute
== PerfEndEntry
) && ((PerfId
& 0x000F) == 0)) {
969 } else if (PerfId
== 0) {
971 // Get ProgressID form the String Token.
973 Status
= GetFpdtRecordId (Attribute
, CallerIdentifier
, String
, &ProgressId
);
974 if (EFI_ERROR (Status
)) {
982 // 2. Get the buffer to store the FPDT record.
984 Status
= GetFpdtRecordPtr (FPDT_MAX_PERF_RECORD_SIZE
, &FpdtRecordPtr
);
985 if (EFI_ERROR (Status
)) {
990 //3. Get the TimeStamp.
993 Ticker
= GetPerformanceCounter ();
994 TimeStamp
= GetTimeInNanoSecond (Ticker
);
995 } else if (Ticker
== 1) {
998 TimeStamp
= GetTimeInNanoSecond (Ticker
);
1002 // 4. Fill in the FPDT record according to different Performance Identifier.
1005 case MODULE_START_ID
:
1007 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1008 StringPtr
= ModuleName
;
1010 // Cache the offset of start image start record and use to update the start image end record if needed.
1012 if (Attribute
== PerfEntry
&& PerfId
== MODULE_START_ID
) {
1013 if (mFpdtBufferIsReported
) {
1014 mCachedLength
= mBootRecordSize
;
1016 mCachedLength
= mPerformanceLength
;
1019 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1020 FpdtRecordPtr
.GuidEvent
->Header
.Type
= FPDT_GUID_EVENT_TYPE
;
1021 FpdtRecordPtr
.GuidEvent
->Header
.Length
= sizeof (FPDT_GUID_EVENT_RECORD
);
1022 FpdtRecordPtr
.GuidEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1023 FpdtRecordPtr
.GuidEvent
->ProgressID
= PerfId
;
1024 FpdtRecordPtr
.GuidEvent
->Timestamp
= TimeStamp
;
1025 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidEvent
->Guid
));
1026 if (CallerIdentifier
== NULL
&& PerfId
== MODULE_END_ID
&& mCachedLength
!= 0) {
1027 if (mFpdtBufferIsReported
) {
1028 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mCachedLength
);
1030 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mCachedLength
);
1032 CopyMem (&FpdtRecordPtr
.GuidEvent
->Guid
, &CachedFpdtRecordPtr
.GuidEvent
->Guid
, sizeof (FpdtRecordPtr
.GuidEvent
->Guid
));
1038 case MODULE_LOADIMAGE_START_ID
:
1039 case MODULE_LOADIMAGE_END_ID
:
1040 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1041 StringPtr
= ModuleName
;
1042 if (PerfId
== MODULE_LOADIMAGE_START_ID
) {
1045 // Cache the offset of load image start record and use to be updated by the load image end record if needed.
1047 if (CallerIdentifier
== NULL
&& Attribute
== PerfEntry
) {
1048 if (mFpdtBufferIsReported
) {
1049 mCachedLength
= mBootRecordSize
;
1051 mCachedLength
= mPerformanceLength
;
1055 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1056 FpdtRecordPtr
.GuidQwordEvent
->Header
.Type
= FPDT_GUID_QWORD_EVENT_TYPE
;
1057 FpdtRecordPtr
.GuidQwordEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_EVENT_RECORD
);
1058 FpdtRecordPtr
.GuidQwordEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1059 FpdtRecordPtr
.GuidQwordEvent
->ProgressID
= PerfId
;
1060 FpdtRecordPtr
.GuidQwordEvent
->Timestamp
= TimeStamp
;
1061 FpdtRecordPtr
.GuidQwordEvent
->Qword
= mLoadImageCount
;
1062 CopyMem (&FpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordEvent
->Guid
));
1063 if (PerfId
== MODULE_LOADIMAGE_END_ID
&& mCachedLength
!= 0) {
1064 if (mFpdtBufferIsReported
) {
1065 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mCachedLength
);
1067 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mCachedLength
);
1069 CopyMem (&CachedFpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (CachedFpdtRecordPtr
.GuidQwordEvent
->Guid
));
1075 case MODULE_DB_START_ID
:
1076 case MODULE_DB_SUPPORT_START_ID
:
1077 case MODULE_DB_SUPPORT_END_ID
:
1078 case MODULE_DB_STOP_START_ID
:
1079 case MODULE_DB_STOP_END_ID
:
1080 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1081 StringPtr
= ModuleName
;
1082 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1083 FpdtRecordPtr
.GuidQwordEvent
->Header
.Type
= FPDT_GUID_QWORD_EVENT_TYPE
;
1084 FpdtRecordPtr
.GuidQwordEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_EVENT_RECORD
);
1085 FpdtRecordPtr
.GuidQwordEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1086 FpdtRecordPtr
.GuidQwordEvent
->ProgressID
= PerfId
;
1087 FpdtRecordPtr
.GuidQwordEvent
->Timestamp
= TimeStamp
;
1088 FpdtRecordPtr
.GuidQwordEvent
->Qword
= Address
;
1089 CopyMem (&FpdtRecordPtr
.GuidQwordEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordEvent
->Guid
));
1093 case MODULE_DB_END_ID
:
1094 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1095 StringPtr
= ModuleName
;
1096 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1097 FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Type
= FPDT_GUID_QWORD_STRING_EVENT_TYPE
;
1098 FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Length
= sizeof (FPDT_GUID_QWORD_STRING_EVENT_RECORD
);;
1099 FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1100 FpdtRecordPtr
.GuidQwordStringEvent
->ProgressID
= PerfId
;
1101 FpdtRecordPtr
.GuidQwordStringEvent
->Timestamp
= TimeStamp
;
1102 FpdtRecordPtr
.GuidQwordStringEvent
->Qword
= Address
;
1103 CopyMem (&FpdtRecordPtr
.GuidQwordStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.GuidQwordStringEvent
->Guid
));
1105 GetDeviceInfoFromHandleAndUpdateLength(CallerIdentifier
, (EFI_HANDLE
)(UINTN
)Address
, FpdtRecordPtr
.GuidQwordStringEvent
->String
, &FpdtRecordPtr
.GuidQwordStringEvent
->Header
.Length
);
1110 case PERF_EVENTSIGNAL_START_ID
:
1111 case PERF_EVENTSIGNAL_END_ID
:
1112 case PERF_CALLBACK_START_ID
:
1113 case PERF_CALLBACK_END_ID
:
1114 if (String
== NULL
|| Guid
== NULL
) {
1115 return EFI_INVALID_PARAMETER
;
1118 if (AsciiStrLen (String
) == 0) {
1119 StringPtr
= "unknown name";
1121 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1122 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Type
= FPDT_DUAL_GUID_STRING_EVENT_TYPE
;
1123 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
= sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD
);
1124 FpdtRecordPtr
.DualGuidStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1125 FpdtRecordPtr
.DualGuidStringEvent
->ProgressID
= PerfId
;
1126 FpdtRecordPtr
.DualGuidStringEvent
->Timestamp
= TimeStamp
;
1127 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid1
, CallerIdentifier
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid1
));
1128 CopyMem (&FpdtRecordPtr
.DualGuidStringEvent
->Guid2
, Guid
, sizeof (FpdtRecordPtr
.DualGuidStringEvent
->Guid2
));
1129 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DualGuidStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DualGuidStringEvent
->Header
.Length
);
1134 case PERF_FUNCTION_START_ID
:
1135 case PERF_FUNCTION_END_ID
:
1136 case PERF_INMODULE_START_ID
:
1137 case PERF_INMODULE_END_ID
:
1138 case PERF_CROSSMODULE_START_ID
:
1139 case PERF_CROSSMODULE_END_ID
:
1140 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1141 if (String
!= NULL
) {
1144 StringPtr
= ModuleName
;
1146 if (AsciiStrLen (StringPtr
) == 0) {
1147 StringPtr
= "unknown name";
1149 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1150 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
1151 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1152 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1153 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
1154 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
1155 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1156 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
1161 if (Attribute
!= PerfEntry
) {
1162 GetModuleInfoFromHandle ((EFI_HANDLE
*)CallerIdentifier
, ModuleName
, sizeof (ModuleName
), &ModuleGuid
);
1163 if (String
!= NULL
) {
1166 StringPtr
= ModuleName
;
1168 if (AsciiStrLen (StringPtr
) == 0) {
1169 StringPtr
= "unknown name";
1171 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1172 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
1173 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1174 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1175 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
1176 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
1177 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1178 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
1181 return EFI_INVALID_PARAMETER
;
1187 // 4.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.
1189 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly
)) {
1190 if (StringPtr
== NULL
||PerfId
== MODULE_DB_SUPPORT_START_ID
|| PerfId
== MODULE_DB_SUPPORT_END_ID
) {
1191 return EFI_INVALID_PARAMETER
;
1193 FpdtRecordPtr
.DynamicStringEvent
->Header
.Type
= FPDT_DYNAMIC_STRING_EVENT_TYPE
;
1194 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1195 FpdtRecordPtr
.DynamicStringEvent
->Header
.Revision
= FPDT_RECORD_REVISION_1
;
1196 FpdtRecordPtr
.DynamicStringEvent
->ProgressID
= PerfId
;
1197 FpdtRecordPtr
.DynamicStringEvent
->Timestamp
= TimeStamp
;
1200 // Cache the event guid in string event record.
1202 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, Guid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1204 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (FpdtRecordPtr
.DynamicStringEvent
->Guid
));
1206 if (AsciiStrLen (StringPtr
) == 0) {
1207 StringPtr
= "unknown name";
1209 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr
.DynamicStringEvent
->String
, StringPtr
, &FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
);
1211 if ((PerfId
== MODULE_LOADIMAGE_START_ID
) || (PerfId
== MODULE_END_ID
)) {
1212 FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
= (UINT8
)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
)+ STRING_SIZE
);
1214 if ((PerfId
== MODULE_LOADIMAGE_END_ID
|| PerfId
== MODULE_END_ID
) && mCachedLength
!= 0) {
1215 if (mFpdtBufferIsReported
) {
1216 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mBootRecordBuffer
+ mCachedLength
);
1218 CachedFpdtRecordPtr
.RecordHeader
= (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER
*)(mPerformancePointer
+ mCachedLength
);
1220 if (PerfId
== MODULE_LOADIMAGE_END_ID
) {
1221 DestMax
= CachedFpdtRecordPtr
.DynamicStringEvent
->Header
.Length
- sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1222 StringLen
= AsciiStrLen (StringPtr
);
1223 if (StringLen
>= DestMax
) {
1224 StringLen
= DestMax
-1;
1226 CopyMem (&CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
, &ModuleGuid
, sizeof (CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
));
1227 AsciiStrnCpyS (CachedFpdtRecordPtr
.DynamicStringEvent
->String
, DestMax
, StringPtr
, StringLen
);
1228 } else if (PerfId
== MODULE_END_ID
) {
1229 DestMax
= FpdtRecordPtr
.DynamicStringEvent
->Header
.Length
- sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD
);
1230 StringLen
= AsciiStrLen (CachedFpdtRecordPtr
.DynamicStringEvent
->String
);
1231 if (StringLen
>= DestMax
) {
1232 StringLen
= DestMax
-1;
1234 CopyMem (&FpdtRecordPtr
.DynamicStringEvent
->Guid
, &CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
, sizeof (CachedFpdtRecordPtr
.DynamicStringEvent
->Guid
));
1235 AsciiStrnCpyS (FpdtRecordPtr
.DynamicStringEvent
->String
, DestMax
, CachedFpdtRecordPtr
.DynamicStringEvent
->String
, StringLen
);
1242 // 5. Update the length of the used buffer after fill in the record.
1244 if (mFpdtBufferIsReported
) {
1245 mBootRecordSize
+= FpdtRecordPtr
.RecordHeader
->Length
;
1246 mAcpiBootPerformanceTable
->Header
.Length
+= FpdtRecordPtr
.RecordHeader
->Length
;
1248 mPerformanceLength
+= FpdtRecordPtr
.RecordHeader
->Length
;
1254 Dumps all the PEI performance.
1256 @param HobStart A pointer to a Guid.
1258 This internal function dumps all the PEI performance log to the DXE performance gauge array.
1259 It retrieves the optional GUID HOB for PEI performance and then saves the performance data
1260 to DXE performance data structures.
1264 InternalGetPeiPerformance (
1268 UINT8
*FirmwarePerformanceHob
;
1269 FPDT_PEI_EXT_PERF_HEADER
*PeiPerformanceLogHeader
;
1271 EFI_HOB_GUID_TYPE
*GuidHob
;
1273 GuidHob
= GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, HobStart
);
1274 while (GuidHob
!= NULL
) {
1275 FirmwarePerformanceHob
= GET_GUID_HOB_DATA (GuidHob
);
1276 PeiPerformanceLogHeader
= (FPDT_PEI_EXT_PERF_HEADER
*)FirmwarePerformanceHob
;
1278 if (mPerformanceLength
+ PeiPerformanceLogHeader
->SizeOfAllEntries
> mMaxPerformanceLength
) {
1279 mPerformancePointer
= ReallocatePool (
1281 mPerformanceLength
+
1282 (UINTN
)PeiPerformanceLogHeader
->SizeOfAllEntries
+
1283 FIRMWARE_RECORD_BUFFER
,
1286 ASSERT (mPerformancePointer
!= NULL
);
1287 mMaxPerformanceLength
= mPerformanceLength
+
1288 (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
) +
1289 FIRMWARE_RECORD_BUFFER
;
1292 EventRec
= mPerformancePointer
+ mPerformanceLength
;
1293 CopyMem (EventRec
, FirmwarePerformanceHob
+ sizeof (FPDT_PEI_EXT_PERF_HEADER
), (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
));
1295 // Update the used buffer size.
1297 mPerformanceLength
+= (UINTN
)(PeiPerformanceLogHeader
->SizeOfAllEntries
);
1298 mLoadImageCount
+= PeiPerformanceLogHeader
->LoadImageCount
;
1301 // Get next performance guid hob
1303 GuidHob
= GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid
, GET_NEXT_HOB (GuidHob
));
1308 Report Boot Perforamnce table address as report status code.
1310 @param Event The event of notify protocol.
1311 @param Context Notify event context.
1316 ReportFpdtRecordBuffer (
1324 if (!mFpdtBufferIsReported
) {
1325 Status
= AllocateBootPerformanceTable ();
1326 if (!EFI_ERROR(Status
)) {
1327 BPDTAddr
= (UINT64
)(UINTN
)mAcpiBootPerformanceTable
;
1328 REPORT_STATUS_CODE_EX (
1330 EFI_SOFTWARE_DXE_BS_DRIVER
,
1333 &gEdkiiFpdtExtendedFirmwarePerformanceGuid
,
1339 // Set FPDT report state to TRUE.
1341 mFpdtBufferIsReported
= TRUE
;
1346 The constructor function initializes Performance infrastructure for DXE phase.
1348 The constructor function publishes Performance and PerformanceEx protocol, allocates memory to log DXE performance
1349 and merges PEI performance data to DXE performance log.
1350 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.
1352 @param ImageHandle The firmware allocated handle for the EFI image.
1353 @param SystemTable A pointer to the EFI System Table.
1355 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
1360 DxeCorePerformanceLibConstructor (
1361 IN EFI_HANDLE ImageHandle
,
1362 IN EFI_SYSTEM_TABLE
*SystemTable
1367 EFI_EVENT ReadyToBootEvent
;
1368 PERFORMANCE_PROPERTY
*PerformanceProperty
;
1370 if (!PerformanceMeasurementEnabled ()) {
1372 // Do not initialize performance infrastructure if not required.
1378 // Dump normal PEI performance records
1380 InternalGetPeiPerformance (GetHobList());
1383 // Install the protocol interfaces for DXE performance library instance.
1386 Status
= gBS
->InstallMultipleProtocolInterfaces (
1388 &gEdkiiPerformanceMeasurementProtocolGuid
,
1389 &mPerformanceMeasurementInterface
,
1392 ASSERT_EFI_ERROR (Status
);
1395 // Register ReadyToBoot event to report StatusCode data
1397 Status
= gBS
->CreateEventEx (
1400 ReportFpdtRecordBuffer
,
1402 &gEfiEventReadyToBootGuid
,
1406 ASSERT_EFI_ERROR (Status
);
1408 Status
= EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid
, (VOID
**) &PerformanceProperty
);
1409 if (EFI_ERROR (Status
)) {
1411 // Install configuration table for performance property.
1413 mPerformanceProperty
.Revision
= PERFORMANCE_PROPERTY_REVISION
;
1414 mPerformanceProperty
.Reserved
= 0;
1415 mPerformanceProperty
.Frequency
= GetPerformanceCounterProperties (
1416 &mPerformanceProperty
.TimerStartValue
,
1417 &mPerformanceProperty
.TimerEndValue
1419 Status
= gBS
->InstallConfigurationTable (&gPerformanceProtocolGuid
, &mPerformanceProperty
);
1420 ASSERT_EFI_ERROR (Status
);
1427 Create performance record with event description and a timestamp.
1429 @param CallerIdentifier - Image handle or pointer to caller ID GUID.
1430 @param Guid - Pointer to a GUID.
1431 @param String - Pointer to a string describing the measurement.
1432 @param TimeStamp - 64-bit time stamp.
1433 @param Address - Pointer to a location in memory relevant to the measurement.
1434 @param Identifier - Performance identifier describing the type of measurement.
1435 @param Attribute - The attribute of the measurement. According to attribute can create a start
1436 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,
1437 or a general record for other Perf macros.
1439 @retval EFI_SUCCESS - Successfully created performance record.
1440 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.
1441 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL
1442 pointer or invalid PerfId.
1446 CreatePerformanceMeasurement (
1447 IN CONST VOID
*CallerIdentifier
,
1448 IN CONST VOID
*Guid
, OPTIONAL
1449 IN CONST CHAR8
*String
, OPTIONAL
1450 IN UINT64 TimeStamp
,
1451 IN UINT64 Address
, OPTIONAL
1452 IN UINT32 Identifier
,
1453 IN PERF_MEASUREMENT_ATTRIBUTE Attribute
1458 Status
= EFI_SUCCESS
;
1460 if (mLockInsertRecord
) {
1461 return EFI_INVALID_PARAMETER
;
1463 mLockInsertRecord
= TRUE
;
1465 Status
= InsertFpdtRecord (CallerIdentifier
, Guid
, String
, TimeStamp
, Address
, (UINT16
)Identifier
, Attribute
);
1467 mLockInsertRecord
= FALSE
;
1473 Adds a record at the end of the performance measurement log
1474 that records the start time of a performance measurement.
1476 Adds a record to the end of the performance measurement log
1477 that contains the Handle, Token, Module and Identifier.
1478 The end time of the new record must be set to zero.
1479 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1480 If TimeStamp is zero, the start time in the record is filled in with the value
1481 read from the current time stamp.
1483 @param Handle Pointer to environment specific context used
1484 to identify the component being measured.
1485 @param Token Pointer to a Null-terminated ASCII string
1486 that identifies the component being measured.
1487 @param Module Pointer to a Null-terminated ASCII string
1488 that identifies the module being measured.
1489 @param TimeStamp 64-bit time stamp.
1490 @param Identifier 32-bit identifier. If the value is 0, the created record
1491 is same as the one created by StartPerformanceMeasurement.
1493 @retval RETURN_SUCCESS The start of the measurement was recorded.
1494 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1499 StartPerformanceMeasurementEx (
1500 IN CONST VOID
*Handle
, OPTIONAL
1501 IN CONST CHAR8
*Token
, OPTIONAL
1502 IN CONST CHAR8
*Module
, OPTIONAL
1503 IN UINT64 TimeStamp
,
1504 IN UINT32 Identifier
1507 CONST CHAR8
*String
;
1509 if (Token
!= NULL
) {
1511 } else if (Module
!= NULL
) {
1517 return (RETURN_STATUS
)CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfStartEntry
);
1521 Searches the performance measurement log from the beginning of the log
1522 for the first matching record that contains a zero end time and fills in a valid end time.
1524 Searches the performance measurement log from the beginning of the log
1525 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.
1526 If the record can not be found then return RETURN_NOT_FOUND.
1527 If the record is found and TimeStamp is not zero,
1528 then the end time in the record is filled in with the value specified by TimeStamp.
1529 If the record is found and TimeStamp is zero, then the end time in the matching record
1530 is filled in with the current time stamp value.
1532 @param Handle Pointer to environment specific context used
1533 to identify the component being measured.
1534 @param Token Pointer to a Null-terminated ASCII string
1535 that identifies the component being measured.
1536 @param Module Pointer to a Null-terminated ASCII string
1537 that identifies the module being measured.
1538 @param TimeStamp 64-bit time stamp.
1539 @param Identifier 32-bit identifier. If the value is 0, the found record
1540 is same as the one found by EndPerformanceMeasurement.
1542 @retval RETURN_SUCCESS The end of the measurement was recorded.
1543 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1548 EndPerformanceMeasurementEx (
1549 IN CONST VOID
*Handle
, OPTIONAL
1550 IN CONST CHAR8
*Token
, OPTIONAL
1551 IN CONST CHAR8
*Module
, OPTIONAL
1552 IN UINT64 TimeStamp
,
1553 IN UINT32 Identifier
1556 CONST CHAR8
*String
;
1558 if (Token
!= NULL
) {
1560 } else if (Module
!= NULL
) {
1566 return (RETURN_STATUS
)CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfEndEntry
);
1570 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1571 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
1572 and then assign the Identifier with 0.
1576 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1577 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1578 and the key for the second entry in the log is returned. If the performance log is empty,
1579 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1580 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1581 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1582 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1583 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1584 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1585 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
1586 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1587 If Handle is NULL, then ASSERT().
1588 If Token is NULL, then ASSERT().
1589 If Module is NULL, then ASSERT().
1590 If StartTimeStamp is NULL, then ASSERT().
1591 If EndTimeStamp is NULL, then ASSERT().
1592 If Identifier is NULL, then ASSERT().
1594 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1595 0, then the first performance measurement log entry is retrieved.
1596 On exit, the key of the next performance log entry.
1597 @param Handle Pointer to environment specific context used to identify the component
1599 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1601 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1603 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1605 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1607 @param Identifier Pointer to the 32-bit identifier that was recorded when the measurement
1610 @return The key for the next performance log entry (in general case).
1615 GetPerformanceMeasurementEx (
1616 IN UINTN LogEntryKey
,
1617 OUT CONST VOID
**Handle
,
1618 OUT CONST CHAR8
**Token
,
1619 OUT CONST CHAR8
**Module
,
1620 OUT UINT64
*StartTimeStamp
,
1621 OUT UINT64
*EndTimeStamp
,
1622 OUT UINT32
*Identifier
1629 Adds a record at the end of the performance measurement log
1630 that records the start time of a performance measurement.
1632 Adds a record to the end of the performance measurement log
1633 that contains the Handle, Token, and Module.
1634 The end time of the new record must be set to zero.
1635 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.
1636 If TimeStamp is zero, the start time in the record is filled in with the value
1637 read from the current time stamp.
1639 @param Handle Pointer to environment specific context used
1640 to identify the component being measured.
1641 @param Token Pointer to a Null-terminated ASCII string
1642 that identifies the component being measured.
1643 @param Module Pointer to a Null-terminated ASCII string
1644 that identifies the module being measured.
1645 @param TimeStamp 64-bit time stamp.
1647 @retval RETURN_SUCCESS The start of the measurement was recorded.
1648 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
1653 StartPerformanceMeasurement (
1654 IN CONST VOID
*Handle
, OPTIONAL
1655 IN CONST CHAR8
*Token
, OPTIONAL
1656 IN CONST CHAR8
*Module
, OPTIONAL
1660 return StartPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
1664 Searches the performance measurement log from the beginning of the log
1665 for the first matching record that contains a zero end time and fills in a valid end time.
1667 Searches the performance measurement log from the beginning of the log
1668 for the first record that matches Handle, Token, and Module and has an end time value of zero.
1669 If the record can not be found then return RETURN_NOT_FOUND.
1670 If the record is found and TimeStamp is not zero,
1671 then the end time in the record is filled in with the value specified by TimeStamp.
1672 If the record is found and TimeStamp is zero, then the end time in the matching record
1673 is filled in with the current time stamp value.
1675 @param Handle Pointer to environment specific context used
1676 to identify the component being measured.
1677 @param Token Pointer to a Null-terminated ASCII string
1678 that identifies the component being measured.
1679 @param Module Pointer to a Null-terminated ASCII string
1680 that identifies the module being measured.
1681 @param TimeStamp 64-bit time stamp.
1683 @retval RETURN_SUCCESS The end of the measurement was recorded.
1684 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
1689 EndPerformanceMeasurement (
1690 IN CONST VOID
*Handle
, OPTIONAL
1691 IN CONST CHAR8
*Token
, OPTIONAL
1692 IN CONST CHAR8
*Module
, OPTIONAL
1696 return EndPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
1700 Attempts to retrieve a performance measurement log entry from the performance measurement log.
1701 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
1702 and then eliminate the Identifier.
1706 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
1707 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
1708 and the key for the second entry in the log is returned. If the performance log is empty,
1709 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
1710 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
1711 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
1712 retrieved and an implementation specific non-zero key value that specifies the end of the performance
1713 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
1714 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
1715 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
1716 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
1717 If Handle is NULL, then ASSERT().
1718 If Token is NULL, then ASSERT().
1719 If Module is NULL, then ASSERT().
1720 If StartTimeStamp is NULL, then ASSERT().
1721 If EndTimeStamp is NULL, then ASSERT().
1723 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
1724 0, then the first performance measurement log entry is retrieved.
1725 On exit, the key of the next performance log entry.
1726 @param Handle Pointer to environment specific context used to identify the component
1728 @param Token Pointer to a Null-terminated ASCII string that identifies the component
1730 @param Module Pointer to a Null-terminated ASCII string that identifies the module
1732 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1734 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
1737 @return The key for the next performance log entry (in general case).
1742 GetPerformanceMeasurement (
1743 IN UINTN LogEntryKey
,
1744 OUT CONST VOID
**Handle
,
1745 OUT CONST CHAR8
**Token
,
1746 OUT CONST CHAR8
**Module
,
1747 OUT UINT64
*StartTimeStamp
,
1748 OUT UINT64
*EndTimeStamp
1755 Returns TRUE if the performance measurement macros are enabled.
1757 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1758 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
1760 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1761 PcdPerformanceLibraryPropertyMask is set.
1762 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
1763 PcdPerformanceLibraryPropertyMask is clear.
1768 PerformanceMeasurementEnabled (
1772 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);
1776 Create performance record with event description and a timestamp.
1778 @param CallerIdentifier - Image handle or pointer to caller ID GUID
1779 @param Guid - Pointer to a GUID
1780 @param String - Pointer to a string describing the measurement
1781 @param Address - Pointer to a location in memory relevant to the measurement
1782 @param Identifier - Performance identifier describing the type of measurement
1784 @retval RETURN_SUCCESS - Successfully created performance record
1785 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
1786 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
1787 pointer or invalid PerfId
1792 LogPerformanceMeasurement (
1793 IN CONST VOID
*CallerIdentifier
,
1794 IN CONST VOID
*Guid
, OPTIONAL
1795 IN CONST CHAR8
*String
, OPTIONAL
1796 IN UINT64 Address
, OPTIONAL
1797 IN UINT32 Identifier
1800 return (RETURN_STATUS
)CreatePerformanceMeasurement (CallerIdentifier
, Guid
, String
, 0, Address
, Identifier
, PerfEntry
);
1804 Check whether the specified performance measurement can be logged.
1806 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
1807 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
1809 @param Type - Type of the performance measurement entry.
1811 @retval TRUE The performance measurement can be logged.
1812 @retval FALSE The performance measurement can NOT be logged.
1817 LogPerformanceMeasurementEnabled (
1822 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
1824 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask
) & Type
) == 0) {