]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Library/EdkDxePerformanceLib/DxePerformanceLib.c
Initial import.
[mirror_edk2.git] / EdkModulePkg / Library / EdkDxePerformanceLib / 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 Retrieves a previously logged performance measurement.
129
130 Looks up the record that matches Handle, Token, and Module.
131 If the record can not be found then return RETURN_NOT_FOUND.
132 If the record is found then the start of the measurement is returned in StartTimeStamp,
133 and the end of the measurement is returned in EndTimeStamp.
134
135 @param LogEntryKey The key for the previous performance measurement log entry.
136 If 0, then the first performance measurement log entry is retrieved.
137 @param Handle Pointer to environment specific context used
138 to identify the component being measured.
139 @param Token Pointer to a Null-terminated ASCII string
140 that identifies the component being measured.
141 @param Module Pointer to a Null-terminated ASCII string
142 that identifies the module being measured.
143 @param StartTimeStamp The 64-bit time stamp that was recorded when the measurement was started.
144 @param EndTimeStamp The 64-bit time stamp that was recorded when the measurement was ended.
145
146 @return The key for the current performance log entry.
147
148 **/
149 UINTN
150 EFIAPI
151 GetPerformanceMeasurement (
152 UINTN LogEntryKey,
153 OUT CONST VOID **Handle,
154 OUT CONST CHAR8 **Token,
155 OUT CONST CHAR8 **Module,
156 OUT UINT64 *StartTimeStamp,
157 OUT UINT64 *EndTimeStamp
158 )
159 {
160 EFI_STATUS Status;
161 GAUGE_DATA_ENTRY *GaugeData;
162
163 ASSERT (Handle != NULL);
164 ASSERT (Token != NULL);
165 ASSERT (Module != NULL);
166 ASSERT (StartTimeStamp != NULL);
167 ASSERT (EndTimeStamp != NULL);
168
169 Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData);
170
171 //
172 // Make sure that LogEntryKey is a valid log entry key,
173 //
174 ASSERT (Status != EFI_INVALID_PARAMETER);
175
176 if (EFI_ERROR (Status)) {
177 //
178 // The LogEntryKey is the last entry (equals to the total entry number).
179 //
180 return 0;
181 }
182
183 ASSERT (GaugeData != NULL);
184
185 *Handle = (VOID *) (UINTN) GaugeData->Handle;
186 *Token = GaugeData->Token;
187 *Module = GaugeData->Module;
188 *StartTimeStamp = GaugeData->StartTimeStamp;
189 *EndTimeStamp = GaugeData->EndTimeStamp;
190
191 return LogEntryKey;
192 }
193
194 /**
195 Returns TRUE if the performance measurement macros are enabled.
196
197 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
198 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.
199
200 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
201 PcdPerformanceLibraryPropertyMask is set.
202 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of
203 PcdPerformanceLibraryPropertyMask is clear.
204
205 **/
206 BOOLEAN
207 EFIAPI
208 PerformanceMeasurementEnabled (
209 VOID
210 )
211 {
212 return ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);
213 }