Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/ETW/Microsoft_Windows_DXGI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using static PresentMonFps.AdvApi32;

namespace PresentMonFps.ETW;

internal static class Microsoft_Windows_DXGI
{
public const string Name = "Microsoft-Windows-DXGI";

public static readonly Guid GUID = new("CA11C036-0102-4A2D-A6AD-F03CFED5D3C9");

public static readonly EVENT_DESCRIPTOR_DECL PresentMultiplaneOverlay_Start = new(0x0037, 0x00, 0x10, 0x00, 0x01, 0x000e, 0x8000000000000002);

public static readonly EVENT_DESCRIPTOR_DECL PresentMultiplaneOverlay_Stop = new(0x0038, 0x00, 0x10, 0x00, 0x02, 0x000e, 0x8000000000000002);

public static readonly EVENT_DESCRIPTOR_DECL Present_Start = new(0x002a, 0x00, 0x10, 0x00, 0x01, 0x0009, 0x8000000000000002);

public static readonly EVENT_DESCRIPTOR_DECL Present_Stop = new(0x002b, 0x00, 0x10, 0x00, 0x02, 0x0009, 0x8000000000000002);

public static readonly EVENT_DESCRIPTOR_DECL ResizeBuffers_Start = new(0x002d, 0x00, 0x10, 0x00, 0x01, 0x0005, 0x8000000000000002);

public static readonly EVENT_DESCRIPTOR_DECL SwapChain_Start = new(0x000a, 0x00, 0x10, 0x00, 0x01, 0x0002, 0x8000000000000001);

public enum Keyword : ulong
{
Objects = 0x1,
Events = 0x2,
JournalEntries = 0x4,
Microsoft_Windows_DXGI_Analytic = 0x8000000000000000,
Microsoft_Windows_DXGI_Logging = 0x4000000000000000,
}

public enum Level : byte
{
win_LogAlways = 0x0,
}

public enum Channel : byte
{
Microsoft_Windows_DXGI_Analytic = 0x10,
Microsoft_Windows_DXGI_Logging = 0x11,
}

public enum DXGIPresentFlags : uint
{
DXGI_PRESENT_TEST = 1,
DXGI_PRESENT_DO_NOT_SEQUENCE = 2,
DXGI_PRESENT_RESTART = 4,
DXGI_PRESENT_DO_NOT_WAIT = 8,
DXGI_PRESENT_STEREO_PREFER_RIGHT = 16,
DXGI_PRESENT_STEREO_TEMPORARY_MONO = 32,
DXGI_PRESENT_RESTRICT_TO_OUTPUT = 64,
}

public enum HybridPresentMode : uint
{
NOT_HYBRID = 0,
TWO_COPY_PATH = 1,
ONE_COPY_PATH_CASO = 2,
}
}
30 changes: 26 additions & 4 deletions src/FpsInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ public static async Task<FpsResult> StartOnceAsync(FpsRequest request)
FpsResult result = new();
FpsCalculator fps = new();
int pid = (int)request.TargetPid;
TraceEventID presentEventId = (TraceEventID)Microsoft_Windows_DxgKrnl.Present_Info.Id;
TraceEventID dxgKrnlPresentEventId = (TraceEventID)Microsoft_Windows_DxgKrnl.Present_Info.Id;
TraceEventID dxgiPresentStartEventId = (TraceEventID)Microsoft_Windows_DXGI.Present_Start.Id;

await Task.Run(() =>
{
using TraceEventSession session = new(SessionName);

session.Source.Dynamic.All += OnDynamicAll;
session.EnableProvider(Microsoft_Windows_DxgKrnl.GUID);
session.EnableProvider(Microsoft_Windows_DXGI.GUID);

_ = Task.Run(() =>
{
Expand Down Expand Up @@ -137,9 +139,18 @@ void OnDynamicAll(TraceEvent data)

/// <see cref="Present"/>
/// <see cref="Microsoft_Windows_DxgKrnl.Name"/>
/// <see cref="Microsoft_Windows_DXGI.Name"/>
if (data.ProviderGuid == Microsoft_Windows_DxgKrnl.GUID)
{
if (data.ID == presentEventId)
if (data.ID == dxgKrnlPresentEventId)
{
DateTime timestamp = data.TimeStamp;
fps.Calculate(timestamp.Ticks);
}
}
else if (data.ProviderGuid == Microsoft_Windows_DXGI.GUID)
{
if (data.ID == dxgiPresentStartEventId)
{
DateTime timestamp = data.TimeStamp;
fps.Calculate(timestamp.Ticks);
Expand Down Expand Up @@ -170,13 +181,15 @@ public static async Task StartForeverAsync(FpsRequest request, Action<FpsResult>
FpsResult result = new();
FpsCalculator fps = new();
int pid = (int)request.TargetPid;
TraceEventID presentEventId = (TraceEventID)Microsoft_Windows_DxgKrnl.Present_Info.Id;
TraceEventID dxgKrnlPresentEventId = (TraceEventID)Microsoft_Windows_DxgKrnl.Present_Info.Id;
TraceEventID dxgiPresentStartEventId = (TraceEventID)Microsoft_Windows_DXGI.Present_Start.Id;

using TraceEventSession session = new(SessionName);

fps.FpsReceived += OnFpsReceived;
session.Source.Dynamic.All += OnDynamicAll;
session.EnableProvider(Microsoft_Windows_DxgKrnl.GUID);
session.EnableProvider(Microsoft_Windows_DXGI.GUID);

Task processTask = Task.Factory.StartNew(session.Source.Process, TaskCreationOptions.LongRunning);
Task consumeTask = Task.Run(() =>
Expand Down Expand Up @@ -208,9 +221,18 @@ void OnDynamicAll(TraceEvent data)

/// <see cref="Present"/>
/// <see cref="Microsoft_Windows_DxgKrnl.Name"/>
/// <see cref="Microsoft_Windows_DXGI.Name"/>
if (data.ProviderGuid == Microsoft_Windows_DxgKrnl.GUID)
{
if (data.ID == presentEventId)
if (data.ID == dxgKrnlPresentEventId)
{
DateTime timestamp = data.TimeStamp;
fps.Calculate(timestamp.Ticks);
}
}
else if (data.ProviderGuid == Microsoft_Windows_DXGI.GUID)
{
if (data.ID == dxgiPresentStartEventId)
{
DateTime timestamp = data.TimeStamp;
fps.Calculate(timestamp.Ticks);
Expand Down
8 changes: 4 additions & 4 deletions src/PresentMonFps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>PresentMonFps</AssemblyName>
<PackageVersion>2.0.5</PackageVersion>
<AssemblyVersion>2.0.5</AssemblyVersion>
<FileVersion>2.0.4</FileVersion>
<Version>$(VersionPrefix)2.0.5</Version>
<PackageVersion>2.0.6</PackageVersion>
<AssemblyVersion>2.0.6</AssemblyVersion>
<FileVersion>2.0.6</FileVersion>
<Version>$(VersionPrefix)2.0.6</Version>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<Authors>Lemutec</Authors>
Expand Down