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.
36 GetPerformanceProtocol (
41 PERFORMANCE_PROTOCOL
*Performance
;
43 if (mPerformance
!= NULL
) {
47 Status
= gBS
->LocateProtocol (&gPerformanceProtocolGuid
, NULL
, (VOID
**) &Performance
);
48 if (!EFI_ERROR (Status
)) {
49 ASSERT (Performance
!= NULL
);
51 // Cache performance protocol.
53 mPerformance
= Performance
;
60 Creates a record for the beginning of a performance measurement.
62 Creates a record that contains the Handle, Token, and Module.
63 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
64 If TimeStamp is zero, then this function reads the current time stamp
65 and adds that time stamp value to the record as the start time.
67 @param Handle Pointer to environment specific context used
68 to identify the component being measured.
69 @param Token Pointer to a Null-terminated ASCII string
70 that identifies the component being measured.
71 @param Module Pointer to a Null-terminated ASCII string
72 that identifies the module being measured.
73 @param TimeStamp 64-bit time stamp.
75 @retval RETURN_SUCCESS The start of the measurement was recorded.
76 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
81 StartPerformanceMeasurement (
82 IN CONST VOID
*Handle
, OPTIONAL
83 IN CONST CHAR8
*Token
, OPTIONAL
84 IN CONST CHAR8
*Module
, OPTIONAL
90 Status
= GetPerformanceProtocol ();
91 if (EFI_ERROR (Status
)) {
92 return RETURN_OUT_OF_RESOURCES
;
95 Status
= mPerformance
->StartGauge (Handle
, Token
, Module
, TimeStamp
);
97 return (RETURN_STATUS
) Status
;
101 Fills in the end time of a performance measurement.
103 Looks up the record that matches Handle, Token, and Module.
104 If the record can not be found then return RETURN_NOT_FOUND.
105 If the record is found and TimeStamp is not zero,
106 then TimeStamp is added to the record as the end time.
107 If the record is found and TimeStamp is zero, then this function reads
108 the current time stamp and adds that time stamp value to the record as the end time.
109 If this function is called multiple times for the same record, then the end time is overwritten.
111 @param Handle Pointer to environment specific context used
112 to identify the component being measured.
113 @param Token Pointer to a Null-terminated ASCII string
114 that identifies the component being measured.
115 @param Module Pointer to a Null-terminated ASCII string
116 that identifies the module being measured.
117 @param TimeStamp 64-bit time stamp.
119 @retval RETURN_SUCCESS The end of the measurement was recorded.
120 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
125 EndPerformanceMeasurement (
126 IN CONST VOID
*Handle
, OPTIONAL
127 IN CONST CHAR8
*Token
, OPTIONAL
128 IN CONST CHAR8
*Module
, OPTIONAL
134 Status
= GetPerformanceProtocol ();
135 if (EFI_ERROR (Status
)) {
136 return RETURN_NOT_FOUND
;
139 Status
= mPerformance
->EndGauge (Handle
, Token
, Module
, TimeStamp
);
141 return (RETURN_STATUS
) Status
;
145 Attempts to retrieve a performance measurement log entry from the performance measurement log.
147 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
148 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
149 and the key for the second entry in the log is returned. If the performance log is empty,
150 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
151 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
152 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
153 retrieved and an implementation specific non-zero key value that specifies the end of the performance
154 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
155 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
156 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
157 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
158 If Handle is NULL, then ASSERT().
159 If Token is NULL, then ASSERT().
160 If Module is NULL, then ASSERT().
161 If StartTimeStamp is NULL, then ASSERT().
162 If EndTimeStamp is NULL, then ASSERT().
164 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
165 0, then the first performance measurement log entry is retrieved.
166 On exit, the key of the next performance lof entry entry.
167 @param Handle Pointer to environment specific context used to identify the component
169 @param Token Pointer to a Null-terminated ASCII string that identifies the component
171 @param Module Pointer to a Null-terminated ASCII string that identifies the module
173 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
175 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
178 @return The key for the next performance log entry (in general case).
183 GetPerformanceMeasurement (
184 IN UINTN LogEntryKey
,
185 OUT CONST VOID
**Handle
,
186 OUT CONST CHAR8
**Token
,
187 OUT CONST CHAR8
**Module
,
188 OUT UINT64
*StartTimeStamp
,
189 OUT UINT64
*EndTimeStamp
193 GAUGE_DATA_ENTRY
*GaugeData
;
195 ASSERT (Handle
!= NULL
);
196 ASSERT (Token
!= NULL
);
197 ASSERT (Module
!= NULL
);
198 ASSERT (StartTimeStamp
!= NULL
);
199 ASSERT (EndTimeStamp
!= NULL
);
201 Status
= GetPerformanceProtocol ();
202 if (EFI_ERROR (Status
)) {
206 Status
= mPerformance
->GetGauge (LogEntryKey
++, &GaugeData
);
209 // Make sure that LogEntryKey is a valid log entry key,
211 ASSERT (Status
!= EFI_INVALID_PARAMETER
);
213 if (EFI_ERROR (Status
)) {
215 // The LogEntryKey is the last entry (equals to the total entry number).
220 ASSERT (GaugeData
!= NULL
);
222 *Handle
= (VOID
*) (UINTN
) GaugeData
->Handle
;
223 *Token
= GaugeData
->Token
;
224 *Module
= GaugeData
->Module
;
225 *StartTimeStamp
= GaugeData
->StartTimeStamp
;
226 *EndTimeStamp
= GaugeData
->EndTimeStamp
;
232 Returns TRUE if the performance measurement macros are enabled.
234 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
235 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
237 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
238 PcdPerformanceLibraryPropertyMask is set.
239 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
240 PcdPerformanceLibraryPropertyMask is clear.
245 PerformanceMeasurementEnabled (
249 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);