2 This file include the file which can help to get the system
3 performance, all the function will only include if the performance
6 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "InternalBdsLib.h"
19 PERF_HEADER mPerfHeader
;
23 Get the short verion of PDB file name to be
24 used in performance data logging.
26 @param PdbFileName The long PDB file name.
27 @param GaugeString The output string to be logged by performance logger.
32 IN CONST CHAR8
*PdbFileName
,
33 OUT CHAR8
*GaugeString
41 if (PdbFileName
== NULL
) {
42 AsciiStrCpy (GaugeString
, " ");
45 for (EndIndex
= 0; PdbFileName
[EndIndex
] != 0; EndIndex
++)
48 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
49 if (PdbFileName
[Index
] == '\\') {
50 StartIndex
= Index
+ 1;
53 if (PdbFileName
[Index
] == '.') {
59 for (Index
= StartIndex
; Index
< EndIndex
; Index
++) {
60 GaugeString
[Index1
] = PdbFileName
[Index
];
62 if (Index1
== PERF_TOKEN_LENGTH
- 1) {
67 GaugeString
[Index1
] = 0;
74 Get the name from the Driver handle, which can be a handle with
75 EFI_LOADED_IMAGE_PROTOCOL or EFI_DRIVER_BINDING_PROTOCOL installed.
76 This name can be used in performance data logging.
78 @param Handle Driver handle.
79 @param GaugeString The output string to be logged by performance logger.
85 OUT CHAR8
*GaugeString
89 EFI_LOADED_IMAGE_PROTOCOL
*Image
;
91 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
93 AsciiStrCpy (GaugeString
, " ");
96 // Get handle name from image protocol
98 Status
= gBS
->HandleProtocol (
100 &gEfiLoadedImageProtocolGuid
,
104 if (EFI_ERROR (Status
)) {
105 Status
= gBS
->OpenProtocol (
107 &gEfiDriverBindingProtocolGuid
,
108 (VOID
**) &DriverBinding
,
111 EFI_OPEN_PROTOCOL_GET_PROTOCOL
113 if (EFI_ERROR (Status
)) {
117 // Get handle name from image protocol
119 Status
= gBS
->HandleProtocol (
120 DriverBinding
->ImageHandle
,
121 &gEfiLoadedImageProtocolGuid
,
126 PdbFileName
= PeCoffLoaderGetPdbPointer (Image
->ImageBase
);
128 if (PdbFileName
!= NULL
) {
129 GetShortPdbFileName (PdbFileName
, GaugeString
);
137 Allocates a block of memory and writes performance data of booting into it.
138 OS can processing these record.
142 WriteBootToOsPerformanceData (
147 EFI_PHYSICAL_ADDRESS AcpiLowMemoryBase
;
148 UINT32 AcpiLowMemoryLength
;
152 CHAR8 GaugeString
[PERF_TOKEN_LENGTH
];
169 // Retrieve time stamp count as early as possible
171 Ticker
= GetPerformanceCounter ();
173 Freq
= GetPerformanceCounterProperties (&StartValue
, &EndValue
);
175 Freq
= DivU64x32 (Freq
, 1000);
177 mPerfHeader
.CpuFreq
= Freq
;
180 // Record BDS raw performance data
182 if (EndValue
>= StartValue
) {
183 mPerfHeader
.BDSRaw
= Ticker
- StartValue
;
186 mPerfHeader
.BDSRaw
= StartValue
- Ticker
;
190 AcpiLowMemoryLength
= 0x2000;
193 // Allocate a block of memory that contain performance data to OS
195 Status
= gBS
->AllocatePages (
197 EfiACPIReclaimMemory
,
198 EFI_SIZE_TO_PAGES (AcpiLowMemoryLength
),
201 if (EFI_ERROR (Status
)) {
206 Ptr
= (UINT8
*) ((UINT32
) AcpiLowMemoryBase
+ sizeof (PERF_HEADER
));
207 LimitCount
= (AcpiLowMemoryLength
- sizeof (PERF_HEADER
)) / sizeof (PERF_DATA
);
210 // Put Detailed performance data into memory
213 Status
= gBS
->LocateHandleBuffer (
220 if (EFI_ERROR (Status
)) {
221 gBS
->FreePages (AcpiLowMemoryBase
, 1);
226 // Get DXE drivers performance
228 for (Index
= 0; Index
< NoHandles
; Index
++) {
231 while ((LogEntryKey
= GetPerformanceMeasurement (
238 if ((Handle
== Handles
[Index
]) && (EndTicker
!= 0)) {
239 Ticker
+= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
243 Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
247 GetNameFromHandle (Handles
[Index
], GaugeString
);
249 AsciiStrCpy (mPerfData
.Token
, GaugeString
);
250 mPerfData
.Duration
= Duration
;
252 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
253 Ptr
+= sizeof (PERF_DATA
);
256 if (mPerfHeader
.Count
== LimitCount
) {
265 // Get inserted performance data
268 while ((LogEntryKey
= GetPerformanceMeasurement (
275 if (Handle
== NULL
&& EndTicker
!= 0) {
277 ZeroMem (&mPerfData
, sizeof (PERF_DATA
));
279 AsciiStrnCpy (mPerfData
.Token
, Token
, PERF_TOKEN_LENGTH
);
280 Ticker
= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
282 mPerfData
.Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
284 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
285 Ptr
+= sizeof (PERF_DATA
);
288 if (mPerfHeader
.Count
== LimitCount
) {
296 mPerfHeader
.Signiture
= PERFORMANCE_SIGNATURE
;
299 // Put performance data to ACPI memory
302 (UINTN
*) (UINTN
) AcpiLowMemoryBase
,
309 &gPerformanceProtocolGuid
,
310 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
311 sizeof (EFI_PHYSICAL_ADDRESS
),