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