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