]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiDpLib/Dp.c
Fix a bug that IsSignatureFoundInDatabase() incorrectly computes CertCount.
[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
41#include <PerformanceTokens.h>\r
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
139 EFI_STRING StringPtr = NULL;\r
140 BOOLEAN SummaryMode = FALSE;\r
141 BOOLEAN VerboseMode = FALSE;\r
142 BOOLEAN AllMode = FALSE;\r
143 BOOLEAN RawMode = FALSE;\r
144 BOOLEAN TraceMode = FALSE;\r
145 BOOLEAN ProfileMode = FALSE;\r
146 BOOLEAN ExcludeMode = FALSE;\r
147\r
148 // Get DP's entry time as soon as possible.\r
149 // This is used as the Shell-Phase end time.\r
150 //\r
151 Ticker = GetPerformanceCounter ();\r
152\r
153 //\r
154 // initialize the shell lib (we must be in non-auto-init...)\r
155 //\r
156 Status = ShellInitialize();\r
157 ASSERT_EFI_ERROR(Status);\r
158\r
159 Status = CommandInit();\r
160 ASSERT_EFI_ERROR(Status);\r
161\r
162 //\r
163 // Process Command Line arguments\r
164 //\r
165 Status = ShellCommandLineParse (ParamList, &ParamPackage, NULL, TRUE);\r
166 if (EFI_ERROR(Status)) {\r
167 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_INVALID_ARG), gDpHiiHandle);\r
168 return SHELL_INVALID_PARAMETER;\r
169 }\r
170\r
171 //\r
172 // Boolean options\r
173 //\r
174 VerboseMode = ShellCommandLineGetFlag (ParamPackage, L"-v");\r
175 SummaryMode = (BOOLEAN) (ShellCommandLineGetFlag (ParamPackage, L"-S") || ShellCommandLineGetFlag (ParamPackage, L"-s"));\r
176 AllMode = ShellCommandLineGetFlag (ParamPackage, L"-A");\r
177 RawMode = ShellCommandLineGetFlag (ParamPackage, L"-R");\r
178#if PROFILING_IMPLEMENTED\r
179 TraceMode = ShellCommandLineGetFlag (ParamPackage, L"-T");\r
180 ProfileMode = ShellCommandLineGetFlag (ParamPackage, L"-P");\r
181#endif // PROFILING_IMPLEMENTED\r
182 ExcludeMode = ShellCommandLineGetFlag (ParamPackage, L"-x");\r
183 mShowId = ShellCommandLineGetFlag (ParamPackage, L"-i");\r
184\r
185 // Options with Values\r
186 CmdLineArg = ShellCommandLineGetValue (ParamPackage, L"-n");\r
187 if (CmdLineArg == NULL) {\r
188 Number2Display = DEFAULT_DISPLAYCOUNT;\r
189 } else {\r
190 Number2Display = StrDecimalToUintn(CmdLineArg);\r
191 if (Number2Display == 0) {\r
192 Number2Display = MAXIMUM_DISPLAYCOUNT;\r
193 }\r
194 }\r
195\r
196 CmdLineArg = ShellCommandLineGetValue (ParamPackage, L"-t");\r
197 if (CmdLineArg == NULL) {\r
198 mInterestThreshold = DEFAULT_THRESHOLD; // 1ms := 1,000 us\r
199 } else {\r
200 mInterestThreshold = StrDecimalToUint64(CmdLineArg);\r
201 }\r
202\r
203 // Handle Flag combinations and default behaviors\r
204 // If both TraceMode and ProfileMode are FALSE, set them both to TRUE\r
205 if ((! TraceMode) && (! ProfileMode)) {\r
206 TraceMode = TRUE;\r
207#if PROFILING_IMPLEMENTED\r
208 ProfileMode = TRUE;\r
209#endif // PROFILING_IMPLEMENTED\r
210 }\r
211\r
212 //\r
213 // Timer specific processing\r
214 //\r
215 // Get the Performance counter characteristics:\r
216 // Freq = Frequency in Hz\r
217 // StartCount = Value loaded into the counter when it starts counting\r
218 // EndCount = Value counter counts to before it needs to be reset\r
219 //\r
220 Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount);\r
221\r
222 // Convert the Frequency from Hz to KHz\r
223 TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000);\r
224\r
225 // Determine in which direction the performance counter counts.\r
226 TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount);\r
227\r
228 //\r
229 // Print header\r
230 //\r
231 // print DP's build version\r
232 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_BUILD_REVISION), gDpHiiHandle, DP_MAJOR_VERSION, DP_MINOR_VERSION);\r
233\r
234 // print performance timer characteristics\r
235 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_KHZ), gDpHiiHandle, TimerInfo.Frequency);\r
236\r
237 if (VerboseMode && !RawMode) {\r
238 StringPtr = HiiGetString (gDpHiiHandle,\r
239 (EFI_STRING_ID) (TimerInfo.CountUp ? STRING_TOKEN (STR_DP_UP) : STRING_TOKEN (STR_DP_DOWN)), NULL);\r
240 ASSERT (StringPtr != NULL);\r
241 // Print Timer count range and direction\r
242 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TIMER_PROPERTIES), gDpHiiHandle,\r
243 StringPtr,\r
244 TimerInfo.StartCount,\r
245 TimerInfo.EndCount\r
246 );\r
247 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), gDpHiiHandle, mInterestThreshold);\r
248 }\r
249\r
250/****************************************************************************\r
251**** Print Sections based on command line options\r
252****\r
253**** Option modes have the following priority:\r
254**** v Verbose -- Valid in combination with any other options\r
255**** t Threshold -- Modifies All, Raw, and Cooked output\r
256**** Default is 0 for All and Raw mode\r
257**** Default is DEFAULT_THRESHOLD for "Cooked" mode\r
258**** n Number2Display Used by All and Raw mode. Otherwise ignored.\r
259**** A All -- R and S options are ignored\r
260**** R Raw -- S option is ignored\r
261**** s Summary -- Modifies "Cooked" output only\r
262**** Cooked (Default)\r
263****\r
264**** The All, Raw, and Cooked modes are modified by the Trace and Profile\r
265**** options.\r
266**** !T && !P := (0) Default, Both are displayed\r
267**** T && !P := (1) Only Trace records are displayed\r
268**** !T && P := (2) Only Profile records are displayed\r
269**** T && P := (3) Same as Default, both are displayed\r
270****************************************************************************/\r
271 GatherStatistics();\r
272 if (AllMode) {\r
273 if (TraceMode) {\r
274 DumpAllTrace( Number2Display, ExcludeMode);\r
275 }\r
276 if (ProfileMode) {\r
277 DumpAllProfile( Number2Display, ExcludeMode);\r
278 }\r
279 } else if (RawMode) {\r
280 if (TraceMode) {\r
281 DumpRawTrace( Number2Display, ExcludeMode);\r
282 }\r
283 if (ProfileMode) {\r
284 DumpRawProfile( Number2Display, ExcludeMode);\r
285 }\r
286 } else {\r
287 //------------- Begin Cooked Mode Processing\r
288 if (TraceMode) {\r
289 ProcessPhases ( Ticker );\r
290 if ( ! SummaryMode) {\r
291 Status = ProcessHandles ( ExcludeMode);\r
292 if ( ! EFI_ERROR( Status)) {\r
293 ProcessPeims ();\r
294 ProcessGlobal ();\r
295 ProcessCumulative ();\r
296 }\r
297 }\r
298 }\r
299 if (ProfileMode) {\r
300 DumpAllProfile( Number2Display, ExcludeMode);\r
301 }\r
302 } //------------- End of Cooked Mode Processing\r
303 if ( VerboseMode || SummaryMode) {\r
304 DumpStatistics();\r
305 }\r
306\r
307 SHELL_FREE_NON_NULL (StringPtr);\r
308\r
309 return SHELL_SUCCESS;\r
310}\r