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.
23 // The package level header files this module uses
27 // The protocols, PPI and GUID defintions for this module
29 #include <Protocol/Performance.h>
31 // The Library classes this module consumes
33 #include <Library/PerformanceLib.h>
34 #include <Library/DebugLib.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/PcdLib.h>
38 STATIC PERFORMANCE_PROTOCOL
*mPerformance
= NULL
;
41 The constructor function caches the pointer to Performance protocol.
43 The constructor function locates Performance protocol from protocol database.
44 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
46 @retval EFI_SUCCESS Performance protocol is successfully located.
47 @retval Other Performance protocol is not located to log performance.
52 GetPerformanceProtocol (
57 PERFORMANCE_PROTOCOL
*Performance
;
59 if (mPerformance
!= NULL
) {
63 Status
= gBS
->LocateProtocol (&gPerformanceProtocolGuid
, NULL
, (VOID
**) &Performance
);
64 if (!EFI_ERROR (Status
)) {
65 ASSERT (Performance
!= NULL
);
67 // Cache performance protocol.
69 mPerformance
= Performance
;
76 Creates a record for the beginning of a performance measurement.
78 Creates a record that contains the Handle, Token, and Module.
79 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
80 If TimeStamp is zero, then this function reads the current time stamp
81 and adds that time stamp value to the record as the start time.
83 @param Handle Pointer to environment specific context used
84 to identify the component being measured.
85 @param Token Pointer to a Null-terminated ASCII string
86 that identifies the component being measured.
87 @param Module Pointer to a Null-terminated ASCII string
88 that identifies the module being measured.
89 @param TimeStamp 64-bit time stamp.
91 @retval RETURN_SUCCESS The start of the measurement was recorded.
92 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
97 StartPerformanceMeasurement (
98 IN CONST VOID
*Handle
, OPTIONAL
99 IN CONST CHAR8
*Token
, OPTIONAL
100 IN CONST CHAR8
*Module
, OPTIONAL
106 Status
= GetPerformanceProtocol ();
107 if (EFI_ERROR (Status
)) {
108 return RETURN_OUT_OF_RESOURCES
;
111 Status
= mPerformance
->StartGauge (Handle
, Token
, Module
, TimeStamp
);
113 return (RETURN_STATUS
) Status
;
117 Fills in the end time of a performance measurement.
119 Looks up the record that matches Handle, Token, and Module.
120 If the record can not be found then return RETURN_NOT_FOUND.
121 If the record is found and TimeStamp is not zero,
122 then TimeStamp is added to the record as the end time.
123 If the record is found and TimeStamp is zero, then this function reads
124 the current time stamp and adds that time stamp value to the record as the end time.
125 If this function is called multiple times for the same record, then the end time is overwritten.
127 @param Handle Pointer to environment specific context used
128 to identify the component being measured.
129 @param Token Pointer to a Null-terminated ASCII string
130 that identifies the component being measured.
131 @param Module Pointer to a Null-terminated ASCII string
132 that identifies the module being measured.
133 @param TimeStamp 64-bit time stamp.
135 @retval RETURN_SUCCESS The end of the measurement was recorded.
136 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
141 EndPerformanceMeasurement (
142 IN CONST VOID
*Handle
, OPTIONAL
143 IN CONST CHAR8
*Token
, OPTIONAL
144 IN CONST CHAR8
*Module
, OPTIONAL
150 Status
= GetPerformanceProtocol ();
151 if (EFI_ERROR (Status
)) {
152 return RETURN_NOT_FOUND
;
155 Status
= mPerformance
->EndGauge (Handle
, Token
, Module
, TimeStamp
);
157 return (RETURN_STATUS
) Status
;
161 Attempts to retrieve a performance measurement log entry from the performance measurement log.
163 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
164 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
165 and the key for the second entry in the log is returned. If the performance log is empty,
166 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
167 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
168 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
169 retrieved and an implementation specific non-zero key value that specifies the end of the performance
170 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
171 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
172 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
173 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
174 If Handle is NULL, then ASSERT().
175 If Token is NULL, then ASSERT().
176 If Module is NULL, then ASSERT().
177 If StartTimeStamp is NULL, then ASSERT().
178 If EndTimeStamp is NULL, then ASSERT().
180 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
181 0, then the first performance measurement log entry is retrieved.
182 On exit, the key of the next performance lof entry entry.
183 @param Handle Pointer to environment specific context used to identify the component
185 @param Token Pointer to a Null-terminated ASCII string that identifies the component
187 @param Module Pointer to a Null-terminated ASCII string that identifies the module
189 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
191 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
194 @return The key for the next performance log entry (in general case).
199 GetPerformanceMeasurement (
200 IN UINTN LogEntryKey
,
201 OUT CONST VOID
**Handle
,
202 OUT CONST CHAR8
**Token
,
203 OUT CONST CHAR8
**Module
,
204 OUT UINT64
*StartTimeStamp
,
205 OUT UINT64
*EndTimeStamp
209 GAUGE_DATA_ENTRY
*GaugeData
;
211 ASSERT (Handle
!= NULL
);
212 ASSERT (Token
!= NULL
);
213 ASSERT (Module
!= NULL
);
214 ASSERT (StartTimeStamp
!= NULL
);
215 ASSERT (EndTimeStamp
!= NULL
);
217 Status
= GetPerformanceProtocol ();
218 if (EFI_ERROR (Status
)) {
222 Status
= mPerformance
->GetGauge (LogEntryKey
++, &GaugeData
);
225 // Make sure that LogEntryKey is a valid log entry key,
227 ASSERT (Status
!= EFI_INVALID_PARAMETER
);
229 if (EFI_ERROR (Status
)) {
231 // The LogEntryKey is the last entry (equals to the total entry number).
236 ASSERT (GaugeData
!= NULL
);
238 *Handle
= (VOID
*) (UINTN
) GaugeData
->Handle
;
239 *Token
= GaugeData
->Token
;
240 *Module
= GaugeData
->Module
;
241 *StartTimeStamp
= GaugeData
->StartTimeStamp
;
242 *EndTimeStamp
= GaugeData
->EndTimeStamp
;
248 Returns TRUE if the performance measurement macros are enabled.
250 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
251 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
253 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
254 PcdPerformanceLibraryPropertyMask is set.
255 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
256 PcdPerformanceLibraryPropertyMask is clear.
261 PerformanceMeasurementEnabled (
265 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);