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