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