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 - 2012, Intel Corporation. All rights reserved.<BR>
7 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
;
21 EFI_PHYSICAL_ADDRESS mAcpiLowMemoryBase
= 0x0FFFFFFFFULL
;
22 UINT32 mAcpiLowMemoryLength
= 0x4000;
25 Get the short verion of PDB file name to be
26 used in performance data logging.
28 @param PdbFileName The long PDB file name.
29 @param GaugeString The output string to be logged by performance logger.
34 IN CONST CHAR8
*PdbFileName
,
35 OUT CHAR8
*GaugeString
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;
76 Get the name from the Driver handle, which can be a handle with
77 EFI_LOADED_IMAGE_PROTOCOL or EFI_DRIVER_BINDING_PROTOCOL installed.
78 This name can be used in performance data logging.
80 @param Handle Driver handle.
81 @param GaugeString The output string to be logged by performance logger.
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
);
139 Allocates a block of memory to store performance data.
143 AllocateMemoryForPerformanceData (
149 if (mAcpiLowMemoryBase
== 0x0FFFFFFFF) {
151 // Allocate a block of memory that contain performance data to OS
153 Status
= gBS
->AllocatePages (
155 EfiReservedMemoryType
,
156 EFI_SIZE_TO_PAGES (mAcpiLowMemoryLength
),
159 if (!EFI_ERROR (Status
)) {
162 &gPerformanceProtocolGuid
,
163 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
164 sizeof (EFI_PHYSICAL_ADDRESS
),
173 Writes performance data of booting into the allocated memory.
174 OS can process these records.
176 @param Event The triggered event.
177 @param Context Context for this event.
182 WriteBootToOsPerformanceData (
191 CHAR8 GaugeString
[PERF_TOKEN_LENGTH
];
207 UINTN NumPerfEntries
;
209 // List of flags indicating PerfEntry contains DXE handle
211 BOOLEAN
*PerfEntriesAsDxeHandle
;
214 // Record the performance data for End of BDS
216 PERF_END(NULL
, "BDS", NULL
, 0);
218 if (mAcpiLowMemoryBase
== 0x0FFFFFFFF) {
223 // Retrieve time stamp count as early as possible
225 Ticker
= GetPerformanceCounter ();
227 Freq
= GetPerformanceCounterProperties (&StartValue
, &EndValue
);
229 Freq
= DivU64x32 (Freq
, 1000);
231 mPerfHeader
.CpuFreq
= Freq
;
234 // Record BDS raw performance data
236 if (EndValue
>= StartValue
) {
237 mPerfHeader
.BDSRaw
= Ticker
- StartValue
;
240 mPerfHeader
.BDSRaw
= StartValue
- Ticker
;
245 // Put Detailed performance data into memory
248 Status
= gBS
->LocateHandleBuffer (
255 if (EFI_ERROR (Status
)) {
259 Ptr
= (UINT8
*) ((UINT32
) mAcpiLowMemoryBase
+ sizeof (PERF_HEADER
));
260 LimitCount
= (mAcpiLowMemoryLength
- sizeof (PERF_HEADER
)) / sizeof (PERF_DATA
);
264 while ((LogEntryKey
= GetPerformanceMeasurement (
273 PerfEntriesAsDxeHandle
= AllocateZeroPool (NumPerfEntries
* sizeof (BOOLEAN
));
274 ASSERT (PerfEntriesAsDxeHandle
!= NULL
);
277 // Get DXE drivers performance
279 for (Index
= 0; Index
< NoHandles
; Index
++) {
283 while ((LogEntryKey
= GetPerformanceMeasurement (
290 if (Handle
== Handles
[Index
] && !PerfEntriesAsDxeHandle
[EntryIndex
]) {
291 PerfEntriesAsDxeHandle
[EntryIndex
] = TRUE
;
294 if ((Handle
== Handles
[Index
]) && (EndTicker
!= 0)) {
295 if (StartTicker
== 1) {
296 StartTicker
= StartValue
;
298 if (EndTicker
== 1) {
299 EndTicker
= StartValue
;
301 Ticker
+= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
305 Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
309 GetNameFromHandle (Handles
[Index
], GaugeString
);
311 AsciiStrCpy (mPerfData
.Token
, GaugeString
);
312 mPerfData
.Duration
= Duration
;
314 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
315 Ptr
+= sizeof (PERF_DATA
);
318 if (mPerfHeader
.Count
== LimitCount
) {
325 // Get inserted performance data
329 while ((LogEntryKey
= GetPerformanceMeasurement (
336 if (!PerfEntriesAsDxeHandle
[EntryIndex
] && EndTicker
!= 0) {
338 ZeroMem (&mPerfData
, sizeof (PERF_DATA
));
340 AsciiStrnCpy (mPerfData
.Token
, Token
, PERF_TOKEN_LENGTH
);
341 if (StartTicker
== 1) {
342 StartTicker
= StartValue
;
344 if (EndTicker
== 1) {
345 EndTicker
= StartValue
;
347 Ticker
= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
349 mPerfData
.Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
351 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
352 Ptr
+= sizeof (PERF_DATA
);
355 if (mPerfHeader
.Count
== LimitCount
) {
365 FreePool (PerfEntriesAsDxeHandle
);
367 mPerfHeader
.Signiture
= PERFORMANCE_SIGNATURE
;
370 // Put performance data to Reserved memory
373 (UINTN
*) (UINTN
) mAcpiLowMemoryBase
,