PerformanceLib.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /** @file
  2. Base Performance Library which provides no service.
  3. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Base.h>
  7. #include <Library/PerformanceLib.h>
  8. #include <Library/DebugLib.h>
  9. #include <Library/PcdLib.h>
  10. /**
  11. Creates a record for the beginning of a performance measurement.
  12. Creates a record that contains the Handle, Token, and Module.
  13. If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
  14. If TimeStamp is zero, then this function reads the current time stamp
  15. and adds that time stamp value to the record as the start time.
  16. @param Handle The pointer to environment specific context used
  17. to identify the component being measured.
  18. @param Token The pointer to a Null-terminated ASCII string
  19. that identifies the component being measured.
  20. @param Module The pointer to a Null-terminated ASCII string
  21. that identifies the module being measured.
  22. @param TimeStamp 64-bit time stamp.
  23. @retval RETURN_SUCCESS The start of the measurement was recorded.
  24. @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
  25. @retval RETURN_DEVICE_ERROR A device error reading the time stamp.
  26. **/
  27. RETURN_STATUS
  28. EFIAPI
  29. StartPerformanceMeasurement (
  30. IN CONST VOID *Handle OPTIONAL,
  31. IN CONST CHAR8 *Token OPTIONAL,
  32. IN CONST CHAR8 *Module OPTIONAL,
  33. IN UINT64 TimeStamp
  34. )
  35. {
  36. return RETURN_SUCCESS;
  37. }
  38. /**
  39. Fills in the end time of a performance measurement.
  40. Looks up the record that matches Handle, Token, and Module.
  41. If the record can not be found then return RETURN_NOT_FOUND.
  42. If the record is found and TimeStamp is not zero,
  43. then TimeStamp is added to the record as the end time.
  44. If the record is found and TimeStamp is zero, then this function reads
  45. the current time stamp and adds that time stamp value to the record as the end time.
  46. @param Handle The pointer to environment specific context used
  47. to identify the component being measured.
  48. @param Token The pointer to a Null-terminated ASCII string
  49. that identifies the component being measured.
  50. @param Module The pointer to a Null-terminated ASCII string
  51. that identifies the module being measured.
  52. @param TimeStamp 64-bit time stamp.
  53. @retval RETURN_SUCCESS The end of the measurement was recorded.
  54. @retval RETURN_NOT_FOUND The specified measurement record could not be found.
  55. @retval RETURN_DEVICE_ERROR A device error reading the time stamp.
  56. **/
  57. RETURN_STATUS
  58. EFIAPI
  59. EndPerformanceMeasurement (
  60. IN CONST VOID *Handle OPTIONAL,
  61. IN CONST CHAR8 *Token OPTIONAL,
  62. IN CONST CHAR8 *Module OPTIONAL,
  63. IN UINT64 TimeStamp
  64. )
  65. {
  66. return RETURN_SUCCESS;
  67. }
  68. /**
  69. Attempts to retrieve a performance measurement log entry from the performance measurement log.
  70. It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,
  71. and then eliminate the Identifier.
  72. Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
  73. zero on entry, then an attempt is made to retrieve the first entry from the performance log,
  74. and the key for the second entry in the log is returned. If the performance log is empty,
  75. then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
  76. log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
  77. returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
  78. retrieved and an implementation specific non-zero key value that specifies the end of the performance
  79. log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
  80. is retrieved and zero is returned. In the cases where a performance log entry can be returned,
  81. the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
  82. If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
  83. If Handle is NULL, then ASSERT().
  84. If Token is NULL, then ASSERT().
  85. If Module is NULL, then ASSERT().
  86. If StartTimeStamp is NULL, then ASSERT().
  87. If EndTimeStamp is NULL, then ASSERT().
  88. @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
  89. 0, then the first performance measurement log entry is retrieved.
  90. On exit, the key of the next performance lof entry entry.
  91. @param Handle The pointer to environment specific context used to identify the component
  92. being measured.
  93. @param Token The pointer to a Null-terminated ASCII string that identifies the component
  94. being measured.
  95. @param Module The pointer to a Null-terminated ASCII string that identifies the module
  96. being measured.
  97. @param StartTimeStamp The pointer to the 64-bit time stamp that was recorded when the measurement
  98. was started.
  99. @param EndTimeStamp The pointer to the 64-bit time stamp that was recorded when the measurement
  100. was ended.
  101. @return The key for the next performance log entry (in general case).
  102. **/
  103. UINTN
  104. EFIAPI
  105. GetPerformanceMeasurement (
  106. IN UINTN LogEntryKey,
  107. OUT CONST VOID **Handle,
  108. OUT CONST CHAR8 **Token,
  109. OUT CONST CHAR8 **Module,
  110. OUT UINT64 *StartTimeStamp,
  111. OUT UINT64 *EndTimeStamp
  112. )
  113. {
  114. ASSERT (Handle != NULL);
  115. ASSERT (Token != NULL);
  116. ASSERT (Module != NULL);
  117. ASSERT (StartTimeStamp != NULL);
  118. ASSERT (EndTimeStamp != NULL);
  119. return 0;
  120. }
  121. /**
  122. Creates a record for the beginning of a performance measurement.
  123. Creates a record that contains the Handle, Token, Module and Identifier.
  124. If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
  125. If TimeStamp is zero, then this function reads the current time stamp
  126. and adds that time stamp value to the record as the start time.
  127. @param Handle Pointer to environment specific context used
  128. to identify the component being measured.
  129. @param Token Pointer to a Null-terminated ASCII string
  130. that identifies the component being measured.
  131. @param Module Pointer to a Null-terminated ASCII string
  132. that identifies the module being measured.
  133. @param TimeStamp 64-bit time stamp.
  134. @param Identifier 32-bit identifier. If the value is 0, the created record
  135. is same as the one created by StartPerformanceMeasurement.
  136. @retval RETURN_SUCCESS The start of the measurement was recorded.
  137. @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
  138. @retval RETURN_DEVICE_ERROR A device error reading the time stamp.
  139. **/
  140. RETURN_STATUS
  141. EFIAPI
  142. StartPerformanceMeasurementEx (
  143. IN CONST VOID *Handle OPTIONAL,
  144. IN CONST CHAR8 *Token OPTIONAL,
  145. IN CONST CHAR8 *Module OPTIONAL,
  146. IN UINT64 TimeStamp,
  147. IN UINT32 Identifier
  148. )
  149. {
  150. return RETURN_SUCCESS;
  151. }
  152. /**
  153. Fills in the end time of a performance measurement.
  154. Looks up the record that matches Handle, Token, Module and Identifier.
  155. If the record can not be found then return RETURN_NOT_FOUND.
  156. If the record is found and TimeStamp is not zero,
  157. then TimeStamp is added to the record as the end time.
  158. If the record is found and TimeStamp is zero, then this function reads
  159. the current time stamp and adds that time stamp value to the record as the end time.
  160. @param Handle Pointer to environment specific context used
  161. to identify the component being measured.
  162. @param Token Pointer to a Null-terminated ASCII string
  163. that identifies the component being measured.
  164. @param Module Pointer to a Null-terminated ASCII string
  165. that identifies the module being measured.
  166. @param TimeStamp 64-bit time stamp.
  167. @param Identifier 32-bit identifier. If the value is 0, the found record
  168. is same as the one found by EndPerformanceMeasurement.
  169. @retval RETURN_SUCCESS The end of the measurement was recorded.
  170. @retval RETURN_NOT_FOUND The specified measurement record could not be found.
  171. @retval RETURN_DEVICE_ERROR A device error reading the time stamp.
  172. **/
  173. RETURN_STATUS
  174. EFIAPI
  175. EndPerformanceMeasurementEx (
  176. IN CONST VOID *Handle OPTIONAL,
  177. IN CONST CHAR8 *Token OPTIONAL,
  178. IN CONST CHAR8 *Module OPTIONAL,
  179. IN UINT64 TimeStamp,
  180. IN UINT32 Identifier
  181. )
  182. {
  183. return RETURN_SUCCESS;
  184. }
  185. /**
  186. Attempts to retrieve a performance measurement log entry from the performance measurement log.
  187. It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,
  188. and then assign the Identifier with 0.
  189. Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
  190. zero on entry, then an attempt is made to retrieve the first entry from the performance log,
  191. and the key for the second entry in the log is returned. If the performance log is empty,
  192. then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
  193. log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
  194. returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
  195. retrieved and an implementation specific non-zero key value that specifies the end of the performance
  196. log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
  197. is retrieved and zero is returned. In the cases where a performance log entry can be returned,
  198. the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.
  199. If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
  200. If Handle is NULL, then ASSERT().
  201. If Token is NULL, then ASSERT().
  202. If Module is NULL, then ASSERT().
  203. If StartTimeStamp is NULL, then ASSERT().
  204. If EndTimeStamp is NULL, then ASSERT().
  205. If Identifier is NULL, then ASSERT().
  206. @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
  207. 0, then the first performance measurement log entry is retrieved.
  208. On exit, the key of the next performance lof entry entry.
  209. @param Handle Pointer to environment specific context used to identify the component
  210. being measured.
  211. @param Token Pointer to a Null-terminated ASCII string that identifies the component
  212. being measured.
  213. @param Module Pointer to a Null-terminated ASCII string that identifies the module
  214. being measured.
  215. @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
  216. was started.
  217. @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
  218. was ended.
  219. @param Identifier Pointer to the 32-bit identifier that was recorded.
  220. @return The key for the next performance log entry (in general case).
  221. **/
  222. UINTN
  223. EFIAPI
  224. GetPerformanceMeasurementEx (
  225. IN UINTN LogEntryKey,
  226. OUT CONST VOID **Handle,
  227. OUT CONST CHAR8 **Token,
  228. OUT CONST CHAR8 **Module,
  229. OUT UINT64 *StartTimeStamp,
  230. OUT UINT64 *EndTimeStamp,
  231. OUT UINT32 *Identifier
  232. )
  233. {
  234. ASSERT (Handle != NULL);
  235. ASSERT (Token != NULL);
  236. ASSERT (Module != NULL);
  237. ASSERT (StartTimeStamp != NULL);
  238. ASSERT (EndTimeStamp != NULL);
  239. ASSERT (Identifier != NULL);
  240. return 0;
  241. }
  242. /**
  243. Returns TRUE if the performance measurement macros are enabled.
  244. This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
  245. PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
  246. @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
  247. PcdPerformanceLibraryPropertyMask is set.
  248. @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
  249. PcdPerformanceLibraryPropertyMask is clear.
  250. **/
  251. BOOLEAN
  252. EFIAPI
  253. PerformanceMeasurementEnabled (
  254. VOID
  255. )
  256. {
  257. return (BOOLEAN)((PcdGet8 (PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
  258. }
  259. /**
  260. Create performance record with event description and a timestamp.
  261. @param CallerIdentifier - Image handle or pointer to caller ID GUID
  262. @param Guid - Pointer to a GUID
  263. @param String - Pointer to a string describing the measurement
  264. @param Address - Pointer to a location in memory relevant to the measurement
  265. @param Identifier - Performance identifier describing the type of measurement
  266. @retval RETURN_SUCCESS - Successfully created performance record
  267. @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records
  268. @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL
  269. pointer or invalid PerfId
  270. **/
  271. RETURN_STATUS
  272. EFIAPI
  273. LogPerformanceMeasurement (
  274. IN CONST VOID *CallerIdentifier OPTIONAL,
  275. IN CONST VOID *Guid OPTIONAL,
  276. IN CONST CHAR8 *String OPTIONAL,
  277. IN UINT64 Address OPTIONAL,
  278. IN UINT32 Identifier
  279. )
  280. {
  281. return RETURN_SUCCESS;
  282. }
  283. /**
  284. Check whether the specified performance measurement can be logged.
  285. This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set
  286. and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.
  287. @param Type - Type of the performance measurement entry.
  288. @retval TRUE The performance measurement can be logged.
  289. @retval FALSE The performance measurement can NOT be logged.
  290. **/
  291. BOOLEAN
  292. EFIAPI
  293. LogPerformanceMeasurementEnabled (
  294. IN CONST UINTN Type
  295. )
  296. {
  297. //
  298. // When Performance measurement is enabled and the type is not filtered, the performance can be logged.
  299. //
  300. if (PerformanceMeasurementEnabled () && ((PcdGet8 (PcdPerformanceLibraryPropertyMask) & Type) == 0)) {
  301. return TRUE;
  302. }
  303. return FALSE;
  304. }