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