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 - 2013, 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
;
24 Get the short verion of PDB file name to be
25 used in performance data logging.
27 @param PdbFileName The long PDB file name.
28 @param GaugeString The output string to be logged by performance logger.
33 IN CONST CHAR8
*PdbFileName
,
34 OUT CHAR8
*GaugeString
42 if (PdbFileName
== NULL
) {
43 AsciiStrCpy (GaugeString
, " ");
46 for (EndIndex
= 0; PdbFileName
[EndIndex
] != 0; EndIndex
++)
49 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
50 if (PdbFileName
[Index
] == '\\') {
51 StartIndex
= Index
+ 1;
54 if (PdbFileName
[Index
] == '.') {
60 for (Index
= StartIndex
; Index
< EndIndex
; Index
++) {
61 GaugeString
[Index1
] = PdbFileName
[Index
];
63 if (Index1
== PERF_TOKEN_LENGTH
- 1) {
68 GaugeString
[Index1
] = 0;
75 Get the name from the Driver handle, which can be a handle with
76 EFI_LOADED_IMAGE_PROTOCOL or EFI_DRIVER_BINDING_PROTOCOL installed.
77 This name can be used in performance data logging.
79 @param Handle Driver handle.
80 @param GaugeString The output string to be logged by performance logger.
86 OUT CHAR8
*GaugeString
90 EFI_LOADED_IMAGE_PROTOCOL
*Image
;
92 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
94 AsciiStrCpy (GaugeString
, " ");
97 // Get handle name from image protocol
99 Status
= gBS
->HandleProtocol (
101 &gEfiLoadedImageProtocolGuid
,
105 if (EFI_ERROR (Status
)) {
106 Status
= gBS
->OpenProtocol (
108 &gEfiDriverBindingProtocolGuid
,
109 (VOID
**) &DriverBinding
,
112 EFI_OPEN_PROTOCOL_GET_PROTOCOL
114 if (EFI_ERROR (Status
)) {
118 // Get handle name from image protocol
120 Status
= gBS
->HandleProtocol (
121 DriverBinding
->ImageHandle
,
122 &gEfiLoadedImageProtocolGuid
,
127 PdbFileName
= PeCoffLoaderGetPdbPointer (Image
->ImageBase
);
129 if (PdbFileName
!= NULL
) {
130 GetShortPdbFileName (PdbFileName
, GaugeString
);
138 Writes performance data of booting into the allocated memory.
139 OS can process these records.
141 @param Event The triggered event.
142 @param Context Context for this event.
147 WriteBootToOsPerformanceData (
156 CHAR8 GaugeString
[PERF_TOKEN_LENGTH
];
172 UINTN NumPerfEntries
;
174 // List of flags indicating PerfEntry contains DXE handle
176 BOOLEAN
*PerfEntriesAsDxeHandle
;
180 // Record the performance data for End of BDS
182 PERF_END(NULL
, "BDS", NULL
, 0);
185 // Retrieve time stamp count as early as possible
187 Ticker
= GetPerformanceCounter ();
189 Freq
= GetPerformanceCounterProperties (&StartValue
, &EndValue
);
191 Freq
= DivU64x32 (Freq
, 1000);
193 mPerfHeader
.CpuFreq
= Freq
;
196 // Record BDS raw performance data
198 if (EndValue
>= StartValue
) {
199 mPerfHeader
.BDSRaw
= Ticker
- StartValue
;
202 mPerfHeader
.BDSRaw
= StartValue
- Ticker
;
206 if (mAcpiLowMemoryBase
== 0x0FFFFFFFF) {
207 VarSize
= sizeof (EFI_PHYSICAL_ADDRESS
);
208 Status
= gRT
->GetVariable (
210 &gPerformanceProtocolGuid
,
215 if (EFI_ERROR (Status
)) {
217 // Fail to get the variable, return.
224 // Put Detailed performance data into memory
227 Status
= gBS
->LocateHandleBuffer (
234 if (EFI_ERROR (Status
)) {
238 Ptr
= (UINT8
*) ((UINT32
) mAcpiLowMemoryBase
+ sizeof (PERF_HEADER
));
239 LimitCount
= (UINT32
) (PERF_DATA_MAX_LENGTH
- sizeof (PERF_HEADER
)) / sizeof (PERF_DATA
);
243 while ((LogEntryKey
= GetPerformanceMeasurement (
252 PerfEntriesAsDxeHandle
= AllocateZeroPool (NumPerfEntries
* sizeof (BOOLEAN
));
253 ASSERT (PerfEntriesAsDxeHandle
!= NULL
);
256 // Get DXE drivers performance
258 for (Index
= 0; Index
< NoHandles
; Index
++) {
262 while ((LogEntryKey
= GetPerformanceMeasurement (
269 if (Handle
== Handles
[Index
] && !PerfEntriesAsDxeHandle
[EntryIndex
]) {
270 PerfEntriesAsDxeHandle
[EntryIndex
] = TRUE
;
273 if ((Handle
== Handles
[Index
]) && (EndTicker
!= 0)) {
274 if (StartTicker
== 1) {
275 StartTicker
= StartValue
;
277 if (EndTicker
== 1) {
278 EndTicker
= StartValue
;
280 Ticker
+= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
284 Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
288 GetNameFromHandle (Handles
[Index
], GaugeString
);
290 AsciiStrCpy (mPerfData
.Token
, GaugeString
);
291 mPerfData
.Duration
= Duration
;
293 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
294 Ptr
+= sizeof (PERF_DATA
);
297 if (mPerfHeader
.Count
== LimitCount
) {
304 // Get inserted performance data
308 while ((LogEntryKey
= GetPerformanceMeasurement (
315 if (!PerfEntriesAsDxeHandle
[EntryIndex
] && EndTicker
!= 0) {
317 ZeroMem (&mPerfData
, sizeof (PERF_DATA
));
319 AsciiStrnCpy (mPerfData
.Token
, Token
, PERF_TOKEN_LENGTH
);
320 if (StartTicker
== 1) {
321 StartTicker
= StartValue
;
323 if (EndTicker
== 1) {
324 EndTicker
= StartValue
;
326 Ticker
= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
328 mPerfData
.Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
330 CopyMem (Ptr
, &mPerfData
, sizeof (PERF_DATA
));
331 Ptr
+= sizeof (PERF_DATA
);
334 if (mPerfHeader
.Count
== LimitCount
) {
344 FreePool (PerfEntriesAsDxeHandle
);
346 mPerfHeader
.Signiture
= PERFORMANCE_SIGNATURE
;
349 // Put performance data to Reserved memory
352 (UINTN
*) (UINTN
) mAcpiLowMemoryBase
,