Commit | Line | Data |
---|---|---|
d41bc92c | 1 | /** @file\r |
2 | Trace reporting for the Dp utility.\r | |
3 | \r | |
115eae65 | 4 | Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.\r |
64c51ed1 | 5 | (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r |
56ba3746 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
d41bc92c | 7 | **/\r |
8 | \r | |
9 | #include <Library/BaseLib.h>\r | |
10 | #include <Library/BaseMemoryLib.h>\r | |
11 | #include <Library/MemoryAllocationLib.h>\r | |
12 | #include <Library/DebugLib.h>\r | |
13 | #include <Library/UefiBootServicesTableLib.h>\r | |
d41bc92c | 14 | #include <Library/PeCoffGetEntryPointLib.h>\r |
15 | #include <Library/PerformanceLib.h>\r | |
16 | #include <Library/PrintLib.h>\r | |
17 | #include <Library/HiiLib.h>\r | |
18 | #include <Library/PcdLib.h>\r | |
19 | \r | |
d41bc92c | 20 | #include "Dp.h"\r |
21 | #include "Literals.h"\r | |
22 | #include "DpInternal.h"\r | |
23 | \r | |
115eae65 DB |
24 | /**\r |
25 | Attempts to retrieve a performance measurement log entry from the performance measurement log.\r | |
26 | \r | |
27 | \r | |
28 | @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r | |
29 | 0, then the first performance measurement log entry is retrieved.\r | |
30 | On exit, the key of the next performance log entry.\r | |
31 | @param Handle Pointer to environment specific context used to identify the component\r | |
32 | being measured.\r | |
33 | @param Token Pointer to a Null-terminated ASCII string that identifies the component\r | |
34 | being measured.\r | |
35 | @param Module Pointer to a Null-terminated ASCII string that identifies the module\r | |
36 | being measured.\r | |
37 | @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
38 | was started.\r | |
39 | @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
40 | was ended.\r | |
41 | @param Identifier Pointer to the 32-bit identifier that was recorded when the measurement\r | |
42 | was ended.\r | |
43 | \r | |
44 | @return The key for the next performance log entry (in general case).\r | |
45 | \r | |
46 | **/\r | |
47 | UINTN\r | |
48 | GetPerformanceMeasurementRecord (\r | |
47d20b54 MK |
49 | IN UINTN LogEntryKey,\r |
50 | OUT CONST VOID **Handle,\r | |
51 | OUT CONST CHAR8 **Token,\r | |
52 | OUT CONST CHAR8 **Module,\r | |
53 | OUT UINT64 *StartTimeStamp,\r | |
54 | OUT UINT64 *EndTimeStamp,\r | |
55 | OUT UINT32 *Identifier\r | |
115eae65 DB |
56 | )\r |
57 | {\r | |
58 | if (LogEntryKey == mMeasurementNum) {\r | |
59 | return 0;\r | |
60 | }\r | |
61 | \r | |
47d20b54 | 62 | *Handle = (VOID *)(UINTN)mMeasurementList[LogEntryKey].Handle;\r |
115eae65 DB |
63 | *Token = mMeasurementList[LogEntryKey].Token;\r |
64 | *Module = mMeasurementList[LogEntryKey].Module;\r | |
65 | *StartTimeStamp = mMeasurementList[LogEntryKey].StartTimeStamp;\r | |
66 | *EndTimeStamp = mMeasurementList[LogEntryKey].EndTimeStamp;\r | |
67 | *Identifier = mMeasurementList[LogEntryKey].Identifier;\r | |
68 | \r | |
47d20b54 | 69 | LogEntryKey++;\r |
115eae65 DB |
70 | \r |
71 | return LogEntryKey;\r | |
72 | }\r | |
73 | \r | |
92034c4c | 74 | /**\r |
d41bc92c | 75 | Collect verbose statistics about the logged performance measurements.\r |
92034c4c | 76 | \r |
d41bc92c | 77 | General Summary information for all Trace measurements is gathered and\r |
78 | stored within the SummaryData structure. This information is both\r | |
79 | used internally by subsequent reporting functions, and displayed\r | |
80 | at the end of verbose reports.\r | |
92034c4c | 81 | \r |
d41bc92c | 82 | @pre The SummaryData and CumData structures must be initialized\r |
83 | prior to calling this function.\r | |
92034c4c | 84 | \r |
d41bc92c | 85 | @post The SummaryData and CumData structures contain statistics for the\r |
86 | current performance logs.\r | |
a06795c6 | 87 | \r |
f16bd394 | 88 | @param[in, out] CustomCumulativeData A pointer to the custom cumulative data.\r |
a06795c6 | 89 | \r |
d41bc92c | 90 | **/\r |
91 | VOID\r | |
47d20b54 MK |
92 | GatherStatistics (\r |
93 | IN OUT PERF_CUM_DATA *CustomCumulativeData OPTIONAL\r | |
a06795c6 | 94 | )\r |
d41bc92c | 95 | {\r |
47d20b54 MK |
96 | MEASUREMENT_RECORD Measurement;\r |
97 | UINT64 Duration;\r | |
98 | UINTN LogEntryKey;\r | |
99 | INTN TIndex;\r | |
d41bc92c | 100 | \r |
101 | LogEntryKey = 0;\r | |
115eae65 | 102 | while ((LogEntryKey = GetPerformanceMeasurementRecord (\r |
47d20b54 MK |
103 | LogEntryKey,\r |
104 | &Measurement.Handle,\r | |
105 | &Measurement.Token,\r | |
106 | &Measurement.Module,\r | |
107 | &Measurement.StartTimeStamp,\r | |
108 | &Measurement.EndTimeStamp,\r | |
109 | &Measurement.Identifier\r | |
110 | )) != 0)\r | |
d41bc92c | 111 | {\r |
112 | ++SummaryData.NumTrace; // Count the number of TRACE Measurement records\r | |
113 | if (Measurement.EndTimeStamp == 0) {\r | |
114 | ++SummaryData.NumIncomplete; // Count the incomplete records\r | |
115 | continue;\r | |
116 | }\r | |
117 | \r | |
118 | if (Measurement.Handle != NULL) {\r | |
119 | ++SummaryData.NumHandles; // Count the number of measurements with non-NULL handles\r | |
120 | }\r | |
121 | \r | |
47d20b54 | 122 | if (IsPhase (&Measurement)) {\r |
d41bc92c | 123 | ++SummaryData.NumSummary; // Count the number of major phases\r |
47d20b54 MK |
124 | } else {\r |
125 | // !IsPhase\r | |
126 | if (Measurement.Handle == NULL) {\r | |
d41bc92c | 127 | ++SummaryData.NumGlobal;\r |
128 | }\r | |
129 | }\r | |
130 | \r | |
115eae65 | 131 | if (AsciiStrCmp (Measurement.Token, ALit_PEIM) == 0) {\r |
d41bc92c | 132 | ++SummaryData.NumPEIMs; // Count PEIM measurements\r |
133 | }\r | |
134 | \r | |
135 | Duration = GetDuration (&Measurement);\r | |
47d20b54 | 136 | TIndex = GetCumulativeItem (&Measurement);\r |
d41bc92c | 137 | if (TIndex >= 0) {\r |
138 | CumData[TIndex].Duration += Duration;\r | |
139 | CumData[TIndex].Count++;\r | |
140 | if ( Duration < CumData[TIndex].MinDur ) {\r | |
141 | CumData[TIndex].MinDur = Duration;\r | |
142 | }\r | |
47d20b54 | 143 | \r |
d41bc92c | 144 | if ( Duration > CumData[TIndex].MaxDur ) {\r |
145 | CumData[TIndex].MaxDur = Duration;\r | |
146 | }\r | |
147 | }\r | |
a06795c6 CS |
148 | \r |
149 | //\r | |
150 | // Collect the data for custom cumulative data.\r | |
151 | //\r | |
152 | if ((CustomCumulativeData != NULL) && (AsciiStrCmp (Measurement.Token, CustomCumulativeData->Name) == 0)) {\r | |
153 | CustomCumulativeData->Duration += Duration;\r | |
154 | CustomCumulativeData->Count++;\r | |
155 | if (Duration < CustomCumulativeData->MinDur) {\r | |
156 | CustomCumulativeData->MinDur = Duration;\r | |
157 | }\r | |
47d20b54 | 158 | \r |
a06795c6 CS |
159 | if (Duration > CustomCumulativeData->MaxDur) {\r |
160 | CustomCumulativeData->MaxDur = Duration;\r | |
161 | }\r | |
162 | }\r | |
d41bc92c | 163 | }\r |
164 | }\r | |
165 | \r | |
92034c4c | 166 | /**\r |
d41bc92c | 167 | Gather and print ALL Trace Records.\r |
92034c4c | 168 | \r |
d41bc92c | 169 | Displays all "interesting" Trace measurements in order.<BR>\r |
170 | The number of records displayed is controlled by:\r | |
171 | - records with a duration less than mInterestThreshold microseconds are not displayed.\r | |
172 | - No more than Limit records are displayed. A Limit of zero will not limit the output.\r | |
173 | - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r | |
174 | displayed.\r | |
92034c4c | 175 | \r |
d41bc92c | 176 | @pre The mInterestThreshold global variable is set to the shortest duration to be printed.\r |
177 | The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.\r | |
178 | They must not be in use by a calling function.\r | |
92034c4c | 179 | \r |
d41bc92c | 180 | @param[in] Limit The number of records to print. Zero is ALL.\r |
181 | @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.\r | |
92034c4c | 182 | \r |
196ccda0 CS |
183 | @retval EFI_SUCCESS The operation was successful.\r |
184 | @retval EFI_ABORTED The user aborts the operation.\r | |
185 | @return Others from a call to gBS->LocateHandleBuffer().\r | |
d41bc92c | 186 | **/\r |
196ccda0 | 187 | EFI_STATUS\r |
47d20b54 MK |
188 | DumpAllTrace (\r |
189 | IN UINTN Limit,\r | |
190 | IN BOOLEAN ExcludeFlag\r | |
d41bc92c | 191 | )\r |
192 | {\r | |
47d20b54 MK |
193 | MEASUREMENT_RECORD Measurement;\r |
194 | UINT64 ElapsedTime;\r | |
195 | UINT64 Duration;\r | |
196 | CHAR16 *IncFlag;\r | |
197 | UINTN LogEntryKey;\r | |
198 | UINTN Count;\r | |
199 | UINTN Index;\r | |
200 | UINTN TIndex;\r | |
201 | \r | |
202 | EFI_HANDLE *HandleBuffer;\r | |
203 | UINTN HandleCount;\r | |
204 | EFI_STATUS Status;\r | |
205 | EFI_STRING StringPtrUnknown;\r | |
d41bc92c | 206 | \r |
92034c4c | 207 | StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);\r |
47d20b54 MK |
208 | IncFlag = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_ALL), NULL);\r |
209 | ShellPrintHiiEx (\r | |
210 | -1,\r | |
211 | -1,\r | |
212 | NULL,\r | |
213 | STRING_TOKEN (STR_DP_SECTION_HEADER),\r | |
214 | mDpHiiHandle,\r | |
215 | (IncFlag == NULL) ? StringPtrUnknown : IncFlag\r | |
216 | );\r | |
d41bc92c | 217 | FreePool (StringPtrUnknown);\r |
218 | \r | |
219 | // Get Handle information\r | |
220 | //\r | |
47d20b54 | 221 | Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);\r |
d41bc92c | 222 | if (EFI_ERROR (Status)) {\r |
92034c4c | 223 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), mDpHiiHandle, Status);\r |
47d20b54 | 224 | } else {\r |
d41bc92c | 225 | // We have successfully populated the HandleBuffer\r |
226 | // Display ALL Measurement Records\r | |
227 | // Up to Limit lines displayed\r | |
228 | // Display only records with Elapsed times >= mInterestThreshold\r | |
229 | // Display driver names in Module field for records with Handles.\r | |
230 | //\r | |
231 | if (mShowId) {\r | |
92034c4c RN |
232 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_HEADR2), mDpHiiHandle);\r |
233 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_DASHES2), mDpHiiHandle);\r | |
d41bc92c | 234 | } else {\r |
92034c4c RN |
235 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_HEADR), mDpHiiHandle);\r |
236 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);\r | |
d41bc92c | 237 | }\r |
238 | \r | |
239 | LogEntryKey = 0;\r | |
47d20b54 MK |
240 | Count = 0;\r |
241 | Index = 0;\r | |
242 | while ( WITHIN_LIMIT (Count, Limit) &&\r | |
115eae65 | 243 | ((LogEntryKey = GetPerformanceMeasurementRecord (\r |
47d20b54 MK |
244 | LogEntryKey,\r |
245 | &Measurement.Handle,\r | |
246 | &Measurement.Token,\r | |
247 | &Measurement.Module,\r | |
248 | &Measurement.StartTimeStamp,\r | |
249 | &Measurement.EndTimeStamp,\r | |
250 | &Measurement.Identifier\r | |
251 | )) != 0)\r | |
252 | )\r | |
d41bc92c | 253 | {\r |
254 | ++Index; // Count every record. First record is 1.\r | |
255 | ElapsedTime = 0;\r | |
256 | SHELL_FREE_NON_NULL (IncFlag);\r | |
257 | if (Measurement.EndTimeStamp != 0) {\r | |
47d20b54 MK |
258 | Duration = GetDuration (&Measurement);\r |
259 | ElapsedTime = DurationInMicroSeconds (Duration);\r | |
260 | IncFlag = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_COMPLETE), NULL);\r | |
261 | } else {\r | |
92034c4c | 262 | IncFlag = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL); // Mark incomplete records\r |
d41bc92c | 263 | }\r |
47d20b54 | 264 | \r |
d41bc92c | 265 | if (((Measurement.EndTimeStamp != 0) && (ElapsedTime < mInterestThreshold)) ||\r |
47d20b54 MK |
266 | ((ExcludeFlag) && (GetCumulativeItem (&Measurement) >= 0))\r |
267 | ) // Ignore "uninteresting" or excluded records\r | |
268 | {\r | |
d41bc92c | 269 | continue;\r |
270 | }\r | |
47d20b54 | 271 | \r |
d41bc92c | 272 | ++Count; // Count the number of records printed\r |
273 | \r | |
274 | // If Handle is non-zero, see if we can determine a name for the driver\r | |
cb4669e0 LE |
275 | AsciiStrToUnicodeStrS (Measurement.Module, mGaugeString, ARRAY_SIZE (mGaugeString)); // Use Module by default\r |
276 | AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));\r | |
d41bc92c | 277 | if (Measurement.Handle != NULL) {\r |
278 | // See if the Handle is in the HandleBuffer\r | |
64c51ed1 | 279 | for (TIndex = 0; TIndex < HandleCount; TIndex++) {\r |
d41bc92c | 280 | if (Measurement.Handle == HandleBuffer[TIndex]) {\r |
2c55a81a | 281 | DpGetNameFromHandle (HandleBuffer[TIndex]);\r |
d41bc92c | 282 | break;\r |
283 | }\r | |
284 | }\r | |
285 | }\r | |
286 | \r | |
115eae65 | 287 | if (AsciiStrCmp (Measurement.Token, ALit_PEIM) == 0) {\r |
d41bc92c | 288 | UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", Measurement.Handle);\r |
289 | }\r | |
290 | \r | |
291 | // Ensure that the argument strings are not too long.\r | |
292 | mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r | |
47d20b54 | 293 | mUnicodeToken[13] = 0;\r |
d41bc92c | 294 | \r |
295 | if (mShowId) {\r | |
47d20b54 MK |
296 | ShellPrintHiiEx (\r |
297 | -1,\r | |
298 | -1,\r | |
299 | NULL,\r | |
300 | STRING_TOKEN (STR_DP_ALL_VARS2),\r | |
301 | mDpHiiHandle,\r | |
d41bc92c | 302 | Index, // 1 based, Which measurement record is being printed\r |
303 | IncFlag,\r | |
304 | Measurement.Handle,\r | |
305 | mGaugeString,\r | |
306 | mUnicodeToken,\r | |
307 | ElapsedTime,\r | |
308 | Measurement.Identifier\r | |
47d20b54 | 309 | );\r |
d41bc92c | 310 | } else {\r |
47d20b54 MK |
311 | ShellPrintHiiEx (\r |
312 | -1,\r | |
313 | -1,\r | |
314 | NULL,\r | |
315 | STRING_TOKEN (STR_DP_ALL_VARS),\r | |
316 | mDpHiiHandle,\r | |
d41bc92c | 317 | Index, // 1 based, Which measurement record is being printed\r |
318 | IncFlag,\r | |
319 | Measurement.Handle,\r | |
320 | mGaugeString,\r | |
321 | mUnicodeToken,\r | |
322 | ElapsedTime\r | |
47d20b54 | 323 | );\r |
d41bc92c | 324 | }\r |
47d20b54 | 325 | \r |
196ccda0 CS |
326 | if (ShellGetExecutionBreakFlag ()) {\r |
327 | Status = EFI_ABORTED;\r | |
328 | break;\r | |
329 | }\r | |
d41bc92c | 330 | }\r |
331 | }\r | |
47d20b54 | 332 | \r |
64c51ed1 | 333 | if (HandleBuffer != NULL) {\r |
d41bc92c | 334 | FreePool (HandleBuffer);\r |
335 | }\r | |
47d20b54 | 336 | \r |
d41bc92c | 337 | SHELL_FREE_NON_NULL (IncFlag);\r |
196ccda0 CS |
338 | \r |
339 | return Status;\r | |
d41bc92c | 340 | }\r |
341 | \r | |
92034c4c | 342 | /**\r |
d41bc92c | 343 | Gather and print Raw Trace Records.\r |
92034c4c | 344 | \r |
d41bc92c | 345 | All Trace measurements with a duration greater than or equal to\r |
346 | mInterestThreshold are printed without interpretation.\r | |
92034c4c | 347 | \r |
d41bc92c | 348 | The number of records displayed is controlled by:\r |
349 | - records with a duration less than mInterestThreshold microseconds are not displayed.\r | |
350 | - No more than Limit records are displayed. A Limit of zero will not limit the output.\r | |
351 | - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not\r | |
352 | displayed.\r | |
92034c4c | 353 | \r |
d41bc92c | 354 | @pre The mInterestThreshold global variable is set to the shortest duration to be printed.\r |
92034c4c | 355 | \r |
d41bc92c | 356 | @param[in] Limit The number of records to print. Zero is ALL.\r |
357 | @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.\r | |
196ccda0 CS |
358 | \r |
359 | @retval EFI_SUCCESS The operation was successful.\r | |
360 | @retval EFI_ABORTED The user aborts the operation.\r | |
d41bc92c | 361 | **/\r |
196ccda0 | 362 | EFI_STATUS\r |
47d20b54 MK |
363 | DumpRawTrace (\r |
364 | IN UINTN Limit,\r | |
365 | IN BOOLEAN ExcludeFlag\r | |
d41bc92c | 366 | )\r |
367 | {\r | |
47d20b54 MK |
368 | MEASUREMENT_RECORD Measurement;\r |
369 | UINT64 ElapsedTime;\r | |
370 | UINT64 Duration;\r | |
371 | UINTN LogEntryKey;\r | |
372 | UINTN Count;\r | |
373 | UINTN Index;\r | |
d41bc92c | 374 | \r |
47d20b54 MK |
375 | EFI_STRING StringPtr;\r |
376 | EFI_STRING StringPtrUnknown;\r | |
377 | EFI_STATUS Status;\r | |
196ccda0 CS |
378 | \r |
379 | Status = EFI_SUCCESS;\r | |
d41bc92c | 380 | \r |
92034c4c | 381 | StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);\r |
47d20b54 MK |
382 | StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWTRACE), NULL);\r |
383 | ShellPrintHiiEx (\r | |
384 | -1,\r | |
385 | -1,\r | |
386 | NULL,\r | |
387 | STRING_TOKEN (STR_DP_SECTION_HEADER),\r | |
388 | mDpHiiHandle,\r | |
389 | (StringPtr == NULL) ? StringPtrUnknown : StringPtr\r | |
390 | );\r | |
d41bc92c | 391 | FreePool (StringPtr);\r |
392 | FreePool (StringPtrUnknown);\r | |
393 | \r | |
394 | if (mShowId) {\r | |
92034c4c RN |
395 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_HEADR2), mDpHiiHandle);\r |
396 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_DASHES2), mDpHiiHandle);\r | |
d41bc92c | 397 | } else {\r |
92034c4c RN |
398 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_HEADR), mDpHiiHandle);\r |
399 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_DASHES), mDpHiiHandle);\r | |
d41bc92c | 400 | }\r |
401 | \r | |
402 | LogEntryKey = 0;\r | |
47d20b54 MK |
403 | Count = 0;\r |
404 | Index = 0;\r | |
405 | while ( WITHIN_LIMIT (Count, Limit) &&\r | |
115eae65 | 406 | ((LogEntryKey = GetPerformanceMeasurementRecord (\r |
47d20b54 MK |
407 | LogEntryKey,\r |
408 | &Measurement.Handle,\r | |
409 | &Measurement.Token,\r | |
410 | &Measurement.Module,\r | |
411 | &Measurement.StartTimeStamp,\r | |
412 | &Measurement.EndTimeStamp,\r | |
413 | &Measurement.Identifier\r | |
414 | )) != 0)\r | |
415 | )\r | |
d41bc92c | 416 | {\r |
417 | ++Index; // Count every record. First record is 1.\r | |
418 | ElapsedTime = 0;\r | |
419 | if (Measurement.EndTimeStamp != 0) {\r | |
47d20b54 MK |
420 | Duration = GetDuration (&Measurement);\r |
421 | ElapsedTime = DurationInMicroSeconds (Duration);\r | |
d41bc92c | 422 | }\r |
47d20b54 | 423 | \r |
d41bc92c | 424 | if ((ElapsedTime < mInterestThreshold) ||\r |
47d20b54 MK |
425 | ((ExcludeFlag) && (GetCumulativeItem (&Measurement) >= 0))\r |
426 | ) // Ignore "uninteresting" or Excluded records\r | |
427 | {\r | |
d41bc92c | 428 | continue;\r |
429 | }\r | |
47d20b54 | 430 | \r |
d41bc92c | 431 | ++Count; // Count the number of records printed\r |
432 | \r | |
433 | if (mShowId) {\r | |
47d20b54 MK |
434 | ShellPrintHiiEx (\r |
435 | -1,\r | |
436 | -1,\r | |
437 | NULL,\r | |
438 | STRING_TOKEN (STR_DP_RAW_VARS2),\r | |
439 | mDpHiiHandle,\r | |
d41bc92c | 440 | Index, // 1 based, Which measurement record is being printed\r |
441 | Measurement.Handle,\r | |
442 | Measurement.StartTimeStamp,\r | |
443 | Measurement.EndTimeStamp,\r | |
444 | Measurement.Token,\r | |
445 | Measurement.Module,\r | |
446 | Measurement.Identifier\r | |
47d20b54 | 447 | );\r |
d41bc92c | 448 | } else {\r |
47d20b54 MK |
449 | ShellPrintHiiEx (\r |
450 | -1,\r | |
451 | -1,\r | |
452 | NULL,\r | |
453 | STRING_TOKEN (STR_DP_RAW_VARS),\r | |
454 | mDpHiiHandle,\r | |
d41bc92c | 455 | Index, // 1 based, Which measurement record is being printed\r |
456 | Measurement.Handle,\r | |
457 | Measurement.StartTimeStamp,\r | |
458 | Measurement.EndTimeStamp,\r | |
459 | Measurement.Token,\r | |
460 | Measurement.Module\r | |
47d20b54 | 461 | );\r |
d41bc92c | 462 | }\r |
47d20b54 | 463 | \r |
196ccda0 CS |
464 | if (ShellGetExecutionBreakFlag ()) {\r |
465 | Status = EFI_ABORTED;\r | |
466 | break;\r | |
467 | }\r | |
d41bc92c | 468 | }\r |
47d20b54 | 469 | \r |
196ccda0 | 470 | return Status;\r |
d41bc92c | 471 | }\r |
472 | \r | |
92034c4c | 473 | /**\r |
d41bc92c | 474 | Gather and print Major Phase metrics.\r |
92034c4c | 475 | \r |
d41bc92c | 476 | **/\r |
477 | VOID\r | |
47d20b54 | 478 | ProcessPhases (\r |
ef224032 | 479 | VOID\r |
d41bc92c | 480 | )\r |
481 | {\r | |
47d20b54 MK |
482 | MEASUREMENT_RECORD Measurement;\r |
483 | UINT64 BdsTimeoutValue;\r | |
484 | UINT64 SecTime;\r | |
485 | UINT64 PeiTime;\r | |
486 | UINT64 DxeTime;\r | |
487 | UINT64 BdsTime;\r | |
488 | UINT64 ElapsedTime;\r | |
489 | UINT64 Duration;\r | |
490 | UINT64 Total;\r | |
491 | EFI_STRING StringPtr;\r | |
492 | UINTN LogEntryKey;\r | |
493 | EFI_STRING StringPtrUnknown;\r | |
d41bc92c | 494 | \r |
495 | BdsTimeoutValue = 0;\r | |
496 | SecTime = 0;\r | |
497 | PeiTime = 0;\r | |
498 | DxeTime = 0;\r | |
499 | BdsTime = 0;\r | |
d41bc92c | 500 | //\r |
501 | // Get Execution Phase Statistics\r | |
502 | //\r | |
92034c4c | 503 | StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);\r |
47d20b54 MK |
504 | StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PHASES), NULL);\r |
505 | ShellPrintHiiEx (\r | |
506 | -1,\r | |
507 | -1,\r | |
508 | NULL,\r | |
509 | STRING_TOKEN (STR_DP_SECTION_HEADER),\r | |
510 | mDpHiiHandle,\r | |
511 | (StringPtr == NULL) ? StringPtrUnknown : StringPtr\r | |
512 | );\r | |
d41bc92c | 513 | FreePool (StringPtr);\r |
514 | FreePool (StringPtrUnknown);\r | |
515 | \r | |
516 | LogEntryKey = 0;\r | |
115eae65 | 517 | while ((LogEntryKey = GetPerformanceMeasurementRecord (\r |
d41bc92c | 518 | LogEntryKey,\r |
519 | &Measurement.Handle,\r | |
520 | &Measurement.Token,\r | |
521 | &Measurement.Module,\r | |
522 | &Measurement.StartTimeStamp,\r | |
523 | &Measurement.EndTimeStamp,\r | |
47d20b54 MK |
524 | &Measurement.Identifier\r |
525 | )) != 0)\r | |
d41bc92c | 526 | {\r |
47d20b54 MK |
527 | if (Measurement.EndTimeStamp == 0) {\r |
528 | // Skip "incomplete" records\r | |
d41bc92c | 529 | continue;\r |
530 | }\r | |
47d20b54 | 531 | \r |
d41bc92c | 532 | Duration = GetDuration (&Measurement);\r |
47d20b54 MK |
533 | if ( (Measurement.Handle != NULL)\r |
534 | && (AsciiStrCmp (Measurement.Token, ALit_BdsTO) == 0)\r | |
535 | )\r | |
d41bc92c | 536 | {\r |
537 | BdsTimeoutValue = Duration;\r | |
115eae65 | 538 | } else if (AsciiStrCmp (Measurement.Token, ALit_SEC) == 0) {\r |
47d20b54 | 539 | SecTime = Duration;\r |
115eae65 | 540 | } else if (AsciiStrCmp (Measurement.Token, ALit_PEI) == 0) {\r |
47d20b54 | 541 | PeiTime = Duration;\r |
115eae65 | 542 | } else if (AsciiStrCmp (Measurement.Token, ALit_DXE) == 0) {\r |
47d20b54 | 543 | DxeTime = Duration;\r |
115eae65 | 544 | } else if (AsciiStrCmp (Measurement.Token, ALit_BDS) == 0) {\r |
47d20b54 | 545 | BdsTime = Duration;\r |
d41bc92c | 546 | }\r |
547 | }\r | |
548 | \r | |
549 | Total = 0;\r | |
550 | \r | |
551 | // print SEC phase duration time\r | |
552 | //\r | |
553 | if (SecTime > 0) {\r | |
47d20b54 MK |
554 | ElapsedTime = DurationInMicroSeconds (SecTime); // Calculate elapsed time in microseconds\r |
555 | Total += DivU64x32 (ElapsedTime, 1000); // Accumulate time in milliseconds\r | |
92034c4c | 556 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SEC_PHASE), mDpHiiHandle, ElapsedTime);\r |
d41bc92c | 557 | }\r |
558 | \r | |
559 | // print PEI phase duration time\r | |
560 | //\r | |
561 | if (PeiTime > 0) {\r | |
115eae65 | 562 | ElapsedTime = DivU64x32 (PeiTime, 1000000);\r |
47d20b54 | 563 | Total += ElapsedTime;\r |
92034c4c | 564 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_PEI, ElapsedTime);\r |
d41bc92c | 565 | }\r |
566 | \r | |
567 | // print DXE phase duration time\r | |
568 | //\r | |
569 | if (DxeTime > 0) {\r | |
115eae65 | 570 | ElapsedTime = DivU64x32 (DxeTime, 1000000);\r |
47d20b54 | 571 | Total += ElapsedTime;\r |
92034c4c | 572 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_DXE, ElapsedTime);\r |
d41bc92c | 573 | }\r |
574 | \r | |
575 | // print BDS phase duration time\r | |
576 | //\r | |
577 | if (BdsTime > 0) {\r | |
115eae65 | 578 | ElapsedTime = DivU64x32 (BdsTime, 1000000);\r |
47d20b54 | 579 | Total += ElapsedTime;\r |
92034c4c | 580 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_BDS, ElapsedTime);\r |
d41bc92c | 581 | }\r |
582 | \r | |
583 | if (BdsTimeoutValue > 0) {\r | |
115eae65 | 584 | ElapsedTime = DivU64x32 (BdsTimeoutValue, 1000000);\r |
92034c4c | 585 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_BDSTO), mDpHiiHandle, ALit_BdsTO, ElapsedTime);\r |
d41bc92c | 586 | }\r |
587 | \r | |
92034c4c | 588 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TOTAL_DURATION), mDpHiiHandle, Total);\r |
d41bc92c | 589 | }\r |
590 | \r | |
92034c4c | 591 | /**\r |
d41bc92c | 592 | Gather and print Handle data.\r |
92034c4c | 593 | \r |
d41bc92c | 594 | @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.\r |
92034c4c | 595 | \r |
196ccda0 CS |
596 | @retval EFI_SUCCESS The operation was successful.\r |
597 | @retval EFI_ABORTED The user aborts the operation.\r | |
598 | @return Others from a call to gBS->LocateHandleBuffer().\r | |
d41bc92c | 599 | **/\r |
600 | EFI_STATUS\r | |
47d20b54 MK |
601 | ProcessHandles (\r |
602 | IN BOOLEAN ExcludeFlag\r | |
d41bc92c | 603 | )\r |
604 | {\r | |
47d20b54 MK |
605 | MEASUREMENT_RECORD Measurement;\r |
606 | UINT64 ElapsedTime;\r | |
607 | UINT64 Duration;\r | |
608 | EFI_HANDLE *HandleBuffer;\r | |
609 | EFI_STRING StringPtr;\r | |
610 | UINTN Index;\r | |
611 | UINTN LogEntryKey;\r | |
612 | UINTN Count;\r | |
613 | UINTN HandleCount;\r | |
614 | EFI_STATUS Status;\r | |
615 | EFI_STRING StringPtrUnknown;\r | |
d41bc92c | 616 | \r |
92034c4c | 617 | StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);\r |
47d20b54 MK |
618 | StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_DRIVERS), NULL);\r |
619 | ShellPrintHiiEx (\r | |
620 | -1,\r | |
621 | -1,\r | |
622 | NULL,\r | |
623 | STRING_TOKEN (STR_DP_SECTION_HEADER),\r | |
624 | mDpHiiHandle,\r | |
625 | (StringPtr == NULL) ? StringPtrUnknown : StringPtr\r | |
626 | );\r | |
d41bc92c | 627 | FreePool (StringPtr);\r |
628 | FreePool (StringPtrUnknown);\r | |
629 | \r | |
64c51ed1 | 630 | Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);\r |
d41bc92c | 631 | if (EFI_ERROR (Status)) {\r |
92034c4c | 632 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), mDpHiiHandle, Status);\r |
47d20b54 MK |
633 | } else {\r |
634 | #if DP_DEBUG == 2\r | |
635 | Print (L"There are %,d Handles defined.\n", (Size / sizeof (HandleBuffer[0])));\r | |
636 | #endif\r | |
d41bc92c | 637 | \r |
638 | if (mShowId) {\r | |
92034c4c | 639 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_SECTION2), mDpHiiHandle);\r |
d41bc92c | 640 | } else {\r |
92034c4c | 641 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_SECTION), mDpHiiHandle);\r |
d41bc92c | 642 | }\r |
47d20b54 | 643 | \r |
92034c4c | 644 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);\r |
d41bc92c | 645 | \r |
646 | LogEntryKey = 0;\r | |
47d20b54 | 647 | Count = 0;\r |
115eae65 | 648 | while ((LogEntryKey = GetPerformanceMeasurementRecord (\r |
d41bc92c | 649 | LogEntryKey,\r |
650 | &Measurement.Handle,\r | |
651 | &Measurement.Token,\r | |
652 | &Measurement.Module,\r | |
653 | &Measurement.StartTimeStamp,\r | |
654 | &Measurement.EndTimeStamp,\r | |
47d20b54 MK |
655 | &Measurement.Identifier\r |
656 | )) != 0)\r | |
d41bc92c | 657 | {\r |
658 | Count++;\r | |
47d20b54 MK |
659 | Duration = GetDuration (&Measurement);\r |
660 | ElapsedTime = DurationInMicroSeconds (Duration);\r | |
d41bc92c | 661 | if ((ElapsedTime < mInterestThreshold) ||\r |
662 | (Measurement.EndTimeStamp == 0) ||\r | |
f45dd2dd | 663 | (!IsCorePerf (&Measurement)) ||\r |
47d20b54 MK |
664 | ((ExcludeFlag) && (GetCumulativeItem (&Measurement) >= 0))\r |
665 | ) // Ignore "uninteresting" or excluded records\r | |
666 | {\r | |
d41bc92c | 667 | continue;\r |
668 | }\r | |
47d20b54 | 669 | \r |
d41bc92c | 670 | mGaugeString[0] = 0; // Empty driver name by default\r |
cb4669e0 | 671 | AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));\r |
d41bc92c | 672 | // See if the Handle is in the HandleBuffer\r |
64c51ed1 | 673 | for (Index = 0; Index < HandleCount; Index++) {\r |
d41bc92c | 674 | if (Measurement.Handle == HandleBuffer[Index]) {\r |
2c55a81a | 675 | DpGetNameFromHandle (HandleBuffer[Index]); // Name is put into mGaugeString\r |
d41bc92c | 676 | break;\r |
677 | }\r | |
678 | }\r | |
47d20b54 | 679 | \r |
d41bc92c | 680 | // Ensure that the argument strings are not too long.\r |
681 | mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r | |
47d20b54 | 682 | mUnicodeToken[11] = 0;\r |
d41bc92c | 683 | if (mGaugeString[0] != 0) {\r |
684 | // Display the record if it has a valid handle.\r | |
685 | if (mShowId) {\r | |
47d20b54 MK |
686 | ShellPrintHiiEx (\r |
687 | -1,\r | |
688 | -1,\r | |
689 | NULL,\r | |
690 | STRING_TOKEN (STR_DP_HANDLE_VARS2),\r | |
691 | mDpHiiHandle,\r | |
d41bc92c | 692 | Count, // 1 based, Which measurement record is being printed\r |
693 | Index + 1, // 1 based, Which handle is being printed\r | |
694 | mGaugeString,\r | |
695 | mUnicodeToken,\r | |
696 | ElapsedTime,\r | |
697 | Measurement.Identifier\r | |
47d20b54 | 698 | );\r |
d41bc92c | 699 | } else {\r |
47d20b54 MK |
700 | ShellPrintHiiEx (\r |
701 | -1,\r | |
702 | -1,\r | |
703 | NULL,\r | |
704 | STRING_TOKEN (STR_DP_HANDLE_VARS),\r | |
705 | mDpHiiHandle,\r | |
d41bc92c | 706 | Count, // 1 based, Which measurement record is being printed\r |
707 | Index + 1, // 1 based, Which handle is being printed\r | |
708 | mGaugeString,\r | |
709 | mUnicodeToken,\r | |
710 | ElapsedTime\r | |
47d20b54 | 711 | );\r |
d41bc92c | 712 | }\r |
713 | }\r | |
47d20b54 | 714 | \r |
196ccda0 CS |
715 | if (ShellGetExecutionBreakFlag ()) {\r |
716 | Status = EFI_ABORTED;\r | |
717 | break;\r | |
718 | }\r | |
d41bc92c | 719 | }\r |
720 | }\r | |
47d20b54 | 721 | \r |
64c51ed1 | 722 | if (HandleBuffer != NULL) {\r |
d41bc92c | 723 | FreePool (HandleBuffer);\r |
724 | }\r | |
47d20b54 | 725 | \r |
d41bc92c | 726 | return Status;\r |
727 | }\r | |
728 | \r | |
92034c4c | 729 | /**\r |
d41bc92c | 730 | Gather and print PEIM data.\r |
92034c4c | 731 | \r |
d41bc92c | 732 | Only prints complete PEIM records\r |
92034c4c | 733 | \r |
196ccda0 CS |
734 | @retval EFI_SUCCESS The operation was successful.\r |
735 | @retval EFI_ABORTED The user aborts the operation.\r | |
d41bc92c | 736 | **/\r |
196ccda0 | 737 | EFI_STATUS\r |
47d20b54 | 738 | ProcessPeims (\r |
d41bc92c | 739 | VOID\r |
47d20b54 | 740 | )\r |
d41bc92c | 741 | {\r |
47d20b54 MK |
742 | MEASUREMENT_RECORD Measurement;\r |
743 | UINT64 Duration;\r | |
744 | UINT64 ElapsedTime;\r | |
745 | EFI_STRING StringPtr;\r | |
746 | UINTN LogEntryKey;\r | |
747 | UINTN TIndex;\r | |
748 | EFI_STRING StringPtrUnknown;\r | |
749 | EFI_STATUS Status;\r | |
196ccda0 CS |
750 | \r |
751 | Status = EFI_SUCCESS;\r | |
d41bc92c | 752 | \r |
92034c4c | 753 | StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);\r |
47d20b54 MK |
754 | StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PEIMS), NULL);\r |
755 | ShellPrintHiiEx (\r | |
756 | -1,\r | |
757 | -1,\r | |
758 | NULL,\r | |
759 | STRING_TOKEN (STR_DP_SECTION_HEADER),\r | |
760 | mDpHiiHandle,\r | |
761 | (StringPtr == NULL) ? StringPtrUnknown : StringPtr\r | |
762 | );\r | |
d41bc92c | 763 | FreePool (StringPtr);\r |
764 | FreePool (StringPtrUnknown);\r | |
765 | \r | |
766 | if (mShowId) {\r | |
92034c4c | 767 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_SECTION2), mDpHiiHandle);\r |
d41bc92c | 768 | } else {\r |
92034c4c | 769 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_SECTION), mDpHiiHandle);\r |
d41bc92c | 770 | }\r |
47d20b54 | 771 | \r |
92034c4c | 772 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);\r |
47d20b54 | 773 | TIndex = 0;\r |
d41bc92c | 774 | LogEntryKey = 0;\r |
115eae65 | 775 | while ((LogEntryKey = GetPerformanceMeasurementRecord (\r |
d41bc92c | 776 | LogEntryKey,\r |
777 | &Measurement.Handle,\r | |
778 | &Measurement.Token,\r | |
779 | &Measurement.Module,\r | |
780 | &Measurement.StartTimeStamp,\r | |
781 | &Measurement.EndTimeStamp,\r | |
47d20b54 MK |
782 | &Measurement.Identifier\r |
783 | )) != 0)\r | |
d41bc92c | 784 | {\r |
785 | TIndex++;\r | |
786 | if ((Measurement.EndTimeStamp == 0) ||\r | |
115eae65 | 787 | (AsciiStrCmp (Measurement.Token, ALit_PEIM) != 0)\r |
47d20b54 MK |
788 | )\r |
789 | {\r | |
d41bc92c | 790 | continue;\r |
791 | }\r | |
792 | \r | |
47d20b54 MK |
793 | Duration = GetDuration (&Measurement);\r |
794 | ElapsedTime = DurationInMicroSeconds (Duration); // Calculate elapsed time in microseconds\r | |
d41bc92c | 795 | if (ElapsedTime >= mInterestThreshold) {\r |
796 | // PEIM FILE Handle is the start address of its FFS file that contains its file guid.\r | |
797 | if (mShowId) {\r | |
47d20b54 MK |
798 | ShellPrintHiiEx (\r |
799 | -1,\r | |
800 | -1,\r | |
801 | NULL,\r | |
802 | STRING_TOKEN (STR_DP_PEIM_VARS2),\r | |
803 | mDpHiiHandle,\r | |
804 | TIndex, // 1 based, Which measurement record is being printed\r | |
805 | Measurement.Handle, // file guid\r | |
806 | ElapsedTime,\r | |
807 | Measurement.Identifier\r | |
808 | );\r | |
d41bc92c | 809 | } else {\r |
47d20b54 MK |
810 | ShellPrintHiiEx (\r |
811 | -1,\r | |
812 | -1,\r | |
813 | NULL,\r | |
814 | STRING_TOKEN (STR_DP_PEIM_VARS),\r | |
815 | mDpHiiHandle,\r | |
816 | TIndex, // 1 based, Which measurement record is being printed\r | |
817 | Measurement.Handle, // file guid\r | |
818 | ElapsedTime\r | |
819 | );\r | |
d41bc92c | 820 | }\r |
821 | }\r | |
47d20b54 | 822 | \r |
196ccda0 CS |
823 | if (ShellGetExecutionBreakFlag ()) {\r |
824 | Status = EFI_ABORTED;\r | |
825 | break;\r | |
826 | }\r | |
d41bc92c | 827 | }\r |
47d20b54 | 828 | \r |
196ccda0 | 829 | return Status;\r |
d41bc92c | 830 | }\r |
831 | \r | |
92034c4c | 832 | /**\r |
d41bc92c | 833 | Gather and print global data.\r |
92034c4c | 834 | \r |
d41bc92c | 835 | Strips out incomplete or "Execution Phase" records\r |
836 | Only prints records where Handle is NULL\r | |
837 | Increment TIndex for every record, even skipped ones, so that we have an\r | |
838 | indication of every measurement record taken.\r | |
92034c4c | 839 | \r |
196ccda0 CS |
840 | @retval EFI_SUCCESS The operation was successful.\r |
841 | @retval EFI_ABORTED The user aborts the operation.\r | |
d41bc92c | 842 | **/\r |
196ccda0 | 843 | EFI_STATUS\r |
47d20b54 | 844 | ProcessGlobal (\r |
d41bc92c | 845 | VOID\r |
47d20b54 | 846 | )\r |
d41bc92c | 847 | {\r |
47d20b54 MK |
848 | MEASUREMENT_RECORD Measurement;\r |
849 | UINT64 Duration;\r | |
850 | UINT64 ElapsedTime;\r | |
851 | EFI_STRING StringPtr;\r | |
852 | UINTN LogEntryKey;\r | |
853 | UINTN Index; // Index, or number, of the measurement record being processed\r | |
854 | EFI_STRING StringPtrUnknown;\r | |
855 | EFI_STATUS Status;\r | |
196ccda0 CS |
856 | \r |
857 | Status = EFI_SUCCESS;\r | |
d41bc92c | 858 | \r |
92034c4c | 859 | StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);\r |
47d20b54 MK |
860 | StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_GENERAL), NULL);\r |
861 | ShellPrintHiiEx (\r | |
862 | -1,\r | |
863 | -1,\r | |
864 | NULL,\r | |
865 | STRING_TOKEN (STR_DP_SECTION_HEADER),\r | |
866 | mDpHiiHandle,\r | |
867 | (StringPtr == NULL) ? StringPtrUnknown : StringPtr\r | |
868 | );\r | |
d41bc92c | 869 | FreePool (StringPtr);\r |
870 | FreePool (StringPtrUnknown);\r | |
871 | \r | |
872 | if (mShowId) {\r | |
92034c4c | 873 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_SECTION2), mDpHiiHandle);\r |
d41bc92c | 874 | } else {\r |
92034c4c | 875 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_SECTION), mDpHiiHandle);\r |
d41bc92c | 876 | }\r |
47d20b54 | 877 | \r |
92034c4c | 878 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);\r |
d41bc92c | 879 | \r |
47d20b54 | 880 | Index = 1;\r |
d41bc92c | 881 | LogEntryKey = 0;\r |
882 | \r | |
115eae65 | 883 | while ((LogEntryKey = GetPerformanceMeasurementRecord (\r |
d41bc92c | 884 | LogEntryKey,\r |
885 | &Measurement.Handle,\r | |
886 | &Measurement.Token,\r | |
887 | &Measurement.Module,\r | |
888 | &Measurement.StartTimeStamp,\r | |
889 | &Measurement.EndTimeStamp,\r | |
47d20b54 MK |
890 | &Measurement.Identifier\r |
891 | )) != 0)\r | |
d41bc92c | 892 | {\r |
cb4669e0 LE |
893 | AsciiStrToUnicodeStrS (Measurement.Module, mGaugeString, ARRAY_SIZE (mGaugeString));\r |
894 | AsciiStrToUnicodeStrS (Measurement.Token, mUnicodeToken, ARRAY_SIZE (mUnicodeToken));\r | |
47d20b54 | 895 | mGaugeString[25] = 0;\r |
d41bc92c | 896 | mUnicodeToken[31] = 0;\r |
47d20b54 MK |
897 | if ( !(IsPhase (&Measurement) ||\r |
898 | IsCorePerf (&Measurement) ||\r | |
899 | (Measurement.EndTimeStamp == 0)\r | |
900 | ))\r | |
d41bc92c | 901 | {\r |
47d20b54 MK |
902 | Duration = GetDuration (&Measurement);\r |
903 | ElapsedTime = DurationInMicroSeconds (Duration);\r | |
d41bc92c | 904 | if (ElapsedTime >= mInterestThreshold) {\r |
905 | if (mShowId) {\r | |
47d20b54 MK |
906 | ShellPrintHiiEx (\r |
907 | -1,\r | |
908 | -1,\r | |
909 | NULL,\r | |
910 | STRING_TOKEN (STR_DP_GLOBAL_VARS2),\r | |
911 | mDpHiiHandle,\r | |
d41bc92c | 912 | Index,\r |
913 | mGaugeString,\r | |
914 | mUnicodeToken,\r | |
915 | ElapsedTime,\r | |
916 | Measurement.Identifier\r | |
917 | );\r | |
918 | } else {\r | |
47d20b54 MK |
919 | ShellPrintHiiEx (\r |
920 | -1,\r | |
921 | -1,\r | |
922 | NULL,\r | |
923 | STRING_TOKEN (STR_DP_GLOBAL_VARS),\r | |
924 | mDpHiiHandle,\r | |
d41bc92c | 925 | Index,\r |
926 | mGaugeString,\r | |
927 | mUnicodeToken,\r | |
928 | ElapsedTime\r | |
929 | );\r | |
930 | }\r | |
931 | }\r | |
932 | }\r | |
47d20b54 | 933 | \r |
196ccda0 CS |
934 | if (ShellGetExecutionBreakFlag ()) {\r |
935 | Status = EFI_ABORTED;\r | |
936 | break;\r | |
937 | }\r | |
47d20b54 | 938 | \r |
d41bc92c | 939 | Index++;\r |
940 | }\r | |
47d20b54 | 941 | \r |
d0a23f9f | 942 | return Status;\r |
d41bc92c | 943 | }\r |
944 | \r | |
92034c4c | 945 | /**\r |
d41bc92c | 946 | Gather and print cumulative data.\r |
92034c4c | 947 | \r |
d41bc92c | 948 | Traverse the measurement records and:<BR>\r |
949 | For each record with a Token listed in the CumData array:<BR>\r | |
950 | - Update the instance count and the total, minimum, and maximum durations.\r | |
951 | Finally, print the gathered cumulative statistics.\r | |
a06795c6 | 952 | \r |
f16bd394 | 953 | @param[in] CustomCumulativeData A pointer to the custom cumulative data.\r |
a06795c6 | 954 | \r |
d41bc92c | 955 | **/\r |
956 | VOID\r | |
47d20b54 MK |
957 | ProcessCumulative (\r |
958 | IN PERF_CUM_DATA *CustomCumulativeData OPTIONAL\r | |
a06795c6 | 959 | )\r |
d41bc92c | 960 | {\r |
47d20b54 MK |
961 | UINT64 AvgDur; // the computed average duration\r |
962 | UINT64 Dur;\r | |
963 | UINT64 MinDur;\r | |
964 | UINT64 MaxDur;\r | |
965 | EFI_STRING StringPtr;\r | |
966 | UINTN TIndex;\r | |
967 | EFI_STRING StringPtrUnknown;\r | |
d41bc92c | 968 | \r |
92034c4c | 969 | StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);\r |
47d20b54 MK |
970 | StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_CUMULATIVE), NULL);\r |
971 | ShellPrintHiiEx (\r | |
972 | -1,\r | |
973 | -1,\r | |
974 | NULL,\r | |
975 | STRING_TOKEN (STR_DP_SECTION_HEADER),\r | |
976 | mDpHiiHandle,\r | |
977 | (StringPtr == NULL) ? StringPtrUnknown : StringPtr\r | |
978 | );\r | |
d41bc92c | 979 | FreePool (StringPtr);\r |
980 | FreePool (StringPtrUnknown);\r | |
981 | \r | |
92034c4c RN |
982 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_1), mDpHiiHandle);\r |
983 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_2), mDpHiiHandle);\r | |
984 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);\r | |
d41bc92c | 985 | \r |
986 | for ( TIndex = 0; TIndex < NumCum; ++TIndex) {\r | |
987 | if (CumData[TIndex].Count != 0) {\r | |
988 | AvgDur = DivU64x32 (CumData[TIndex].Duration, CumData[TIndex].Count);\r | |
47d20b54 MK |
989 | AvgDur = DurationInMicroSeconds (AvgDur);\r |
990 | Dur = DurationInMicroSeconds (CumData[TIndex].Duration);\r | |
991 | MaxDur = DurationInMicroSeconds (CumData[TIndex].MaxDur);\r | |
992 | MinDur = DurationInMicroSeconds (CumData[TIndex].MinDur);\r | |
993 | \r | |
994 | ShellPrintHiiEx (\r | |
995 | -1,\r | |
996 | -1,\r | |
997 | NULL,\r | |
998 | STRING_TOKEN (STR_DP_CUMULATIVE_STATS),\r | |
999 | mDpHiiHandle,\r | |
1000 | CumData[TIndex].Name,\r | |
1001 | CumData[TIndex].Count,\r | |
1002 | Dur,\r | |
1003 | AvgDur,\r | |
1004 | MinDur,\r | |
1005 | MaxDur\r | |
1006 | );\r | |
d41bc92c | 1007 | }\r |
1008 | }\r | |
a06795c6 CS |
1009 | \r |
1010 | //\r | |
1011 | // Print the custom cumulative data.\r | |
1012 | //\r | |
1013 | if (CustomCumulativeData != NULL) {\r | |
1014 | if (CustomCumulativeData->Count != 0) {\r | |
1015 | AvgDur = DivU64x32 (CustomCumulativeData->Duration, CustomCumulativeData->Count);\r | |
1016 | AvgDur = DurationInMicroSeconds (AvgDur);\r | |
1017 | Dur = DurationInMicroSeconds (CustomCumulativeData->Duration);\r | |
1018 | MaxDur = DurationInMicroSeconds (CustomCumulativeData->MaxDur);\r | |
1019 | MinDur = DurationInMicroSeconds (CustomCumulativeData->MinDur);\r | |
1020 | } else {\r | |
1021 | AvgDur = 0;\r | |
1022 | Dur = 0;\r | |
1023 | MaxDur = 0;\r | |
1024 | MinDur = 0;\r | |
1025 | }\r | |
47d20b54 MK |
1026 | \r |
1027 | ShellPrintHiiEx (\r | |
1028 | -1,\r | |
1029 | -1,\r | |
1030 | NULL,\r | |
1031 | STRING_TOKEN (STR_DP_CUMULATIVE_STATS),\r | |
1032 | mDpHiiHandle,\r | |
1033 | CustomCumulativeData->Name,\r | |
1034 | CustomCumulativeData->Count,\r | |
1035 | Dur,\r | |
1036 | AvgDur,\r | |
1037 | MinDur,\r | |
1038 | MaxDur\r | |
1039 | );\r | |
a06795c6 | 1040 | }\r |
d41bc92c | 1041 | }\r |