4 This library instance provides infrastructure for DXE phase drivers to log performance
5 data. It consumes Performance Protocol published by DxeCorePerformanceLib
6 to log performance data. If Performance Protocol is not available, it does not log any
7 performance information.
9 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
10 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 #include <Guid/Performance.h>
25 #include <Library/PerformanceLib.h>
26 #include <Library/DebugLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/PcdLib.h>
31 // The cached performance protocol interface.
33 PERFORMANCE_PROTOCOL
*mPerformance
= NULL
;
36 The constructor function caches the pointer to Performance protocol.
38 The constructor function locates Performance protocol from protocol database.
39 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
41 @retval EFI_SUCCESS Performance protocol is successfully located.
42 @retval Other Performance protocol is not located to log performance.
46 GetPerformanceProtocol (
51 PERFORMANCE_PROTOCOL
*Performance
;
53 if (mPerformance
!= NULL
) {
57 Status
= gBS
->LocateProtocol (&gPerformanceProtocolGuid
, NULL
, (VOID
**) &Performance
);
58 if (!EFI_ERROR (Status
)) {
59 ASSERT (Performance
!= NULL
);
61 // Cache performance protocol.
63 mPerformance
= Performance
;
70 Creates a record for the beginning of a performance measurement.
72 Creates a record that contains the Handle, Token, and Module.
73 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
74 If TimeStamp is zero, then this function reads the current time stamp
75 and adds that time stamp value to the record as the start time.
77 @param Handle Pointer to environment specific context used
78 to identify the component being measured.
79 @param Token Pointer to a Null-terminated ASCII string
80 that identifies the component being measured.
81 @param Module Pointer to a Null-terminated ASCII string
82 that identifies the module being measured.
83 @param TimeStamp 64-bit time stamp.
85 @retval RETURN_SUCCESS The start of the measurement was recorded.
86 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
91 StartPerformanceMeasurement (
92 IN CONST VOID
*Handle
, OPTIONAL
93 IN CONST CHAR8
*Token
, OPTIONAL
94 IN CONST CHAR8
*Module
, OPTIONAL
100 Status
= GetPerformanceProtocol ();
101 if (EFI_ERROR (Status
)) {
102 return RETURN_OUT_OF_RESOURCES
;
105 Status
= mPerformance
->StartGauge (Handle
, Token
, Module
, TimeStamp
);
107 return (RETURN_STATUS
) Status
;
111 Fills in the end time of a performance measurement.
113 Looks up the record that matches Handle, Token, and Module.
114 If the record can not be found then return RETURN_NOT_FOUND.
115 If the record is found and TimeStamp is not zero,
116 then TimeStamp is added to the record as the end time.
117 If the record is found and TimeStamp is zero, then this function reads
118 the current time stamp and adds that time stamp value to the record as the end time.
120 @param Handle Pointer to environment specific context used
121 to identify the component being measured.
122 @param Token Pointer to a Null-terminated ASCII string
123 that identifies the component being measured.
124 @param Module Pointer to a Null-terminated ASCII string
125 that identifies the module being measured.
126 @param TimeStamp 64-bit time stamp.
128 @retval RETURN_SUCCESS The end of the measurement was recorded.
129 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
134 EndPerformanceMeasurement (
135 IN CONST VOID
*Handle
, OPTIONAL
136 IN CONST CHAR8
*Token
, OPTIONAL
137 IN CONST CHAR8
*Module
, OPTIONAL
143 Status
= GetPerformanceProtocol ();
144 if (EFI_ERROR (Status
)) {
145 return RETURN_NOT_FOUND
;
148 Status
= mPerformance
->EndGauge (Handle
, Token
, Module
, TimeStamp
);
150 return (RETURN_STATUS
) Status
;
154 Attempts to retrieve a performance measurement log entry from the performance measurement log.
156 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
157 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
158 and the key for the second entry in the log is returned. If the performance log is empty,
159 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
160 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
161 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
162 retrieved and an implementation specific non-zero key value that specifies the end of the performance
163 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
164 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
165 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
166 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
167 If Handle is NULL, then ASSERT().
168 If Token is NULL, then ASSERT().
169 If Module is NULL, then ASSERT().
170 If StartTimeStamp is NULL, then ASSERT().
171 If EndTimeStamp is NULL, then ASSERT().
173 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
174 0, then the first performance measurement log entry is retrieved.
175 On exit, the key of the next performance log entry.
176 @param Handle Pointer to environment specific context used to identify the component
178 @param Token Pointer to a Null-terminated ASCII string that identifies the component
180 @param Module Pointer to a Null-terminated ASCII string that identifies the module
182 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
184 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
187 @return The key for the next performance log entry (in general case).
192 GetPerformanceMeasurement (
193 IN UINTN LogEntryKey
,
194 OUT CONST VOID
**Handle
,
195 OUT CONST CHAR8
**Token
,
196 OUT CONST CHAR8
**Module
,
197 OUT UINT64
*StartTimeStamp
,
198 OUT UINT64
*EndTimeStamp
202 GAUGE_DATA_ENTRY
*GaugeData
;
204 ASSERT (Handle
!= NULL
);
205 ASSERT (Token
!= NULL
);
206 ASSERT (Module
!= NULL
);
207 ASSERT (StartTimeStamp
!= NULL
);
208 ASSERT (EndTimeStamp
!= NULL
);
210 Status
= GetPerformanceProtocol ();
211 if (EFI_ERROR (Status
)) {
215 Status
= mPerformance
->GetGauge (LogEntryKey
++, &GaugeData
);
218 // Make sure that LogEntryKey is a valid log entry key,
220 ASSERT (Status
!= EFI_INVALID_PARAMETER
);
222 if (EFI_ERROR (Status
)) {
224 // The LogEntryKey is the last entry (equals to the total entry number).
229 ASSERT (GaugeData
!= NULL
);
231 *Handle
= (VOID
*) (UINTN
) GaugeData
->Handle
;
232 *Token
= GaugeData
->Token
;
233 *Module
= GaugeData
->Module
;
234 *StartTimeStamp
= GaugeData
->StartTimeStamp
;
235 *EndTimeStamp
= GaugeData
->EndTimeStamp
;
241 Returns TRUE if the performance measurement macros are enabled.
243 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
244 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
246 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
247 PcdPerformanceLibraryPropertyMask is set.
248 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
249 PcdPerformanceLibraryPropertyMask is clear.
254 PerformanceMeasurementEnabled (
258 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);