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.
22 STATIC PERFORMANCE_PROTOCOL
*mPerformance
= NULL
;
25 The constructor function caches the pointer to Performance protocol.
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.
30 @retval EFI_SUCCESS Performance protocol is successfully located.
31 @retval Other Performance protocol is not located to log performance.
35 GetPerformanceProtocol (
40 PERFORMANCE_PROTOCOL
*Performance
;
42 if (mPerformance
!= NULL
) {
46 Status
= gBS
->LocateProtocol (&gPerformanceProtocolGuid
, NULL
, (VOID
**) &Performance
);
47 if (!EFI_ERROR (Status
)) {
48 ASSERT (Performance
!= NULL
);
50 // Cache performance protocol.
52 mPerformance
= Performance
;
59 Creates a record for the beginning of a performance measurement.
61 Creates a record that contains the Handle, Token, and Module.
62 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
63 If TimeStamp is zero, then this function reads the current time stamp
64 and adds that time stamp value to the record as the start time.
66 @param Handle Pointer to environment specific context used
67 to identify the component being measured.
68 @param Token Pointer to a Null-terminated ASCII string
69 that identifies the component being measured.
70 @param Module Pointer to a Null-terminated ASCII string
71 that identifies the module being measured.
72 @param TimeStamp 64-bit time stamp.
74 @retval RETURN_SUCCESS The start of the measurement was recorded.
75 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
80 StartPerformanceMeasurement (
81 IN CONST VOID
*Handle
, OPTIONAL
82 IN CONST CHAR8
*Token
, OPTIONAL
83 IN CONST CHAR8
*Module
, OPTIONAL
89 Status
= GetPerformanceProtocol ();
90 if (EFI_ERROR (Status
)) {
91 return RETURN_OUT_OF_RESOURCES
;
94 Status
= mPerformance
->StartGauge (Handle
, Token
, Module
, TimeStamp
);
96 return (RETURN_STATUS
) Status
;
100 Fills in the end time of a performance measurement.
102 Looks up the record that matches Handle, Token, and Module.
103 If the record can not be found then return RETURN_NOT_FOUND.
104 If the record is found and TimeStamp is not zero,
105 then TimeStamp is added to the record as the end time.
106 If the record is found and TimeStamp is zero, then this function reads
107 the current time stamp and adds that time stamp value to the record as the end time.
108 If this function is called multiple times for the same record, then the end time is overwritten.
110 @param Handle Pointer to environment specific context used
111 to identify the component being measured.
112 @param Token Pointer to a Null-terminated ASCII string
113 that identifies the component being measured.
114 @param Module Pointer to a Null-terminated ASCII string
115 that identifies the module being measured.
116 @param TimeStamp 64-bit time stamp.
118 @retval RETURN_SUCCESS The end of the measurement was recorded.
119 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
124 EndPerformanceMeasurement (
125 IN CONST VOID
*Handle
, OPTIONAL
126 IN CONST CHAR8
*Token
, OPTIONAL
127 IN CONST CHAR8
*Module
, OPTIONAL
133 Status
= GetPerformanceProtocol ();
134 if (EFI_ERROR (Status
)) {
135 return RETURN_NOT_FOUND
;
138 Status
= mPerformance
->EndGauge (Handle
, Token
, Module
, TimeStamp
);
140 return (RETURN_STATUS
) Status
;
144 Attempts to retrieve a performance measurement log entry from the performance measurement log.
146 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
147 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
148 and the key for the second entry in the log is returned. If the performance log is empty,
149 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
150 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
151 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
152 retrieved and an implementation specific non-zero key value that specifies the end of the performance
153 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
154 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
155 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
156 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
157 If Handle is NULL, then ASSERT().
158 If Token is NULL, then ASSERT().
159 If Module is NULL, then ASSERT().
160 If StartTimeStamp is NULL, then ASSERT().
161 If EndTimeStamp is NULL, then ASSERT().
163 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
164 0, then the first performance measurement log entry is retrieved.
165 On exit, the key of the next performance lof entry entry.
166 @param Handle Pointer to environment specific context used to identify the component
168 @param Token Pointer to a Null-terminated ASCII string that identifies the component
170 @param Module Pointer to a Null-terminated ASCII string that identifies the module
172 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
174 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
177 @return The key for the next performance log entry (in general case).
182 GetPerformanceMeasurement (
183 IN UINTN LogEntryKey
,
184 OUT CONST VOID
**Handle
,
185 OUT CONST CHAR8
**Token
,
186 OUT CONST CHAR8
**Module
,
187 OUT UINT64
*StartTimeStamp
,
188 OUT UINT64
*EndTimeStamp
192 GAUGE_DATA_ENTRY
*GaugeData
;
194 ASSERT (Handle
!= NULL
);
195 ASSERT (Token
!= NULL
);
196 ASSERT (Module
!= NULL
);
197 ASSERT (StartTimeStamp
!= NULL
);
198 ASSERT (EndTimeStamp
!= NULL
);
200 Status
= GetPerformanceProtocol ();
201 if (EFI_ERROR (Status
)) {
205 Status
= mPerformance
->GetGauge (LogEntryKey
++, &GaugeData
);
208 // Make sure that LogEntryKey is a valid log entry key,
210 ASSERT (Status
!= EFI_INVALID_PARAMETER
);
212 if (EFI_ERROR (Status
)) {
214 // The LogEntryKey is the last entry (equals to the total entry number).
219 ASSERT (GaugeData
!= NULL
);
221 *Handle
= (VOID
*) (UINTN
) GaugeData
->Handle
;
222 *Token
= GaugeData
->Token
;
223 *Module
= GaugeData
->Module
;
224 *StartTimeStamp
= GaugeData
->StartTimeStamp
;
225 *EndTimeStamp
= GaugeData
->EndTimeStamp
;
231 Returns TRUE if the performance measurement macros are enabled.
233 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
234 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
236 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
237 PcdPerformanceLibraryPropertyMask is set.
238 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
239 PcdPerformanceLibraryPropertyMask is clear.
244 PerformanceMeasurementEnabled (
248 return ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);