4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Protocol/Performance.h>
20 #include <Library/PerformanceLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/PcdLib.h>
25 STATIC PERFORMANCE_PROTOCOL
*mPerformance
= NULL
;
28 The constructor function caches the pointer to Performance protocol.
30 The constructor function locates Performance protocol from protocol database.
31 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
33 @retval EFI_SUCCESS Performance protocol is successfully located.
34 @retval Other Performance protocol is not located to log performance.
39 GetPerformanceProtocol (
44 PERFORMANCE_PROTOCOL
*Performance
;
46 if (mPerformance
!= NULL
) {
50 Status
= gBS
->LocateProtocol (&gPerformanceProtocolGuid
, NULL
, (VOID
**) &Performance
);
51 if (!EFI_ERROR (Status
)) {
52 ASSERT (Performance
!= NULL
);
54 // Cache performance protocol.
56 mPerformance
= Performance
;
63 Creates a record for the beginning of a performance measurement.
65 Creates a record that contains the Handle, Token, and Module.
66 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
67 If TimeStamp is zero, then this function reads the current time stamp
68 and adds that time stamp value to the record as the start time.
70 @param Handle Pointer to environment specific context used
71 to identify the component being measured.
72 @param Token Pointer to a Null-terminated ASCII string
73 that identifies the component being measured.
74 @param Module Pointer to a Null-terminated ASCII string
75 that identifies the module being measured.
76 @param TimeStamp 64-bit time stamp.
78 @retval RETURN_SUCCESS The start of the measurement was recorded.
79 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
84 StartPerformanceMeasurement (
85 IN CONST VOID
*Handle
, OPTIONAL
86 IN CONST CHAR8
*Token
, OPTIONAL
87 IN CONST CHAR8
*Module
, OPTIONAL
93 Status
= GetPerformanceProtocol ();
94 if (EFI_ERROR (Status
)) {
95 return RETURN_OUT_OF_RESOURCES
;
98 Status
= mPerformance
->StartGauge (Handle
, Token
, Module
, TimeStamp
);
100 return (RETURN_STATUS
) Status
;
104 Fills in the end time of a performance measurement.
106 Looks up the record that matches Handle, Token, and Module.
107 If the record can not be found then return RETURN_NOT_FOUND.
108 If the record is found and TimeStamp is not zero,
109 then TimeStamp is added to the record as the end time.
110 If the record is found and TimeStamp is zero, then this function reads
111 the current time stamp and adds that time stamp value to the record as the end time.
112 If this function is called multiple times for the same record, then the end time is overwritten.
114 @param Handle Pointer to environment specific context used
115 to identify the component being measured.
116 @param Token Pointer to a Null-terminated ASCII string
117 that identifies the component being measured.
118 @param Module Pointer to a Null-terminated ASCII string
119 that identifies the module being measured.
120 @param TimeStamp 64-bit time stamp.
122 @retval RETURN_SUCCESS The end of the measurement was recorded.
123 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
128 EndPerformanceMeasurement (
129 IN CONST VOID
*Handle
, OPTIONAL
130 IN CONST CHAR8
*Token
, OPTIONAL
131 IN CONST CHAR8
*Module
, OPTIONAL
137 Status
= GetPerformanceProtocol ();
138 if (EFI_ERROR (Status
)) {
139 return RETURN_NOT_FOUND
;
142 Status
= mPerformance
->EndGauge (Handle
, Token
, Module
, TimeStamp
);
144 return (RETURN_STATUS
) Status
;
148 Attempts to retrieve a performance measurement log entry from the performance measurement log.
150 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
151 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
152 and the key for the second entry in the log is returned. If the performance log is empty,
153 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
154 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
155 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
156 retrieved and an implementation specific non-zero key value that specifies the end of the performance
157 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
158 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
159 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
160 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
161 If Handle is NULL, then ASSERT().
162 If Token is NULL, then ASSERT().
163 If Module is NULL, then ASSERT().
164 If StartTimeStamp is NULL, then ASSERT().
165 If EndTimeStamp is NULL, then ASSERT().
167 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
168 0, then the first performance measurement log entry is retrieved.
169 On exit, the key of the next performance lof entry entry.
170 @param Handle Pointer to environment specific context used to identify the component
172 @param Token Pointer to a Null-terminated ASCII string that identifies the component
174 @param Module Pointer to a Null-terminated ASCII string that identifies the module
176 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
178 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
181 @return The key for the next performance log entry (in general case).
186 GetPerformanceMeasurement (
187 IN UINTN LogEntryKey
,
188 OUT CONST VOID
**Handle
,
189 OUT CONST CHAR8
**Token
,
190 OUT CONST CHAR8
**Module
,
191 OUT UINT64
*StartTimeStamp
,
192 OUT UINT64
*EndTimeStamp
196 GAUGE_DATA_ENTRY
*GaugeData
;
198 ASSERT (Handle
!= NULL
);
199 ASSERT (Token
!= NULL
);
200 ASSERT (Module
!= NULL
);
201 ASSERT (StartTimeStamp
!= NULL
);
202 ASSERT (EndTimeStamp
!= NULL
);
204 Status
= GetPerformanceProtocol ();
205 if (EFI_ERROR (Status
)) {
209 Status
= mPerformance
->GetGauge (LogEntryKey
++, &GaugeData
);
212 // Make sure that LogEntryKey is a valid log entry key,
214 ASSERT (Status
!= EFI_INVALID_PARAMETER
);
216 if (EFI_ERROR (Status
)) {
218 // The LogEntryKey is the last entry (equals to the total entry number).
223 ASSERT (GaugeData
!= NULL
);
225 *Handle
= (VOID
*) (UINTN
) GaugeData
->Handle
;
226 *Token
= GaugeData
->Token
;
227 *Module
= GaugeData
->Module
;
228 *StartTimeStamp
= GaugeData
->StartTimeStamp
;
229 *EndTimeStamp
= GaugeData
->EndTimeStamp
;
235 Returns TRUE if the performance measurement macros are enabled.
237 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
238 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
240 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
241 PcdPerformanceLibraryPropertyMask is set.
242 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
243 PcdPerformanceLibraryPropertyMask is clear.
248 PerformanceMeasurementEnabled (
252 return (BOOLEAN
) ((PcdGet8(PcdPerformanceLibraryPropertyMask
) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED
) != 0);