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