]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/PerformanceLib.h
Update function comments to remove confused description on PerformanceLib EndPerforma...
[mirror_edk2.git] / MdePkg / Include / Library / PerformanceLib.h
1 /** @file
2 Provides services to log the execution times and retrieve them later.
3
4 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
5 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
9
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.
12
13 **/
14
15 #ifndef __PERFORMANCE_LIB_H__
16 #define __PERFORMANCE_LIB_H__
17
18 ///
19 /// Performance library propery mask bits
20 ///
21 #define PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED 0x00000001
22
23 /**
24 Creates a record for the beginning of a performance measurement.
25
26 Creates a record that contains the Handle, Token, and Module.
27 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
28 If TimeStamp is zero, then this function reads the current time stamp
29 and adds that time stamp value to the record as the start time.
30
31 @param Handle Pointer to environment specific context used
32 to identify the component being measured.
33 @param Token Pointer to a Null-terminated ASCII string
34 that identifies the component being measured.
35 @param Module Pointer to a Null-terminated ASCII string
36 that identifies the module being measured.
37 @param TimeStamp 64-bit time stamp.
38
39 @retval RETURN_SUCCESS The start of the measurement was recorded.
40 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
41 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.
42
43 **/
44 RETURN_STATUS
45 EFIAPI
46 StartPerformanceMeasurement (
47 IN CONST VOID *Handle, OPTIONAL
48 IN CONST CHAR8 *Token, OPTIONAL
49 IN CONST CHAR8 *Module, OPTIONAL
50 IN UINT64 TimeStamp
51 );
52
53 /**
54 Fills in the end time of a performance measurement.
55
56 Looks up the record that matches Handle, Token, and Module.
57 If the record can not be found then return RETURN_NOT_FOUND.
58 If the record is found and TimeStamp is not zero,
59 then TimeStamp is added to the record as the end time.
60 If the record is found and TimeStamp is zero, then this function reads
61 the current time stamp and adds that time stamp value to the record as the end time.
62
63 @param Handle Pointer to environment specific context used
64 to identify the component being measured.
65 @param Token Pointer to a Null-terminated ASCII string
66 that identifies the component being measured.
67 @param Module Pointer to a Null-terminated ASCII string
68 that identifies the module being measured.
69 @param TimeStamp 64-bit time stamp.
70
71 @retval RETURN_SUCCESS The end of the measurement was recorded.
72 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
73 @retval RETURN_DEVICE_ERROR A device error reading the time stamp.
74
75 **/
76 RETURN_STATUS
77 EFIAPI
78 EndPerformanceMeasurement (
79 IN CONST VOID *Handle, OPTIONAL
80 IN CONST CHAR8 *Token, OPTIONAL
81 IN CONST CHAR8 *Module, OPTIONAL
82 IN UINT64 TimeStamp
83 );
84
85 /**
86 Attempts to retrieve a performance measurement log entry from the performance measurement log.
87
88 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
89 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
90 and the key for the second entry in the log is returned. If the performance log is empty,
91 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
92 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
93 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
94 retrieved and an implementation specific non-zero key value that specifies the end of the performance
95 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
96 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
97 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
98 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
99 If Handle is NULL, then ASSERT().
100 If Token is NULL, then ASSERT().
101 If Module is NULL, then ASSERT().
102 If StartTimeStamp is NULL, then ASSERT().
103 If EndTimeStamp is NULL, then ASSERT().
104
105 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
106 0, then the first performance measurement log entry is retrieved.
107 On exit, the key of the next performance lof entry entry.
108 @param Handle Pointer to environment specific context used to identify the component
109 being measured.
110 @param Token Pointer to a Null-terminated ASCII string that identifies the component
111 being measured.
112 @param Module Pointer to a Null-terminated ASCII string that identifies the module
113 being measured.
114 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
115 was started.
116 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
117 was ended.
118
119 @return The key for the next performance log entry (in general case).
120
121 **/
122 UINTN
123 EFIAPI
124 GetPerformanceMeasurement (
125 IN UINTN LogEntryKey,
126 OUT CONST VOID **Handle,
127 OUT CONST CHAR8 **Token,
128 OUT CONST CHAR8 **Module,
129 OUT UINT64 *StartTimeStamp,
130 OUT UINT64 *EndTimeStamp
131 );
132
133 /**
134 Returns TRUE if the performance measurement macros are enabled.
135
136 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
137 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
138
139 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
140 PcdPerformanceLibraryPropertyMask is set.
141 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
142 PcdPerformanceLibraryPropertyMask is clear.
143
144 **/
145 BOOLEAN
146 EFIAPI
147 PerformanceMeasurementEnabled (
148 VOID
149 );
150
151 /**
152 Macro that calls EndPerformanceMeasurement().
153
154 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
155 then EndPerformanceMeasurement() is called.
156
157 **/
158 #define PERF_END(Handle, Token, Module, TimeStamp) \
159 do { \
160 if (PerformanceMeasurementEnabled ()) { \
161 EndPerformanceMeasurement (Handle, Token, Module, TimeStamp); \
162 } \
163 } while (FALSE)
164
165 /**
166 Macro that calls StartPerformanceMeasurement().
167
168 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
169 then StartPerformanceMeasurement() is called.
170
171 **/
172 #define PERF_START(Handle, Token, Module, TimeStamp) \
173 do { \
174 if (PerformanceMeasurementEnabled ()) { \
175 StartPerformanceMeasurement (Handle, Token, Module, TimeStamp); \
176 } \
177 } while (FALSE)
178
179 /**
180 Macro that marks the beginning of performance measurement source code.
181
182 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
183 then this macro marks the beginning of source code that is included in a module.
184 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.
185
186 **/
187 #define PERF_CODE_BEGIN() do { if (PerformanceMeasurementEnabled ()) { UINT8 __PerformanceCodeLocal
188
189 /**
190 Macro that marks the end of performance measurement source code.
191
192 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
193 then this macro marks the end of source code that is included in a module.
194 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.
195
196 **/
197 #define PERF_CODE_END() __PerformanceCodeLocal = 0; __PerformanceCodeLocal++; } } while (FALSE)
198
199 /**
200 Macro that declares a section of performance measurement source code.
201
202 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
203 then the source code specified by Expression is included in a module.
204 Otherwise, the source specified by Expression is not included in a module.
205
206 @param Expression Performance measurement source code to include in a module.
207
208 **/
209 #define PERF_CODE(Expression) \
210 PERF_CODE_BEGIN (); \
211 Expression \
212 PERF_CODE_END ()
213
214
215 #endif