PerformanceLib.h 33 KB

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