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