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
17 #include <Guid/PerformanceMeasurement.h>
19 #include <Library/PerformanceLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/PcdLib.h>
25 // The cached Performance Protocol and PerformanceEx Protocol interface.
27 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL
*mPerformanceMeasurement
= NULL
;
30 The function caches the pointers to PerformanceEx protocol and Performance Protocol.
32 The function locates PerformanceEx protocol and Performance Protocol from protocol database.
34 @retval EFI_SUCCESS PerformanceEx protocol or Performance Protocol is successfully located.
35 @retval EFI_NOT_FOUND Both PerformanceEx protocol and Performance Protocol are not located to log performance.
39 GetPerformanceMeasurementProtocol (
44 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL
*PerformanceMeasurement
;
46 if (mPerformanceMeasurement
!= NULL
) {
50 Status
= gBS
->LocateProtocol (&gEdkiiPerformanceMeasurementProtocolGuid
, NULL
, (VOID
**) &PerformanceMeasurement
);
51 if (!EFI_ERROR (Status
)) {
52 ASSERT (PerformanceMeasurement
!= NULL
);
54 // Cache PerformanceMeasurement Protocol.
56 mPerformanceMeasurement
= PerformanceMeasurement
;
64 Creates a record for the beginning of a performance measurement.
66 Creates a record that contains the Handle, Token, Module and Identifier.
67 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
68 If TimeStamp is zero, then this function reads the current time stamp
69 and adds that time stamp value to the record as the start time.
71 @param Handle Pointer to environment specific context used
72 to identify the component being measured.
73 @param Token Pointer to a Null-terminated ASCII string
74 that identifies the component being measured.
75 @param Module Pointer to a Null-terminated ASCII string
76 that identifies the module being measured.
77 @param TimeStamp 64-bit time stamp.
78 @param Identifier 32-bit identifier. If the value is 0, the created record
79 is same as the one created by StartPerformanceMeasurement.
81 @retval RETURN_SUCCESS The start of the measurement was recorded.
82 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
87 StartPerformanceMeasurementEx (
88 IN CONST VOID
*Handle
, OPTIONAL
89 IN CONST CHAR8
*Token
, OPTIONAL
90 IN CONST CHAR8
*Module
, OPTIONAL
98 Status
= GetPerformanceMeasurementProtocol ();
99 if (EFI_ERROR (Status
)) {
100 return RETURN_NOT_FOUND
;
105 } else if (Module
!= NULL
) {
111 if (mPerformanceMeasurement
!= NULL
) {
112 Status
= mPerformanceMeasurement
->CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfStartEntry
);
117 return (RETURN_STATUS
) Status
;
121 Fills in the end time of a performance measurement.
123 Looks up the record that matches Handle, Token and Module.
124 If the record can not be found then return RETURN_NOT_FOUND.
125 If the record is found and TimeStamp is not zero,
126 then TimeStamp is added to the record as the end time.
127 If the record is found and TimeStamp is zero, then this function reads
128 the current time stamp and adds that time stamp value to the record as the end time.
130 @param Handle Pointer to environment specific context used
131 to identify the component being measured.
132 @param Token Pointer to a Null-terminated ASCII string
133 that identifies the component being measured.
134 @param Module Pointer to a Null-terminated ASCII string
135 that identifies the module being measured.
136 @param TimeStamp 64-bit time stamp.
137 @param Identifier 32-bit identifier. If the value is 0, the found record
138 is same as the one found by EndPerformanceMeasurement.
140 @retval RETURN_SUCCESS The end of the measurement was recorded.
141 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
146 EndPerformanceMeasurementEx (
147 IN CONST VOID
*Handle
, OPTIONAL
148 IN CONST CHAR8
*Token
, OPTIONAL
149 IN CONST CHAR8
*Module
, OPTIONAL
157 Status
= GetPerformanceMeasurementProtocol ();
158 if (EFI_ERROR (Status
)) {
159 return RETURN_NOT_FOUND
;
164 } else if (Module
!= NULL
) {
170 if (mPerformanceMeasurement
!= NULL
) {
171 Status
= mPerformanceMeasurement
->CreatePerformanceMeasurement (Handle
, NULL
, String
, TimeStamp
, 0, Identifier
, PerfEndEntry
);
176 return (RETURN_STATUS
) Status
;
180 Attempts to retrieve a performance measurement log entry from the performance measurement log.
181 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
182 and then assign the Identifier with 0.
184 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
185 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
186 and the key for the second entry in the log is returned. If the performance log is empty,
187 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
188 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
189 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
190 retrieved and an implementation specific non-zero key value that specifies the end of the performance
191 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
192 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
193 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
194 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
195 If Handle is NULL, then ASSERT().
196 If Token is NULL, then ASSERT().
197 If Module is NULL, then ASSERT().
198 If StartTimeStamp is NULL, then ASSERT().
199 If EndTimeStamp is NULL, then ASSERT().
200 If Identifier is NULL, then ASSERT().
202 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
203 0, then the first performance measurement log entry is retrieved.
204 On exit, the key of the next performance log entry.
205 @param Handle Pointer to environment specific context used to identify the component
207 @param Token Pointer to a Null-terminated ASCII string that identifies the component
209 @param Module Pointer to a Null-terminated ASCII string that identifies the module
211 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
213 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
215 @param Identifier Pointer to the 32-bit identifier that was recorded.
217 @return The key for the next performance log entry (in general case).
222 GetPerformanceMeasurementEx (
223 IN UINTN LogEntryKey
,
224 OUT CONST VOID
**Handle
,
225 OUT CONST CHAR8
**Token
,
226 OUT CONST CHAR8
**Module
,
227 OUT UINT64
*StartTimeStamp
,
228 OUT UINT64
*EndTimeStamp
,
229 OUT UINT32
*Identifier
237 Creates a record for the beginning of a performance measurement.
239 Creates a record that contains the Handle, Token, and Module.
240 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
241 If TimeStamp is zero, then this function reads the current time stamp
242 and adds that time stamp value to the record as the start time.
244 @param Handle Pointer to environment specific context used
245 to identify the component being measured.
246 @param Token Pointer to a Null-terminated ASCII string
247 that identifies the component being measured.
248 @param Module Pointer to a Null-terminated ASCII string
249 that identifies the module being measured.
250 @param TimeStamp 64-bit time stamp.
252 @retval RETURN_SUCCESS The start of the measurement was recorded.
253 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
258 StartPerformanceMeasurement (
259 IN CONST VOID
*Handle
, OPTIONAL
260 IN CONST CHAR8
*Token
, OPTIONAL
261 IN CONST CHAR8
*Module
, OPTIONAL
265 return StartPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
269 Fills in the end time of a performance measurement.
271 Looks up the record that matches Handle, Token, and Module.
272 If the record can not be found then return RETURN_NOT_FOUND.
273 If the record is found and TimeStamp is not zero,
274 then TimeStamp is added to the record as the end time.
275 If the record is found and TimeStamp is zero, then this function reads
276 the current time stamp and adds that time stamp value to the record as the end time.
278 @param Handle Pointer to environment specific context used
279 to identify the component being measured.
280 @param Token Pointer to a Null-terminated ASCII string
281 that identifies the component being measured.
282 @param Module Pointer to a Null-terminated ASCII string
283 that identifies the module being measured.
284 @param TimeStamp 64-bit time stamp.
286 @retval RETURN_SUCCESS The end of the measurement was recorded.
287 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
292 EndPerformanceMeasurement (
293 IN CONST VOID
*Handle
, OPTIONAL
294 IN CONST CHAR8
*Token
, OPTIONAL
295 IN CONST CHAR8
*Module
, OPTIONAL
299 return EndPerformanceMeasurementEx (Handle
, Token
, Module
, TimeStamp
, 0);
303 Attempts to retrieve a performance measurement log entry from the performance measurement log.
304 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
305 and then eliminate the Identifier.
307 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
308 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
309 and the key for the second entry in the log is returned. If the performance log is empty,
310 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
311 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
312 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
313 retrieved and an implementation specific non-zero key value that specifies the end of the performance
314 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
315 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
316 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
317 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
318 If Handle is NULL, then ASSERT().
319 If Token is NULL, then ASSERT().
320 If Module is NULL, then ASSERT().
321 If StartTimeStamp is NULL, then ASSERT().
322 If EndTimeStamp is NULL, then ASSERT().
324 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
325 0, then the first performance measurement log entry is retrieved.
326 On exit, the key of the next performance log entry.
327 @param Handle Pointer to environment specific context used to identify the component
329 @param Token Pointer to a Null-terminated ASCII string that identifies the component
331 @param Module Pointer to a Null-terminated ASCII string that identifies the module
333 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
335 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
338 @return The key for the next performance log entry (in general case).
343 GetPerformanceMeasurement (
344 IN UINTN LogEntryKey
,
345 OUT CONST VOID
**Handle
,
346 OUT CONST CHAR8
**Token
,
347 OUT CONST CHAR8
**Module
,
348 OUT UINT64
*StartTimeStamp
,
349 OUT UINT64
*EndTimeStamp
356 Returns TRUE if the performance measurement macros are enabled.
358 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
359 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
361 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
362 PcdPerformanceLibraryPropertyMask is set.
363 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
364 PcdPerformanceLibraryPropertyMask is clear.
369 PerformanceMeasurementEnabled (
373 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);
377 Create performance record with event description and a timestamp.
379 @param CallerIdentifier - Image handle or pointer to caller ID GUID
380 @param Guid - Pointer to a GUID
381 @param String - Pointer to a string describing the measurement
382 @param Address - Pointer to a location in memory relevant to the measurement
383 @param Identifier - Performance identifier describing the type of measurement
385 @retval RETURN_SUCCESS - Successfully created performance record
386 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
387 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
388 pointer or invalid PerfId
393 LogPerformanceMeasurement (
394 IN CONST VOID
*CallerIdentifier
,
395 IN CONST VOID
*Guid
, OPTIONAL
396 IN CONST CHAR8
*String
, OPTIONAL
397 IN UINT64 Address
, OPTIONAL
403 Status
= GetPerformanceMeasurementProtocol ();
404 if (EFI_ERROR (Status
)) {
405 return RETURN_OUT_OF_RESOURCES
;
408 if (mPerformanceMeasurement
!= NULL
) {
409 Status
= mPerformanceMeasurement
->CreatePerformanceMeasurement (CallerIdentifier
, Guid
, String
, 0, Address
, Identifier
, PerfEntry
);
414 return (RETURN_STATUS
) Status
;
418 Check whether the specified performance measurement can be logged.
420 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
421 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
423 @param Type - Type of the performance measurement entry.
425 @retval TRUE The performance measurement can be logged.
426 @retval FALSE The performance measurement can NOT be logged.
431 LogPerformanceMeasurementEnabled (
436 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
438 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask
) & Type
) == 0) {