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