Skip to content

Commit fe32039

Browse files
committed
Merge commit '8f008aa6f39a121e22e968fef4c85f14a5957cfd'
2 parents 98715d3 + 8f008aa commit fe32039

File tree

8 files changed

+951
-2
lines changed

8 files changed

+951
-2
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Text;
5+
6+
namespace JukalkawelocerLalainurbolea.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+
private readonly List<double> _stepTimeList = new List<double>(20);
75+
76+
public void StepStart()
77+
{
78+
_stopwatch.Restart();
79+
_count++;
80+
}
81+
82+
public void StepStop()
83+
{
84+
_stopwatch.Stop();
85+
_total += _stopwatch.Elapsed.TotalMilliseconds;
86+
87+
if (_stepTimeList.Count < _stepTimeList.Capacity)
88+
{
89+
_stepTimeList.Add(_stopwatch.Elapsed.TotalMilliseconds);
90+
}
91+
92+
if (!enable)
93+
{
94+
return;
95+
}
96+
97+
if (!AutoOutput)
98+
{
99+
return;
100+
}
101+
102+
if (CanOutput)
103+
{
104+
Output();
105+
}
106+
}
107+
108+
internal bool CanOutput => (_count > 100 && _total > 1000) || _count > 1000;
109+
110+
public void Output()
111+
{
112+
var ave = _total / _count;
113+
114+
Console.WriteLine($"[{name}] 平均毫秒: {ave}");
115+
116+
_count = 0;
117+
_total = 0;
118+
}
119+
120+
private Stopwatch _stopwatch = Stopwatch.StartNew();
121+
private double _total;
122+
private int _count;
123+
}
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="JukalkawelocerLalainurbolea.csproj" />
3+
</Solution>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
EnumDisplayMonitors
2+
GetMonitorInfo
3+
MONITORINFOEXW
4+
EnumDisplaySettings
5+
GetDisplayConfigBufferSizes
6+
QueryDisplayConfig
7+
DisplayConfigGetDeviceInfo
8+
9+
RegisterClassEx
10+
GetModuleHandle
11+
LoadCursor
12+
IDC_ARROW
13+
CreateWindowEx
14+
CW_USEDEFAULT
15+
ShowWindow
16+
SHOW_WINDOW_CMD
17+
GetMessage
18+
TranslateMessage
19+
DispatchMessage
20+
DefWindowProc
21+
GetClientRect
22+
WM_PAINT
23+
GetWindowLong
24+
SetWindowLong
25+
NCCALCSIZE_PARAMS
26+
WaitForSingleObjectEx
27+
28+
ClientToScreen
29+
WM_POINTERUPDATE
30+
GetPointerDeviceRects
31+
GetPointerTouchInfo
32+
EnableMouseInPointer

0 commit comments

Comments
 (0)