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