]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiDpLib/Dp.c
UefiCpuPkg: PiSmmCpuDxeSmm: Remove Framework compatibility
[mirror_edk2.git] / ShellPkg / Library / UefiDpLib / Dp.c
CommitLineData
d41bc92c 1/** @file\r
2 Shell command for Displaying Performance Metrics.\r
3\r
4 The Dp command 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
16 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.\r
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 "UefiDpLib.h"\r
27#include <Guid/GlobalVariable.h>\r
28#include <Library/PrintLib.h>\r
29#include <Library/HandleParsingLib.h>\r
30#include <Library/DevicePathLib.h>\r
31\r
32#include <Library/ShellLib.h>\r
33#include <Library/BaseLib.h>\r
34#include <Library/MemoryAllocationLib.h>\r
35#include <Library/DebugLib.h>\r
36#include <Library/TimerLib.h>\r
37#include <Library/UefiLib.h>\r
38\r
39#include <Guid/Performance.h>\r
40\r
dd42277f 41#include "PerformanceTokens.h"\r
d41bc92c 42#include "Dp.h"\r
43#include "Literals.h"\r
44#include "DpInternal.h"\r
45\r
46//\r
47/// Module-Global Variables\r
48///@{\r
49CHAR16 mGaugeString[DP_GAUGE_STRING_LENGTH + 1];\r
50CHAR16 mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE];\r
51UINT64 mInterestThreshold;\r
52BOOLEAN mShowId = FALSE;\r
53\r
54PERF_SUMMARY_DATA SummaryData = { 0 }; ///< Create the SummaryData structure and init. to ZERO.\r
55\r
56/// Timer Specific Information.\r
57TIMER_INFO TimerInfo;\r
58\r
59/// Items for which to gather cumulative statistics.\r
60PERF_CUM_DATA CumData[] = {\r
61 PERF_INIT_CUM_DATA (LOAD_IMAGE_TOK),\r
62 PERF_INIT_CUM_DATA (START_IMAGE_TOK),\r
63 PERF_INIT_CUM_DATA (DRIVERBINDING_START_TOK),\r
64 PERF_INIT_CUM_DATA (DRIVERBINDING_SUPPORT_TOK)\r
65};\r
66\r
67/// Number of items for which we are gathering cumulative statistics.\r
68UINT32 const NumCum = sizeof(CumData) / sizeof(PERF_CUM_DATA);\r
69\r
70STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
71 {L"-v", TypeFlag}, // -v Verbose Mode\r
72 {L"-A", TypeFlag}, // -A All, Cooked\r
73 {L"-R", TypeFlag}, // -R RAW All\r
74 {L"-s", TypeFlag}, // -s Summary\r
75#if PROFILING_IMPLEMENTED\r
76 {L"-P", TypeFlag}, // -P Dump Profile Data\r
77 {L"-T", TypeFlag}, // -T Dump Trace Data\r
78#endif // PROFILING_IMPLEMENTED\r
79 {L"-x", TypeFlag}, // -x eXclude Cumulative Items\r
80 {L"-i", TypeFlag}, // -i Display Identifier\r
81 {L"-n", TypeValue}, // -n # Number of records to display for A and R\r
82 {L"-t", TypeValue}, // -t # Threshold of interest\r
83 {NULL, TypeMax}\r
84 };\r
85\r
86///@}\r
87\r
88/**\r
89 Display the trailing Verbose information.\r
90**/\r
91VOID\r
92DumpStatistics( void )\r
93{\r
94 EFI_STRING StringPtr;\r
95 EFI_STRING StringPtrUnknown;\r
96 StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_STATISTICS), NULL);\r
97 StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);\r
98 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle,\r
99 (StringPtr == NULL) ? StringPtrUnknown : StringPtr);\r
100 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMTRACE), gDpHiiHandle, SummaryData.NumTrace);\r
101 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE), gDpHiiHandle, SummaryData.NumIncomplete);\r
102 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMPHASES), gDpHiiHandle, SummaryData.NumSummary);\r
103 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMHANDLES), gDpHiiHandle, SummaryData.NumHandles, SummaryData.NumTrace - SummaryData.NumHandles);\r
104 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMPEIMS), gDpHiiHandle, SummaryData.NumPEIMs);\r
105 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMGLOBALS), gDpHiiHandle, SummaryData.NumGlobal);\r
106#if PROFILING_IMPLEMENTED\r
107 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMPROFILE), gDpHiiHandle, SummaryData.NumProfile);\r
108#endif // PROFILING_IMPLEMENTED\r
109 SHELL_FREE_NON_NULL (StringPtr);\r
110 SHELL_FREE_NON_NULL (StringPtrUnknown);\r
111}\r
112\r
113/** \r
114 Dump performance data.\r
115 \r
116 @param[in] ImageHandle The image handle.\r
117 @param[in] SystemTable The system table.\r
118 \r
119 @retval EFI_SUCCESS Command completed successfully.\r
120 @retval EFI_INVALID_PARAMETER Command usage error.\r
121 @retval value Unknown error.\r
122 \r
123**/\r
124SHELL_STATUS\r
125EFIAPI\r
126ShellCommandRunDp (\r
127 IN EFI_HANDLE ImageHandle,\r
128 IN EFI_SYSTEM_TABLE *SystemTable\r
129 )\r
130{\r
131 LIST_ENTRY *ParamPackage;\r
132 CONST CHAR16 *CmdLineArg;\r
133 EFI_STATUS Status;\r
134\r
135 UINT64 Freq;\r
136 UINT64 Ticker;\r
137 UINTN Number2Display;\r
138\r
a9b4ff8d
ED
139 EFI_STRING StringPtr;\r
140 BOOLEAN SummaryMode;\r
141 BOOLEAN VerboseMode;\r
142 BOOLEAN AllMode;\r
143 BOOLEAN RawMode;\r
144 BOOLEAN TraceMode;\r
145 BOOLEAN ProfileMode;\r
146 BOOLEAN ExcludeMode;\r
147\r
148 StringPtr = NULL;\r
149 SummaryMode = FALSE;\r
150 VerboseMode = FALSE;\r
151 AllMode = FALSE;\r
152 RawMode = FALSE;\r
153 TraceMode = FALSE;\r
154 ProfileMode = FALSE;\r
155 ExcludeMode = FALSE;\r
d41bc92c 156\r
157 // Get DP's entry time as soon as possible.\r
158 // This is used as the Shell-Phase end time.\r
159 //\r
160 Ticker = GetPerformanceCounter ();\r
161\r
162 //\r
163 // initialize the shell lib (we must be in non-auto-init...)\r
164 //\r
165 Status = ShellInitialize();\r
166 ASSERT_EFI_ERROR(Status);\r
167\r
168 Status = CommandInit();\r
169 ASSERT_EFI_ERROR(Status);\r
170\r
171 //\r
172 // Process Command Line arguments\r
173 //\r
174 Status = ShellCommandLineParse (ParamList, &ParamPackage, NULL, TRUE);\r
175 if (EFI_ERROR(Status)) {\r
176 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_INVALID_ARG), gDpHiiHandle);\r
177 return SHELL_INVALID_PARAMETER;\r
178 }\r
179\r
180 //\r
181 // Boolean options\r
182 //\r
183 VerboseMode = ShellCommandLineGetFlag (ParamPackage, L"-v");\r
184 SummaryMode = (BOOLEAN) (ShellCommandLineGetFlag (ParamPackage, L"-S") || ShellCommandLineGetFlag (ParamPackage, L"-s"));\r
185 AllMode = ShellCommandLineGetFlag (ParamPackage, L"-A");\r
186 RawMode = ShellCommandLineGetFlag (ParamPackage, L"-R");\r
187#if PROFILING_IMPLEMENTED\r
188 TraceMode = ShellCommandLineGetFlag (ParamPackage, L"-T");\r
189 ProfileMode = ShellCommandLineGetFlag (ParamPackage, L"-P");\r
190#endif // PROFILING_IMPLEMENTED\r
191 ExcludeMode = ShellCommandLineGetFlag (ParamPackage, L"-x");\r
192 mShowId = ShellCommandLineGetFlag (ParamPackage, L"-i");\r
193\r
194 // Options with Values\r
195 CmdLineArg = ShellCommandLineGetValue (ParamPackage, L"-n");\r
196 if (CmdLineArg == NULL) {\r
197 Number2Display = DEFAULT_DISPLAYCOUNT;\r
198 } else {\r
199 Number2Display = StrDecimalToUintn(CmdLineArg);\r
200 if (Number2Display == 0) {\r
201 Number2Display = MAXIMUM_DISPLAYCOUNT;\r
202 }\r
203 }\r
204\r
205 CmdLineArg = ShellCommandLineGetValue (ParamPackage, L"-t");\r
206 if (CmdLineArg == NULL) {\r
207 mInterestThreshold = DEFAULT_THRESHOLD; // 1ms := 1,000 us\r
208 } else {\r
209 mInterestThreshold = StrDecimalToUint64(CmdLineArg);\r
210 }\r
211\r
212 // Handle Flag combinations and default behaviors\r
213 // If both TraceMode and ProfileMode are FALSE, set them both to TRUE\r
214 if ((! TraceMode) && (! ProfileMode)) {\r
215 TraceMode = TRUE;\r
216#if PROFILING_IMPLEMENTED\r
217 ProfileMode = TRUE;\r
218#endif // PROFILING_IMPLEMENTED\r
219 }\r
220\r
221 //\r
222 // Timer specific processing\r
223 //\r
224 // Get the Performance counter characteristics:\r
225 // Freq = Frequency in Hz\r
226 // StartCount = Value loaded into the counter when it starts counting\r
227 // EndCount = Value counter counts to before it needs to be reset\r
228 //\r
229 Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount);\r
230\r
231 // Convert the Frequency from Hz to KHz\r
232 TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000);\r
233\r
234 // Determine in which direction the performance counter counts.\r
235 TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount);\r
236\r
237 //\r
238 // Print header\r
239 //\r
240 // print DP's build version\r
241 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_BUILD_REVISION), gDpHiiHandle, DP_MAJOR_VERSION, DP_MINOR_VERSION);\r
242\r
243 // print performance timer characteristics\r
244 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_KHZ), gDpHiiHandle, TimerInfo.Frequency);\r
245\r
246 if (VerboseMode && !RawMode) {\r
247 StringPtr = HiiGetString (gDpHiiHandle,\r
248 (EFI_STRING_ID) (TimerInfo.CountUp ? STRING_TOKEN (STR_DP_UP) : STRING_TOKEN (STR_DP_DOWN)), NULL);\r
249 ASSERT (StringPtr != NULL);\r
250 // Print Timer count range and direction\r
251 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TIMER_PROPERTIES), gDpHiiHandle,\r
252 StringPtr,\r
253 TimerInfo.StartCount,\r
254 TimerInfo.EndCount\r
255 );\r
256 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), gDpHiiHandle, mInterestThreshold);\r
257 }\r
258\r
259/****************************************************************************\r
260**** Print Sections based on command line options\r
261****\r
262**** Option modes have the following priority:\r
263**** v Verbose -- Valid in combination with any other options\r
264**** t Threshold -- Modifies All, Raw, and Cooked output\r
265**** Default is 0 for All and Raw mode\r
266**** Default is DEFAULT_THRESHOLD for "Cooked" mode\r
267**** n Number2Display Used by All and Raw mode. Otherwise ignored.\r
268**** A All -- R and S options are ignored\r
269**** R Raw -- S option is ignored\r
270**** s Summary -- Modifies "Cooked" output only\r
271**** Cooked (Default)\r
272****\r
273**** The All, Raw, and Cooked modes are modified by the Trace and Profile\r
274**** options.\r
275**** !T && !P := (0) Default, Both are displayed\r
276**** T && !P := (1) Only Trace records are displayed\r
277**** !T && P := (2) Only Profile records are displayed\r
278**** T && P := (3) Same as Default, both are displayed\r
279****************************************************************************/\r
280 GatherStatistics();\r
281 if (AllMode) {\r
282 if (TraceMode) {\r
283 DumpAllTrace( Number2Display, ExcludeMode);\r
284 }\r
285 if (ProfileMode) {\r
286 DumpAllProfile( Number2Display, ExcludeMode);\r
287 }\r
288 } else if (RawMode) {\r
289 if (TraceMode) {\r
290 DumpRawTrace( Number2Display, ExcludeMode);\r
291 }\r
292 if (ProfileMode) {\r
293 DumpRawProfile( Number2Display, ExcludeMode);\r
294 }\r
295 } else {\r
296 //------------- Begin Cooked Mode Processing\r
297 if (TraceMode) {\r
298 ProcessPhases ( Ticker );\r
299 if ( ! SummaryMode) {\r
300 Status = ProcessHandles ( ExcludeMode);\r
301 if ( ! EFI_ERROR( Status)) {\r
302 ProcessPeims ();\r
303 ProcessGlobal ();\r
304 ProcessCumulative ();\r
305 }\r
306 }\r
307 }\r
308 if (ProfileMode) {\r
309 DumpAllProfile( Number2Display, ExcludeMode);\r
310 }\r
311 } //------------- End of Cooked Mode Processing\r
312 if ( VerboseMode || SummaryMode) {\r
313 DumpStatistics();\r
314 }\r
315\r
316 SHELL_FREE_NON_NULL (StringPtr);\r
317\r
318 return SHELL_SUCCESS;\r
319}\r