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
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.
25 #include <Protocol/Performance.h>
27 #include <Library/PerformanceLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/PcdLib.h>
32 STATIC PERFORMANCE_PROTOCOL
*mPerformance
= NULL
;
35 The constructor function caches the pointer to Performance protocol.
37 The constructor function locates Performance protocol from protocol database.
38 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
40 @retval EFI_SUCCESS Performance protocol is successfully located.
41 @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.
119 If this function is called multiple times for the same record, then the end time is overwritten.
121 @param Handle Pointer to environment specific context used
122 to identify the component being measured.
123 @param Token Pointer to a Null-terminated ASCII string
124 that identifies the component being measured.
125 @param Module Pointer to a Null-terminated ASCII string
126 that identifies the module being measured.
127 @param TimeStamp 64-bit time stamp.
129 @retval RETURN_SUCCESS The end of the measurement was recorded.
130 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
135 EndPerformanceMeasurement (
136 IN CONST VOID
*Handle
, OPTIONAL
137 IN CONST CHAR8
*Token
, OPTIONAL
138 IN CONST CHAR8
*Module
, OPTIONAL
144 Status
= GetPerformanceProtocol ();
145 if (EFI_ERROR (Status
)) {
146 return RETURN_NOT_FOUND
;
149 Status
= mPerformance
->EndGauge (Handle
, Token
, Module
, TimeStamp
);
151 return (RETURN_STATUS
) Status
;
155 Attempts to retrieve a performance measurement log entry from the performance measurement log.
157 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
158 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
159 and the key for the second entry in the log is returned. If the performance log is empty,
160 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
161 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
162 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
163 retrieved and an implementation specific non-zero key value that specifies the end of the performance
164 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
165 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
166 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
167 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
168 If Handle is NULL, then ASSERT().
169 If Token is NULL, then ASSERT().
170 If Module is NULL, then ASSERT().
171 If StartTimeStamp is NULL, then ASSERT().
172 If EndTimeStamp is NULL, then ASSERT().
174 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
175 0, then the first performance measurement log entry is retrieved.
176 On exit, the key of the next performance lof entry entry.
177 @param Handle Pointer to environment specific context used to identify the component
179 @param Token Pointer to a Null-terminated ASCII string that identifies the component
181 @param Module Pointer to a Null-terminated ASCII string that identifies the module
183 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
185 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
188 @return The key for the next performance log entry (in general case).
193 GetPerformanceMeasurement (
194 IN UINTN LogEntryKey
,
195 OUT CONST VOID
**Handle
,
196 OUT CONST CHAR8
**Token
,
197 OUT CONST CHAR8
**Module
,
198 OUT UINT64
*StartTimeStamp
,
199 OUT UINT64
*EndTimeStamp
203 GAUGE_DATA_ENTRY
*GaugeData
;
205 ASSERT (Handle
!= NULL
);
206 ASSERT (Token
!= NULL
);
207 ASSERT (Module
!= NULL
);
208 ASSERT (StartTimeStamp
!= NULL
);
209 ASSERT (EndTimeStamp
!= NULL
);
211 Status
= GetPerformanceProtocol ();
212 if (EFI_ERROR (Status
)) {
216 Status
= mPerformance
->GetGauge (LogEntryKey
++, &GaugeData
);
219 // Make sure that LogEntryKey is a valid log entry key,
221 ASSERT (Status
!= EFI_INVALID_PARAMETER
);
223 if (EFI_ERROR (Status
)) {
225 // The LogEntryKey is the last entry (equals to the total entry number).
230 ASSERT (GaugeData
!= NULL
);
232 *Handle
= (VOID
*) (UINTN
) GaugeData
->Handle
;
233 *Token
= GaugeData
->Token
;
234 *Module
= GaugeData
->Module
;
235 *StartTimeStamp
= GaugeData
->StartTimeStamp
;
236 *EndTimeStamp
= GaugeData
->EndTimeStamp
;
242 Returns TRUE if the performance measurement macros are enabled.
244 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
245 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
247 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
248 PcdPerformanceLibraryPropertyMask is set.
249 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
250 PcdPerformanceLibraryPropertyMask is clear.
255 PerformanceMeasurementEnabled (
259 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);