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