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