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