-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ETW trace processor to find chrome.exe idle wakeups
An idle wakeup is when a CPU goes from idle to running code. These can be energy intensive because they suggest that the CPU was in a potentially low power state and was then forced to run code.
- Loading branch information
1 parent
d107b77
commit 6da5fdb
Showing
5 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2021 Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Detect idle wakeups in Chrome in an ETW using TraceProcessing | ||
// Explanations of the techniques can be found here: | ||
// https://randomascii.wordpress.com/2020/01/05/bulk-etw-trace-analysis-in-c/ | ||
|
||
// See this blog post for details of the Trace Processor package used to | ||
// drive this: | ||
// https://blogs.windows.com/windowsdeveloper/2019/05/09/announcing-traceprocessor-preview-0-1-0/ | ||
// Note that this URL has changed once already, so caveat blog lector | ||
|
||
using Microsoft.Windows.EventTracing; | ||
class IdleWakeups | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
foreach (string traceName in args) | ||
{ | ||
Console.WriteLine("Processing trace '{0}'", traceName); | ||
var settings = new TraceProcessorSettings | ||
{ | ||
// Don't print a setup message on first run. | ||
SuppressFirstTimeSetupMessage = true | ||
}; | ||
using (ITraceProcessor trace = TraceProcessor.Create(traceName, settings)) | ||
{ | ||
// Specify what data we want, process the trace, then get the data. | ||
var pendingContextSwitchData = trace.UseContextSwitchData(); | ||
trace.Process(); | ||
var csData = pendingContextSwitchData.Result; | ||
|
||
long chromeSwitches = 0; | ||
long chromeIdleSwitches = 0; | ||
// Iterate through all context switches in the trace. | ||
foreach (var contextSwitch in csData.ContextSwitches) | ||
{ | ||
var imageName = contextSwitch.SwitchIn.Process.ImageName; | ||
var oldImageName = contextSwitch.SwitchOut.Process.ImageName; | ||
if (imageName == "chrome.exe") | ||
{ | ||
chromeSwitches++; | ||
if (oldImageName == "Idle") | ||
chromeIdleSwitches++; | ||
} | ||
} | ||
Console.WriteLine("{0} idlewakeups out of {1} context switches ({2:P}).", | ||
chromeIdleSwitches, chromeSwitches, | ||
chromeIdleSwitches / (double)chromeSwitches); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Windows.EventTracing.Processing.All" Version="1.9.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31912.275 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdleWakeups", "IdleWakeups.csproj", "{B088F2D9-100B-401D-A43A-3358BF682195}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{B088F2D9-100B-401D-A43A-3358BF682195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B088F2D9-100B-401D-A43A-3358BF682195}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B088F2D9-100B-401D-A43A-3358BF682195}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B088F2D9-100B-401D-A43A-3358BF682195}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {1273C88D-6FDB-4224-9D13-03762DB203A5} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters