Skip to content

Commit cd0e554

Browse files
committed
Merge commit 'd4b5206c2adddb2432ba5e64a6a5f507a65d3e57'
2 parents 082fe95 + d4b5206 commit cd0e554

File tree

6 files changed

+986
-0
lines changed

6 files changed

+986
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Text;
5+
6+
namespace NalaylikikiLijinewi.Diagnostics;
7+
8+
public class StepPerformanceCounter
9+
{
10+
public StepPerformanceCounter(string name)
11+
{
12+
RootName = name;
13+
}
14+
15+
private string RootName { get; }
16+
17+
public static readonly StepPerformanceCounter RenderThreadCounter = new StepPerformanceCounter("Render");
18+
19+
public StepStartContext StepStart(string name, bool enable = true, bool isMainStep = false)
20+
{
21+
var counterName = $"{RootName}.{name}";
22+
23+
if (!_dictionary.TryGetValue(counterName, out var counter))
24+
{
25+
counter = new PerformanceCounter(name, enable)
26+
{
27+
AutoOutput = true,
28+
};
29+
_dictionary[counterName] = counter;
30+
}
31+
32+
if (enable)
33+
{
34+
counter.StepStart();
35+
}
36+
37+
return new StepStartContext(counter, this)
38+
{
39+
Enable = enable,
40+
//IsMainStep = isMainStep,
41+
};
42+
}
43+
44+
private readonly Dictionary<string, PerformanceCounter> _dictionary = [];
45+
46+
public void StepStop(string name)
47+
{
48+
var counterName = $"{RootName}.{name}";
49+
_dictionary[counterName].StepStop();
50+
}
51+
}
52+
53+
public readonly record struct StepStartContext(PerformanceCounter Counter, StepPerformanceCounter Total) : IDisposable
54+
{
55+
internal bool Enable { get; init; }
56+
57+
//internal bool IsMainStep { get; init; }
58+
59+
public void Dispose()
60+
{
61+
if (!Enable)
62+
{
63+
return;
64+
}
65+
66+
Counter.StepStop();
67+
}
68+
}
69+
70+
public class PerformanceCounter(string name, bool enable = true)
71+
{
72+
public bool AutoOutput { get; init; }
73+
74+
public void StepStart()
75+
{
76+
_stopwatch.Restart();
77+
_count++;
78+
}
79+
80+
public void StepStop()
81+
{
82+
_stopwatch.Stop();
83+
_total += _stopwatch.Elapsed.TotalMilliseconds;
84+
85+
if (!enable)
86+
{
87+
return;
88+
}
89+
90+
if (!AutoOutput)
91+
{
92+
return;
93+
}
94+
95+
if (CanOutput)
96+
{
97+
Output();
98+
}
99+
}
100+
101+
internal bool CanOutput => (_count > 100 && _total > 1000) || _count > 1000;
102+
103+
public void Output()
104+
{
105+
var ave = _total / _count;
106+
107+
Console.WriteLine($"[{name}] 平均毫秒: {ave}");
108+
109+
_count = 0;
110+
_total = 0;
111+
}
112+
113+
private Stopwatch _stopwatch = Stopwatch.StartNew();
114+
private double _total;
115+
private int _count;
116+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<IsAotCompatible>true</IsAotCompatible>
8+
<PublishAot>true</PublishAot>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Vortice.Direct2D1" Version="3.8.2" />
13+
<PackageReference Include="Vortice.Direct3D11" Version="3.8.2" />
14+
<PackageReference Include="Vortice.DirectComposition" Version="3.8.2" />
15+
<PackageReference Include="Vortice.DXGI" Version="3.8.2" />
16+
<PackageReference Include="Vortice.Win32" Version="2.3.0" />
17+
18+
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.257">
19+
<PrivateAssets>all</PrivateAssets>
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
21+
</PackageReference>
22+
23+
<PackageReference Include="MicroCom.Runtime" Version="0.11.0" />
24+
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<!-- By default, any projects supports Windows, Linux, MacOS platforms. -->
29+
<!-- To properly support analyzers, we need to re-set this value -->
30+
<!-- https://github.com/dotnet/sdk/blob/v8.0.403/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.SupportedPlatforms.props -->
31+
<SupportedPlatform Remove="@(SupportedPlatform)" />
32+
<SupportedPlatform Include="Windows" />
33+
</ItemGroup>
34+
35+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="NalaylikikiLijinewi.csproj" />
3+
</Solution>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
EnumDisplayMonitors
2+
GetMonitorInfo
3+
MONITORINFOEXW
4+
EnumDisplaySettings
5+
GetDisplayConfigBufferSizes
6+
QueryDisplayConfig
7+
DisplayConfigGetDeviceInfo
8+
DISPLAYCONFIG_SOURCE_DEVICE_NAME
9+
DISPLAYCONFIG_TARGET_DEVICE_NAME
10+
11+
RegisterClassEx
12+
GetModuleHandle
13+
LoadCursor
14+
IDC_ARROW
15+
WndProc
16+
CreateWindowEx
17+
CW_USEDEFAULT
18+
ShowWindow
19+
SW_SHOW
20+
GetMessage
21+
TranslateMessage
22+
DispatchMessage
23+
DefWindowProc
24+
GetClientRect
25+
WM_PAINT
26+
GetWindowLong
27+
SetWindowLong
28+
DwmIsCompositionEnabled
29+
UpdateLayeredWindow
30+
DwmExtendFrameIntoClientArea
31+
DCompositionCreateDevice
32+
NCCALCSIZE_PARAMS
33+
EnableMouseInPointer
34+
WM_POINTERUPDATE
35+
GetPointerTouchInfo
36+
GetPointerDeviceRects
37+
ClientToScreen

0 commit comments

Comments
 (0)