2 Library that provides services to measure module execution performance
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
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.
13 Module Name: PerformanceLib.h
17 #ifndef __PERFORMANCE_LIB_H__
18 #define __PERFORMANCE_LIB_H__
21 // Performance library propery mask bits
23 #define PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED 0x00000001
26 Creates a record for the beginning of a performance measurement.
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.
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.
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.
47 StartPerformanceMeasurement (
48 IN CONST VOID
*Handle
, OPTIONAL
49 IN CONST CHAR8
*Token
, OPTIONAL
50 IN CONST CHAR8
*Module
, OPTIONAL
55 Fills in the end time of a performance measurement.
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.
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.
73 @retval RETURN_SUCCESS The end of the measurement was recorded.
74 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
79 EndPerformanceMeasurement (
80 IN CONST VOID
*Handle
, OPTIONAL
81 IN CONST CHAR8
*Token
, OPTIONAL
82 IN CONST CHAR8
*Module
, OPTIONAL
87 Retrieves a previously logged performance measurement.
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.
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.
105 @return The key for the current performance log entry.
110 GetPerformanceMeasurement (
112 OUT CONST VOID
**Handle
,
113 OUT CONST CHAR8
**Token
,
114 OUT CONST CHAR8
**Module
,
115 OUT UINT64
*StartTimeStamp
,
116 OUT UINT64
*EndTimeStamp
120 Returns TRUE if the performance measurement macros are enabled.
122 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
123 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
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.
133 PerformanceMeasurementEnabled (
138 Macro that calls EndPerformanceMeasurement().
140 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
141 then EndPerformanceMeasurement() is called.
144 #define PERF_END(Handle, Token, Module, TimeStamp) \
146 if (PerformanceMeasurementEnabled ()) { \
147 EndPerformanceMeasurement (Handle, Token, Module, TimeStamp); \
152 Macro that calls StartPerformanceMeasurement().
154 If the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set,
155 then StartPerformanceMeasurement() is called.
158 #define PERF_START(Handle, Token, Module, TimeStamp) \
160 if (PerformanceMeasurementEnabled ()) { \
161 StartPerformanceMeasurement (Handle, Token, Module, TimeStamp); \
166 Macro that marks the beginning of performance measurement source code.
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.
173 #define PERF_CODE_BEGIN() do { if (PerformanceMeasurementEnabled ()) { UINT8 __PerformanceCodeLocal
176 Macro that marks the end of performance measurement source code.
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.
183 #define PERF_CODE_END() __PerformanceCodeLocal = 0; } } while (FALSE)
186 Macro that declares a section of performance measurement source code.
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.
192 @param Expression Performance measurement source code to include in a module.
195 #define PERF_CODE(Expression) \
196 PERF_CODE_BEGIN (); \