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