]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c
1. UINTN & INTN issue for EBC architecture:
[mirror_edk2.git] / EdkModulePkg / Library / DxePerformanceLib / DxePerformanceLib.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 DxePerformanceLib.c
15
16 Abstract:
17
18 Performance Library
19
20 --*/
21
22 STATIC PERFORMANCE_PROTOCOL *mPerformance = NULL;
23
24 /**
25 The constructor function caches the pointer to Performance protocol.
26
27 The constructor function locates Performance protocol from protocol database.
28 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
29
30 @param ImageHandle The firmware allocated handle for the EFI image.
31 @param SystemTable A pointer to the EFI System Table.
32
33 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
34
35 **/
36 EFI_STATUS
37 EFIAPI
38 PerformanceLibConstructor (
39 IN EFI_HANDLE ImageHandle,
40 IN EFI_SYSTEM_TABLE *SystemTable
41 )
42 {
43 EFI_STATUS Status;
44
45 Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &mPerformance);
46 ASSERT_EFI_ERROR (Status);
47 ASSERT (mPerformance != NULL);
48
49 return Status;
50 }
51
52 /**
53 Creates a record for the beginning of a performance measurement.
54
55 Creates a record that contains the Handle, Token, and Module.
56 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.
57 If TimeStamp is zero, then this function reads the current time stamp
58 and adds that time stamp value to the record as the start time.
59
60 @param Handle Pointer to environment specific context used
61 to identify the component being measured.
62 @param Token Pointer to a Null-terminated ASCII string
63 that identifies the component being measured.
64 @param Module Pointer to a Null-terminated ASCII string
65 that identifies the module being measured.
66 @param TimeStamp 64-bit time stamp.
67
68 @retval RETURN_SUCCESS The start of the measurement was recorded.
69 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.
70
71 **/
72 RETURN_STATUS
73 EFIAPI
74 StartPerformanceMeasurement (
75 IN CONST VOID *Handle, OPTIONAL
76 IN CONST CHAR8 *Token, OPTIONAL
77 IN CONST CHAR8 *Module, OPTIONAL
78 IN UINT64 TimeStamp
79 )
80 {
81 EFI_STATUS Status;
82
83 Status = mPerformance->StartGauge (Handle, Token, Module, TimeStamp);
84
85 return (RETURN_STATUS) Status;
86 }
87
88 /**
89 Fills in the end time of a performance measurement.
90
91 Looks up the record that matches Handle, Token, and Module.
92 If the record can not be found then return RETURN_NOT_FOUND.
93 If the record is found and TimeStamp is not zero,
94 then TimeStamp is added to the record as the end time.
95 If the record is found and TimeStamp is zero, then this function reads
96 the current time stamp and adds that time stamp value to the record as the end time.
97 If this function is called multiple times for the same record, then the end time is overwritten.
98
99 @param Handle Pointer to environment specific context used
100 to identify the component being measured.
101 @param Token Pointer to a Null-terminated ASCII string
102 that identifies the component being measured.
103 @param Module Pointer to a Null-terminated ASCII string
104 that identifies the module being measured.
105 @param TimeStamp 64-bit time stamp.
106
107 @retval RETURN_SUCCESS The end of the measurement was recorded.
108 @retval RETURN_NOT_FOUND The specified measurement record could not be found.
109
110 **/
111 RETURN_STATUS
112 EFIAPI
113 EndPerformanceMeasurement (
114 IN CONST VOID *Handle, OPTIONAL
115 IN CONST CHAR8 *Token, OPTIONAL
116 IN CONST CHAR8 *Module, OPTIONAL
117 IN UINT64 TimeStamp
118 )
119 {
120 EFI_STATUS Status;
121
122 Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp);
123
124 return (RETURN_STATUS) Status;
125 }
126
127 /**
128 Attempts to retrieve a performance measurement log entry from the performance measurement log.
129
130 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is
131 zero on entry, then an attempt is made to retrieve the first entry from the performance log,
132 and the key for the second entry in the log is returned. If the performance log is empty,
133 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance
134 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is
135 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is
136 retrieved and an implementation specific non-zero key value that specifies the end of the performance
137 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry
138 is retrieved and zero is returned. In the cases where a performance log entry can be returned,
139 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.
140 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().
141 If Handle is NULL, then ASSERT().
142 If Token is NULL, then ASSERT().
143 If Module is NULL, then ASSERT().
144 If StartTimeStamp is NULL, then ASSERT().
145 If EndTimeStamp is NULL, then ASSERT().
146
147 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.
148 0, then the first performance measurement log entry is retrieved.
149 On exit, the key of the next performance lof entry entry.
150 @param Handle Pointer to environment specific context used to identify the component
151 being measured.
152 @param Token Pointer to a Null-terminated ASCII string that identifies the component
153 being measured.
154 @param Module Pointer to a Null-terminated ASCII string that identifies the module
155 being measured.
156 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
157 was started.
158 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement
159 was ended.
160
161 @return The key for the next performance log entry (in general case).
162
163 **/
164 UINTN
165 EFIAPI
166 GetPerformanceMeasurement (
167 IN UINTN LogEntryKey,
168 OUT CONST VOID **Handle,
169 OUT CONST CHAR8 **Token,
170 OUT CONST CHAR8 **Module,
171 OUT UINT64 *StartTimeStamp,
172 OUT UINT64 *EndTimeStamp
173 )
174 {
175 EFI_STATUS Status;
176 GAUGE_DATA_ENTRY *GaugeData;
177
178 ASSERT (Handle != NULL);
179 ASSERT (Token != NULL);
180 ASSERT (Module != NULL);
181 ASSERT (StartTimeStamp != NULL);
182 ASSERT (EndTimeStamp != NULL);
183
184 Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData);
185
186 //
187 // Make sure that LogEntryKey is a valid log entry key,
188 //
189 ASSERT (Status != EFI_INVALID_PARAMETER);
190
191 if (EFI_ERROR (Status)) {
192 //
193 // The LogEntryKey is the last entry (equals to the total entry number).
194 //
195 return 0;
196 }
197
198 ASSERT (GaugeData != NULL);
199
200 *Handle = (VOID *) (UINTN) GaugeData->Handle;
201 *Token = GaugeData->Token;
202 *Module = GaugeData->Module;
203 *StartTimeStamp = GaugeData->StartTimeStamp;
204 *EndTimeStamp = GaugeData->EndTimeStamp;
205
206 return LogEntryKey;
207 }
208
209 /**
210 Returns TRUE if the performance measurement macros are enabled.
211
212 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
213 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
214
215 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
216 PcdPerformanceLibraryPropertyMask is set.
217 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
218 PcdPerformanceLibraryPropertyMask is clear.
219
220 **/
221 BOOLEAN
222 EFIAPI
223 PerformanceMeasurementEnabled (
224 VOID
225 )
226 {
227 return ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
228 }