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 STATIC PERF_HEADER mPerfHeader
;
20 STATIC PERF_DATA mPerfData
;
43 if (PdbFileName
== NULL
) {
44 AsciiStrCpy (GaugeString
, " ");
47 for (EndIndex
= 0; PdbFileName
[EndIndex
] != 0; EndIndex
++)
50 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
51 if (PdbFileName
[Index
] == '\\') {
52 StartIndex
= Index
+ 1;
55 if (PdbFileName
[Index
] == '.') {
61 for (Index
= StartIndex
; Index
< EndIndex
; Index
++) {
62 GaugeString
[Index1
] = PdbFileName
[Index
];
64 if (Index1
== PERF_TOKEN_LENGTH
- 1) {
69 GaugeString
[Index1
] = 0;
79 OUT CHAR8
*GaugeString
83 EFI_LOADED_IMAGE_PROTOCOL
*Image
;
85 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
87 AsciiStrCpy (GaugeString
, " ");
90 // Get handle name from image protocol
92 Status
= gBS
->HandleProtocol (
94 &gEfiLoadedImageProtocolGuid
,
98 if (EFI_ERROR (Status
)) {
99 Status
= gBS
->OpenProtocol (
101 &gEfiDriverBindingProtocolGuid
,
102 (VOID
**) &DriverBinding
,
105 EFI_OPEN_PROTOCOL_GET_PROTOCOL
107 if (EFI_ERROR (Status
)) {
111 // Get handle name from image protocol
113 Status
= gBS
->HandleProtocol (
114 DriverBinding
->ImageHandle
,
115 &gEfiLoadedImageProtocolGuid
,
120 PdbFileName
= PeCoffLoaderGetPdbPointer (Image
->ImageBase
);
122 if (PdbFileName
!= NULL
) {
123 GetShortPdbFileName (PdbFileName
, GaugeString
);
130 WriteBootToOsPerformanceData (
137 Allocates a block of memory and writes performance data of booting to OS into it.
150 EFI_PHYSICAL_ADDRESS AcpiLowMemoryBase
;
151 UINT32 AcpiLowMemoryLength
;
155 CHAR8 GaugeString
[PERF_TOKEN_LENGTH
];
172 // Retrive time stamp count as early as possilbe
174 Ticker
= GetPerformanceCounter ();
176 Freq
= GetPerformanceCounterProperties (&StartValue
, &EndValue
);
178 Freq
= DivU64x32 (Freq
, 1000);
180 mPerfHeader
.CpuFreq
= Freq
;
183 // Record BDS raw performance data
185 if (EndValue
>= StartValue
) {
186 mPerfHeader
.BDSRaw
= Ticker
- StartValue
;
189 mPerfHeader
.BDSRaw
= StartValue
- Ticker
;
193 AcpiLowMemoryLength
= 0x2000;
196 // Allocate a block of memory that contain performance data to OS
198 Status
= gBS
->AllocatePages (
200 EfiACPIReclaimMemory
,
201 EFI_SIZE_TO_PAGES (AcpiLowMemoryLength
),
204 if (EFI_ERROR (Status
)) {
209 Ptr
= (UINT8
*) ((UINT32
) AcpiLowMemoryBase
+ sizeof (PERF_HEADER
));
210 LimitCount
= (AcpiLowMemoryLength
- sizeof (PERF_HEADER
)) / sizeof (PERF_DATA
);
213 // Put Detailed performance data into memory
216 Status
= gBS
->LocateHandleBuffer (
223 if (EFI_ERROR (Status
)) {
224 gBS
->FreePages (AcpiLowMemoryBase
, 1);
228 // Get DXE drivers performance
230 for (Index
= 0; Index
< NoHandles
; Index
++) {
233 while ((LogEntryKey
= GetPerformanceMeasurement (
240 if ((Handle
== Handles
[Index
]) && (EndTicker
!= 0)) {
241 Ticker
+= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
245 Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
249 GetNameFromHandle (Handles
[Index
], GaugeString
);
251 AsciiStrCpy (mPerfData
.Token
, GaugeString
);
252 mPerfData
.Duration
= Duration
;
254 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
255 Ptr
+= sizeof (PERF_DATA
);
258 if (mPerfHeader
.Count
== LimitCount
) {
267 // Get inserted performance data
270 while ((LogEntryKey
= GetPerformanceMeasurement (
277 if (Handle
== NULL
&& EndTicker
!= 0) {
279 ZeroMem (&mPerfData
, sizeof (PERF_DATA
));
281 AsciiStrnCpy (mPerfData
.Token
, Token
, PERF_TOKEN_LENGTH
);
282 Ticker
= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
284 mPerfData
.Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
286 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
287 Ptr
+= sizeof (PERF_DATA
);
290 if (mPerfHeader
.Count
== LimitCount
) {
298 mPerfHeader
.Signiture
= PERFORMANCE_SIGNATURE
;
301 // Put performance data to memory
304 (UINTN
*) (UINTN
) AcpiLowMemoryBase
,
311 &gEfiGenericPlatformVariableGuid
,
312 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
313 sizeof (EFI_PHYSICAL_ADDRESS
),