]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c
Add new extension PerformanceLib APIs to store ID info.
[mirror_edk2.git] / MdeModulePkg / Library / DxePerformanceLib / DxePerformanceLib.c
CommitLineData
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
3dffec12 9 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 10This program and the accompanying materials\r
a0afd019 11are licensed and made available under the terms and conditions of the BSD License\r
12which accompanies this distribution. The full text of the license may be found at\r
13http://opensource.org/licenses/bsd-license.php\r
14\r
15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
8dbae30d 16WITHOUT 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 33PERFORMANCE_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 45EFI_STATUS\r
46GetPerformanceProtocol (\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
89RETURN_STATUS\r
90EFIAPI\r
91StartPerformanceMeasurement (\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
a0afd019 119\r
120 @param Handle Pointer to environment specific context used\r
121 to identify the component being measured.\r
122 @param Token Pointer to a Null-terminated ASCII string\r
123 that identifies the component being measured.\r
124 @param Module Pointer to a Null-terminated ASCII string\r
125 that identifies the module being measured.\r
126 @param TimeStamp 64-bit time stamp.\r
127\r
128 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
129 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
130\r
131**/\r
132RETURN_STATUS\r
133EFIAPI\r
134EndPerformanceMeasurement (\r
135 IN CONST VOID *Handle, OPTIONAL\r
136 IN CONST CHAR8 *Token, OPTIONAL\r
137 IN CONST CHAR8 *Module, OPTIONAL\r
138 IN UINT64 TimeStamp\r
139 )\r
140{\r
141 EFI_STATUS Status;\r
142\r
143 Status = GetPerformanceProtocol ();\r
144 if (EFI_ERROR (Status)) {\r
145 return RETURN_NOT_FOUND;\r
146 }\r
147\r
148 Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp);\r
149\r
150 return (RETURN_STATUS) Status;\r
151}\r
152\r
153/**\r
154 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
155\r
156 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
157 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
158 and the key for the second entry in the log is returned. If the performance log is empty,\r
159 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
160 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
161 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
162 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
163 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
164 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
165 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
166 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
167 If Handle is NULL, then ASSERT().\r
168 If Token is NULL, then ASSERT().\r
169 If Module is NULL, then ASSERT().\r
170 If StartTimeStamp is NULL, then ASSERT().\r
171 If EndTimeStamp is NULL, then ASSERT().\r
172\r
173 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
174 0, then the first performance measurement log entry is retrieved.\r
857dfc45 175 On exit, the key of the next performance log entry.\r
a0afd019 176 @param Handle Pointer to environment specific context used to identify the component\r
177 being measured.\r
178 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
179 being measured.\r
180 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
181 being measured.\r
182 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
183 was started.\r
184 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
185 was ended.\r
186\r
187 @return The key for the next performance log entry (in general case).\r
188\r
189**/\r
190UINTN\r
191EFIAPI\r
192GetPerformanceMeasurement (\r
193 IN UINTN LogEntryKey,\r
194 OUT CONST VOID **Handle,\r
195 OUT CONST CHAR8 **Token,\r
196 OUT CONST CHAR8 **Module,\r
197 OUT UINT64 *StartTimeStamp,\r
198 OUT UINT64 *EndTimeStamp\r
199 )\r
200{\r
201 EFI_STATUS Status;\r
202 GAUGE_DATA_ENTRY *GaugeData;\r
203\r
204 ASSERT (Handle != NULL);\r
205 ASSERT (Token != NULL);\r
206 ASSERT (Module != NULL);\r
207 ASSERT (StartTimeStamp != NULL);\r
208 ASSERT (EndTimeStamp != NULL);\r
209\r
210 Status = GetPerformanceProtocol ();\r
211 if (EFI_ERROR (Status)) {\r
212 return 0;\r
213 }\r
214\r
215 Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData);\r
216\r
217 //\r
218 // Make sure that LogEntryKey is a valid log entry key,\r
219 //\r
220 ASSERT (Status != EFI_INVALID_PARAMETER);\r
221\r
222 if (EFI_ERROR (Status)) {\r
223 //\r
224 // The LogEntryKey is the last entry (equals to the total entry number).\r
225 //\r
226 return 0;\r
227 }\r
228\r
229 ASSERT (GaugeData != NULL);\r
230\r
231 *Handle = (VOID *) (UINTN) GaugeData->Handle;\r
232 *Token = GaugeData->Token;\r
233 *Module = GaugeData->Module;\r
234 *StartTimeStamp = GaugeData->StartTimeStamp;\r
235 *EndTimeStamp = GaugeData->EndTimeStamp;\r
236\r
237 return LogEntryKey;\r
238}\r
239\r
240/**\r
241 Returns TRUE if the performance measurement macros are enabled.\r
242\r
243 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
244 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
245\r
246 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
247 PcdPerformanceLibraryPropertyMask is set.\r
248 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
249 PcdPerformanceLibraryPropertyMask is clear.\r
250\r
251**/\r
252BOOLEAN\r
253EFIAPI\r
254PerformanceMeasurementEnabled (\r
255 VOID\r
256 )\r
257{\r
258 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
259}\r