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 - 2017, 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
] == '\\') || (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
== StringSize
- 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_SIZE
];
179 // Record the performance data for End of BDS
181 PERF_END(NULL
, "BDS", NULL
, 0);
184 // Retrieve time stamp count as early as possible
186 Ticker
= GetPerformanceCounter ();
188 Freq
= GetPerformanceCounterProperties (&StartValue
, &EndValue
);
190 Freq
= DivU64x32 (Freq
, 1000);
192 mBmPerfHeader
.CpuFreq
= Freq
;
195 // Record BDS raw performance data
197 if (EndValue
>= StartValue
) {
198 mBmPerfHeader
.BDSRaw
= Ticker
- StartValue
;
201 mBmPerfHeader
.BDSRaw
= StartValue
- Ticker
;
206 // Reset the entry count
208 mBmPerfHeader
.Count
= 0;
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
);
246 // Get performance data
249 while ((LogEntryKey
= GetPerformanceMeasurement (
256 if (EndTicker
!= 0) {
257 if (StartTicker
== 1) {
258 StartTicker
= StartValue
;
260 if (EndTicker
== 1) {
261 EndTicker
= StartValue
;
263 Ticker
= CountUp
? (EndTicker
- StartTicker
) : (StartTicker
- EndTicker
);
265 Duration
= (UINT32
) DivU64x32 (Ticker
, (UINT32
) Freq
);
270 ZeroMem (&mBmPerfData
, sizeof (PERF_DATA
));
272 mBmPerfData
.Duration
= Duration
;
275 // See if the Handle is in the handle buffer
278 for (Index
= 0; Index
< NoHandles
; Index
++) {
279 if (Handle
== Handles
[Index
]) {
280 BmGetNameFromHandle (Handles
[Index
], GaugeString
, PERF_TOKEN_SIZE
);
281 AsciiStrCpyS (mBmPerfData
.Token
, PERF_TOKEN_SIZE
, GaugeString
);
288 AsciiStrnCpyS (mBmPerfData
.Token
, PERF_TOKEN_SIZE
, Token
, PERF_TOKEN_LENGTH
);
291 CopyMem (Ptr
, &mBmPerfData
, sizeof (PERF_DATA
));
292 Ptr
+= sizeof (PERF_DATA
);
294 mBmPerfHeader
.Count
++;
295 if (mBmPerfHeader
.Count
== LimitCount
) {
305 mBmPerfHeader
.Signiture
= PERFORMANCE_SIGNATURE
;
308 // Put performance data to Reserved memory
311 (UINTN
*) (UINTN
) mBmAcpiLowMemoryBase
,