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