]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/PerformanceLib.h
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Include / Library / PerformanceLib.h
CommitLineData
fb3df220 1/** @file\r
50a64e5b 2 Provides services to log the execution times and retrieve them later.\r
fb3df220 3\r
2c5b667e 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
fb3df220 6\r
fb3df220 7**/\r
8\r
9#ifndef __PERFORMANCE_LIB_H__\r
10#define __PERFORMANCE_LIB_H__\r
11\r
fc30687f 12///\r
13/// Performance library propery mask bits\r
14///\r
fb3df220 15#define PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED 0x00000001\r
16\r
2c5b667e
BD
17//\r
18// Public Progress Identifiers for Event Records.\r
19//\r
20#define PERF_EVENT_ID 0x00\r
21\r
22#define MODULE_START_ID 0x01\r
23#define MODULE_END_ID 0x02\r
24#define MODULE_LOADIMAGE_START_ID 0x03\r
25#define MODULE_LOADIMAGE_END_ID 0x04\r
26#define MODULE_DB_START_ID 0x05\r
27#define MODULE_DB_END_ID 0x06\r
28#define MODULE_DB_SUPPORT_START_ID 0x07\r
29#define MODULE_DB_SUPPORT_END_ID 0x08\r
30#define MODULE_DB_STOP_START_ID 0x09\r
31#define MODULE_DB_STOP_END_ID 0x0A\r
32\r
33#define PERF_EVENTSIGNAL_START_ID 0x10\r
34#define PERF_EVENTSIGNAL_END_ID 0x11\r
35#define PERF_CALLBACK_START_ID 0x20\r
36#define PERF_CALLBACK_END_ID 0x21\r
37#define PERF_FUNCTION_START_ID 0x30\r
38#define PERF_FUNCTION_END_ID 0x31\r
39#define PERF_INMODULE_START_ID 0x40\r
40#define PERF_INMODULE_END_ID 0x41\r
41#define PERF_CROSSMODULE_START_ID 0x50\r
42#define PERF_CROSSMODULE_END_ID 0x51\r
43\r
44//\r
45// Declare bits for PcdPerformanceLibraryPropertyMask and\r
46// also used as the Type parameter of LogPerformanceMeasurementEnabled().\r
47//\r
48#define PERF_CORE_START_IMAGE 0x0002\r
49#define PERF_CORE_LOAD_IMAGE 0x0004\r
50#define PERF_CORE_DB_SUPPORT 0x0008\r
51#define PERF_CORE_DB_START 0x0010\r
52#define PERF_CORE_DB_STOP 0x0020\r
53\r
54#define PERF_GENERAL_TYPE 0x0040\r
55\r
fb3df220 56/**\r
9095d37b
LG
57 Creates a record for the beginning of a performance measurement.\r
58\r
fb3df220 59 Creates a record that contains the Handle, Token, and Module.\r
60 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
61 If TimeStamp is zero, then this function reads the current time stamp\r
62 and adds that time stamp value to the record as the start time.\r
63\r
64 @param Handle Pointer to environment specific context used\r
65 to identify the component being measured.\r
66 @param Token Pointer to a Null-terminated ASCII string\r
67 that identifies the component being measured.\r
68 @param Module Pointer to a Null-terminated ASCII string\r
69 that identifies the module being measured.\r
70 @param TimeStamp 64-bit time stamp.\r
71\r
72 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
73 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
8404146c 74 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r
fb3df220 75\r
76**/\r
77RETURN_STATUS\r
78EFIAPI\r
79StartPerformanceMeasurement (\r
80 IN CONST VOID *Handle, OPTIONAL\r
81 IN CONST CHAR8 *Token, OPTIONAL\r
82 IN CONST CHAR8 *Module, OPTIONAL\r
83 IN UINT64 TimeStamp\r
84 );\r
85\r
86/**\r
9095d37b
LG
87 Fills in the end time of a performance measurement.\r
88\r
fb3df220 89 Looks up the record that matches Handle, Token, and Module.\r
90 If the record can not be found then return RETURN_NOT_FOUND.\r
91 If the record is found and TimeStamp is not zero,\r
92 then TimeStamp is added to the record as the end time.\r
93 If the record is found and TimeStamp is zero, then this function reads\r
94 the current time stamp and adds that time stamp value to the record as the end time.\r
fb3df220 95\r
96 @param Handle Pointer to environment specific context used\r
97 to identify the component being measured.\r
98 @param Token Pointer to a Null-terminated ASCII string\r
99 that identifies the component being measured.\r
100 @param Module Pointer to a Null-terminated ASCII string\r
101 that identifies the module being measured.\r
102 @param TimeStamp 64-bit time stamp.\r
103\r
104 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
105 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
8404146c 106 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r
fb3df220 107\r
108**/\r
109RETURN_STATUS\r
110EFIAPI\r
111EndPerformanceMeasurement (\r
112 IN CONST VOID *Handle, OPTIONAL\r
113 IN CONST CHAR8 *Token, OPTIONAL\r
114 IN CONST CHAR8 *Module, OPTIONAL\r
115 IN UINT64 TimeStamp\r
116 );\r
117\r
118/**\r
9095d37b 119 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
ba14539c
SZ
120 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
121 and then eliminate the Identifier.\r
122\r
fb3df220 123 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
124 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
125 and the key for the second entry in the log is returned. If the performance log is empty,\r
126 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
127 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
128 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
129 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
130 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
131 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
132 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
133 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
134 If Handle is NULL, then ASSERT().\r
135 If Token is NULL, then ASSERT().\r
136 If Module is NULL, then ASSERT().\r
137 If StartTimeStamp is NULL, then ASSERT().\r
138 If EndTimeStamp is NULL, then ASSERT().\r
139\r
140 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
141 0, then the first performance measurement log entry is retrieved.\r
142 On exit, the key of the next performance lof entry entry.\r
143 @param Handle Pointer to environment specific context used to identify the component\r
9095d37b 144 being measured.\r
fb3df220 145 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
9095d37b 146 being measured.\r
fb3df220 147 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
148 being measured.\r
149 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
150 was started.\r
151 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
152 was ended.\r
153\r
154 @return The key for the next performance log entry (in general case).\r
155\r
156**/\r
157UINTN\r
158EFIAPI\r
159GetPerformanceMeasurement (\r
9095d37b 160 IN UINTN LogEntryKey,\r
fb3df220 161 OUT CONST VOID **Handle,\r
162 OUT CONST CHAR8 **Token,\r
163 OUT CONST CHAR8 **Module,\r
164 OUT UINT64 *StartTimeStamp,\r
165 OUT UINT64 *EndTimeStamp\r
166 );\r
167\r
ba14539c
SZ
168/**\r
169 Creates a record for the beginning of a performance measurement.\r
170\r
171 Creates a record that contains the Handle, Token, Module and Identifier.\r
172 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
173 If TimeStamp is zero, then this function reads the current time stamp\r
174 and adds that time stamp value to the record as the start time.\r
175\r
176 @param Handle Pointer to environment specific context used\r
177 to identify the component being measured.\r
178 @param Token Pointer to a Null-terminated ASCII string\r
179 that identifies the component being measured.\r
180 @param Module Pointer to a Null-terminated ASCII string\r
181 that identifies the module being measured.\r
182 @param TimeStamp 64-bit time stamp.\r
183 @param Identifier 32-bit identifier. If the value is 0, the created record\r
184 is same as the one created by StartPerformanceMeasurement.\r
185\r
186 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
187 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
188 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r
189\r
190**/\r
191RETURN_STATUS\r
192EFIAPI\r
193StartPerformanceMeasurementEx (\r
194 IN CONST VOID *Handle, OPTIONAL\r
195 IN CONST CHAR8 *Token, OPTIONAL\r
196 IN CONST CHAR8 *Module, OPTIONAL\r
197 IN UINT64 TimeStamp,\r
198 IN UINT32 Identifier\r
199 );\r
200\r
201/**\r
202 Fills in the end time of a performance measurement.\r
203\r
ef8d4170 204 Looks up the record that matches Handle, Token and Module.\r
ba14539c
SZ
205 If the record can not be found then return RETURN_NOT_FOUND.\r
206 If the record is found and TimeStamp is not zero,\r
207 then TimeStamp is added to the record as the end time.\r
208 If the record is found and TimeStamp is zero, then this function reads\r
209 the current time stamp and adds that time stamp value to the record as the end time.\r
210\r
211 @param Handle Pointer to environment specific context used\r
212 to identify the component being measured.\r
213 @param Token Pointer to a Null-terminated ASCII string\r
214 that identifies the component being measured.\r
215 @param Module Pointer to a Null-terminated ASCII string\r
216 that identifies the module being measured.\r
217 @param TimeStamp 64-bit time stamp.\r
218 @param Identifier 32-bit identifier. If the value is 0, the found record\r
219 is same as the one found by EndPerformanceMeasurement.\r
220\r
221 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
222 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
223 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r
224\r
225**/\r
226RETURN_STATUS\r
227EFIAPI\r
228EndPerformanceMeasurementEx (\r
229 IN CONST VOID *Handle, OPTIONAL\r
230 IN CONST CHAR8 *Token, OPTIONAL\r
231 IN CONST CHAR8 *Module, OPTIONAL\r
232 IN UINT64 TimeStamp,\r
233 IN UINT32 Identifier\r
234 );\r
235\r
236/**\r
237 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
238 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
239 and then assign the Identifier with 0.\r
240\r
241 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
242 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
243 and the key for the second entry in the log is returned. If the performance log is empty,\r
244 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
245 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
246 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
247 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
248 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
249 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
250 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
251 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
252 If Handle is NULL, then ASSERT().\r
253 If Token is NULL, then ASSERT().\r
254 If Module is NULL, then ASSERT().\r
255 If StartTimeStamp is NULL, then ASSERT().\r
256 If EndTimeStamp is NULL, then ASSERT().\r
257 If Identifier is NULL, then ASSERT().\r
258\r
259 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
260 0, then the first performance measurement log entry is retrieved.\r
261 On exit, the key of the next performance of entry entry.\r
262 @param Handle Pointer to environment specific context used to identify the component\r
263 being measured.\r
264 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
265 being measured.\r
266 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
267 being measured.\r
268 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
269 was started.\r
270 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
271 was ended.\r
272 @param Identifier Pointer to the 32-bit identifier that was recorded.\r
273\r
274 @return The key for the next performance log entry (in general case).\r
275\r
276**/\r
277UINTN\r
278EFIAPI\r
279GetPerformanceMeasurementEx (\r
9095d37b 280 IN UINTN LogEntryKey,\r
ba14539c
SZ
281 OUT CONST VOID **Handle,\r
282 OUT CONST CHAR8 **Token,\r
283 OUT CONST CHAR8 **Module,\r
284 OUT UINT64 *StartTimeStamp,\r
285 OUT UINT64 *EndTimeStamp,\r
286 OUT UINT32 *Identifier\r
287 );\r
288\r
fb3df220 289/**\r
9095d37b
LG
290 Returns TRUE if the performance measurement macros are enabled.\r
291\r
fb3df220 292 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
293 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
294\r
295 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
296 PcdPerformanceLibraryPropertyMask is set.\r
297 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
298 PcdPerformanceLibraryPropertyMask is clear.\r
299\r
300**/\r
301BOOLEAN\r
302EFIAPI\r
303PerformanceMeasurementEnabled (\r
304 VOID\r
305 );\r
306\r
2c5b667e
BD
307\r
308/**\r
309 Check whether the specified performance measurement can be logged.\r
310\r
311 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set\r
312 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.\r
313\r
314 @param Type - Type of the performance measurement entry.\r
315\r
316 @retval TRUE The performance measurement can be logged.\r
317 @retval FALSE The performance measurement can NOT be logged.\r
318\r
319**/\r
320BOOLEAN\r
321EFIAPI\r
322LogPerformanceMeasurementEnabled (\r
323 IN CONST UINTN Type\r
324 );\r
325\r
326/**\r
327 Create performance record with event description.\r
328\r
329 @param CallerIdentifier - Image handle or pointer to caller ID GUID\r
330 @param Guid - Pointer to a GUID.\r
331 Used for event signal perf and callback perf to cache the event guid.\r
332 @param String - Pointer to a string describing the measurement\r
333 @param Address - Pointer to a location in memory relevant to the measurement.\r
334 @param Identifier - Performance identifier describing the type of measurement.\r
335\r
336 @retval RETURN_SUCCESS - Successfully created performance record\r
337 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records\r
338 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
339 pointer or invalid Identifier.\r
340\r
341**/\r
342RETURN_STATUS\r
343EFIAPI\r
344LogPerformanceMeasurement (\r
345 IN CONST VOID *CallerIdentifier, OPTIONAL\r
346 IN CONST VOID *Guid, OPTIONAL\r
347 IN CONST CHAR8 *String, OPTIONAL\r
348 IN UINT64 Address, OPTIONAL\r
349 IN UINT32 Identifier\r
350 );\r
351\r
352/**\r
353 Begin Macro to measure the performance of StartImage in core.\r
354\r
355 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
356 and the BIT1(dsiable PERF_CORE_START_IMAGE) of PcdPerformanceLibraryPropertyMask is not set.\r
357 then LogPerformanceMeasurement() is called.\r
358\r
359**/\r
360#define PERF_START_IMAGE_BEGIN(ModuleHandle) \\r
361 do { \\r
362 if (LogPerformanceMeasurementEnabled (PERF_CORE_START_IMAGE)) { \\r
363 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_START_ID); \\r
364 } \\r
365 } while (FALSE)\r
366\r
367/**\r
368 End Macro to measure the performance of StartImage in core.\r
369\r
370 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
371 and the BIT1 (dsiable PERF_CORE_START_IMAGE)of PcdPerformanceLibraryPropertyMask is not set.\r
372 then LogPerformanceMeasurement() is called.\r
373\r
374**/\r
375#define PERF_START_IMAGE_END(ModuleHandle) \\r
376 do { \\r
377 if (LogPerformanceMeasurementEnabled (PERF_CORE_START_IMAGE)) { \\r
378 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_END_ID); \\r
379 } \\r
380 } while (FALSE)\r
381\r
382/**\r
383 Begin Macro to measure the performance of LoadImage in core.\r
384\r
385 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
386 and the BIT2 (dsiable PERF_CORE_LOAD_IAMGE) of PcdPerformanceLibraryPropertyMask is not set.\r
387 then LogPerformanceMeasurement() is called.\r
388\r
389**/\r
390#define PERF_LOAD_IMAGE_BEGIN(ModuleHandle) \\r
391 do { \\r
392 if (LogPerformanceMeasurementEnabled (PERF_CORE_LOAD_IMAGE)) { \\r
393 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_LOADIMAGE_START_ID); \\r
394 } \\r
395 } while (FALSE)\r
396\r
397/**\r
398 End Macro to measure the performance of LoadImage in core.\r
399\r
400 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
401 and the BIT2 (dsiable PERF_CORE_LOAD_IAMGE) of PcdPerformanceLibraryPropertyMask is not set.\r
402 then LogPerformanceMeasurement() is called.\r
403\r
404**/\r
405#define PERF_LOAD_IMAGE_END(ModuleHandle) \\r
406 do { \\r
407 if (LogPerformanceMeasurementEnabled (PERF_CORE_LOAD_IMAGE)) { \\r
408 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, 0, MODULE_LOADIMAGE_END_ID); \\r
409 } \\r
410 } while (FALSE)\r
411\r
412/**\r
413 Start Macro to measure the performance of DriverBinding Support in core.\r
414\r
415 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
416 and the BIT3 (dsiable PERF_CORE_DB_SUPPORT) of PcdPerformanceLibraryPropertyMask is not set.\r
417 then LogPerformanceMeasurement() is called.\r
418\r
419**/\r
420#define PERF_DRIVER_BINDING_SUPPORT_BEGIN(ModuleHandle, ControllerHandle) \\r
421 do { \\r
422 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_SUPPORT)) { \\r
423 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_SUPPORT_START_ID); \\r
424 } \\r
425 } while (FALSE)\r
426\r
427/**\r
428 End Macro to measure the performance of DriverBinding Support in core.\r
429\r
430 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
431 and the BIT3 (dsiable PERF_CORE_DB_SUPPORT) of PcdPerformanceLibraryPropertyMask is not set.\r
432 then LogPerformanceMeasurement() is called.\r
433\r
434**/\r
435#define PERF_DRIVER_BINDING_SUPPORT_END(ModuleHandle, ControllerHandle) \\r
436 do { \\r
437 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_SUPPORT)) { \\r
438 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_SUPPORT_END_ID); \\r
439 } \\r
440 } while (FALSE)\r
441\r
442/**\r
443 Begin Macro to measure the performance of DriverBinding Start in core.\r
444\r
445 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
446 and the BIT4 (dsiable PERF_CORE_DB_START) of PcdPerformanceLibraryPropertyMask is not set.\r
447 then LogPerformanceMeasurement() is called.\r
448\r
449**/\r
450#define PERF_DRIVER_BINDING_START_BEGIN(ModuleHandle, ControllerHandle) \\r
451 do { \\r
452 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_START)) { \\r
453 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_START_ID); \\r
454 } \\r
455 } while (FALSE)\r
456\r
457/**\r
458 End Macro to measure the performance of DriverBinding Start in core.\r
459\r
460 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
461 and the BIT4 (dsiable PERF_CORE_DB_START) of PcdPerformanceLibraryPropertyMask is not set.\r
462 then LogPerformanceMeasurement() is called.\r
463\r
464**/\r
465#define PERF_DRIVER_BINDING_START_END(ModuleHandle, ControllerHandle) \\r
466 do { \\r
467 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_START)) { \\r
468 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_END_ID); \\r
469 } \\r
470 } while (FALSE)\r
471\r
472/**\r
473 Start Macro to measure the performance of DriverBinding Stop in core.\r
474\r
475 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
476 and the BIT5 (dsiable PERF_CORE_DB_STOP) of PcdPerformanceLibraryPropertyMask is not set.\r
477 then LogPerformanceMeasurement() is called.\r
478\r
479**/\r
480#define PERF_DRIVER_BINDING_STOP_BEGIN(ModuleHandle, ControllerHandle) \\r
481 do { \\r
482 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_STOP)) { \\r
483 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_STOP_START_ID); \\r
484 } \\r
485 } while (FALSE)\r
486\r
487/**\r
488 End Macro to measure the performance of DriverBinding Stop in core.\r
489\r
490 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
491 and the BIT5 (dsiable PERF_CORE_DB_STOP) of PcdPerformanceLibraryPropertyMask is not set.\r
492 then LogPerformanceMeasurement() is called.\r
493\r
494**/\r
495#define PERF_DRIVER_BINDING_STOP_END(ModuleHandle, ControllerHandle) \\r
496 do { \\r
497 if (LogPerformanceMeasurementEnabled (PERF_CORE_DB_STOP)) { \\r
498 LogPerformanceMeasurement (ModuleHandle, NULL, NULL, (UINT64)(UINTN)ControllerHandle, MODULE_DB_STOP_END_ID); \\r
499 } \\r
500 } while (FALSE)\r
501\r
502/**\r
503 Macro to measure the time from power-on to this macro execution.\r
504 It can be used to log a meaningful thing which happens at a time point.\r
505\r
506 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
507 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
508 then LogPerformanceMeasurement() is called.\r
509\r
510**/\r
511#define PERF_EVENT(EventString) \\r
512 do { \\r
513 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
514 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, EventString , 0, PERF_EVENT_ID); \\r
515 } \\r
516 } while (FALSE)\r
517\r
518/**\r
519 Begin Macro to measure the perofrmance of evnent signal behavior in any module.\r
520 The event guid will be passed with this macro.\r
521\r
522 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
523 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
524 then LogPerformanceMeasurement() is called.\r
525\r
526**/\r
527#define PERF_EVENT_SIGNAL_BEGIN(EventGuid) \\r
528 do { \\r
529 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
530 LogPerformanceMeasurement (&gEfiCallerIdGuid, EventGuid, __FUNCTION__ , 0, PERF_EVENTSIGNAL_START_ID); \\r
531 } \\r
532 } while (FALSE)\r
533\r
534/**\r
535 End Macro to measure the perofrmance of evnent signal behavior in any module.\r
536 The event guid will be passed with this macro.\r
537\r
538 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
539 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
540 then LogPerformanceMeasurement() is called.\r
541\r
542**/\r
543#define PERF_EVENT_SIGNAL_END(EventGuid) \\r
544 do { \\r
545 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
546 LogPerformanceMeasurement (&gEfiCallerIdGuid, EventGuid, __FUNCTION__ , 0, PERF_EVENTSIGNAL_END_ID); \\r
547 } \\r
548 } while (FALSE)\r
549\r
550/**\r
551 Begin Macro to measure the perofrmance of a callback function in any module.\r
552 The event guid which trigger the callback function will be passed with this macro.\r
553\r
554 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
555 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
556 then LogPerformanceMeasurement() is called.\r
557\r
558**/\r
559#define PERF_CALLBACK_BEGIN(TriggerGuid) \\r
560 do { \\r
561 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
562 LogPerformanceMeasurement (&gEfiCallerIdGuid, TriggerGuid, __FUNCTION__ , 0, PERF_CALLBACK_START_ID); \\r
563 } \\r
564 } while (FALSE)\r
565\r
566/**\r
567 End Macro to measure the perofrmance of a callback function in any module.\r
568 The event guid which trigger the callback function will be passed with this macro.\r
569\r
570 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
571 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
572 then LogPerformanceMeasurement() is called.\r
573\r
574**/\r
575#define PERF_CALLBACK_END(TriggerGuid) \\r
576 do { \\r
577 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
578 LogPerformanceMeasurement (&gEfiCallerIdGuid, TriggerGuid, __FUNCTION__ , 0, PERF_CALLBACK_END_ID); \\r
579 } \\r
580 } while (FALSE)\r
581\r
582/**\r
583 Begin Macro to measure the perofrmance of a general function in any module.\r
584\r
585 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
586 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
587 then LogPerformanceMeasurement() is called.\r
588\r
589**/\r
590#define PERF_FUNCTION_BEGIN() \\r
591 do { \\r
592 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
593 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, __FUNCTION__ , 0, PERF_FUNCTION_START_ID); \\r
594 } \\r
595 } while (FALSE)\r
596\r
597/**\r
598 End Macro to measure the perofrmance of a general function in any module.\r
599\r
600 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
601 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
602 then LogPerformanceMeasurement() is called.\r
603\r
604**/\r
605#define PERF_FUNCTION_END() \\r
606 do { \\r
607 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
608 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, __FUNCTION__ , 0, PERF_FUNCTION_END_ID); \\r
609 } \\r
610 } while (FALSE)\r
611\r
612/**\r
613 Begin Macro to measure the perofrmance of a behavior within one module.\r
614\r
615 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
616 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
617 then LogPerformanceMeasurement() is called.\r
618\r
619**/\r
620#define PERF_INMODULE_BEGIN(MeasurementString) \\r
621 do { \\r
622 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
623 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_INMODULE_START_ID); \\r
624 } \\r
625 } while (FALSE)\r
626\r
627/**\r
628 End Macro to measure the perofrmance of a behavior within one module.\r
629\r
630 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
631 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
632 then LogPerformanceMeasurement() is called.\r
633\r
634**/\r
635#define PERF_INMODULE_END(MeasurementString) \\r
636 do { \\r
637 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
638 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_INMODULE_END_ID); \\r
639 } \\r
640 } while (FALSE)\r
641\r
642/**\r
643 Begin Macro to measure the perofrmance of a behavior in different modules.\r
644 Such as the performance of PEI phase, DXE phase, BDS phase.\r
645\r
646 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
647 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
648 then LogPerformanceMeasurement() is called.\r
649\r
650**/\r
651#define PERF_CROSSMODULE_BEGIN(MeasurementString) \\r
652 do { \\r
653 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
654 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_CROSSMODULE_START_ID); \\r
655 } \\r
656 } while (FALSE)\r
657\r
658/**\r
659 End Macro to measure the perofrmance of a behavior in different modules.\r
660 Such as the performance of PEI phase, DXE phase, BDS phase.\r
661\r
662 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
663 and the BIT6 (dsiable PERF_GENERAL_TYPE) of PcdPerformanceLibraryPropertyMask is not set.\r
664 then LogPerformanceMeasurement() is called.\r
665\r
666**/\r
667#define PERF_CROSSMODULE_END(MeasurementString) \\r
668 do { \\r
669 if (LogPerformanceMeasurementEnabled (PERF_GENERAL_TYPE)) { \\r
670 LogPerformanceMeasurement (&gEfiCallerIdGuid, NULL, MeasurementString, 0, PERF_CROSSMODULE_END_ID); \\r
671 } \\r
672 } while (FALSE)\r
673\r
fb3df220 674/**\r
675 Macro that calls EndPerformanceMeasurement().\r
676\r
677 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
678 then EndPerformanceMeasurement() is called.\r
679\r
680**/\r
681#define PERF_END(Handle, Token, Module, TimeStamp) \\r
682 do { \\r
683 if (PerformanceMeasurementEnabled ()) { \\r
684 EndPerformanceMeasurement (Handle, Token, Module, TimeStamp); \\r
685 } \\r
686 } while (FALSE)\r
687\r
688/**\r
689 Macro that calls StartPerformanceMeasurement().\r
690\r
691 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
692 then StartPerformanceMeasurement() is called.\r
693\r
694**/\r
695#define PERF_START(Handle, Token, Module, TimeStamp) \\r
696 do { \\r
697 if (PerformanceMeasurementEnabled ()) { \\r
698 StartPerformanceMeasurement (Handle, Token, Module, TimeStamp); \\r
699 } \\r
700 } while (FALSE)\r
701\r
ba14539c
SZ
702/**\r
703 Macro that calls EndPerformanceMeasurementEx().\r
704\r
705 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
706 then EndPerformanceMeasurementEx() is called.\r
707\r
708**/\r
709#define PERF_END_EX(Handle, Token, Module, TimeStamp, Identifier) \\r
710 do { \\r
711 if (PerformanceMeasurementEnabled ()) { \\r
712 EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, Identifier); \\r
713 } \\r
714 } while (FALSE)\r
715\r
716/**\r
717 Macro that calls StartPerformanceMeasurementEx().\r
718\r
719 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
720 then StartPerformanceMeasurementEx() is called.\r
721\r
722**/\r
723#define PERF_START_EX(Handle, Token, Module, TimeStamp, Identifier) \\r
724 do { \\r
725 if (PerformanceMeasurementEnabled ()) { \\r
726 StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, Identifier); \\r
727 } \\r
728 } while (FALSE)\r
729\r
fb3df220 730/**\r
731 Macro that marks the beginning of performance measurement source code.\r
732\r
733 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
734 then this macro marks the beginning of source code that is included in a module.\r
735 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.\r
736\r
737**/\r
738#define PERF_CODE_BEGIN() do { if (PerformanceMeasurementEnabled ()) { UINT8 __PerformanceCodeLocal\r
739\r
740/**\r
741 Macro that marks the end of performance measurement source code.\r
742\r
743 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
744 then this macro marks the end of source code that is included in a module.\r
745 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.\r
746\r
747**/\r
748#define PERF_CODE_END() __PerformanceCodeLocal = 0; __PerformanceCodeLocal++; } } while (FALSE)\r
749\r
750/**\r
751 Macro that declares a section of performance measurement source code.\r
752\r
753 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r
754 then the source code specified by Expression is included in a module.\r
755 Otherwise, the source specified by Expression is not included in a module.\r
756\r
757 @param Expression Performance measurement source code to include in a module.\r
758\r
759**/\r
760#define PERF_CODE(Expression) \\r
761 PERF_CODE_BEGIN (); \\r
762 Expression \\r
763 PERF_CODE_END ()\r
764\r
765\r
766#endif\r