]>
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 | |
45 | /// @{\r | |
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 | |
86 | /// @}\r | |
87 | \r | |
88 | /// Display Usage and Help information.\r | |
89 | VOID\r | |
90 | ShowHelp( void )\r | |
91 | {\r | |
92 | PrintToken (STRING_TOKEN (STR_DP_HELP_HEAD));\r | |
93 | #if PROFILING_IMPLEMENTED\r | |
94 | PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS));\r | |
95 | #else\r | |
96 | PrintToken (STRING_TOKEN (STR_DP_HELP_FLAGS_2));\r | |
97 | #endif // PROFILING_IMPLEMENTED\r | |
98 | PrintToken (STRING_TOKEN (STR_DP_HELP_PAGINATE));\r | |
99 | PrintToken (STRING_TOKEN (STR_DP_HELP_VERBOSE));\r | |
100 | PrintToken (STRING_TOKEN (STR_DP_HELP_EXCLUDE));\r | |
101 | PrintToken (STRING_TOKEN (STR_DP_HELP_STAT));\r | |
102 | PrintToken (STRING_TOKEN (STR_DP_HELP_ALL));\r | |
103 | PrintToken (STRING_TOKEN (STR_DP_HELP_RAW));\r | |
104 | #if PROFILING_IMPLEMENTED\r | |
105 | PrintToken (STRING_TOKEN (STR_DP_HELP_TRACE));\r | |
106 | PrintToken (STRING_TOKEN (STR_DP_HELP_PROFILE));\r | |
107 | #endif // PROFILING_IMPLEMENTED\r | |
108 | PrintToken (STRING_TOKEN (STR_DP_HELP_THRESHOLD));\r | |
109 | PrintToken (STRING_TOKEN (STR_DP_HELP_COUNT));\r | |
110 | PrintToken (STRING_TOKEN (STR_DP_HELP_HELP));\r | |
111 | Print(L"\n");\r | |
112 | }\r | |
113 | \r | |
114 | /// Display the trailing Verbose information.\r | |
115 | VOID\r | |
116 | DumpStatistics( void )\r | |
117 | {\r | |
118 | EFI_STRING StringPtr;\r | |
119 | \r | |
120 | StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_SECTION_STATISTICS), NULL);\r | |
121 | PrintToken( STRING_TOKEN (STR_DP_SECTION_HEADER),\r | |
122 | (StringPtr == NULL) ? ALit_UNKNOWN: StringPtr);\r | |
123 | \r | |
124 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMTRACE), SummaryData.NumTrace);\r | |
125 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE), SummaryData.NumIncomplete);\r | |
126 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPHASES), SummaryData.NumSummary);\r | |
127 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMHANDLES), SummaryData.NumHandles, SummaryData.NumTrace - SummaryData.NumHandles);\r | |
128 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPEIMS), SummaryData.NumPEIMs);\r | |
129 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMGLOBALS), SummaryData.NumGlobal);\r | |
130 | #if PROFILING_IMPLEMENTED\r | |
131 | PrintToken( STRING_TOKEN (STR_DP_STATS_NUMPROFILE), SummaryData.NumProfile);\r | |
132 | #endif // PROFILING_IMPLEMENTED\r | |
133 | }\r | |
134 | \r | |
135 | /** Dump performance data.\r | |
136 | *\r | |
137 | * @param[in] ImageHandle The image handle.\r | |
138 | * @param[in] SystemTable The system table.\r | |
139 | *\r | |
140 | * @retval EFI_SUCCESS Command completed successfully.\r | |
141 | * @retval EFI_INVALID_PARAMETER Command usage error.\r | |
142 | * @retval value Unknown error.\r | |
143 | *\r | |
144 | **/\r | |
145 | EFI_STATUS\r | |
146 | EFIAPI\r | |
147 | InitializeDp (\r | |
148 | IN EFI_HANDLE ImageHandle,\r | |
149 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
150 | )\r | |
151 | {\r | |
152 | UINT64 Freq;\r | |
153 | UINT64 Ticker;\r | |
154 | \r | |
155 | LIST_ENTRY *ParamPackage;\r | |
156 | CONST CHAR16 *CmdLineArg;\r | |
157 | EFI_STRING StringPtr;\r | |
158 | UINTN Number2Display;\r | |
159 | \r | |
160 | EFI_STATUS Status;\r | |
161 | BOOLEAN SummaryMode = FALSE;\r | |
162 | BOOLEAN VerboseMode = FALSE;\r | |
163 | BOOLEAN AllMode = FALSE;\r | |
164 | BOOLEAN RawMode = FALSE;\r | |
165 | BOOLEAN TraceMode = FALSE;\r | |
166 | BOOLEAN ProfileMode = FALSE;\r | |
167 | BOOLEAN ExcludeMode = FALSE;\r | |
168 | \r | |
169 | \r | |
170 | // Get DP's entry time as soon as possible.\r | |
171 | // This is used as the Shell-Phase end time.\r | |
172 | //\r | |
173 | Ticker = GetPerformanceCounter ();\r | |
174 | \r | |
175 | // Register our string package with HII and return the handle to it.\r | |
176 | //\r | |
177 | gHiiHandle = HiiAddPackages (&gEfiCallerIdGuid, ImageHandle, DPStrings, NULL);\r | |
178 | ASSERT (gHiiHandle != NULL);\r | |
179 | \r | |
180 | /****************************************************************************\r | |
181 | **** Process Command Line arguments ****\r | |
182 | ****************************************************************************/\r | |
183 | Status = ShellCommandLineParse (DpParamList, &ParamPackage, NULL, TRUE);\r | |
184 | \r | |
185 | if (EFI_ERROR(Status)) {\r | |
186 | PrintToken (STRING_TOKEN (STR_DP_INVALID_ARG));\r | |
187 | ShowHelp();\r | |
188 | }\r | |
189 | else {\r | |
190 | if (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_QH) ||\r | |
191 | ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_LH) ||\r | |
192 | ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UH))\r | |
193 | {\r | |
194 | ShowHelp();\r | |
195 | }\r | |
196 | else {\r | |
197 | // Boolean Options\r | |
198 | VerboseMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_LV));\r | |
199 | SummaryMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_US) ||\r | |
200 | ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_LS));\r | |
201 | AllMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UA));\r | |
202 | RawMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UR));\r | |
203 | #if PROFILING_IMPLEMENTED\r | |
204 | TraceMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UT));\r | |
205 | ProfileMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_UP));\r | |
206 | #endif // PROFILING_IMPLEMENTED\r | |
207 | ExcludeMode = (ShellCommandLineGetFlag (ParamPackage, STR_DP_OPTION_LX));\r | |
208 | \r | |
209 | // Options with Values\r | |
210 | CmdLineArg = ( ShellCommandLineGetValue (ParamPackage, STR_DP_OPTION_LN));\r | |
211 | if (CmdLineArg == NULL) {\r | |
212 | Number2Display = DEFAULT_DISPLAYCOUNT;\r | |
213 | }\r | |
214 | else {\r | |
215 | Number2Display = StrDecimalToUintn(CmdLineArg);\r | |
216 | if (Number2Display == 0) {\r | |
217 | Number2Display = MAXIMUM_DISPLAYCOUNT;\r | |
218 | }\r | |
219 | }\r | |
220 | CmdLineArg = (ShellCommandLineGetValue (ParamPackage, STR_DP_OPTION_LT));\r | |
221 | if (CmdLineArg == NULL) {\r | |
222 | mInterestThreshold = DEFAULT_THRESHOLD; // 1ms := 1,000 us\r | |
223 | }\r | |
224 | else {\r | |
225 | mInterestThreshold = StrDecimalToUint64(CmdLineArg);\r | |
226 | }\r | |
227 | // Handle Flag combinations and default behaviors\r | |
228 | // If both TraceMode and ProfileMode are FALSE, set them both to TRUE\r | |
229 | if ((! TraceMode) && (! ProfileMode)) {\r | |
230 | TraceMode = TRUE;\r | |
231 | #if PROFILING_IMPLEMENTED\r | |
232 | ProfileMode = TRUE;\r | |
233 | #endif // PROFILING_IMPLEMENTED\r | |
234 | }\r | |
235 | \r | |
236 | /****************************************************************************\r | |
237 | **** Timer specific processing ****\r | |
238 | ****************************************************************************/\r | |
239 | // Get the Performance counter characteristics:\r | |
240 | // Freq = Frequency in Hz\r | |
241 | // StartCount = Value loaded into the counter when it starts counting\r | |
242 | // EndCount = Value counter counts to before it needs to be reset\r | |
243 | //\r | |
244 | Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount);\r | |
245 | \r | |
246 | // Convert the Frequency from Hz to KHz\r | |
247 | TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000);\r | |
248 | \r | |
249 | // Determine in which direction the performance counter counts.\r | |
250 | TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount);\r | |
251 | \r | |
252 | /****************************************************************************\r | |
253 | **** Print heading ****\r | |
254 | ****************************************************************************/\r | |
255 | // print DP's build version\r | |
256 | PrintToken (STRING_TOKEN (STR_DP_BUILD_REVISION), DP_MAJOR_VERSION, DP_MINOR_VERSION);\r | |
257 | \r | |
258 | // print performance timer characteristics\r | |
259 | PrintToken (STRING_TOKEN (STR_DP_KHZ), TimerInfo.Frequency); // Print Timer frequency in KHz\r | |
260 | \r | |
261 | if ((VerboseMode) &&\r | |
262 | (! RawMode)\r | |
263 | ) {\r | |
264 | StringPtr = HiiGetString (gHiiHandle,\r | |
265 | TimerInfo.CountUp ? STRING_TOKEN (STR_DP_UP) : STRING_TOKEN (STR_DP_DOWN),\r | |
266 | NULL);\r | |
267 | ASSERT (StringPtr != NULL);\r | |
268 | PrintToken (STRING_TOKEN (STR_DP_TIMER_PROPERTIES), // Print Timer count range and direction\r | |
269 | StringPtr,\r | |
270 | TimerInfo.StartCount,\r | |
271 | TimerInfo.EndCount\r | |
272 | );\r | |
273 | PrintToken (STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), mInterestThreshold);\r | |
274 | }\r | |
275 | \r | |
276 | /* **************************************************************************\r | |
277 | **** Print Sections based on command line options\r | |
278 | ****\r | |
279 | **** Option modes have the following priority:\r | |
280 | **** v Verbose -- Valid in combination with any other options\r | |
281 | **** t Threshold -- Modifies All, Raw, and Cooked output\r | |
282 | **** Default is 0 for All and Raw mode\r | |
283 | **** Default is DEFAULT_THRESHOLD for "Cooked" mode\r | |
284 | **** n Number2Display Used by All and Raw mode. Otherwise ignored.\r | |
285 | **** A All -- R and S options are ignored\r | |
286 | **** R Raw -- S option is ignored\r | |
287 | **** s Summary -- Modifies "Cooked" output only\r | |
288 | **** Cooked (Default)\r | |
289 | ****\r | |
290 | **** The All, Raw, and Cooked modes are modified by the Trace and Profile\r | |
291 | **** options.\r | |
292 | **** !T && !P := (0) Default, Both are displayed\r | |
293 | **** T && !P := (1) Only Trace records are displayed\r | |
294 | **** !T && P := (2) Only Profile records are displayed\r | |
295 | **** T && P := (3) Same as Default, both are displayed\r | |
296 | ****************************************************************************/\r | |
297 | GatherStatistics();\r | |
298 | if (AllMode) {\r | |
299 | if (TraceMode) {\r | |
300 | DumpAllTrace( Number2Display, ExcludeMode);\r | |
301 | }\r | |
302 | if (ProfileMode) {\r | |
303 | DumpAllProfile( Number2Display, ExcludeMode);\r | |
304 | }\r | |
305 | }\r | |
306 | else if (RawMode) {\r | |
307 | if (TraceMode) {\r | |
308 | DumpRawTrace( Number2Display, ExcludeMode);\r | |
309 | }\r | |
310 | if (ProfileMode) {\r | |
311 | DumpRawProfile( Number2Display, ExcludeMode);\r | |
312 | }\r | |
313 | }\r | |
314 | else {\r | |
315 | //------------- Begin Cooked Mode Processing\r | |
316 | if (TraceMode) {\r | |
317 | ProcessPhases ( Ticker );\r | |
318 | if ( ! SummaryMode) {\r | |
319 | Status = ProcessHandles ( ExcludeMode);\r | |
320 | if ( ! EFI_ERROR( Status)) {\r | |
321 | ProcessPeims ( );\r | |
322 | ProcessGlobal ( );\r | |
323 | ProcessCumulative ();\r | |
324 | }\r | |
325 | }\r | |
326 | }\r | |
327 | if (ProfileMode) {\r | |
328 | DumpAllProfile( Number2Display, ExcludeMode);\r | |
329 | }\r | |
330 | } //------------- End of Cooked Mode Processing\r | |
331 | if ( VerboseMode || SummaryMode) {\r | |
332 | DumpStatistics();\r | |
333 | }\r | |
334 | }\r | |
335 | }\r | |
336 | (void) FreePool (mPrintTokenBuffer);\r | |
337 | HiiRemovePackages (gHiiHandle);\r | |
338 | return Status;\r | |
339 | }\r |