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