]>
Commit | Line | Data |
---|---|---|
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 | |
121 | PERFORMANCE_PROTOCOL PerformanceInterface = {\r | |
122 | StartGauge,\r | |
123 | EndGauge,\r | |
124 | GetGauge\r | |
125 | };\r | |
126 | \r | |
127 | \r | |
128 | /**\r | |
129 | Searches in the gauge array with keyword Handle, Token and Module.\r | |
130 | \r | |
131 | This internal function searches for the gauge entry in the gauge array.\r | |
132 | If there is an entry that exactly matches the given key word triple\r | |
133 | and its end time stamp is zero, then the index of that gauge entry is returned;\r | |
134 | otherwise, the the number of gauge entries in the array is returned. \r | |
135 | \r | |
136 | @param Handle Pointer to environment specific context used\r | |
137 | to identify the component being measured.\r | |
138 | @param Token Pointer to a Null-terminated ASCII string\r | |
139 | that identifies the component being measured.\r | |
140 | @param Module Pointer to a Null-terminated ASCII string\r | |
141 | that identifies the module being measured.\r | |
142 | \r | |
143 | @retval The index of gauge entry in the array.\r | |
144 | \r | |
145 | **/\r | |
146 | UINT32\r | |
147 | InternalSearchForGaugeEntry (\r | |
148 | IN CONST VOID *Handle, OPTIONAL\r | |
149 | IN CONST CHAR8 *Token, OPTIONAL\r | |
150 | IN CONST CHAR8 *Module OPTIONAL\r | |
151 | )\r | |
152 | {\r | |
153 | UINT32 Index;\r | |
154 | UINT32 NumberOfEntries;\r | |
155 | GAUGE_DATA_ENTRY *GaugeEntryArray;\r | |
156 | \r | |
157 | if (Token == NULL) {\r | |
158 | Token = "";\r | |
159 | }\r | |
160 | if (Module == NULL) {\r | |
161 | Module = "";\r | |
162 | }\r | |
163 | \r | |
164 | NumberOfEntries = mGaugeData->NumberOfEntries;\r | |
165 | GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r | |
166 | \r | |
167 | for (Index = 0; Index < NumberOfEntries; Index++) {\r | |
168 | if ((GaugeEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r | |
169 | AsciiStrnCmp (GaugeEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r | |
170 | AsciiStrnCmp (GaugeEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r | |
171 | GaugeEntryArray[Index].EndTimeStamp == 0\r | |
172 | ) {\r | |
173 | break;\r | |
174 | }\r | |
175 | }\r | |
176 | \r | |
177 | return Index;\r | |
178 | }\r | |
179 | \r | |
180 | /**\r | |
181 | Adds a record at the end of the performance measurement log\r | |
182 | that records the start time of a performance measurement.\r | |
183 | \r | |
184 | Adds a record to the end of the performance measurement log\r | |
185 | that contains the Handle, Token, and Module.\r | |
186 | The end time of the new record must be set to zero.\r | |
187 | If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r | |
188 | If TimeStamp is zero, the start time in the record is filled in with the value\r | |
189 | read from the current time stamp. \r | |
190 | \r | |
191 | @param Handle Pointer to environment specific context used\r | |
192 | to identify the component being measured.\r | |
193 | @param Token Pointer to a Null-terminated ASCII string\r | |
194 | that identifies the component being measured.\r | |
195 | @param Module Pointer to a Null-terminated ASCII string\r | |
196 | that identifies the module being measured.\r | |
197 | @param TimeStamp 64-bit time stamp.\r | |
198 | \r | |
199 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
200 | @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
201 | \r | |
202 | **/\r | |
203 | EFI_STATUS\r | |
204 | EFIAPI\r | |
205 | StartGauge (\r | |
206 | IN CONST VOID *Handle, OPTIONAL\r | |
207 | IN CONST CHAR8 *Token, OPTIONAL\r | |
208 | IN CONST CHAR8 *Module, OPTIONAL\r | |
209 | IN UINT64 TimeStamp\r | |
210 | )\r | |
211 | {\r | |
212 | GAUGE_DATA_ENTRY *GaugeEntryArray;\r | |
213 | UINTN GaugeDataSize;\r | |
214 | UINTN OldGaugeDataSize;\r | |
215 | GAUGE_DATA_HEADER *OldGaugeData;\r | |
216 | EFI_STATUS Status;\r | |
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 | |
226 | mMaxGaugeRecords *= 2;\r | |
227 | GaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r | |
228 | Status = gBS->AllocatePool (\r | |
229 | EfiBootServicesData,\r | |
230 | GaugeDataSize,\r | |
231 | (VOID **) &mGaugeData\r | |
232 | );\r | |
233 | if (EFI_ERROR (Status)) {\r | |
234 | return Status;\r | |
235 | }\r | |
236 | //\r | |
237 | // Initialize new data arry and migrate old data one. \r | |
238 | //\r | |
239 | mGaugeData = ZeroMem (mGaugeData, GaugeDataSize);\r | |
240 | mGaugeData = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);\r | |
241 | \r | |
242 | gBS->FreePool (OldGaugeData); \r | |
243 | }\r | |
244 | \r | |
245 | GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r | |
246 | GaugeEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r | |
247 | \r | |
248 | if (Token != NULL) {\r | |
249 | AsciiStrnCpy (GaugeEntryArray[Index].Token, Token, DXE_PERFORMANCE_STRING_LENGTH);\r | |
250 | }\r | |
251 | if (Module != NULL) {\r | |
252 | AsciiStrnCpy (GaugeEntryArray[Index].Module, Module, DXE_PERFORMANCE_STRING_LENGTH);\r | |
253 | }\r | |
254 | \r | |
255 | if (TimeStamp == 0) {\r | |
256 | TimeStamp = GetPerformanceCounter ();\r | |
257 | }\r | |
258 | GaugeEntryArray[Index].StartTimeStamp = TimeStamp;\r | |
259 | \r | |
260 | mGaugeData->NumberOfEntries++;\r | |
261 | \r | |
262 | return EFI_SUCCESS;\r | |
263 | }\r | |
264 | \r | |
265 | /**\r | |
266 | Searches the performance measurement log from the beginning of the log\r | |
267 | for the first matching record that contains a zero end time and fills in a valid end time. \r | |
268 | \r | |
269 | Searches the performance measurement log from the beginning of the log\r | |
270 | for the first record that matches Handle, Token, and Module and has an end time value of zero.\r | |
271 | If the record can not be found then return EFI_NOT_FOUND.\r | |
272 | If the record is found and TimeStamp is not zero,\r | |
273 | then the end time in the record is filled in with the value specified by TimeStamp.\r | |
274 | If the record is found and TimeStamp is zero, then the end time in the matching record\r | |
275 | is filled in with the current time stamp value.\r | |
276 | \r | |
277 | @param Handle Pointer to environment specific context used\r | |
278 | to identify the component being measured.\r | |
279 | @param Token Pointer to a Null-terminated ASCII string\r | |
280 | that identifies the component being measured.\r | |
281 | @param Module Pointer to a Null-terminated ASCII string\r | |
282 | that identifies the module being measured.\r | |
283 | @param TimeStamp 64-bit time stamp.\r | |
284 | \r | |
285 | @retval EFI_SUCCESS The end of the measurement was recorded.\r | |
286 | @retval EFI_NOT_FOUND The specified measurement record could not be found.\r | |
287 | \r | |
288 | **/\r | |
289 | EFI_STATUS\r | |
290 | EFIAPI\r | |
291 | EndGauge (\r | |
292 | IN CONST VOID *Handle, OPTIONAL\r | |
293 | IN CONST CHAR8 *Token, OPTIONAL\r | |
294 | IN CONST CHAR8 *Module, OPTIONAL\r | |
295 | IN UINT64 TimeStamp\r | |
296 | )\r | |
297 | {\r | |
298 | GAUGE_DATA_ENTRY *GaugeEntryArray;\r | |
299 | UINT32 Index;\r | |
300 | \r | |
301 | if (TimeStamp == 0) {\r | |
302 | TimeStamp = GetPerformanceCounter ();\r | |
303 | }\r | |
304 | \r | |
305 | Index = InternalSearchForGaugeEntry (Handle, Token, Module);\r | |
306 | if (Index >= mGaugeData->NumberOfEntries) {\r | |
307 | return EFI_NOT_FOUND;\r | |
308 | }\r | |
309 | GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r | |
310 | GaugeEntryArray[Index].EndTimeStamp = TimeStamp;\r | |
311 | \r | |
312 | return EFI_SUCCESS;\r | |
313 | }\r | |
314 | \r | |
315 | /**\r | |
316 | Retrieves a previously logged performance measurement. \r | |
317 | \r | |
318 | Retrieves the performance log entry from the performance log specified by LogEntryKey.\r | |
319 | If it stands for a valid entry, then EFI_SUCCESS is returned and\r | |
320 | GaugeDataEntry stores the pointer to that entry.\r | |
321 | \r | |
322 | @param LogEntryKey The key for the previous performance measurement log entry.\r | |
323 | If 0, then the first performance measurement log entry is retrieved.\r | |
324 | @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey\r | |
325 | if the retrieval is successful.\r | |
326 | \r | |
327 | @retval EFI_SUCCESS The GuageDataEntry is successfuly found based on LogEntryKey.\r | |
328 | @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r | |
329 | @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r | |
330 | @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL. \r | |
331 | \r | |
332 | **/\r | |
333 | EFI_STATUS\r | |
334 | EFIAPI\r | |
335 | GetGauge (\r | |
336 | IN UINTN LogEntryKey,\r | |
337 | OUT GAUGE_DATA_ENTRY **GaugeDataEntry\r | |
338 | )\r | |
339 | {\r | |
340 | UINTN NumberOfEntries;\r | |
341 | GAUGE_DATA_ENTRY *LogEntryArray;\r | |
342 | \r | |
343 | NumberOfEntries = (UINTN) (mGaugeData->NumberOfEntries);\r | |
344 | if (LogEntryKey > NumberOfEntries) {\r | |
345 | return EFI_INVALID_PARAMETER;\r | |
346 | }\r | |
347 | if (LogEntryKey == NumberOfEntries) {\r | |
348 | return EFI_NOT_FOUND;\r | |
349 | }\r | |
350 | \r | |
351 | LogEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r | |
352 | \r | |
353 | if (GaugeDataEntry == NULL) {\r | |
354 | return EFI_INVALID_PARAMETER;\r | |
355 | }\r | |
356 | *GaugeDataEntry = &LogEntryArray[LogEntryKey];\r | |
357 | \r | |
358 | return EFI_SUCCESS;\r | |
359 | }\r | |
360 | \r | |
361 | /**\r | |
362 | Dumps all the PEI performance log to DXE performance gauge array.\r | |
363 | \r | |
364 | This internal function dumps all the PEI performance log to the DXE performance gauge array.\r | |
365 | It retrieves the optional GUID HOB for PEI performance and then saves the performance data\r | |
366 | to DXE performance data structures.\r | |
367 | \r | |
368 | **/\r | |
369 | VOID\r | |
370 | InternalGetPeiPerformance (\r | |
371 | VOID\r | |
372 | )\r | |
373 | {\r | |
374 | EFI_HOB_GUID_TYPE *GuidHob;\r | |
375 | PEI_PERFORMANCE_LOG_HEADER *LogHob;\r | |
376 | PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r | |
377 | GAUGE_DATA_ENTRY *GaugeEntryArray;\r | |
378 | UINT32 Index;\r | |
379 | UINT32 NumberOfEntries;\r | |
380 | \r | |
381 | NumberOfEntries = 0;\r | |
382 | GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r | |
383 | \r | |
384 | //\r | |
385 | // Dump PEI Log Entries to DXE Guage Data structure. \r | |
386 | //\r | |
387 | GuidHob = GetFirstGuidHob (&gPeiPerformanceHobGuid);\r | |
388 | if (GuidHob != NULL) {\r | |
389 | LogHob = GET_GUID_HOB_DATA (GuidHob);\r | |
390 | LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (LogHob + 1);\r | |
391 | GaugeEntryArray = (GAUGE_DATA_ENTRY *) (mGaugeData + 1);\r | |
392 | \r | |
393 | NumberOfEntries = LogHob->NumberOfEntries;\r | |
394 | for (Index = 0; Index < NumberOfEntries; Index++) {\r | |
395 | GaugeEntryArray[Index].Handle = LogEntryArray[Index].Handle;\r | |
396 | AsciiStrnCpy (GaugeEntryArray[Index].Token, LogEntryArray[Index].Token, DXE_PERFORMANCE_STRING_LENGTH);\r | |
397 | AsciiStrnCpy (GaugeEntryArray[Index].Module, LogEntryArray[Index].Module, DXE_PERFORMANCE_STRING_LENGTH);\r | |
398 | GaugeEntryArray[Index].StartTimeStamp = LogEntryArray[Index].StartTimeStamp;\r | |
399 | GaugeEntryArray[Index].EndTimeStamp = LogEntryArray[Index].EndTimeStamp;\r | |
400 | }\r | |
401 | }\r | |
402 | mGaugeData->NumberOfEntries = NumberOfEntries;\r | |
403 | }\r | |
404 | \r | |
405 | /**\r | |
406 | The constructor function initializes Performance infrastructure for DXE phase.\r | |
407 | \r | |
408 | The constructor function publishes Performance protocol, allocates memory to log DXE performance\r | |
409 | and merges PEI performance data to DXE performance log.\r | |
410 | It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS. \r | |
411 | \r | |
412 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
413 | @param SystemTable A pointer to the EFI System Table.\r | |
414 | \r | |
415 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
416 | \r | |
417 | **/\r | |
418 | EFI_STATUS\r | |
419 | EFIAPI\r | |
420 | DxeCorePerformanceLibConstructor (\r | |
421 | IN EFI_HANDLE ImageHandle,\r | |
422 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
423 | )\r | |
424 | {\r | |
425 | EFI_STATUS Status;\r | |
426 | EFI_HANDLE Handle;\r | |
427 | UINTN GaugeDataSize;\r | |
428 | \r | |
429 | //\r | |
430 | // Install the protocol interfaces.\r | |
431 | //\r | |
432 | Handle = NULL;\r | |
433 | Status = gBS->InstallProtocolInterface (\r | |
434 | &Handle,\r | |
435 | &gPerformanceProtocolGuid,\r | |
436 | EFI_NATIVE_INTERFACE,\r | |
437 | &PerformanceInterface\r | |
438 | );\r | |
439 | ASSERT_EFI_ERROR (Status);\r | |
440 | \r | |
441 | mMaxGaugeRecords = INIT_DXE_GAUGE_DATA_ENTRIES + MAX_PEI_PERFORMANCE_LOG_ENTRIES;\r | |
442 | GaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY) * mMaxGaugeRecords;\r | |
443 | Status = gBS->AllocatePool (\r | |
444 | EfiBootServicesData,\r | |
445 | GaugeDataSize,\r | |
446 | (VOID **) &mGaugeData\r | |
447 | );\r | |
448 | ASSERT_EFI_ERROR (Status);\r | |
449 | \r | |
450 | ZeroMem (mGaugeData, GaugeDataSize);\r | |
451 | \r | |
452 | InternalGetPeiPerformance ();\r | |
453 | \r | |
454 | return Status;\r | |
455 | }\r | |
456 | \r | |
457 | /**\r | |
458 | Adds a record at the end of the performance measurement log\r | |
459 | that records the start time of a performance measurement.\r | |
460 | \r | |
461 | Adds a record to the end of the performance measurement log\r | |
462 | that contains the Handle, Token, and Module.\r | |
463 | The end time of the new record must be set to zero.\r | |
464 | If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r | |
465 | If TimeStamp is zero, the start time in the record is filled in with the value\r | |
466 | read from the current time stamp. \r | |
467 | \r | |
468 | @param Handle Pointer to environment specific context used\r | |
469 | to identify the component being measured.\r | |
470 | @param Token Pointer to a Null-terminated ASCII string\r | |
471 | that identifies the component being measured.\r | |
472 | @param Module Pointer to a Null-terminated ASCII string\r | |
473 | that identifies the module being measured.\r | |
474 | @param TimeStamp 64-bit time stamp.\r | |
475 | \r | |
476 | @retval RETURN_SUCCESS The start of the measurement was recorded.\r | |
477 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
478 | \r | |
479 | **/\r | |
480 | RETURN_STATUS\r | |
481 | EFIAPI\r | |
482 | StartPerformanceMeasurement (\r | |
483 | IN CONST VOID *Handle, OPTIONAL\r | |
484 | IN CONST CHAR8 *Token, OPTIONAL\r | |
485 | IN CONST CHAR8 *Module, OPTIONAL\r | |
486 | IN UINT64 TimeStamp\r | |
487 | )\r | |
488 | {\r | |
489 | EFI_STATUS Status;\r | |
490 | \r | |
491 | Status = StartGauge (Handle, Token, Module, TimeStamp);\r | |
492 | return (RETURN_STATUS) Status;\r | |
493 | }\r | |
494 | \r | |
495 | /**\r | |
496 | Searches the performance measurement log from the beginning of the log\r | |
497 | for the first matching record that contains a zero end time and fills in a valid end time. \r | |
498 | \r | |
499 | Searches the performance measurement log from the beginning of the log\r | |
500 | for the first record that matches Handle, Token, and Module and has an end time value of zero.\r | |
501 | If the record can not be found then return RETURN_NOT_FOUND.\r | |
502 | If the record is found and TimeStamp is not zero,\r | |
503 | then the end time in the record is filled in with the value specified by TimeStamp.\r | |
504 | If the record is found and TimeStamp is zero, then the end time in the matching record\r | |
505 | is filled in with the current time stamp value.\r | |
506 | \r | |
507 | @param Handle Pointer to environment specific context used\r | |
508 | to identify the component being measured.\r | |
509 | @param Token Pointer to a Null-terminated ASCII string\r | |
510 | that identifies the component being measured.\r | |
511 | @param Module Pointer to a Null-terminated ASCII string\r | |
512 | that identifies the module being measured.\r | |
513 | @param TimeStamp 64-bit time stamp.\r | |
514 | \r | |
515 | @retval RETURN_SUCCESS The end of the measurement was recorded.\r | |
516 | @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r | |
517 | \r | |
518 | **/\r | |
519 | RETURN_STATUS\r | |
520 | EFIAPI\r | |
521 | EndPerformanceMeasurement (\r | |
522 | IN CONST VOID *Handle, OPTIONAL\r | |
523 | IN CONST CHAR8 *Token, OPTIONAL\r | |
524 | IN CONST CHAR8 *Module, OPTIONAL\r | |
525 | IN UINT64 TimeStamp\r | |
526 | )\r | |
527 | {\r | |
528 | EFI_STATUS Status;\r | |
529 | \r | |
530 | Status = EndGauge (Handle, Token, Module, TimeStamp);\r | |
531 | return (RETURN_STATUS) Status;\r | |
532 | }\r | |
533 | \r | |
534 | /**\r | |
535 | Retrieves a previously logged performance measurement. \r | |
536 | \r | |
537 | Retrieves the performance log entry from the performance log\r | |
538 | that immediately follows the log entry specified by LogEntryKey.\r | |
539 | If LogEntryKey is zero, then the first entry from the performance log is returned.\r | |
540 | If the log entry specified by LogEntryKey is the last entry in the performance log,\r | |
541 | then 0 is returned. Otherwise, the performance log entry is returned in Handle,\r | |
542 | Token, Module, StartTimeStamp, and EndTimeStamp.\r | |
543 | The key for the current performance log entry is returned. \r | |
544 | \r | |
545 | @param LogEntryKey The key for the previous performance measurement log entry.\r | |
546 | If 0, then the first performance measurement log entry is retrieved.\r | |
547 | @param Handle Pointer to environment specific context used\r | |
548 | to identify the component being measured.\r | |
549 | @param Token Pointer to a Null-terminated ASCII string\r | |
550 | that identifies the component being measured.\r | |
551 | @param Module Pointer to a Null-terminated ASCII string\r | |
552 | that identifies the module being measured.\r | |
553 | @param StartTimeStamp The 64-bit time stamp that was recorded when the measurement was started.\r | |
554 | @param EndTimeStamp The 64-bit time stamp that was recorded when the measurement was ended.\r | |
555 | \r | |
556 | @return The key for the current performance log entry.\r | |
557 | \r | |
558 | **/\r | |
559 | UINTN\r | |
560 | EFIAPI\r | |
561 | GetPerformanceMeasurement (\r | |
562 | UINTN LogEntryKey, \r | |
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 |