]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
FixedPcd macro should *not* be used in Library's inf file.
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
CommitLineData
a0afd019 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 DxeCorePerformance.c\r
15\r
16Abstract:\r
17\r
18 Support for measurement of DXE performance \r
19\r
20--*/\r
21\r
ed7748fe 22\r
a0afd019 23#include <PiDxe.h>\r
ed7748fe 24\r
a0afd019 25#include <Protocol/Performance.h>\r
26#include <Guid/PeiPerformanceHob.h>\r
ed7748fe 27\r
a0afd019 28#include <Library/PerformanceLib.h>\r
29#include <Library/DebugLib.h>\r
30#include <Library/HobLib.h>\r
31#include <Library/BaseLib.h>\r
32#include <Library/BaseMemoryLib.h>\r
33#include <Library/TimerLib.h>\r
34#include <Library/PcdLib.h>\r
35#include <Library/UefiBootServicesTableLib.h>\r
36#include <Library/MemoryAllocationLib.h>\r
37\r
38//\r
39// Interface declarations for Performance Protocol.\r
40//\r
41/**\r
42 Adds a record at the end of the performance measurement log\r
43 that records the start time of a performance measurement.\r
44\r
45 Adds a record to the end of the performance measurement log\r
46 that contains the Handle, Token, and Module.\r
47 The end time of the new record must be set to zero.\r
48 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
49 If TimeStamp is zero, the start time in the record is filled in with the value\r
50 read from the current time stamp.\r
51\r
52 @param Handle Pointer to environment specific context used\r
53 to identify the component being measured.\r
54 @param Token Pointer to a Null-terminated ASCII string\r
55 that identifies the component being measured.\r
56 @param Module Pointer to a Null-terminated ASCII string\r
57 that identifies the module being measured.\r
58 @param TimeStamp 64-bit time stamp.\r
59\r
60 @retval EFI_SUCCESS The data was read correctly from the device.\r
61 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
62\r
63**/\r
64STATIC\r
65EFI_STATUS\r
66EFIAPI\r
67StartGauge (\r
68 IN CONST VOID *Handle, OPTIONAL\r
69 IN CONST CHAR8 *Token, OPTIONAL\r
70 IN CONST CHAR8 *Module, OPTIONAL\r
71 IN UINT64 TimeStamp\r
72 );\r
73\r
74/**\r
75 Searches the performance measurement log from the beginning of the log\r
76 for the first matching record that contains a zero end time and fills in a valid end time.\r
77\r
78 Searches the performance measurement log from the beginning of the log\r
79 for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
80 If the record can not be found then return EFI_NOT_FOUND.\r
81 If the record is found and TimeStamp is not zero,\r
82 then the end time in the record is filled in with the value specified by TimeStamp.\r
83 If the record is found and TimeStamp is zero, then the end time in the matching record\r
84 is filled in with the current time stamp value.\r
85\r
86 @param Handle Pointer to environment specific context used\r
87 to identify the component being measured.\r
88 @param Token Pointer to a Null-terminated ASCII string\r
89 that identifies the component being measured.\r
90 @param Module Pointer to a Null-terminated ASCII string\r
91 that identifies the module being measured.\r
92 @param TimeStamp 64-bit time stamp.\r
93\r
94 @retval EFI_SUCCESS The end of the measurement was recorded.\r
95 @retval EFI_NOT_FOUND The specified measurement record could not be found.\r
96\r
97**/\r
98STATIC\r
99EFI_STATUS\r
100EFIAPI\r
101EndGauge (\r
102 IN CONST VOID *Handle, OPTIONAL\r
103 IN CONST CHAR8 *Token, OPTIONAL\r
104 IN CONST CHAR8 *Module, OPTIONAL\r
105 IN UINT64 TimeStamp\r
106 );\r
107\r
108/**\r
109 Retrieves a previously logged performance measurement.\r
110\r
111 Retrieves the performance log entry from the performance log specified by LogEntryKey.\r
112 If it stands for a valid entry, then EFI_SUCCESS is returned and\r
113 GaugeDataEntry stores the pointer to that entry.\r
114\r
115 @param LogEntryKey The key for the previous performance measurement log entry.\r
116 If 0, then the first performance measurement log entry is retrieved.\r
117 @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey\r
118 if the retrieval is successful.\r
119\r
120 @retval EFI_SUCCESS The GuageDataEntry is successfuly found based on LogEntryKey.\r
121 @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r
122 @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r
123 @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL.\r
124\r
125**/\r
126STATIC\r
127EFI_STATUS\r
128EFIAPI\r
129GetGauge (\r
130 IN UINTN LogEntryKey,\r
131 OUT GAUGE_DATA_ENTRY **GaugeDataEntry\r
132 );\r
133\r
134//\r
135// Definition for global variables.\r
136//\r
137STATIC GAUGE_DATA_HEADER *mGaugeData;\r
138STATIC UINT32 mMaxGaugeRecords;\r
139\r
140EFI_HANDLE mHandle = NULL;\r
141PERFORMANCE_PROTOCOL mPerformanceInterface = {\r
142 StartGauge,\r
143 EndGauge,\r
144 GetGauge\r
145 };\r
146\r
147\r
148/**\r
149 Searches in the gauge array with keyword Handle, Token and Module.\r
150\r
151 This internal function searches for the gauge entry in the gauge array.\r
152 If there is an entry that exactly matches the given key word triple\r
153 and its end time stamp is zero, then the index of that gauge entry is returned;\r
154 otherwise, the the number of gauge entries in the array is returned.\r
155\r
156 @param Handle Pointer to environment specific context used\r
157 to identify the component being measured.\r
158 @param Token Pointer to a Null-terminated ASCII string\r
159 that identifies the component being measured.\r
160 @param Module Pointer to a Null-terminated ASCII string\r
161 that identifies the module being measured.\r
162\r
163 @retval The index of gauge entry in the array.\r
164\r
165**/\r
166STATIC\r
167UINT32\r
168InternalSearchForGaugeEntry (\r
169 IN CONST VOID *Handle, OPTIONAL\r
170 IN CONST CHAR8 *Token, OPTIONAL\r
171 IN CONST CHAR8 *Module OPTIONAL\r
172 )\r
173{\r
174 UINT32 Index;\r
175 UINT32 NumberOfEntries;\r
176 GAUGE_DATA_ENTRY *GaugeEntryArray;\r
177\r
178 if (Token == NULL) {\r
179 Token = "";\r
180 }\r
181 if (Module == NULL) {\r
182 Module = "";\r
183 }\r
184\r
185 NumberOfEntries = mGaugeData->NumberOfEntries;\r
186 GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
187\r
188 for (Index = 0; Index < NumberOfEntries; Index++) {\r
189 if ((GaugeEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
190 AsciiStrnCmp (GaugeEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
191 AsciiStrnCmp (GaugeEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
192 GaugeEntryArray[Index].EndTimeStamp == 0\r
193 ) {\r
194 break;\r
195 }\r
196 }\r
197\r
198 return Index;\r
199}\r
200\r
201/**\r
202 Adds a record at the end of the performance measurement log\r
203 that records the start time of a performance measurement.\r
204\r
205 Adds a record to the end of the performance measurement log\r
206 that contains the Handle, Token, and Module.\r
207 The end time of the new record must be set to zero.\r
208 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
209 If TimeStamp is zero, the start time in the record is filled in with the value\r
210 read from the current time stamp.\r
211\r
212 @param Handle Pointer to environment specific context used\r
213 to identify the component being measured.\r
214 @param Token Pointer to a Null-terminated ASCII string\r
215 that identifies the component being measured.\r
216 @param Module Pointer to a Null-terminated ASCII string\r
217 that identifies the module being measured.\r
218 @param TimeStamp 64-bit time stamp.\r
219\r
220 @retval EFI_SUCCESS The data was read correctly from the device.\r
221 @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
222\r
223**/\r
224STATIC\r
225EFI_STATUS\r
226EFIAPI\r
227StartGauge (\r
228 IN CONST VOID *Handle, OPTIONAL\r
229 IN CONST CHAR8 *Token, OPTIONAL\r
230 IN CONST CHAR8 *Module, OPTIONAL\r
231 IN UINT64 TimeStamp\r
232 )\r
233{\r
234 GAUGE_DATA_ENTRY *GaugeEntryArray;\r
235 UINTN GaugeDataSize;\r
236 UINTN OldGaugeDataSize;\r
237 GAUGE_DATA_HEADER *OldGaugeData;\r
238 UINT32 Index;\r
239\r
240 Index = mGaugeData->NumberOfEntries;\r
241 if (Index >= mMaxGaugeRecords) {\r
242 //\r
243 // Try to enlarge the scale of gauge arrary.\r
244 //\r
245 OldGaugeData = mGaugeData;\r
246 OldGaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
247\r
248 mMaxGaugeRecords *= 2;\r
249 GaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r
250\r
251 mGaugeData = AllocateZeroPool (GaugeDataSize);\r
252 if (mGaugeData == NULL) {\r
253 return EFI_OUT_OF_RESOURCES;\r
254 }\r
255 //\r
256 // Initialize new data arry and migrate old data one.\r
257 //\r
258 mGaugeData = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);\r
259\r
260 FreePool (OldGaugeData);\r
261 }\r
262\r
263 GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
264 GaugeEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
265\r
266 if (Token != NULL) {\r
267 AsciiStrnCpy (GaugeEntryArray[Index].Token, Token, DXE_PERFORMANCE_STRING_LENGTH);\r
268 }\r
269 if (Module != NULL) {\r
270 AsciiStrnCpy (GaugeEntryArray[Index].Module, Module, DXE_PERFORMANCE_STRING_LENGTH);\r
271 }\r
272\r
273 if (TimeStamp == 0) {\r
274 TimeStamp = GetPerformanceCounter ();\r
275 }\r
276 GaugeEntryArray[Index].StartTimeStamp = TimeStamp;\r
277\r
278 mGaugeData->NumberOfEntries++;\r
279\r
280 return EFI_SUCCESS;\r
281}\r
282\r
283/**\r
284 Searches the performance measurement log from the beginning of the log\r
285 for the first matching record that contains a zero end time and fills in a valid end time.\r
286\r
287 Searches the performance measurement log from the beginning of the log\r
288 for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
289 If the record can not be found then return EFI_NOT_FOUND.\r
290 If the record is found and TimeStamp is not zero,\r
291 then the end time in the record is filled in with the value specified by TimeStamp.\r
292 If the record is found and TimeStamp is zero, then the end time in the matching record\r
293 is filled in with the current time stamp value.\r
294\r
295 @param Handle Pointer to environment specific context used\r
296 to identify the component being measured.\r
297 @param Token Pointer to a Null-terminated ASCII string\r
298 that identifies the component being measured.\r
299 @param Module Pointer to a Null-terminated ASCII string\r
300 that identifies the module being measured.\r
301 @param TimeStamp 64-bit time stamp.\r
302\r
303 @retval EFI_SUCCESS The end of the measurement was recorded.\r
304 @retval EFI_NOT_FOUND The specified measurement record could not be found.\r
305\r
306**/\r
307STATIC\r
308EFI_STATUS\r
309EFIAPI\r
310EndGauge (\r
311 IN CONST VOID *Handle, OPTIONAL\r
312 IN CONST CHAR8 *Token, OPTIONAL\r
313 IN CONST CHAR8 *Module, OPTIONAL\r
314 IN UINT64 TimeStamp\r
315 )\r
316{\r
317 GAUGE_DATA_ENTRY *GaugeEntryArray;\r
318 UINT32 Index;\r
319\r
320 if (TimeStamp == 0) {\r
321 TimeStamp = GetPerformanceCounter ();\r
322 }\r
323\r
324 Index = InternalSearchForGaugeEntry (Handle, Token, Module);\r
325 if (Index >= mGaugeData->NumberOfEntries) {\r
326 return EFI_NOT_FOUND;\r
327 }\r
328 GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
329 GaugeEntryArray[Index].EndTimeStamp = TimeStamp;\r
330\r
331 return EFI_SUCCESS;\r
332}\r
333\r
334/**\r
335 Retrieves a previously logged performance measurement.\r
336\r
337 Retrieves the performance log entry from the performance log specified by LogEntryKey.\r
338 If it stands for a valid entry, then EFI_SUCCESS is returned and\r
339 GaugeDataEntry stores the pointer to that entry.\r
340\r
341 @param LogEntryKey The key for the previous performance measurement log entry.\r
342 If 0, then the first performance measurement log entry is retrieved.\r
343 @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey\r
344 if the retrieval is successful.\r
345\r
346 @retval EFI_SUCCESS The GuageDataEntry is successfuly found based on LogEntryKey.\r
347 @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r
348 @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r
349 @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL.\r
350\r
351**/\r
352STATIC\r
353EFI_STATUS\r
354EFIAPI\r
355GetGauge (\r
356 IN UINTN LogEntryKey,\r
357 OUT GAUGE_DATA_ENTRY **GaugeDataEntry\r
358 )\r
359{\r
360 UINTN NumberOfEntries;\r
361 GAUGE_DATA_ENTRY *LogEntryArray;\r
362\r
363 NumberOfEntries = (UINTN) (mGaugeData->NumberOfEntries);\r
364 if (LogEntryKey > NumberOfEntries) {\r
365 return EFI_INVALID_PARAMETER;\r
366 }\r
367 if (LogEntryKey == NumberOfEntries) {\r
368 return EFI_NOT_FOUND;\r
369 }\r
370\r
371 LogEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
372\r
373 if (GaugeDataEntry == NULL) {\r
374 return EFI_INVALID_PARAMETER;\r
375 }\r
376 *GaugeDataEntry = &LogEntryArray[LogEntryKey];\r
377\r
378 return EFI_SUCCESS;\r
379}\r
380\r
381/**\r
382 Dumps all the PEI performance log to DXE performance gauge array.\r
383\r
384 This internal function dumps all the PEI performance log to the DXE performance gauge array.\r
385 It retrieves the optional GUID HOB for PEI performance and then saves the performance data\r
386 to DXE performance data structures.\r
387\r
388**/\r
389STATIC\r
390VOID\r
391InternalGetPeiPerformance (\r
392 VOID\r
393 )\r
394{\r
395 EFI_HOB_GUID_TYPE *GuidHob;\r
396 PEI_PERFORMANCE_LOG_HEADER *LogHob;\r
397 PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
398 GAUGE_DATA_ENTRY *GaugeEntryArray;\r
399 UINT32 Index;\r
400 UINT32 NumberOfEntries;\r
401\r
402 NumberOfEntries = 0;\r
403 GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
404\r
405 //\r
406 // Dump PEI Log Entries to DXE Guage Data structure.\r
407 //\r
408 GuidHob = GetFirstGuidHob (&gPeiPerformanceHobGuid);\r
409 if (GuidHob != NULL) {\r
410 LogHob = GET_GUID_HOB_DATA (GuidHob);\r
411 LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (LogHob + 1);\r
412 GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r
413\r
414 NumberOfEntries = LogHob->NumberOfEntries;\r
415 for (Index = 0; Index < NumberOfEntries; Index++) {\r
416 GaugeEntryArray[Index].Handle = LogEntryArray[Index].Handle;\r
417 AsciiStrnCpy (GaugeEntryArray[Index].Token, LogEntryArray[Index].Token, DXE_PERFORMANCE_STRING_LENGTH);\r
418 AsciiStrnCpy (GaugeEntryArray[Index].Module, LogEntryArray[Index].Module, DXE_PERFORMANCE_STRING_LENGTH);\r
419 GaugeEntryArray[Index].StartTimeStamp = LogEntryArray[Index].StartTimeStamp;\r
420 GaugeEntryArray[Index].EndTimeStamp = LogEntryArray[Index].EndTimeStamp;\r
421 }\r
422 }\r
423 mGaugeData->NumberOfEntries = NumberOfEntries;\r
424}\r
425\r
426/**\r
427 The constructor function initializes Performance infrastructure for DXE phase.\r
428\r
429 The constructor function publishes Performance protocol, allocates memory to log DXE performance\r
430 and merges PEI performance data to DXE performance log.\r
431 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.\r
432\r
433 @param ImageHandle The firmware allocated handle for the EFI image.\r
434 @param SystemTable A pointer to the EFI System Table.\r
435\r
436 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
437\r
438**/\r
439EFI_STATUS\r
440EFIAPI\r
441DxeCorePerformanceLibConstructor (\r
442 IN EFI_HANDLE ImageHandle,\r
443 IN EFI_SYSTEM_TABLE *SystemTable\r
444 )\r
445{\r
446 EFI_STATUS Status;\r
447\r
448 if (!PerformanceMeasurementEnabled ()) {\r
449 //\r
450 // Do not initialize performance infrastructure if not required.\r
451 //\r
452 return EFI_SUCCESS;\r
453 }\r
454 //\r
455 // Install the protocol interfaces.\r
456 //\r
457 Status = gBS->InstallProtocolInterface (\r
458 &mHandle,\r
459 &gPerformanceProtocolGuid,\r
460 EFI_NATIVE_INTERFACE,\r
461 &mPerformanceInterface\r
462 );\r
463 ASSERT_EFI_ERROR (Status);\r
464\r
465 mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + PcdGet8 (PcdMaxPeiPerformanceLogEntries);\r
466\r
467 mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords));\r
468 ASSERT (mGaugeData != NULL);\r
469\r
470 InternalGetPeiPerformance ();\r
471\r
472 return Status;\r
473}\r
474\r
475/**\r
476 Adds a record at the end of the performance measurement log\r
477 that records the start time of a performance measurement.\r
478\r
479 Adds a record to the end of the performance measurement log\r
480 that contains the Handle, Token, and Module.\r
481 The end time of the new record must be set to zero.\r
482 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
483 If TimeStamp is zero, the start time in the record is filled in with the value\r
484 read from the current time stamp.\r
485\r
486 @param Handle Pointer to environment specific context used\r
487 to identify the component being measured.\r
488 @param Token Pointer to a Null-terminated ASCII string\r
489 that identifies the component being measured.\r
490 @param Module Pointer to a Null-terminated ASCII string\r
491 that identifies the module being measured.\r
492 @param TimeStamp 64-bit time stamp.\r
493\r
494 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
495 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
496\r
497**/\r
498RETURN_STATUS\r
499EFIAPI\r
500StartPerformanceMeasurement (\r
501 IN CONST VOID *Handle, OPTIONAL\r
502 IN CONST CHAR8 *Token, OPTIONAL\r
503 IN CONST CHAR8 *Module, OPTIONAL\r
504 IN UINT64 TimeStamp\r
505 )\r
506{\r
507 EFI_STATUS Status;\r
508\r
509 Status = StartGauge (Handle, Token, Module, TimeStamp);\r
510 return (RETURN_STATUS) Status;\r
511}\r
512\r
513/**\r
514 Searches the performance measurement log from the beginning of the log\r
515 for the first matching record that contains a zero end time and fills in a valid end time.\r
516\r
517 Searches the performance measurement log from the beginning of the log\r
518 for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
519 If the record can not be found then return RETURN_NOT_FOUND.\r
520 If the record is found and TimeStamp is not zero,\r
521 then the end time in the record is filled in with the value specified by TimeStamp.\r
522 If the record is found and TimeStamp is zero, then the end time in the matching record\r
523 is filled in with the current time stamp value.\r
524\r
525 @param Handle Pointer to environment specific context used\r
526 to identify the component being measured.\r
527 @param Token Pointer to a Null-terminated ASCII string\r
528 that identifies the component being measured.\r
529 @param Module Pointer to a Null-terminated ASCII string\r
530 that identifies the module being measured.\r
531 @param TimeStamp 64-bit time stamp.\r
532\r
533 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
534 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
535\r
536**/\r
537RETURN_STATUS\r
538EFIAPI\r
539EndPerformanceMeasurement (\r
540 IN CONST VOID *Handle, OPTIONAL\r
541 IN CONST CHAR8 *Token, OPTIONAL\r
542 IN CONST CHAR8 *Module, OPTIONAL\r
543 IN UINT64 TimeStamp\r
544 )\r
545{\r
546 EFI_STATUS Status;\r
547\r
548 Status = EndGauge (Handle, Token, Module, TimeStamp);\r
549 return (RETURN_STATUS) Status;\r
550}\r
551\r
552/**\r
553 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
554\r
555 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
556 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
557 and the key for the second entry in the log is returned. If the performance log is empty,\r
558 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
559 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
560 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
561 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
562 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
563 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
564 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
565 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
566 If Handle is NULL, then ASSERT().\r
567 If Token is NULL, then ASSERT().\r
568 If Module is NULL, then ASSERT().\r
569 If StartTimeStamp is NULL, then ASSERT().\r
570 If EndTimeStamp is NULL, then ASSERT().\r
571\r
572 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
573 0, then the first performance measurement log entry is retrieved.\r
574 On exit, the key of the next performance lof entry entry.\r
575 @param Handle Pointer to environment specific context used to identify the component\r
576 being measured.\r
577 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
578 being measured.\r
579 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
580 being measured.\r
581 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
582 was started.\r
583 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
584 was ended.\r
585\r
586 @return The key for the next performance log entry (in general case).\r
587\r
588**/\r
589UINTN\r
590EFIAPI\r
591GetPerformanceMeasurement (\r
592 IN UINTN LogEntryKey,\r
593 OUT CONST VOID **Handle,\r
594 OUT CONST CHAR8 **Token,\r
595 OUT CONST CHAR8 **Module,\r
596 OUT UINT64 *StartTimeStamp,\r
597 OUT UINT64 *EndTimeStamp\r
598 )\r
599{\r
600 EFI_STATUS Status;\r
601 GAUGE_DATA_ENTRY *GaugeData;\r
602\r
603 ASSERT (Handle != NULL);\r
604 ASSERT (Token != NULL);\r
605 ASSERT (Module != NULL);\r
606 ASSERT (StartTimeStamp != NULL);\r
607 ASSERT (EndTimeStamp != NULL);\r
608\r
609 Status = GetGauge (LogEntryKey++, &GaugeData);\r
610\r
611 //\r
612 // Make sure that LogEntryKey is a valid log entry key,\r
613 //\r
614 ASSERT (Status != EFI_INVALID_PARAMETER);\r
615\r
616 if (EFI_ERROR (Status)) {\r
617 //\r
618 // The LogEntryKey is the last entry (equals to the total entry number).\r
619 //\r
620 return 0;\r
621 }\r
622\r
623 ASSERT (GaugeData != NULL);\r
624\r
625 *Handle = (VOID *) (UINTN) GaugeData->Handle;\r
626 *Token = GaugeData->Token;\r
627 *Module = GaugeData->Module;\r
628 *StartTimeStamp = GaugeData->StartTimeStamp;\r
629 *EndTimeStamp = GaugeData->EndTimeStamp;\r
630\r
631 return LogEntryKey;\r
632}\r
633\r
634/**\r
635 Returns TRUE if the performance measurement macros are enabled.\r
636\r
637 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
638 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
639\r
640 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
641 PcdPerformanceLibraryPropertyMask is set.\r
642 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
643 PcdPerformanceLibraryPropertyMask is clear.\r
644\r
645**/\r
646BOOLEAN\r
647EFIAPI\r
648PerformanceMeasurementEnabled (\r
649 VOID\r
650 )\r
651{\r
652 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
653}\r