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