]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/PerformanceLib.h
36564095e9ec5cd9ec7e78cd11d43cde6e528c2b
[mirror_edk2.git] / MdePkg / Include / Library / PerformanceLib.h
1 /** @file
2 Library that provides services to measure module execution performance
3
4 Copyright (c) 2004, 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 Retrieves a previously logged performance measurement.
88
89 Looks up the record that matches Handle, Token, and Module.
90 If the record can not be found then return RETURN_NOT_FOUND.
91 If the record is found then the start of the measurement is returned in StartTimeStamp,
92 and the end of the measurement is returned in EndTimeStamp.
93
94 @param LogEntryKey The key for the previous performance measurement log entry.
95 If 0, then the first performance measurement log entry is retrieved.
96 @param Handle Pointer to environment specific context used
97 to identify the component being measured.
98 @param Token Pointer to a Null-terminated ASCII string
99 that identifies the component being measured.
100 @param Module Pointer to a Null-terminated ASCII string
101 that identifies the module being measured.
102 @param StartTimeStamp The 64-bit time stamp that was recorded when the measurement was started.
103 @param EndTimeStamp The 64-bit time stamp that was recorded when the measurement was ended.
104
105 @return The key for the current performance log entry.
106
107 **/
108 UINTN
109 EFIAPI
110 GetPerformanceMeasurement (
111 UINTN LogEntryKey,
112 OUT CONST VOID **Handle,
113 OUT CONST CHAR8 **Token,
114 OUT CONST CHAR8 **Module,
115 OUT UINT64 *StartTimeStamp,
116 OUT UINT64 *EndTimeStamp
117 );
118
119 /**
120 Returns TRUE if the performance measurement macros are enabled.
121
122 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
123 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
124
125 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
126 PcdPerformanceLibraryPropertyMask is set.
127 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
128 PcdPerformanceLibraryPropertyMask is clear.
129
130 **/
131 BOOLEAN
132 EFIAPI
133 PerformanceMeasurementEnabled (
134 VOID
135 );
136
137 /**
138 Macro that calls EndPerformanceMeasurement().
139
140 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
141 then EndPerformanceMeasurement() is called.
142
143 **/
144 #define PERF_END(Handle, Token, Module, TimeStamp) \
145 do { \
146 if (PerformanceMeasurementEnabled ()) { \
147 EndPerformanceMeasurement (Handle, Token, Module, TimeStamp); \
148 } \
149 } while (FALSE)
150
151 /**
152 Macro that calls StartPerformanceMeasurement().
153
154 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
155 then StartPerformanceMeasurement() is called.
156
157 **/
158 #define PERF_START(Handle, Token, Module, TimeStamp) \
159 do { \
160 if (PerformanceMeasurementEnabled ()) { \
161 StartPerformanceMeasurement (Handle, Token, Module, TimeStamp); \
162 } \
163 } while (FALSE)
164
165 /**
166 Macro that marks the beginning of performance measurement source code.
167
168 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
169 then this macro marks the beginning of source code that is included in a module.
170 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.
171
172 **/
173 #define PERF_CODE_BEGIN() do { if (PerformanceMeasurementEnabled ()) { UINT8 __PerformanceCodeLocal
174
175 /**
176 Macro that marks the end of performance measurement source code.
177
178 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
179 then this macro marks the end of source code that is included in a module.
180 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.
181
182 **/
183 #define PERF_CODE_END() __PerformanceCodeLocal = 0; } } while (FALSE)
184
185 /**
186 Macro that declares a section of performance measurement source code.
187
188 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
189 then the source code specified by Expression is included in a module.
190 Otherwise, the source specified by Expression is not included in a module.
191
192 @param Expression Performance measurement source code to include in a module.
193
194 **/
195 #define PERF_CODE(Expression) \
196 PERF_CODE_BEGIN (); \
197 Expression \
198 PERF_CODE_END ()
199
200
201 #endif