Commit | Line | Data |
---|---|---|
c06ad33e | 1 | /** @file\r |
2 | * Shell application for Displaying Performance Metrics.\r | |
3 | *\r | |
4 | * The Dp application reads performance data and presents it in several\r | |
5 | * different formats depending upon the needs of the user. Both\r | |
6 | * Trace and Measured Profiling information is processed and presented.\r | |
7 | *\r | |
8 | * Dp uses the "PerformanceLib" to read the measurement records.\r | |
9 | * The "TimerLib" provides information about the timer, such as frequency,\r | |
10 | * beginning, and ending counter values.\r | |
11 | * Measurement records contain identifying information (Handle, Token, Module)\r | |
12 | * and start and end time values.\r | |
13 | * Dp uses this information to group records in different ways. It also uses\r | |
14 | * timer information to calculate elapsed time for each measurement.\r | |
15 | *\r | |
92ea1df8 | 16 | * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r |
c06ad33e | 17 | * This program and the accompanying materials\r |
18 | * are licensed and made available under the terms and conditions of the BSD License\r | |
19 | * which accompanies this distribution. The full text of the license may be found at\r | |
20 | * http://opensource.org/licenses/bsd-license.php\r | |
21 | *\r | |
22 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
23 | * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
24 | **/\r | |
25 | \r | |
26 | #include <Library/UefiApplicationEntryPoint.h>\r | |
27 | #include <Library/ShellLib.h>\r | |
28 | #include <Library/BaseLib.h>\r | |
29 | #include <Library/MemoryAllocationLib.h>\r | |
30 | #include <Library/DebugLib.h>\r | |
31 | #include <Library/TimerLib.h>\r | |
32 | #include <Library/UefiLib.h>\r | |
33 | #include <Library/HiiLib.h>\r | |
34 | #include <Library/PcdLib.h>\r | |
35 | \r | |
36 | #include <Guid/Performance.h>\r | |
37 | \r | |
38 | #include <PerformanceTokens.h>\r | |
39 | #include "Dp.h"\r | |
40 | #include "Literals.h"\r | |
41 | #include "DpInternal.h"\r | |
42 | \r | |
43 | //\r | |
44 | /// Module-Global Variables\r | |
9dd74618 | 45 | ///@{\r |
c06ad33e | 46 | EFI_HII_HANDLE gHiiHandle;\r |
47 | CHAR16 *mPrintTokenBuffer = NULL;\r | |
48 | CHAR16 mGaugeString[DXE_PERFORMANCE_STRING_SIZE];\r | |
49 | CHAR16 mUnicodeToken[PERF_TOKEN_LENGTH + 1];\r | |
50 | UINT64 mInterestThreshold;\r | |
51 | \r | |
52 | PERF_SUMMARY_DATA SummaryData = { 0 }; ///< Create the SummaryData structure and init. to ZERO.\r | |
53 | \r | |
54 | /// Timer Specific Information.\r | |
55 | TIMER_INFO TimerInfo;\r | |
56 | \r | |
57 | /// Items for which to gather cumulative statistics.\r | |
58 | PERF_CUM_DATA CumData[] = {\r | |
59 | PERF_INIT_CUM_DATA (LOAD_IMAGE_TOK),\r | |
60 | PERF_INIT_CUM_DATA (START_IMAGE_TOK),\r | |
61 | PERF_INIT_CUM_DATA (DRIVERBINDING_START_TOK),\r | |
62 | PERF_INIT_CUM_DATA (DRIVERBINDING_SUPPORT_TOK)\r | |
63 | };\r | |
64 | \r | |
65 | /// Number of items for which we are gathering cumulative statistics.\r | |
66 | UINT32 const NumCum = sizeof(CumData) / sizeof(PERF_CUM_DATA);\r | |
67 | \r | |
68 | SHELL_PARAM_ITEM DpParamList[] = {\r | |
69 | {STR_DP_OPTION_QH, TypeFlag}, // -? Help\r | |
70 | {STR_DP_OPTION_LH, TypeFlag}, // -h Help\r | |
71 | {STR_DP_OPTION_UH, TypeFlag}, // -H Help\r | |
72 | {STR_DP_OPTION_LV, TypeFlag}, // -v Verbose Mode\r | |
73 | {STR_DP_OPTION_UA, TypeFlag}, // -A All, Cooked\r | |
74 | {STR_DP_OPTION_UR, TypeFlag}, // -R RAW All\r | |
75 | {STR_DP_OPTION_LS, TypeFlag}, // -s Summary\r | |
76 | #if PROFILING_IMPLEMENTED\r | |
77 | {STR_DP_OPTION_UP, TypeFlag}, // -P Dump Profile Data\r | |
78 | {STR_DP_OPTION_UT, TypeFlag}, // -T Dump Trace Data\r | |
79 | #endif\r | |
80 | {STR_DP_OPTION_LX, TypeFlag}, // -x eXclude Cumulative Items\r | |
81 | {STR_DP_OPTION_LN, TypeValue}, // -n # Number of records to display for A and R\r | |
82 | {STR_DP_OPTION_LT, TypeValue}, // -t # Threshold of interest\r | |
83 | {NULL, TypeMax}\r | |
84 | };\r | |
85 | \r | |
9dd74618 | 86 | ///@}\r |
c06ad33e | 87 | \r |
9dd74618 ED |
88 | /**\r |
89 | Display Usage and Help information.\r | |
90 | **/\r | |
c06ad33e | 91 | VOID\r |
92 | ShowHelp( void )\r | |
93 | {\r | |
94 | PrintToken (STRING_TOKEN (STR_DP_HELP_HEAD));\r | |
95 | #if PROFILING_IMPLEMENTED\r | |
96 | PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS));\r | |
97 | #else\r | |
98 | PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS_2));\r | |
99 | #endif // PROFILING_IMPLEMENTED\r | |
100 | PrintToken (STRING_TOKEN (STR_DP_HELP_PAGINATE));\r | |
101 | PrintToken (STRING_TOKEN (STR_DP_HELP_VERBOSE));\r | |
102 | PrintToken (STRING_TOKEN (STR_DP_HELP_EXCLUDE));\r | |
103 | PrintToken (STRING_TOKEN (STR_DP_HELP_STAT));\r | |
104 | PrintToken (STRING_TOKEN (STR_DP_HELP_ALL));\r | |
105 | PrintToken (STRING_TOKEN (STR_DP_HELP_RAW));\r | |
106 | #if PROFILING_IMPLEMENTED\r | |
107 | PrintToken (STRING_TOKEN (STR_DP_HELP_TRACE));\r | |
108 | PrintToken (STRING_TOKEN (STR_DP_HELP_PROFILE));\r | |
109 | #endif // PROFILING_IMPLEMENTED\r | |
110 | PrintToken (STRING_TOKEN (STR_DP_HELP_THRESHOLD));\r | |
111 | PrintToken (STRING_TOKEN (STR_DP_HELP_COUNT));\r | |
112 | PrintToken (STRING_TOKEN (STR_DP_HELP_HELP));\r | |
113 | Print(L"\n");\r | |
114 | }\r | |
115 | \r | |
9dd74618 ED |
116 | /**\r |
117 | Display the trailing Verbose information.\r | |
118 | **/\r | |
c06ad33e | 119 | VOID\r |
120 | DumpStatistics( void )\r | |
121 | {\r | |
122 | EFI_STRING StringPtr;\r | |
123 | \r | |
124 | StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_STATISTICS), NULL);\r | |
125 | PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r | |
126 | (StringPtr == NULL) ? ALit_UNKNOWN: StringPtr);\r | |
127 | \r | |
128 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMTRACE), SummaryData.NumTrace);\r | |
129 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE), SummaryData.NumIncomplete);\r | |
130 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPHASES), SummaryData.NumSummary);\r | |
131 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMHANDLES), SummaryData.NumHandles, SummaryData.NumTrace - SummaryData.NumHandles);\r | |
132 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPEIMS), SummaryData.NumPEIMs);\r | |
133 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMGLOBALS), SummaryData.NumGlobal);\r | |
134 | #if PROFILING_IMPLEMENTED\r | |
135 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPROFILE), SummaryData.NumProfile);\r | |
136 | #endif // PROFILING_IMPLEMENTED\r | |
137 | }\r | |
138 | \r | |
9dd74618 ED |
139 | /** \r |
140 | Dump performance data.\r | |
141 | \r | |
142 | @param[in] ImageHandle The image handle.\r | |
143 | @param[in] SystemTable The system table.\r | |
144 | \r | |
145 | @retval EFI_SUCCESS Command completed successfully.\r | |
146 | @retval EFI_INVALID_PARAMETER Command usage error.\r | |
147 | @retval value Unknown error.\r | |
148 | \r | |
c06ad33e | 149 | **/\r |
150 | EFI_STATUS\r | |
151 | EFIAPI\r | |
152 | InitializeDp (\r | |
153 | IN EFI_HANDLE ImageHandle,\r | |
154 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
155 | )\r | |
156 | {\r | |
157 | UINT64 Freq;\r | |
158 | UINT64 Ticker;\r | |
159 | \r | |
160 | LIST_ENTRY *ParamPackage;\r | |
161 | CONST CHAR16 *CmdLineArg;\r | |
162 | EFI_STRING StringPtr;\r | |
163 | UINTN Number2Display;\r | |
164 | \r | |
165 | EFI_STATUS Status;\r | |
9dd74618 ED |
166 | BOOLEAN SummaryMode;\r |
167 | BOOLEAN VerboseMode;\r | |
168 | BOOLEAN AllMode;\r | |
169 | BOOLEAN RawMode;\r | |
170 | BOOLEAN TraceMode;\r | |
171 | BOOLEAN ProfileMode;\r | |
172 | BOOLEAN ExcludeMode;\r | |
173 | \r | |
174 | SummaryMode = FALSE;\r | |
175 | VerboseMode = FALSE;\r | |
176 | AllMode = FALSE;\r | |
177 | RawMode = FALSE;\r | |
178 | TraceMode = FALSE;\r | |
179 | ProfileMode = FALSE;\r | |
180 | ExcludeMode = FALSE;\r | |
c06ad33e | 181 | // Get DP's entry time as soon as possible.\r |
182 | // This is used as the Shell-Phase end time.\r | |
183 | //\r | |
184 | Ticker = GetPerformanceCounter ();\r | |
185 | \r | |
186 | // Register our string package with HII and return the handle to it.\r | |
187 | //\r | |
188 | gHiiHandle = HiiAddPackages (&gEfiCallerIdGuid, ImageHandle, DPStrings, NULL);\r | |
189 | ASSERT (gHiiHandle != NULL);\r | |
190 | \r | |
191 | /****************************************************************************\r | |
192 | **** Process Command Line arguments ****\r | |
193 | ****************************************************************************/\r | |
194 | Status = ShellCommandLineParse (DpParamList, &ParamPackage, NULL, TRUE);\r | |
195 | \r | |
196 | if (EFI_ERROR(Status)) {\r | |
197 | PrintToken (STRING_TOKEN (STR_DP_INVALID_ARG));\r | |
198 | ShowHelp();\r | |
199 | }\r | |
200 | else {\r | |
201 | if (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_QH) ||\r | |
202 | ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_LH) ||\r | |
203 | ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UH))\r | |
204 | {\r | |
205 | ShowHelp();\r | |
206 | }\r | |
207 | else {\r | |
208 | // Boolean Options\r | |
209 | VerboseMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_LV));\r | |
210 | SummaryMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_US) ||\r | |
211 | ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_LS));\r | |
212 | AllMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UA));\r | |
213 | RawMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UR));\r | |
214 | #if PROFILING_IMPLEMENTED\r | |
215 | TraceMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UT));\r | |
216 | ProfileMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UP));\r | |
217 | #endif // PROFILING_IMPLEMENTED\r | |
218 | ExcludeMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_LX));\r | |
219 | \r | |
220 | // Options with Values\r | |
221 | CmdLineArg = ( ShellCommandLineGetValue (ParamPackage, STR_DP_OPTION_LN));\r | |
222 | if (CmdLineArg == NULL) {\r | |
223 | Number2Display = DEFAULT_DISPLAYCOUNT;\r | |
224 | }\r | |
225 | else {\r | |
226 | Number2Display = StrDecimalToUintn(CmdLineArg);\r | |
227 | if (Number2Display == 0) {\r | |
228 | Number2Display = MAXIMUM_DISPLAYCOUNT;\r | |
229 | }\r | |
230 | }\r | |
231 | CmdLineArg = (ShellCommandLineGetValue (ParamPackage, STR_DP_OPTION_LT));\r | |
232 | if (CmdLineArg == NULL) {\r | |
233 | mInterestThreshold = DEFAULT_THRESHOLD; // 1ms := 1,000 us\r | |
234 | }\r | |
235 | else {\r | |
236 | mInterestThreshold = StrDecimalToUint64(CmdLineArg);\r | |
237 | }\r | |
238 | // Handle Flag combinations and default behaviors\r | |
239 | // If both TraceMode and ProfileMode are FALSE, set them both to TRUE\r | |
240 | if ((! TraceMode) && (! ProfileMode)) {\r | |
241 | TraceMode = TRUE;\r | |
242 | #if PROFILING_IMPLEMENTED\r | |
243 | ProfileMode = TRUE;\r | |
244 | #endif // PROFILING_IMPLEMENTED\r | |
245 | }\r | |
246 | \r | |
247 | /****************************************************************************\r | |
248 | **** Timer specific processing ****\r | |
249 | ****************************************************************************/\r | |
250 | // Get the Performance counter characteristics:\r | |
251 | // Freq = Frequency in Hz\r | |
252 | // StartCount = Value loaded into the counter when it starts counting\r | |
253 | // EndCount = Value counter counts to before it needs to be reset\r | |
254 | //\r | |
255 | Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount);\r | |
256 | \r | |
257 | // Convert the Frequency from Hz to KHz\r | |
258 | TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000);\r | |
259 | \r | |
260 | // Determine in which direction the performance counter counts.\r | |
261 | TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount);\r | |
262 | \r | |
263 | /****************************************************************************\r | |
264 | **** Print heading ****\r | |
265 | ****************************************************************************/\r | |
266 | // print DP's build version\r | |
267 | PrintToken (STRING_TOKEN (STR_DP_BUILD_REVISION), DP_MAJOR_VERSION, DP_MINOR_VERSION);\r | |
268 | \r | |
269 | // print performance timer characteristics\r | |
270 | PrintToken (STRING_TOKEN (STR_DP_KHZ), TimerInfo.Frequency); // Print Timer frequency in KHz\r | |
271 | \r | |
272 | if ((VerboseMode) &&\r | |
273 | (! RawMode)\r | |
274 | ) {\r | |
275 | StringPtr = HiiGetString (gHiiHandle,\r | |
276 | TimerInfo.CountUp ? STRING_TOKEN (STR_DP_UP) : STRING_TOKEN (STR_DP_DOWN),\r | |
277 | NULL);\r | |
278 | ASSERT (StringPtr != NULL);\r | |
279 | PrintToken (STRING_TOKEN (STR_DP_TIMER_PROPERTIES), // Print Timer count range and direction\r | |
280 | StringPtr,\r | |
281 | TimerInfo.StartCount,\r | |
282 | TimerInfo.EndCount\r | |
283 | );\r | |
284 | PrintToken (STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), mInterestThreshold);\r | |
285 | }\r | |
286 | \r | |
287 | /* **************************************************************************\r | |
288 | **** Print Sections based on command line options\r | |
289 | ****\r | |
290 | **** Option modes have the following priority:\r | |
291 | **** v Verbose -- Valid in combination with any other options\r | |
292 | **** t Threshold -- Modifies All, Raw, and Cooked output\r | |
293 | **** Default is 0 for All and Raw mode\r | |
294 | **** Default is DEFAULT_THRESHOLD for "Cooked" mode\r | |
295 | **** n Number2Display Used by All and Raw mode. Otherwise ignored.\r | |
296 | **** A All -- R and S options are ignored\r | |
297 | **** R Raw -- S option is ignored\r | |
298 | **** s Summary -- Modifies "Cooked" output only\r | |
299 | **** Cooked (Default)\r | |
300 | ****\r | |
301 | **** The All, Raw, and Cooked modes are modified by the Trace and Profile\r | |
302 | **** options.\r | |
303 | **** !T && !P := (0) Default, Both are displayed\r | |
304 | **** T && !P := (1) Only Trace records are displayed\r | |
305 | **** !T && P := (2) Only Profile records are displayed\r | |
306 | **** T && P := (3) Same as Default, both are displayed\r | |
307 | ****************************************************************************/\r | |
308 | GatherStatistics();\r | |
309 | if (AllMode) {\r | |
310 | if (TraceMode) {\r | |
311 | DumpAllTrace( Number2Display, ExcludeMode);\r | |
312 | }\r | |
313 | if (ProfileMode) {\r | |
314 | DumpAllProfile( Number2Display, ExcludeMode);\r | |
315 | }\r | |
316 | }\r | |
317 | else if (RawMode) {\r | |
318 | if (TraceMode) {\r | |
319 | DumpRawTrace( Number2Display, ExcludeMode);\r | |
320 | }\r | |
321 | if (ProfileMode) {\r | |
322 | DumpRawProfile( Number2Display, ExcludeMode);\r | |
323 | }\r | |
324 | }\r | |
325 | else {\r | |
326 | //------------- Begin Cooked Mode Processing\r | |
327 | if (TraceMode) {\r | |
328 | ProcessPhases ( Ticker );\r | |
329 | if ( ! SummaryMode) {\r | |
330 | Status = ProcessHandles ( ExcludeMode);\r | |
331 | if ( ! EFI_ERROR( Status)) {\r | |
332 | ProcessPeims ( );\r | |
333 | ProcessGlobal ( );\r | |
334 | ProcessCumulative ();\r | |
335 | }\r | |
336 | }\r | |
337 | }\r | |
338 | if (ProfileMode) {\r | |
339 | DumpAllProfile( Number2Display, ExcludeMode);\r | |
340 | }\r | |
341 | } //------------- End of Cooked Mode Processing\r | |
342 | if ( VerboseMode || SummaryMode) {\r | |
343 | DumpStatistics();\r | |
344 | }\r | |
345 | }\r | |
346 | }\r | |
347 | (void) FreePool (mPrintTokenBuffer);\r | |
348 | HiiRemovePackages (gHiiHandle);\r | |
349 | return Status;\r | |
350 | }\r |