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