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 Retrieves a previously logged performance measurement.
130 Looks up the record that matches Handle, Token, and Module.
131 If the record can not be found then return RETURN_NOT_FOUND.
132 If the record is found then the start of the measurement is returned in StartTimeStamp,
133 and the end of the measurement is returned in EndTimeStamp.
135 @param LogEntryKey The key for the previous performance measurement log entry.
136 If 0, then the first performance measurement log entry is retrieved.
137 @param Handle Pointer to environment specific context used
138 to identify the component being measured.
139 @param Token Pointer to a Null-terminated ASCII string
140 that identifies the component being measured.
141 @param Module Pointer to a Null-terminated ASCII string
142 that identifies the module being measured.
143 @param StartTimeStamp The 64-bit time stamp that was recorded when the measurement was started.
144 @param EndTimeStamp The 64-bit time stamp that was recorded when the measurement was ended.
146 @return The key for the current performance log entry.
151 GetPerformanceMeasurement (
153 OUT CONST VOID
**Handle
,
154 OUT CONST CHAR8
**Token
,
155 OUT CONST CHAR8
**Module
,
156 OUT UINT64
*StartTimeStamp
,
157 OUT UINT64
*EndTimeStamp
161 GAUGE_DATA_ENTRY
*GaugeData
;
163 ASSERT (Handle
!= NULL
);
164 ASSERT (Token
!= NULL
);
165 ASSERT (Module
!= NULL
);
166 ASSERT (StartTimeStamp
!= NULL
);
167 ASSERT (EndTimeStamp
!= NULL
);
169 Status
= mPerformance
->GetGauge (LogEntryKey
++, &GaugeData
);
172 // Make sure that LogEntryKey is a valid log entry key,
174 ASSERT (Status
!= EFI_INVALID_PARAMETER
);
176 if (EFI_ERROR (Status
)) {
178 // The LogEntryKey is the last entry (equals to the total entry number).
183 ASSERT (GaugeData
!= NULL
);
185 *Handle
= (VOID
*) (UINTN
) GaugeData
->Handle
;
186 *Token
= GaugeData
->Token
;
187 *Module
= GaugeData
->Module
;
188 *StartTimeStamp
= GaugeData
->StartTimeStamp
;
189 *EndTimeStamp
= GaugeData
->EndTimeStamp
;
195 Returns TRUE if the performance measurement macros are enabled.
197 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
198 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
200 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
201 PcdPerformanceLibraryPropertyMask is set.
202 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
203 PcdPerformanceLibraryPropertyMask is clear.
208 PerformanceMeasurementEnabled (
212 return ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);