4 This library instance provides infrastructure for DXE phase drivers to log performance
5 data. It consumes PerformanceEx or Performance Protocol published by DxeCorePerformanceLib
6 to log performance data. If both PerformanceEx and Performance Protocol is not available, it does not log any
7 performance information.
9 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
10 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Guid/PerformanceMeasurement.h>
18 #include <Library/PerformanceLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/PcdLib.h>
24 // The cached Performance Protocol and PerformanceEx Protocol interface.
26 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL
*mPerformanceMeasurement
= NULL
;
29 The function caches the pointers to PerformanceEx protocol and Performance Protocol.
31 The function locates PerformanceEx protocol and Performance Protocol from protocol database.
33 @retval EFI_SUCCESS PerformanceEx protocol or Performance Protocol is successfully located.
34 @retval EFI_NOT_FOUND Both PerformanceEx protocol and Performance Protocol are not located to log performance.
38 GetPerformanceMeasurementProtocol (
43 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL
*PerformanceMeasurement
;
45 if (mPerformanceMeasurement
!= NULL
) {
49 Status
= gBS
->LocateProtocol (&gEdkiiPerformanceMeasurementProtocolGuid
, NULL
, (VOID
**)&PerformanceMeasurement
);
50 if (!EFI_ERROR (Status
)) {
51 ASSERT (PerformanceMeasurement
!= NULL
);
53 // Cache PerformanceMeasurement Protocol.
55 mPerformanceMeasurement
= PerformanceMeasurement
;
63 Creates a record for the beginning of a performance measurement.
65 Creates a record that contains the Handle, Token, Module and Identifier.
66 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
67 If TimeStamp is zero, then this function reads the current time stamp
68 and adds that time stamp value to the record as the start time.
70 @param Handle Pointer to environment specific context used
71 to identify the component being measured.
72 @param Token Pointer to a Null-terminated ASCII string
73 that identifies the component being measured.
74 @param Module Pointer to a Null-terminated ASCII string
75 that identifies the module being measured.
76 @param TimeStamp 64-bit time stamp.
77 @param Identifier 32-bit identifier. If the value is 0, the created record
78 is same as the one created by StartPerformanceMeasurement.
80 @retval RETURN_SUCCESS The start of the measurement was recorded.
81 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
86 StartPerformanceMeasurementEx (
87 IN CONST VOID
*Handle OPTIONAL
,
88 IN CONST CHAR8
*Token OPTIONAL
,
89 IN CONST CHAR8
*Module OPTIONAL
,
97 Status
= GetPerformanceMeasurementProtocol ();
98 if (EFI_ERROR (Status
)) {
99 return RETURN_NOT_FOUND
;
104 } else if (Module
!= NULL
) {
110 if (mPerformanceMeasurement
!= NULL
) {
111 Status
= mPerformanceMeasurement
->CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfStartEntry
);
116 return (RETURN_STATUS
)Status
;
120 Fills in the end time of a performance measurement.
122 Looks up the record that matches Handle, Token and Module.
123 If the record can not be found then return RETURN_NOT_FOUND.
124 If the record is found and TimeStamp is not zero,
125 then TimeStamp is added to the record as the end time.
126 If the record is found and TimeStamp is zero, then this function reads
127 the current time stamp and adds that time stamp value to the record as the end time.
129 @param Handle Pointer to environment specific context used
130 to identify the component being measured.
131 @param Token Pointer to a Null-terminated ASCII string
132 that identifies the component being measured.
133 @param Module Pointer to a Null-terminated ASCII string
134 that identifies the module being measured.
135 @param TimeStamp 64-bit time stamp.
136 @param Identifier 32-bit identifier. If the value is 0, the found record
137 is same as the one found by EndPerformanceMeasurement.
139 @retval RETURN_SUCCESS The end of the measurement was recorded.
140 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
145 EndPerformanceMeasurementEx (
146 IN CONST VOID
*Handle OPTIONAL
,
147 IN CONST CHAR8
*Token OPTIONAL
,
148 IN CONST CHAR8
*Module OPTIONAL
,
156 Status
= GetPerformanceMeasurementProtocol ();
157 if (EFI_ERROR (Status
)) {
158 return RETURN_NOT_FOUND
;
163 } else if (Module
!= NULL
) {
169 if (mPerformanceMeasurement
!= NULL
) {
170 Status
= mPerformanceMeasurement
->CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfEndEntry
);
175 return (RETURN_STATUS
)Status
;
179 Attempts to retrieve a performance measurement log entry from the performance measurement log.
180 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
181 and then assign the Identifier with 0.
183 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
184 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
185 and the key for the second entry in the log is returned. If the performance log is empty,
186 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
187 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
188 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
189 retrieved and an implementation specific non-zero key value that specifies the end of the performance
190 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
191 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
192 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
193 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
194 If Handle is NULL, then ASSERT().
195 If Token is NULL, then ASSERT().
196 If Module is NULL, then ASSERT().
197 If StartTimeStamp is NULL, then ASSERT().
198 If EndTimeStamp is NULL, then ASSERT().
199 If Identifier is NULL, then ASSERT().
201 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
202 0, then the first performance measurement log entry is retrieved.
203 On exit, the key of the next performance log entry.
204 @param Handle Pointer to environment specific context used to identify the component
206 @param Token Pointer to a Null-terminated ASCII string that identifies the component
208 @param Module Pointer to a Null-terminated ASCII string that identifies the module
210 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
212 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
214 @param Identifier Pointer to the 32-bit identifier that was recorded.
216 @return The key for the next performance log entry (in general case).
221 GetPerformanceMeasurementEx (
222 IN UINTN LogEntryKey
,
223 OUT CONST VOID
**Handle
,
224 OUT CONST CHAR8
**Token
,
225 OUT CONST CHAR8
**Module
,
226 OUT UINT64
*StartTimeStamp
,
227 OUT UINT64
*EndTimeStamp
,
228 OUT UINT32
*Identifier
235 Creates a record for the beginning of a performance measurement.
237 Creates a record that contains the Handle, Token, and Module.
238 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
239 If TimeStamp is zero, then this function reads the current time stamp
240 and adds that time stamp value to the record as the start time.
242 @param Handle Pointer to environment specific context used
243 to identify the component being measured.
244 @param Token Pointer to a Null-terminated ASCII string
245 that identifies the component being measured.
246 @param Module Pointer to a Null-terminated ASCII string
247 that identifies the module being measured.
248 @param TimeStamp 64-bit time stamp.
250 @retval RETURN_SUCCESS The start of the measurement was recorded.
251 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
256 StartPerformanceMeasurement (
257 IN CONST VOID
*Handle OPTIONAL
,
258 IN CONST CHAR8
*Token OPTIONAL
,
259 IN CONST CHAR8
*Module OPTIONAL
,
263 return StartPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
267 Fills in the end time of a performance measurement.
269 Looks up the record that matches Handle, Token, and Module.
270 If the record can not be found then return RETURN_NOT_FOUND.
271 If the record is found and TimeStamp is not zero,
272 then TimeStamp is added to the record as the end time.
273 If the record is found and TimeStamp is zero, then this function reads
274 the current time stamp and adds that time stamp value to the record as the end time.
276 @param Handle Pointer to environment specific context used
277 to identify the component being measured.
278 @param Token Pointer to a Null-terminated ASCII string
279 that identifies the component being measured.
280 @param Module Pointer to a Null-terminated ASCII string
281 that identifies the module being measured.
282 @param TimeStamp 64-bit time stamp.
284 @retval RETURN_SUCCESS The end of the measurement was recorded.
285 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
290 EndPerformanceMeasurement (
291 IN CONST VOID
*Handle OPTIONAL
,
292 IN CONST CHAR8
*Token OPTIONAL
,
293 IN CONST CHAR8
*Module OPTIONAL
,
297 return EndPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
301 Attempts to retrieve a performance measurement log entry from the performance measurement log.
302 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
303 and then eliminate the Identifier.
305 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
306 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
307 and the key for the second entry in the log is returned. If the performance log is empty,
308 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
309 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
310 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
311 retrieved and an implementation specific non-zero key value that specifies the end of the performance
312 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
313 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
314 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
315 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
316 If Handle is NULL, then ASSERT().
317 If Token is NULL, then ASSERT().
318 If Module is NULL, then ASSERT().
319 If StartTimeStamp is NULL, then ASSERT().
320 If EndTimeStamp is NULL, then ASSERT().
322 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
323 0, then the first performance measurement log entry is retrieved.
324 On exit, the key of the next performance log entry.
325 @param Handle Pointer to environment specific context used to identify the component
327 @param Token Pointer to a Null-terminated ASCII string that identifies the component
329 @param Module Pointer to a Null-terminated ASCII string that identifies the module
331 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
333 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
336 @return The key for the next performance log entry (in general case).
341 GetPerformanceMeasurement (
342 IN UINTN LogEntryKey
,
343 OUT CONST VOID
**Handle
,
344 OUT CONST CHAR8
**Token
,
345 OUT CONST CHAR8
**Module
,
346 OUT UINT64
*StartTimeStamp
,
347 OUT UINT64
*EndTimeStamp
354 Returns TRUE if the performance measurement macros are enabled.
356 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
357 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
359 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
360 PcdPerformanceLibraryPropertyMask is set.
361 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
362 PcdPerformanceLibraryPropertyMask is clear.
367 PerformanceMeasurementEnabled (
371 return (BOOLEAN
)((PcdGet8 (PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);
375 Create performance record with event description and a timestamp.
377 @param CallerIdentifier - Image handle or pointer to caller ID GUID
378 @param Guid - Pointer to a GUID
379 @param String - Pointer to a string describing the measurement
380 @param Address - Pointer to a location in memory relevant to the measurement
381 @param Identifier - Performance identifier describing the type of measurement
383 @retval RETURN_SUCCESS - Successfully created performance record
384 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
385 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
386 pointer or invalid PerfId
391 LogPerformanceMeasurement (
392 IN CONST VOID
*CallerIdentifier
,
393 IN CONST VOID
*Guid OPTIONAL
,
394 IN CONST CHAR8
*String OPTIONAL
,
395 IN UINT64 Address OPTIONAL
,
401 Status
= GetPerformanceMeasurementProtocol ();
402 if (EFI_ERROR (Status
)) {
403 return RETURN_OUT_OF_RESOURCES
;
406 if (mPerformanceMeasurement
!= NULL
) {
407 Status
= mPerformanceMeasurement
->CreatePerformanceMeasurement (CallerIdentifier
, Guid
, String
, 0, Address
, Identifier
, PerfEntry
);
412 return (RETURN_STATUS
)Status
;
416 Check whether the specified performance measurement can be logged.
418 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
419 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
421 @param Type - Type of the performance measurement entry.
423 @retval TRUE The performance measurement can be logged.
424 @retval FALSE The performance measurement can NOT be logged.
429 LogPerformanceMeasurementEnabled (
434 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
436 if (PerformanceMeasurementEnabled () && ((PcdGet8 (PcdPerformanceLibraryPropertyMask
) & Type
) == 0)) {