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