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