]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Include/Library/PerformanceLib.h
2 Provides services to log the execution times and retrieve them later.
4 Copyright (c) 2006 - 2008 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
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.
15 #ifndef __PERFORMANCE_LIB_H__
16 #define __PERFORMANCE_LIB_H__
19 /// Performance library propery mask bits
21 #define PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED 0x00000001
24 Creates a record for the beginning of a performance measurement.
26 Creates a record that contains the Handle, Token, and Module.
27 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
28 If TimeStamp is zero, then this function reads the current time stamp
29 and adds that time stamp value to the record as the start time.
31 @param Handle Pointer to environment specific context used
32 to identify the component being measured.
33 @param Token Pointer to a Null-terminated ASCII string
34 that identifies the component being measured.
35 @param Module Pointer to a Null-terminated ASCII string
36 that identifies the module being measured.
37 @param TimeStamp 64-bit time stamp.
39 @retval RETURN_SUCCESS The start of the measurement was recorded.
40 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
45 StartPerformanceMeasurement (
46 IN CONST VOID
*Handle
, OPTIONAL
47 IN CONST CHAR8
*Token
, OPTIONAL
48 IN CONST CHAR8
*Module
, OPTIONAL
53 Fills in the end time of a performance measurement.
55 Looks up the record that matches Handle, Token, and Module.
56 If the record can not be found then return RETURN_NOT_FOUND.
57 If the record is found and TimeStamp is not zero,
58 then TimeStamp is added to the record as the end time.
59 If the record is found and TimeStamp is zero, then this function reads
60 the current time stamp and adds that time stamp value to the record as the end time.
61 If this function is called multiple times for the same record, then the end time is overwritten.
63 @param Handle Pointer to environment specific context used
64 to identify the component being measured.
65 @param Token Pointer to a Null-terminated ASCII string
66 that identifies the component being measured.
67 @param Module Pointer to a Null-terminated ASCII string
68 that identifies the module being measured.
69 @param TimeStamp 64-bit time stamp.
71 @retval RETURN_SUCCESS The end of the measurement was recorded.
72 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
77 EndPerformanceMeasurement (
78 IN CONST VOID
*Handle
, OPTIONAL
79 IN CONST CHAR8
*Token
, OPTIONAL
80 IN CONST CHAR8
*Module
, OPTIONAL
85 Attempts to retrieve a performance measurement log entry from the performance measurement log.
87 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
88 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
89 and the key for the second entry in the log is returned. If the performance log is empty,
90 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
91 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
92 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
93 retrieved and an implementation specific non-zero key value that specifies the end of the performance
94 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
95 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
96 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
97 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
98 If Handle is NULL, then ASSERT().
99 If Token is NULL, then ASSERT().
100 If Module is NULL, then ASSERT().
101 If StartTimeStamp is NULL, then ASSERT().
102 If EndTimeStamp is NULL, then ASSERT().
104 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
105 0, then the first performance measurement log entry is retrieved.
106 On exit, the key of the next performance lof entry entry.
107 @param Handle Pointer to environment specific context used to identify the component
109 @param Token Pointer to a Null-terminated ASCII string that identifies the component
111 @param Module Pointer to a Null-terminated ASCII string that identifies the module
113 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
115 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
118 @return The key for the next performance log entry (in general case).
123 GetPerformanceMeasurement (
124 IN UINTN LogEntryKey
,
125 OUT CONST VOID
**Handle
,
126 OUT CONST CHAR8
**Token
,
127 OUT CONST CHAR8
**Module
,
128 OUT UINT64
*StartTimeStamp
,
129 OUT UINT64
*EndTimeStamp
133 Returns TRUE if the performance measurement macros are enabled.
135 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
136 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
138 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
139 PcdPerformanceLibraryPropertyMask is set.
140 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
141 PcdPerformanceLibraryPropertyMask is clear.
146 PerformanceMeasurementEnabled (
151 Macro that calls EndPerformanceMeasurement().
153 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
154 then EndPerformanceMeasurement() is called.
157 #define PERF_END(Handle, Token, Module, TimeStamp) \
159 if (PerformanceMeasurementEnabled ()) { \
160 EndPerformanceMeasurement (Handle, Token, Module, TimeStamp); \
165 Macro that calls StartPerformanceMeasurement().
167 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
168 then StartPerformanceMeasurement() is called.
171 #define PERF_START(Handle, Token, Module, TimeStamp) \
173 if (PerformanceMeasurementEnabled ()) { \
174 StartPerformanceMeasurement (Handle, Token, Module, TimeStamp); \
179 Macro that marks the beginning of performance measurement source code.
181 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
182 then this macro marks the beginning of source code that is included in a module.
183 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.
186 #define PERF_CODE_BEGIN() do { if (PerformanceMeasurementEnabled ()) { UINT8 __PerformanceCodeLocal
189 Macro that marks the end of performance measurement source code.
191 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
192 then this macro marks the end of source code that is included in a module.
193 Otherwise, the source lines between PERF_CODE_BEGIN() and PERF_CODE_END() are not included in a module.
196 #define PERF_CODE_END() __PerformanceCodeLocal = 0; __PerformanceCodeLocal++; } } while (FALSE)
199 Macro that declares a section of performance measurement source code.
201 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
202 then the source code specified by Expression is included in a module.
203 Otherwise, the source specified by Expression is not included in a module.
205 @param Expression Performance measurement source code to include in a module.
208 #define PERF_CODE(Expression) \
209 PERF_CODE_BEGIN (); \