]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c
[Description]:
[mirror_edk2.git] / MdeModulePkg / Library / DxePerformanceLib / DxePerformanceLib.c
CommitLineData
8dbae30d 1/** @file\r
2 Performance Library\r
a0afd019 3\r
8dbae30d 4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
a0afd019 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
8dbae30d 11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
a0afd019 12\r
8dbae30d 13**/\r
a0afd019 14\r
ed7748fe 15\r
a0afd019 16#include <PiDxe.h>\r
ed7748fe 17\r
a0afd019 18#include <Protocol/Performance.h>\r
ed7748fe 19\r
a0afd019 20#include <Library/PerformanceLib.h>\r
21#include <Library/DebugLib.h>\r
22#include <Library/UefiBootServicesTableLib.h>\r
23#include <Library/PcdLib.h>\r
24\r
25STATIC PERFORMANCE_PROTOCOL *mPerformance = NULL;\r
26\r
27/**\r
28 The constructor function caches the pointer to Performance protocol.\r
29\r
30 The constructor function locates Performance protocol from protocol database.\r
31 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.\r
32\r
33 @retval EFI_SUCCESS Performance protocol is successfully located.\r
34 @retval Other Performance protocol is not located to log performance.\r
35\r
36**/\r
37STATIC\r
38EFI_STATUS\r
39GetPerformanceProtocol (\r
40 VOID\r
41 )\r
42{\r
43 EFI_STATUS Status;\r
44 PERFORMANCE_PROTOCOL *Performance;\r
45\r
46 if (mPerformance != NULL) {\r
47 return EFI_SUCCESS;\r
48 }\r
49\r
50 Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &Performance);\r
51 if (!EFI_ERROR (Status)) {\r
52 ASSERT (Performance != NULL);\r
53 //\r
54 // Cache performance protocol.\r
55 //\r
56 mPerformance = Performance;\r
57 }\r
58\r
59 return Status;\r
60}\r
61\r
62/**\r
63 Creates a record for the beginning of a performance measurement.\r
64\r
65 Creates a record that contains the Handle, Token, and Module.\r
66 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
67 If TimeStamp is zero, then this function reads the current time stamp\r
68 and adds that time stamp value to the record as the start time.\r
69\r
70 @param Handle Pointer to environment specific context used\r
71 to identify the component being measured.\r
72 @param Token Pointer to a Null-terminated ASCII string\r
73 that identifies the component being measured.\r
74 @param Module Pointer to a Null-terminated ASCII string\r
75 that identifies the module being measured.\r
76 @param TimeStamp 64-bit time stamp.\r
77\r
78 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
79 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
80\r
81**/\r
82RETURN_STATUS\r
83EFIAPI\r
84StartPerformanceMeasurement (\r
85 IN CONST VOID *Handle, OPTIONAL\r
86 IN CONST CHAR8 *Token, OPTIONAL\r
87 IN CONST CHAR8 *Module, OPTIONAL\r
88 IN UINT64 TimeStamp\r
89 )\r
90{\r
91 EFI_STATUS Status;\r
92\r
93 Status = GetPerformanceProtocol ();\r
94 if (EFI_ERROR (Status)) {\r
95 return RETURN_OUT_OF_RESOURCES;\r
96 }\r
97\r
98 Status = mPerformance->StartGauge (Handle, Token, Module, TimeStamp);\r
99\r
100 return (RETURN_STATUS) Status;\r
101}\r
102\r
103/**\r
104 Fills in the end time of a performance measurement.\r
105\r
106 Looks up the record that matches Handle, Token, and Module.\r
107 If the record can not be found then return RETURN_NOT_FOUND.\r
108 If the record is found and TimeStamp is not zero,\r
109 then TimeStamp is added to the record as the end time.\r
110 If the record is found and TimeStamp is zero, then this function reads\r
111 the current time stamp and adds that time stamp value to the record as the end time.\r
112 If this function is called multiple times for the same record, then the end time is overwritten.\r
113\r
114 @param Handle Pointer to environment specific context used\r
115 to identify the component being measured.\r
116 @param Token Pointer to a Null-terminated ASCII string\r
117 that identifies the component being measured.\r
118 @param Module Pointer to a Null-terminated ASCII string\r
119 that identifies the module being measured.\r
120 @param TimeStamp 64-bit time stamp.\r
121\r
122 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
123 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
124\r
125**/\r
126RETURN_STATUS\r
127EFIAPI\r
128EndPerformanceMeasurement (\r
129 IN CONST VOID *Handle, OPTIONAL\r
130 IN CONST CHAR8 *Token, OPTIONAL\r
131 IN CONST CHAR8 *Module, OPTIONAL\r
132 IN UINT64 TimeStamp\r
133 )\r
134{\r
135 EFI_STATUS Status;\r
136\r
137 Status = GetPerformanceProtocol ();\r
138 if (EFI_ERROR (Status)) {\r
139 return RETURN_NOT_FOUND;\r
140 }\r
141\r
142 Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp);\r
143\r
144 return (RETURN_STATUS) Status;\r
145}\r
146\r
147/**\r
148 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
149\r
150 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
151 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
152 and the key for the second entry in the log is returned. If the performance log is empty,\r
153 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
154 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
155 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
156 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
157 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
158 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
159 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
160 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
161 If Handle is NULL, then ASSERT().\r
162 If Token is NULL, then ASSERT().\r
163 If Module is NULL, then ASSERT().\r
164 If StartTimeStamp is NULL, then ASSERT().\r
165 If EndTimeStamp is NULL, then ASSERT().\r
166\r
167 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
168 0, then the first performance measurement log entry is retrieved.\r
169 On exit, the key of the next performance lof entry entry.\r
170 @param Handle Pointer to environment specific context used to identify the component\r
171 being measured.\r
172 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
173 being measured.\r
174 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
175 being measured.\r
176 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
177 was started.\r
178 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
179 was ended.\r
180\r
181 @return The key for the next performance log entry (in general case).\r
182\r
183**/\r
184UINTN\r
185EFIAPI\r
186GetPerformanceMeasurement (\r
187 IN UINTN LogEntryKey,\r
188 OUT CONST VOID **Handle,\r
189 OUT CONST CHAR8 **Token,\r
190 OUT CONST CHAR8 **Module,\r
191 OUT UINT64 *StartTimeStamp,\r
192 OUT UINT64 *EndTimeStamp\r
193 )\r
194{\r
195 EFI_STATUS Status;\r
196 GAUGE_DATA_ENTRY *GaugeData;\r
197\r
198 ASSERT (Handle != NULL);\r
199 ASSERT (Token != NULL);\r
200 ASSERT (Module != NULL);\r
201 ASSERT (StartTimeStamp != NULL);\r
202 ASSERT (EndTimeStamp != NULL);\r
203\r
204 Status = GetPerformanceProtocol ();\r
205 if (EFI_ERROR (Status)) {\r
206 return 0;\r
207 }\r
208\r
209 Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData);\r
210\r
211 //\r
212 // Make sure that LogEntryKey is a valid log entry key,\r
213 //\r
214 ASSERT (Status != EFI_INVALID_PARAMETER);\r
215\r
216 if (EFI_ERROR (Status)) {\r
217 //\r
218 // The LogEntryKey is the last entry (equals to the total entry number).\r
219 //\r
220 return 0;\r
221 }\r
222\r
223 ASSERT (GaugeData != NULL);\r
224\r
225 *Handle = (VOID *) (UINTN) GaugeData->Handle;\r
226 *Token = GaugeData->Token;\r
227 *Module = GaugeData->Module;\r
228 *StartTimeStamp = GaugeData->StartTimeStamp;\r
229 *EndTimeStamp = GaugeData->EndTimeStamp;\r
230\r
231 return LogEntryKey;\r
232}\r
233\r
234/**\r
235 Returns TRUE if the performance measurement macros are enabled.\r
236\r
237 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
238 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
239\r
240 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
241 PcdPerformanceLibraryPropertyMask is set.\r
242 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
243 PcdPerformanceLibraryPropertyMask is clear.\r
244\r
245**/\r
246BOOLEAN\r
247EFIAPI\r
248PerformanceMeasurementEnabled (\r
249 VOID\r
250 )\r
251{\r
252 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
253}\r