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 @param ImageHandle The firmware allocated handle for the EFI image.
31 @param SystemTable A pointer to the EFI System Table.
33 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
38 PerformanceLibConstructor (
39 IN EFI_HANDLE ImageHandle
,
40 IN EFI_SYSTEM_TABLE
*SystemTable
45 Status
= gBS
->LocateProtocol (&gPerformanceProtocolGuid
, NULL
, (VOID
**) &mPerformance
);
46 ASSERT_EFI_ERROR (Status
);
47 ASSERT (mPerformance
!= NULL
);
53 Creates a record for the beginning of a performance measurement.
55 Creates a record that contains the Handle, Token, and Module.
56 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
57 If TimeStamp is zero, then this function reads the current time stamp
58 and adds that time stamp value to the record as the start time.
60 @param Handle Pointer to environment specific context used
61 to identify the component being measured.
62 @param Token Pointer to a Null-terminated ASCII string
63 that identifies the component being measured.
64 @param Module Pointer to a Null-terminated ASCII string
65 that identifies the module being measured.
66 @param TimeStamp 64-bit time stamp.
68 @retval RETURN_SUCCESS The start of the measurement was recorded.
69 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
74 StartPerformanceMeasurement (
75 IN CONST VOID
*Handle
, OPTIONAL
76 IN CONST CHAR8
*Token
, OPTIONAL
77 IN CONST CHAR8
*Module
, OPTIONAL
83 Status
= mPerformance
->StartGauge (Handle
, Token
, Module
, TimeStamp
);
85 return (RETURN_STATUS
) Status
;
89 Fills in the end time of a performance measurement.
91 Looks up the record that matches Handle, Token, and Module.
92 If the record can not be found then return RETURN_NOT_FOUND.
93 If the record is found and TimeStamp is not zero,
94 then TimeStamp is added to the record as the end time.
95 If the record is found and TimeStamp is zero, then this function reads
96 the current time stamp and adds that time stamp value to the record as the end time.
97 If this function is called multiple times for the same record, then the end time is overwritten.
99 @param Handle Pointer to environment specific context used
100 to identify the component being measured.
101 @param Token Pointer to a Null-terminated ASCII string
102 that identifies the component being measured.
103 @param Module Pointer to a Null-terminated ASCII string
104 that identifies the module being measured.
105 @param TimeStamp 64-bit time stamp.
107 @retval RETURN_SUCCESS The end of the measurement was recorded.
108 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
113 EndPerformanceMeasurement (
114 IN CONST VOID
*Handle
, OPTIONAL
115 IN CONST CHAR8
*Token
, OPTIONAL
116 IN CONST CHAR8
*Module
, OPTIONAL
122 Status
= mPerformance
->EndGauge (Handle
, Token
, Module
, TimeStamp
);
124 return (RETURN_STATUS
) Status
;
128 Attempts to retrieve a performance measurement log entry from the performance measurement log.
130 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
131 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
132 and the key for the second entry in the log is returned. If the performance log is empty,
133 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
134 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
135 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
136 retrieved and an implementation specific non-zero key value that specifies the end of the performance
137 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
138 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
139 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
140 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
141 If Handle is NULL, then ASSERT().
142 If Token is NULL, then ASSERT().
143 If Module is NULL, then ASSERT().
144 If StartTimeStamp is NULL, then ASSERT().
145 If EndTimeStamp is NULL, then ASSERT().
147 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
148 0, then the first performance measurement log entry is retrieved.
149 On exit, the key of the next performance lof entry entry.
150 @param Handle Pointer to environment specific context used to identify the component
152 @param Token Pointer to a Null-terminated ASCII string that identifies the component
154 @param Module Pointer to a Null-terminated ASCII string that identifies the module
156 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
158 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
161 @return The key for the next performance log entry (in general case).
166 GetPerformanceMeasurement (
167 IN UINTN LogEntryKey
,
168 OUT CONST VOID
**Handle
,
169 OUT CONST CHAR8
**Token
,
170 OUT CONST CHAR8
**Module
,
171 OUT UINT64
*StartTimeStamp
,
172 OUT UINT64
*EndTimeStamp
176 GAUGE_DATA_ENTRY
*GaugeData
;
178 ASSERT (Handle
!= NULL
);
179 ASSERT (Token
!= NULL
);
180 ASSERT (Module
!= NULL
);
181 ASSERT (StartTimeStamp
!= NULL
);
182 ASSERT (EndTimeStamp
!= NULL
);
184 Status
= mPerformance
->GetGauge (LogEntryKey
++, &GaugeData
);
187 // Make sure that LogEntryKey is a valid log entry key,
189 ASSERT (Status
!= EFI_INVALID_PARAMETER
);
191 if (EFI_ERROR (Status
)) {
193 // The LogEntryKey is the last entry (equals to the total entry number).
198 ASSERT (GaugeData
!= NULL
);
200 *Handle
= (VOID
*) (UINTN
) GaugeData
->Handle
;
201 *Token
= GaugeData
->Token
;
202 *Module
= GaugeData
->Module
;
203 *StartTimeStamp
= GaugeData
->StartTimeStamp
;
204 *EndTimeStamp
= GaugeData
->EndTimeStamp
;
210 Returns TRUE if the performance measurement macros are enabled.
212 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
213 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
215 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
216 PcdPerformanceLibraryPropertyMask is set.
217 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
218 PcdPerformanceLibraryPropertyMask is clear.
223 PerformanceMeasurementEnabled (
227 return ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);