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 - 2015, 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 "InternalBm.h"
19 PERF_HEADER mBmPerfHeader
;
20 PERF_DATA mBmPerfData
;
21 EFI_PHYSICAL_ADDRESS mBmAcpiLowMemoryBase
= 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.
29 @param StringSize The buffer size of GaugeString in bytes.
33 BmGetShortPdbFileName (
34 IN CONST CHAR8
*PdbFileName
,
35 OUT CHAR8
*GaugeString
,
44 if (PdbFileName
== NULL
) {
45 AsciiStrCpyS (GaugeString
, StringSize
, " ");
48 for (EndIndex
= 0; PdbFileName
[EndIndex
] != 0; EndIndex
++)
51 for (Index
= 0; PdbFileName
[Index
] != 0; Index
++) {
52 if (PdbFileName
[Index
] == '\\') {
53 StartIndex
= Index
+ 1;
56 if (PdbFileName
[Index
] == '.') {
62 for (Index
= StartIndex
; Index
< EndIndex
; Index
++) {
63 GaugeString
[Index1
] = PdbFileName
[Index
];
65 if (Index1
== PERF_TOKEN_LENGTH
- 1) {
70 GaugeString
[Index1
] = 0;
77 Get the name from the Driver handle, which can be a handle with
78 EFI_LOADED_IMAGE_PROTOCOL or EFI_DRIVER_BINDING_PROTOCOL installed.
79 This name can be used in performance data logging.
81 @param Handle Driver handle.
82 @param GaugeString The output string to be logged by performance logger.
83 @param StringSize The buffer size of GaugeString in bytes.
89 OUT CHAR8
*GaugeString
,
94 EFI_LOADED_IMAGE_PROTOCOL
*Image
;
96 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
98 AsciiStrCpyS (GaugeString
, StringSize
, " ");
101 // Get handle name from image protocol
103 Status
= gBS
->HandleProtocol (
105 &gEfiLoadedImageProtocolGuid
,
109 if (EFI_ERROR (Status
)) {
110 Status
= gBS
->OpenProtocol (
112 &gEfiDriverBindingProtocolGuid
,
113 (VOID
**) &DriverBinding
,
116 EFI_OPEN_PROTOCOL_GET_PROTOCOL
118 if (EFI_ERROR (Status
)) {
122 // Get handle name from image protocol
124 Status
= gBS
->HandleProtocol (
125 DriverBinding
->ImageHandle
,
126 &gEfiLoadedImageProtocolGuid
,
131 PdbFileName
= PeCoffLoaderGetPdbPointer (Image
->ImageBase
);
133 if (PdbFileName
!= NULL
) {
134 BmGetShortPdbFileName (PdbFileName
, GaugeString
, StringSize
);
142 Writes performance data of booting into the allocated memory.
143 OS can process these records.
145 @param Event The triggered event.
146 @param Context Context for this event.
151 BmWriteBootToOsPerformanceData (
160 CHAR8 GaugeString
[PERF_TOKEN_LENGTH
];
176 UINTN NumPerfEntries
;
178 // List of flags indicating PerfEntry contains DXE handle
180 BOOLEAN
*PerfEntriesAsDxeHandle
;
184 // Record the performance data for End of BDS
186 PERF_END(NULL
, "BDS", NULL
, 0);
189 // Retrieve time stamp count as early as possible
191 Ticker
= GetPerformanceCounter ();
193 Freq
= GetPerformanceCounterProperties (&StartValue
, &EndValue
);
195 Freq
= DivU64x32 (Freq
, 1000);
197 mBmPerfHeader
.CpuFreq
= Freq
;
200 // Record BDS raw performance data
202 if (EndValue
>= StartValue
) {
203 mBmPerfHeader
.BDSRaw
= Ticker
- StartValue
;
206 mBmPerfHeader
.BDSRaw
= StartValue
- Ticker
;
210 if (mBmAcpiLowMemoryBase
== 0x0FFFFFFFF) {
211 VarSize
= sizeof (EFI_PHYSICAL_ADDRESS
);
212 Status
= gRT
->GetVariable (
214 &gPerformanceProtocolGuid
,
217 &mBmAcpiLowMemoryBase
219 if (EFI_ERROR (Status
)) {
221 // Fail to get the variable, return.
228 // Put Detailed performance data into memory
231 Status
= gBS
->LocateHandleBuffer (
238 if (EFI_ERROR (Status
)) {
242 Ptr
= (UINT8
*) ((UINT32
) mBmAcpiLowMemoryBase
+ sizeof (PERF_HEADER
));
243 LimitCount
= (UINT32
) (PERF_DATA_MAX_LENGTH
- sizeof (PERF_HEADER
)) / sizeof (PERF_DATA
);
247 while ((LogEntryKey
= GetPerformanceMeasurement (
256 PerfEntriesAsDxeHandle
= AllocateZeroPool (NumPerfEntries
* sizeof (BOOLEAN
));
257 ASSERT (PerfEntriesAsDxeHandle
!= NULL
);
260 // Get DXE drivers performance
262 for (Index
= 0; Index
< NoHandles
; Index
++) {
266 while ((LogEntryKey
= GetPerformanceMeasurement (
273 if (Handle
== Handles
[Index
] && !PerfEntriesAsDxeHandle
[EntryIndex
]) {
274 PerfEntriesAsDxeHandle
[EntryIndex
] = TRUE
;
277 if ((Handle
== Handles
[Index
]) && (EndTicker
!= 0)) {
278 if (StartTicker
== 1) {
279 StartTicker
= StartValue
;
281 if (EndTicker
== 1) {
282 EndTicker
= StartValue
;
284 Ticker
+= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
288 Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
292 BmGetNameFromHandle (Handles
[Index
], GaugeString
, PERF_TOKEN_LENGTH
);
294 AsciiStrCpyS (mBmPerfData
.Token
, PERF_TOKEN_SIZE
, GaugeString
);
295 mBmPerfData
.Duration
= Duration
;
297 CopyMem (Ptr
, &mBmPerfData
, sizeof (PERF_DATA
));
298 Ptr
+= sizeof (PERF_DATA
);
300 mBmPerfHeader
.Count
++;
301 if (mBmPerfHeader
.Count
== LimitCount
) {
308 // Get inserted performance data
312 while ((LogEntryKey
= GetPerformanceMeasurement (
319 if (!PerfEntriesAsDxeHandle
[EntryIndex
] && EndTicker
!= 0) {
321 ZeroMem (&mBmPerfData
, sizeof (PERF_DATA
));
323 AsciiStrnCpyS (mBmPerfData
.Token
, PERF_TOKEN_SIZE
, Token
, PERF_TOKEN_LENGTH
);
324 if (StartTicker
== 1) {
325 StartTicker
= StartValue
;
327 if (EndTicker
== 1) {
328 EndTicker
= StartValue
;
330 Ticker
= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
332 mBmPerfData
.Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
334 CopyMem (Ptr
, &mBmPerfData
, sizeof (PERF_DATA
));
335 Ptr
+= sizeof (PERF_DATA
);
337 mBmPerfHeader
.Count
++;
338 if (mBmPerfHeader
.Count
== LimitCount
) {
348 FreePool (PerfEntriesAsDxeHandle
);
350 mBmPerfHeader
.Signiture
= PERFORMANCE_SIGNATURE
;
353 // Put performance data to Reserved memory
356 (UINTN
*) (UINTN
) mBmAcpiLowMemoryBase
,