3 Copyright (c) 2004 - 2007, 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
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.
18 This file include the file which can help to get the system
19 performance, all the function will only include if the performance
25 #include "InternalBdsLib.h"
27 STATIC PERF_HEADER mPerfHeader
;
28 STATIC PERF_DATA mPerfData
;
51 if (PdbFileName
== NULL
) {
52 AsciiStrCpy (GaugeString
, " ");
55 for (EndIndex
= 0; PdbFileName
[EndIndex
] != 0; EndIndex
++)
58 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
59 if (PdbFileName
[Index
] == '\\') {
60 StartIndex
= Index
+ 1;
63 if (PdbFileName
[Index
] == '.') {
69 for (Index
= StartIndex
; Index
< EndIndex
; Index
++) {
70 GaugeString
[Index1
] = PdbFileName
[Index
];
72 if (Index1
== PERF_TOKEN_LENGTH
- 1) {
77 GaugeString
[Index1
] = 0;
87 OUT CHAR8
*GaugeString
91 EFI_LOADED_IMAGE_PROTOCOL
*Image
;
93 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
95 AsciiStrCpy (GaugeString
, " ");
98 // Get handle name from image protocol
100 Status
= gBS
->HandleProtocol (
102 &gEfiLoadedImageProtocolGuid
,
106 if (EFI_ERROR (Status
)) {
107 Status
= gBS
->OpenProtocol (
109 &gEfiDriverBindingProtocolGuid
,
110 (VOID
**) &DriverBinding
,
113 EFI_OPEN_PROTOCOL_GET_PROTOCOL
115 if (EFI_ERROR (Status
)) {
119 // Get handle name from image protocol
121 Status
= gBS
->HandleProtocol (
122 DriverBinding
->ImageHandle
,
123 &gEfiLoadedImageProtocolGuid
,
128 PdbFileName
= PeCoffLoaderGetPdbPointer (Image
->ImageBase
);
130 if (PdbFileName
!= NULL
) {
131 GetShortPdbFileName (PdbFileName
, GaugeString
);
138 WriteBootToOsPerformanceData (
145 Allocates a block of memory and writes performance data of booting to OS into it.
158 EFI_PHYSICAL_ADDRESS AcpiLowMemoryBase
;
159 UINT32 AcpiLowMemoryLength
;
163 CHAR8 GaugeString
[PERF_TOKEN_LENGTH
];
180 // Retrive time stamp count as early as possilbe
182 Ticker
= GetPerformanceCounter ();
184 Freq
= GetPerformanceCounterProperties (&StartValue
, &EndValue
);
186 Freq
= DivU64x32 (Freq
, 1000);
188 mPerfHeader
.CpuFreq
= Freq
;
191 // Record BDS raw performance data
193 if (EndValue
>= StartValue
) {
194 mPerfHeader
.BDSRaw
= Ticker
- StartValue
;
197 mPerfHeader
.BDSRaw
= StartValue
- Ticker
;
201 AcpiLowMemoryLength
= 0x2000;
204 // Allocate a block of memory that contain performance data to OS
206 Status
= gBS
->AllocatePages (
208 EfiACPIReclaimMemory
,
209 EFI_SIZE_TO_PAGES (AcpiLowMemoryLength
),
212 if (EFI_ERROR (Status
)) {
217 Ptr
= (UINT8
*) ((UINT32
) AcpiLowMemoryBase
+ sizeof (PERF_HEADER
));
218 LimitCount
= (AcpiLowMemoryLength
- sizeof (PERF_HEADER
)) / sizeof (PERF_DATA
);
221 // Put Detailed performance data into memory
224 Status
= gBS
->LocateHandleBuffer (
231 if (EFI_ERROR (Status
)) {
232 gBS
->FreePages (AcpiLowMemoryBase
, 1);
236 // Get DXE drivers performance
238 for (Index
= 0; Index
< NoHandles
; Index
++) {
241 while ((LogEntryKey
= GetPerformanceMeasurement (
248 if ((Handle
== Handles
[Index
]) && (EndTicker
!= 0)) {
249 Ticker
+= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
253 Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
257 GetNameFromHandle (Handles
[Index
], GaugeString
);
259 AsciiStrCpy (mPerfData
.Token
, GaugeString
);
260 mPerfData
.Duration
= Duration
;
262 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
263 Ptr
+= sizeof (PERF_DATA
);
266 if (mPerfHeader
.Count
== LimitCount
) {
275 // Get inserted performance data
278 while ((LogEntryKey
= GetPerformanceMeasurement (
285 if (Handle
== NULL
&& EndTicker
!= 0) {
287 ZeroMem (&mPerfData
, sizeof (PERF_DATA
));
289 AsciiStrnCpy (mPerfData
.Token
, Token
, PERF_TOKEN_LENGTH
);
290 Ticker
= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
292 mPerfData
.Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
294 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
295 Ptr
+= sizeof (PERF_DATA
);
298 if (mPerfHeader
.Count
== LimitCount
) {
306 mPerfHeader
.Signiture
= PERFORMANCE_SIGNATURE
;
309 // Put performance data to memory
312 (UINTN
*) (UINTN
) AcpiLowMemoryBase
,
319 &gEfiGenericPlatformVariableGuid
,
320 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
321 sizeof (EFI_PHYSICAL_ADDRESS
),