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