]>
Commit | Line | Data |
---|---|---|
fb3df220 | 1 | /** @file\r |
50a64e5b | 2 | Provides services to log the execution times and retrieve them later.\r |
fb3df220 | 3 | \r |
05570a7e | 4 | Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r |
9df063a0 | 5 | This program and the accompanying materials\r |
50a64e5b | 6 | are licensed and made available under the terms and conditions of the BSD License\r |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
fb3df220 | 9 | \r |
50a64e5b | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
fb3df220 | 12 | \r |
fb3df220 | 13 | **/\r |
14 | \r | |
15 | #ifndef __PERFORMANCE_LIB_H__\r | |
16 | #define __PERFORMANCE_LIB_H__\r | |
17 | \r | |
fc30687f | 18 | ///\r |
19 | /// Performance library propery mask bits\r | |
20 | ///\r | |
fb3df220 | 21 | #define PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED 0x00000001\r |
22 | \r | |
23 | /**\r | |
24 | Creates a record for the beginning of a performance measurement. \r | |
25 | \r | |
26 | Creates a record that contains the Handle, Token, and Module.\r | |
27 | If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r | |
28 | If TimeStamp is zero, then this function reads the current time stamp\r | |
29 | and adds that time stamp value to the record as the start time.\r | |
30 | \r | |
31 | @param Handle Pointer to environment specific context used\r | |
32 | to identify the component being measured.\r | |
33 | @param Token Pointer to a Null-terminated ASCII string\r | |
34 | that identifies the component being measured.\r | |
35 | @param Module Pointer to a Null-terminated ASCII string\r | |
36 | that identifies the module being measured.\r | |
37 | @param TimeStamp 64-bit time stamp.\r | |
38 | \r | |
39 | @retval RETURN_SUCCESS The start of the measurement was recorded.\r | |
40 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
8404146c | 41 | @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r |
fb3df220 | 42 | \r |
43 | **/\r | |
44 | RETURN_STATUS\r | |
45 | EFIAPI\r | |
46 | StartPerformanceMeasurement (\r | |
47 | IN CONST VOID *Handle, OPTIONAL\r | |
48 | IN CONST CHAR8 *Token, OPTIONAL\r | |
49 | IN CONST CHAR8 *Module, OPTIONAL\r | |
50 | IN UINT64 TimeStamp\r | |
51 | );\r | |
52 | \r | |
53 | /**\r | |
54 | Fills in the end time of a performance measurement. \r | |
55 | \r | |
56 | Looks up the record that matches Handle, Token, and Module.\r | |
57 | If the record can not be found then return RETURN_NOT_FOUND.\r | |
58 | If the record is found and TimeStamp is not zero,\r | |
59 | then TimeStamp is added to the record as the end time.\r | |
60 | If the record is found and TimeStamp is zero, then this function reads\r | |
61 | the current time stamp and adds that time stamp value to the record as the end time.\r | |
fb3df220 | 62 | \r |
63 | @param Handle Pointer to environment specific context used\r | |
64 | to identify the component being measured.\r | |
65 | @param Token Pointer to a Null-terminated ASCII string\r | |
66 | that identifies the component being measured.\r | |
67 | @param Module Pointer to a Null-terminated ASCII string\r | |
68 | that identifies the module being measured.\r | |
69 | @param TimeStamp 64-bit time stamp.\r | |
70 | \r | |
71 | @retval RETURN_SUCCESS The end of the measurement was recorded.\r | |
72 | @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r | |
8404146c | 73 | @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r |
fb3df220 | 74 | \r |
75 | **/\r | |
76 | RETURN_STATUS\r | |
77 | EFIAPI\r | |
78 | EndPerformanceMeasurement (\r | |
79 | IN CONST VOID *Handle, OPTIONAL\r | |
80 | IN CONST CHAR8 *Token, OPTIONAL\r | |
81 | IN CONST CHAR8 *Module, OPTIONAL\r | |
82 | IN UINT64 TimeStamp\r | |
83 | );\r | |
84 | \r | |
85 | /**\r | |
86 | Attempts to retrieve a performance measurement log entry from the performance measurement log. \r | |
ba14539c SZ |
87 | It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r |
88 | and then eliminate the Identifier.\r | |
89 | \r | |
fb3df220 | 90 | Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r |
91 | zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r | |
92 | and the key for the second entry in the log is returned. If the performance log is empty,\r | |
93 | then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r | |
94 | log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r | |
95 | returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r | |
96 | retrieved and an implementation specific non-zero key value that specifies the end of the performance\r | |
97 | log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r | |
98 | is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r | |
99 | the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r | |
100 | If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r | |
101 | If Handle is NULL, then ASSERT().\r | |
102 | If Token is NULL, then ASSERT().\r | |
103 | If Module is NULL, then ASSERT().\r | |
104 | If StartTimeStamp is NULL, then ASSERT().\r | |
105 | If EndTimeStamp is NULL, then ASSERT().\r | |
106 | \r | |
107 | @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r | |
108 | 0, then the first performance measurement log entry is retrieved.\r | |
109 | On exit, the key of the next performance lof entry entry.\r | |
110 | @param Handle Pointer to environment specific context used to identify the component\r | |
111 | being measured. \r | |
112 | @param Token Pointer to a Null-terminated ASCII string that identifies the component\r | |
113 | being measured. \r | |
114 | @param Module Pointer to a Null-terminated ASCII string that identifies the module\r | |
115 | being measured.\r | |
116 | @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
117 | was started.\r | |
118 | @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
119 | was ended.\r | |
120 | \r | |
121 | @return The key for the next performance log entry (in general case).\r | |
122 | \r | |
123 | **/\r | |
124 | UINTN\r | |
125 | EFIAPI\r | |
126 | GetPerformanceMeasurement (\r | |
127 | IN UINTN LogEntryKey, \r | |
128 | OUT CONST VOID **Handle,\r | |
129 | OUT CONST CHAR8 **Token,\r | |
130 | OUT CONST CHAR8 **Module,\r | |
131 | OUT UINT64 *StartTimeStamp,\r | |
132 | OUT UINT64 *EndTimeStamp\r | |
133 | );\r | |
134 | \r | |
ba14539c SZ |
135 | /**\r |
136 | Creates a record for the beginning of a performance measurement.\r | |
137 | \r | |
138 | Creates a record that contains the Handle, Token, Module and Identifier.\r | |
139 | If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r | |
140 | If TimeStamp is zero, then this function reads the current time stamp\r | |
141 | and adds that time stamp value to the record as the start time.\r | |
142 | \r | |
143 | @param Handle Pointer to environment specific context used\r | |
144 | to identify the component being measured.\r | |
145 | @param Token Pointer to a Null-terminated ASCII string\r | |
146 | that identifies the component being measured.\r | |
147 | @param Module Pointer to a Null-terminated ASCII string\r | |
148 | that identifies the module being measured.\r | |
149 | @param TimeStamp 64-bit time stamp.\r | |
150 | @param Identifier 32-bit identifier. If the value is 0, the created record\r | |
151 | is same as the one created by StartPerformanceMeasurement.\r | |
152 | \r | |
153 | @retval RETURN_SUCCESS The start of the measurement was recorded.\r | |
154 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
155 | @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r | |
156 | \r | |
157 | **/\r | |
158 | RETURN_STATUS\r | |
159 | EFIAPI\r | |
160 | StartPerformanceMeasurementEx (\r | |
161 | IN CONST VOID *Handle, OPTIONAL\r | |
162 | IN CONST CHAR8 *Token, OPTIONAL\r | |
163 | IN CONST CHAR8 *Module, OPTIONAL\r | |
164 | IN UINT64 TimeStamp,\r | |
165 | IN UINT32 Identifier\r | |
166 | );\r | |
167 | \r | |
168 | /**\r | |
169 | Fills in the end time of a performance measurement.\r | |
170 | \r | |
171 | Looks up the record that matches Handle, Token, Module and Identifier.\r | |
172 | If the record can not be found then return RETURN_NOT_FOUND.\r | |
173 | If the record is found and TimeStamp is not zero,\r | |
174 | then TimeStamp is added to the record as the end time.\r | |
175 | If the record is found and TimeStamp is zero, then this function reads\r | |
176 | the current time stamp and adds that time stamp value to the record as the end time.\r | |
177 | \r | |
178 | @param Handle Pointer to environment specific context used\r | |
179 | to identify the component being measured.\r | |
180 | @param Token Pointer to a Null-terminated ASCII string\r | |
181 | that identifies the component being measured.\r | |
182 | @param Module Pointer to a Null-terminated ASCII string\r | |
183 | that identifies the module being measured.\r | |
184 | @param TimeStamp 64-bit time stamp.\r | |
185 | @param Identifier 32-bit identifier. If the value is 0, the found record\r | |
186 | is same as the one found by EndPerformanceMeasurement.\r | |
187 | \r | |
188 | @retval RETURN_SUCCESS The end of the measurement was recorded.\r | |
189 | @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r | |
190 | @retval RETURN_DEVICE_ERROR A device error reading the time stamp.\r | |
191 | \r | |
192 | **/\r | |
193 | RETURN_STATUS\r | |
194 | EFIAPI\r | |
195 | EndPerformanceMeasurementEx (\r | |
196 | IN CONST VOID *Handle, OPTIONAL\r | |
197 | IN CONST CHAR8 *Token, OPTIONAL\r | |
198 | IN CONST CHAR8 *Module, OPTIONAL\r | |
199 | IN UINT64 TimeStamp,\r | |
200 | IN UINT32 Identifier\r | |
201 | );\r | |
202 | \r | |
203 | /**\r | |
204 | Attempts to retrieve a performance measurement log entry from the performance measurement log.\r | |
205 | It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r | |
206 | and then assign the Identifier with 0.\r | |
207 | \r | |
208 | Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r | |
209 | zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r | |
210 | and the key for the second entry in the log is returned. If the performance log is empty,\r | |
211 | then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r | |
212 | log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r | |
213 | returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r | |
214 | retrieved and an implementation specific non-zero key value that specifies the end of the performance\r | |
215 | log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r | |
216 | is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r | |
217 | the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r | |
218 | If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r | |
219 | If Handle is NULL, then ASSERT().\r | |
220 | If Token is NULL, then ASSERT().\r | |
221 | If Module is NULL, then ASSERT().\r | |
222 | If StartTimeStamp is NULL, then ASSERT().\r | |
223 | If EndTimeStamp is NULL, then ASSERT().\r | |
224 | If Identifier is NULL, then ASSERT().\r | |
225 | \r | |
226 | @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r | |
227 | 0, then the first performance measurement log entry is retrieved.\r | |
228 | On exit, the key of the next performance of entry entry.\r | |
229 | @param Handle Pointer to environment specific context used to identify the component\r | |
230 | being measured.\r | |
231 | @param Token Pointer to a Null-terminated ASCII string that identifies the component\r | |
232 | being measured.\r | |
233 | @param Module Pointer to a Null-terminated ASCII string that identifies the module\r | |
234 | being measured.\r | |
235 | @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
236 | was started.\r | |
237 | @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
238 | was ended.\r | |
239 | @param Identifier Pointer to the 32-bit identifier that was recorded.\r | |
240 | \r | |
241 | @return The key for the next performance log entry (in general case).\r | |
242 | \r | |
243 | **/\r | |
244 | UINTN\r | |
245 | EFIAPI\r | |
246 | GetPerformanceMeasurementEx (\r | |
247 | IN UINTN LogEntryKey, \r | |
248 | OUT CONST VOID **Handle,\r | |
249 | OUT CONST CHAR8 **Token,\r | |
250 | OUT CONST CHAR8 **Module,\r | |
251 | OUT UINT64 *StartTimeStamp,\r | |
252 | OUT UINT64 *EndTimeStamp,\r | |
253 | OUT UINT32 *Identifier\r | |
254 | );\r | |
255 | \r | |
fb3df220 | 256 | /**\r |
257 | Returns TRUE if the performance measurement macros are enabled. \r | |
258 | \r | |
259 | This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
260 | PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r | |
261 | \r | |
262 | @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
263 | PcdPerformanceLibraryPropertyMask is set.\r | |
264 | @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
265 | PcdPerformanceLibraryPropertyMask is clear.\r | |
266 | \r | |
267 | **/\r | |
268 | BOOLEAN\r | |
269 | EFIAPI\r | |
270 | PerformanceMeasurementEnabled (\r | |
271 | VOID\r | |
272 | );\r | |
273 | \r | |
274 | /**\r | |
275 | Macro that calls EndPerformanceMeasurement().\r | |
276 | \r | |
277 | If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r | |
278 | then EndPerformanceMeasurement() is called.\r | |
279 | \r | |
280 | **/\r | |
281 | #define PERF_END(Handle, Token, Module, TimeStamp) \\r | |
282 | do { \\r | |
283 | if (PerformanceMeasurementEnabled ()) { \\r | |
284 | EndPerformanceMeasurement (Handle, Token, Module, TimeStamp); \\r | |
285 | } \\r | |
286 | } while (FALSE)\r | |
287 | \r | |
288 | /**\r | |
289 | Macro that calls StartPerformanceMeasurement().\r | |
290 | \r | |
291 | If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r | |
292 | then StartPerformanceMeasurement() is called.\r | |
293 | \r | |
294 | **/\r | |
295 | #define PERF_START(Handle, Token, Module, TimeStamp) \\r | |
296 | do { \\r | |
297 | if (PerformanceMeasurementEnabled ()) { \\r | |
298 | StartPerformanceMeasurement (Handle, Token, Module, TimeStamp); \\r | |
299 | } \\r | |
300 | } while (FALSE)\r | |
301 | \r | |
ba14539c SZ |
302 | /**\r |
303 | Macro that calls EndPerformanceMeasurementEx().\r | |
304 | \r | |
305 | If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r | |
306 | then EndPerformanceMeasurementEx() is called.\r | |
307 | \r | |
308 | **/\r | |
309 | #define PERF_END_EX(Handle, Token, Module, TimeStamp, Identifier) \\r | |
310 | do { \\r | |
311 | if (PerformanceMeasurementEnabled ()) { \\r | |
312 | EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, Identifier); \\r | |
313 | } \\r | |
314 | } while (FALSE)\r | |
315 | \r | |
316 | /**\r | |
317 | Macro that calls StartPerformanceMeasurementEx().\r | |
318 | \r | |
319 | If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r | |
320 | then StartPerformanceMeasurementEx() is called.\r | |
321 | \r | |
322 | **/\r | |
323 | #define PERF_START_EX(Handle, Token, Module, TimeStamp, Identifier) \\r | |
324 | do { \\r | |
325 | if (PerformanceMeasurementEnabled ()) { \\r | |
326 | StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, Identifier); \\r | |
327 | } \\r | |
328 | } while (FALSE)\r | |
329 | \r | |
fb3df220 | 330 | /**\r |
331 | Macro that marks the beginning of performance measurement source code.\r | |
332 | \r | |
333 | If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r | |
334 | then this macro marks the beginning of source code that is included in a module.\r | |
335 | Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.\r | |
336 | \r | |
337 | **/\r | |
338 | #define PERF_CODE_BEGIN() do { if (PerformanceMeasurementEnabled ()) { UINT8 __PerformanceCodeLocal\r | |
339 | \r | |
340 | /**\r | |
341 | Macro that marks the end of performance measurement source code.\r | |
342 | \r | |
343 | If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r | |
344 | then this macro marks the end of source code that is included in a module.\r | |
345 | Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.\r | |
346 | \r | |
347 | **/\r | |
348 | #define PERF_CODE_END() __PerformanceCodeLocal = 0; __PerformanceCodeLocal++; } } while (FALSE)\r | |
349 | \r | |
350 | /**\r | |
351 | Macro that declares a section of performance measurement source code.\r | |
352 | \r | |
353 | If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,\r | |
354 | then the source code specified by Expression is included in a module.\r | |
355 | Otherwise, the source specified by Expression is not included in a module.\r | |
356 | \r | |
357 | @param Expression Performance measurement source code to include in a module.\r | |
358 | \r | |
359 | **/\r | |
360 | #define PERF_CODE(Expression) \\r | |
361 | PERF_CODE_BEGIN (); \\r | |
362 | Expression \\r | |
363 | PERF_CODE_END ()\r | |
364 | \r | |
365 | \r | |
366 | #endif\r |