]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c
MdeModulePkg/BmpSupportLib: Check PixelHeight/PixelWidth against 0
[mirror_edk2.git] / MdeModulePkg / Library / DxePerformanceLib / DxePerformanceLib.c
... / ...
CommitLineData
1/** @file\r
2 Performance Library\r
3\r
4 This library instance provides infrastructure for DXE phase drivers to log performance\r
5 data. It consumes PerformanceEx or Performance Protocol published by DxeCorePerformanceLib\r
6 to log performance data. If both PerformanceEx and Performance Protocol is not available, it does not log any\r
7 performance information.\r
8\r
9 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
10This program and the accompanying materials\r
11are licensed and made available under the terms and conditions of the BSD License\r
12which accompanies this distribution. The full text of the license may be found at\r
13http://opensource.org/licenses/bsd-license.php\r
14\r
15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
18**/\r
19\r
20\r
21#include <PiDxe.h>\r
22\r
23#include <Guid/PerformanceMeasurement.h>\r
24\r
25#include <Library/PerformanceLib.h>\r
26#include <Library/DebugLib.h>\r
27#include <Library/UefiBootServicesTableLib.h>\r
28#include <Library/PcdLib.h>\r
29\r
30//\r
31// The cached Performance Protocol and PerformanceEx Protocol interface.\r
32//\r
33EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL *mPerformanceMeasurement = NULL;\r
34\r
35/**\r
36 The function caches the pointers to PerformanceEx protocol and Performance Protocol.\r
37\r
38 The function locates PerformanceEx protocol and Performance Protocol from protocol database.\r
39\r
40 @retval EFI_SUCCESS PerformanceEx protocol or Performance Protocol is successfully located.\r
41 @retval EFI_NOT_FOUND Both PerformanceEx protocol and Performance Protocol are not located to log performance.\r
42\r
43**/\r
44EFI_STATUS\r
45GetPerformanceMeasurementProtocol (\r
46 VOID\r
47 )\r
48{\r
49 EFI_STATUS Status;\r
50 EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL *PerformanceMeasurement;\r
51\r
52 if (mPerformanceMeasurement != NULL) {\r
53 return EFI_SUCCESS;\r
54 }\r
55\r
56 Status = gBS->LocateProtocol (&gEdkiiPerformanceMeasurementProtocolGuid, NULL, (VOID **) &PerformanceMeasurement);\r
57 if (!EFI_ERROR (Status)) {\r
58 ASSERT (PerformanceMeasurement != NULL);\r
59 //\r
60 // Cache PerformanceMeasurement Protocol.\r
61 //\r
62 mPerformanceMeasurement = PerformanceMeasurement;\r
63 return EFI_SUCCESS;\r
64 }\r
65\r
66 return EFI_NOT_FOUND;\r
67}\r
68\r
69/**\r
70 Creates a record for the beginning of a performance measurement.\r
71\r
72 Creates a record that contains the Handle, Token, Module and Identifier.\r
73 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
74 If TimeStamp is zero, then this function reads the current time stamp\r
75 and adds that time stamp value to the record as the start time.\r
76\r
77 @param Handle Pointer to environment specific context used\r
78 to identify the component being measured.\r
79 @param Token Pointer to a Null-terminated ASCII string\r
80 that identifies the component being measured.\r
81 @param Module Pointer to a Null-terminated ASCII string\r
82 that identifies the module being measured.\r
83 @param TimeStamp 64-bit time stamp.\r
84 @param Identifier 32-bit identifier. If the value is 0, the created record\r
85 is same as the one created by StartPerformanceMeasurement.\r
86\r
87 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
88 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
89\r
90**/\r
91RETURN_STATUS\r
92EFIAPI\r
93StartPerformanceMeasurementEx (\r
94 IN CONST VOID *Handle, OPTIONAL\r
95 IN CONST CHAR8 *Token, OPTIONAL\r
96 IN CONST CHAR8 *Module, OPTIONAL\r
97 IN UINT64 TimeStamp,\r
98 IN UINT32 Identifier\r
99 )\r
100{\r
101 EFI_STATUS Status;\r
102 CONST CHAR8* String;\r
103\r
104 Status = GetPerformanceMeasurementProtocol ();\r
105 if (EFI_ERROR (Status)) {\r
106 return RETURN_NOT_FOUND;\r
107 }\r
108\r
109 if (Token != NULL) {\r
110 String = Token;\r
111 } else if (Module != NULL) {\r
112 String = Module;\r
113 } else {\r
114 String = NULL;\r
115 }\r
116\r
117 if (mPerformanceMeasurement != NULL) {\r
118 Status = mPerformanceMeasurement->CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfStartEntry);\r
119 } else {\r
120 ASSERT (FALSE);\r
121 }\r
122\r
123 return (RETURN_STATUS) Status;\r
124}\r
125\r
126/**\r
127 Fills in the end time of a performance measurement.\r
128\r
129 Looks up the record that matches Handle, Token and Module.\r
130 If the record can not be found then return RETURN_NOT_FOUND.\r
131 If the record is found and TimeStamp is not zero,\r
132 then TimeStamp is added to the record as the end time.\r
133 If the record is found and TimeStamp is zero, then this function reads\r
134 the current time stamp and adds that time stamp value to the record as the end time.\r
135\r
136 @param Handle Pointer to environment specific context used\r
137 to identify the component being measured.\r
138 @param Token Pointer to a Null-terminated ASCII string\r
139 that identifies the component being measured.\r
140 @param Module Pointer to a Null-terminated ASCII string\r
141 that identifies the module being measured.\r
142 @param TimeStamp 64-bit time stamp.\r
143 @param Identifier 32-bit identifier. If the value is 0, the found record\r
144 is same as the one found by EndPerformanceMeasurement.\r
145\r
146 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
147 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
148\r
149**/\r
150RETURN_STATUS\r
151EFIAPI\r
152EndPerformanceMeasurementEx (\r
153 IN CONST VOID *Handle, OPTIONAL\r
154 IN CONST CHAR8 *Token, OPTIONAL\r
155 IN CONST CHAR8 *Module, OPTIONAL\r
156 IN UINT64 TimeStamp,\r
157 IN UINT32 Identifier\r
158 )\r
159{\r
160 EFI_STATUS Status;\r
161 CONST CHAR8* String;\r
162\r
163 Status = GetPerformanceMeasurementProtocol ();\r
164 if (EFI_ERROR (Status)) {\r
165 return RETURN_NOT_FOUND;\r
166 }\r
167\r
168 if (Token != NULL) {\r
169 String = Token;\r
170 } else if (Module != NULL) {\r
171 String = Module;\r
172 } else {\r
173 String = NULL;\r
174 }\r
175\r
176 if (mPerformanceMeasurement != NULL) {\r
177 Status = mPerformanceMeasurement->CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfEndEntry);\r
178 } else {\r
179 ASSERT (FALSE);\r
180 }\r
181\r
182 return (RETURN_STATUS) Status;\r
183}\r
184\r
185/**\r
186 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
187 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
188 and then assign the Identifier with 0.\r
189\r
190 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
191 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
192 and the key for the second entry in the log is returned. If the performance log is empty,\r
193 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
194 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
195 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
196 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
197 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
198 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
199 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
200 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
201 If Handle is NULL, then ASSERT().\r
202 If Token is NULL, then ASSERT().\r
203 If Module is NULL, then ASSERT().\r
204 If StartTimeStamp is NULL, then ASSERT().\r
205 If EndTimeStamp is NULL, then ASSERT().\r
206 If Identifier is NULL, then ASSERT().\r
207\r
208 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
209 0, then the first performance measurement log entry is retrieved.\r
210 On exit, the key of the next performance log entry.\r
211 @param Handle Pointer to environment specific context used to identify the component\r
212 being measured.\r
213 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
214 being measured.\r
215 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
216 being measured.\r
217 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
218 was started.\r
219 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
220 was ended.\r
221 @param Identifier Pointer to the 32-bit identifier that was recorded.\r
222\r
223 @return The key for the next performance log entry (in general case).\r
224\r
225**/\r
226UINTN\r
227EFIAPI\r
228GetPerformanceMeasurementEx (\r
229 IN UINTN LogEntryKey,\r
230 OUT CONST VOID **Handle,\r
231 OUT CONST CHAR8 **Token,\r
232 OUT CONST CHAR8 **Module,\r
233 OUT UINT64 *StartTimeStamp,\r
234 OUT UINT64 *EndTimeStamp,\r
235 OUT UINT32 *Identifier\r
236 )\r
237{\r
238 return 0;\r
239\r
240}\r
241\r
242/**\r
243 Creates a record for the beginning of a performance measurement.\r
244\r
245 Creates a record that contains the Handle, Token, and Module.\r
246 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
247 If TimeStamp is zero, then this function reads the current time stamp\r
248 and adds that time stamp value to the record as the start time.\r
249\r
250 @param Handle Pointer to environment specific context used\r
251 to identify the component being measured.\r
252 @param Token Pointer to a Null-terminated ASCII string\r
253 that identifies the component being measured.\r
254 @param Module Pointer to a Null-terminated ASCII string\r
255 that identifies the module being measured.\r
256 @param TimeStamp 64-bit time stamp.\r
257\r
258 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
259 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
260\r
261**/\r
262RETURN_STATUS\r
263EFIAPI\r
264StartPerformanceMeasurement (\r
265 IN CONST VOID *Handle, OPTIONAL\r
266 IN CONST CHAR8 *Token, OPTIONAL\r
267 IN CONST CHAR8 *Module, OPTIONAL\r
268 IN UINT64 TimeStamp\r
269 )\r
270{\r
271 return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
272}\r
273\r
274/**\r
275 Fills in the end time of a performance measurement.\r
276\r
277 Looks up the record that matches Handle, Token, and Module.\r
278 If the record can not be found then return RETURN_NOT_FOUND.\r
279 If the record is found and TimeStamp is not zero,\r
280 then TimeStamp is added to the record as the end time.\r
281 If the record is found and TimeStamp is zero, then this function reads\r
282 the current time stamp and adds that time stamp value to the record as the end time.\r
283\r
284 @param Handle Pointer to environment specific context used\r
285 to identify the component being measured.\r
286 @param Token Pointer to a Null-terminated ASCII string\r
287 that identifies the component being measured.\r
288 @param Module Pointer to a Null-terminated ASCII string\r
289 that identifies the module being measured.\r
290 @param TimeStamp 64-bit time stamp.\r
291\r
292 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
293 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
294\r
295**/\r
296RETURN_STATUS\r
297EFIAPI\r
298EndPerformanceMeasurement (\r
299 IN CONST VOID *Handle, OPTIONAL\r
300 IN CONST CHAR8 *Token, OPTIONAL\r
301 IN CONST CHAR8 *Module, OPTIONAL\r
302 IN UINT64 TimeStamp\r
303 )\r
304{\r
305 return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
306}\r
307\r
308/**\r
309 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
310 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
311 and then eliminate the Identifier.\r
312\r
313 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
314 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
315 and the key for the second entry in the log is returned. If the performance log is empty,\r
316 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
317 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
318 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
319 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
320 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
321 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
322 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
323 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
324 If Handle is NULL, then ASSERT().\r
325 If Token is NULL, then ASSERT().\r
326 If Module is NULL, then ASSERT().\r
327 If StartTimeStamp is NULL, then ASSERT().\r
328 If EndTimeStamp is NULL, then ASSERT().\r
329\r
330 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
331 0, then the first performance measurement log entry is retrieved.\r
332 On exit, the key of the next performance log entry.\r
333 @param Handle Pointer to environment specific context used to identify the component\r
334 being measured.\r
335 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
336 being measured.\r
337 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
338 being measured.\r
339 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
340 was started.\r
341 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
342 was ended.\r
343\r
344 @return The key for the next performance log entry (in general case).\r
345\r
346**/\r
347UINTN\r
348EFIAPI\r
349GetPerformanceMeasurement (\r
350 IN UINTN LogEntryKey,\r
351 OUT CONST VOID **Handle,\r
352 OUT CONST CHAR8 **Token,\r
353 OUT CONST CHAR8 **Module,\r
354 OUT UINT64 *StartTimeStamp,\r
355 OUT UINT64 *EndTimeStamp\r
356 )\r
357{\r
358 return 0;\r
359}\r
360\r
361/**\r
362 Returns TRUE if the performance measurement macros are enabled.\r
363\r
364 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
365 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
366\r
367 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
368 PcdPerformanceLibraryPropertyMask is set.\r
369 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
370 PcdPerformanceLibraryPropertyMask is clear.\r
371\r
372**/\r
373BOOLEAN\r
374EFIAPI\r
375PerformanceMeasurementEnabled (\r
376 VOID\r
377 )\r
378{\r
379 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
380}\r
381\r
382/**\r
383 Create performance record with event description and a timestamp.\r
384\r
385 @param CallerIdentifier - Image handle or pointer to caller ID GUID\r
386 @param Guid - Pointer to a GUID\r
387 @param String - Pointer to a string describing the measurement\r
388 @param Address - Pointer to a location in memory relevant to the measurement\r
389 @param Identifier - Performance identifier describing the type of measurement\r
390\r
391 @retval RETURN_SUCCESS - Successfully created performance record\r
392 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records\r
393 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
394 pointer or invalid PerfId\r
395\r
396**/\r
397RETURN_STATUS\r
398EFIAPI\r
399LogPerformanceMeasurement (\r
400 IN CONST VOID *CallerIdentifier,\r
401 IN CONST VOID *Guid, OPTIONAL\r
402 IN CONST CHAR8 *String, OPTIONAL\r
403 IN UINT64 Address, OPTIONAL\r
404 IN UINT32 Identifier\r
405 )\r
406{\r
407 EFI_STATUS Status;\r
408\r
409 Status = GetPerformanceMeasurementProtocol ();\r
410 if (EFI_ERROR (Status)) {\r
411 return RETURN_OUT_OF_RESOURCES;\r
412 }\r
413\r
414 if (mPerformanceMeasurement != NULL) {\r
415 Status = mPerformanceMeasurement->CreatePerformanceMeasurement (CallerIdentifier, Guid, String, 0, Address, Identifier, PerfEntry);\r
416 } else {\r
417 ASSERT (FALSE);\r
418 }\r
419\r
420 return (RETURN_STATUS) Status;\r
421}\r
422\r
423/**\r
424 Check whether the specified performance measurement can be logged.\r
425\r
426 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set\r
427 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.\r
428\r
429 @param Type - Type of the performance measurement entry.\r
430\r
431 @retval TRUE The performance measurement can be logged.\r
432 @retval FALSE The performance measurement can NOT be logged.\r
433\r
434**/\r
435BOOLEAN\r
436EFIAPI\r
437LogPerformanceMeasurementEnabled (\r
438 IN CONST UINTN Type\r
439 )\r
440{\r
441 //\r
442 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.\r
443 //\r
444 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask) & Type) == 0) {\r
445 return TRUE;\r
446 }\r
447 return FALSE;\r
448}\r