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