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