Skip to content

Commit 7732af0

Browse files
committed
clean up debug window and add system memory
1 parent a9ab00e commit 7732af0

File tree

15 files changed

+243
-122
lines changed

15 files changed

+243
-122
lines changed

Framework/Intersect.Framework.Core/Config/OptionsStrings.Designer.cs

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Framework/Intersect.Framework.Core/GameObjects/DescriptorStrings.Designer.cs

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Framework/Intersect.Framework/Intersect.Framework.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<ItemGroup>
4+
<PackageReference Include="Hardware.Info" Version="101.0.1" />
45
<PackageReference Include="MessagePack.Annotations" Version="2.6.100-alpha" />
56
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="7.0.14" />
67
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
@@ -32,4 +33,8 @@
3233
</EmbeddedResource>
3334
</ItemGroup>
3435

36+
<ItemGroup>
37+
<Folder Include="System\" />
38+
</ItemGroup>
39+
3540
</Project>

Framework/Intersect.Framework/Reflection/ReflectionStrings.Designer.cs

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Intersect.Framework.SystemInformation;
2+
3+
public interface IGPUStatisticsProvider
4+
{
5+
long? AvailableMemory { get; }
6+
7+
long? TotalMemory { get; }
8+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Hardware.Info;
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace Intersect.Framework.SystemInformation;
5+
6+
public class PlatformStatistics
7+
{
8+
private static readonly HardwareInfo HardwareInfo;
9+
10+
public static IGPUStatisticsProvider? GPUStatisticsProvider { get; set; }
11+
12+
public static ILogger? Logger { get; set; }
13+
14+
public static long AvailablePhysicalMemory => (long)HardwareInfo.MemoryStatus.AvailablePhysical;
15+
16+
public static long TotalPhysicalMemory => (long)HardwareInfo.MemoryStatus.TotalPhysical;
17+
18+
public static long AvailableGPUMemory => GPUStatisticsProvider?.AvailableMemory ?? AvailableSystemMemory;
19+
20+
public static long TotalGPUMemory => GPUStatisticsProvider?.TotalMemory ?? TotalSystemMemory;
21+
22+
public static long AvailableSystemMemory => (long)HardwareInfo.MemoryStatus.AvailableVirtual;
23+
24+
public static long TotalSystemMemory => (long)HardwareInfo.MemoryStatus.TotalVirtual;
25+
26+
public static void Refresh()
27+
{
28+
try
29+
{
30+
HardwareInfo.RefreshMemoryStatus();
31+
}
32+
catch
33+
{
34+
// Do nothing
35+
}
36+
}
37+
38+
static PlatformStatistics()
39+
{
40+
HardwareInfo = new HardwareInfo();
41+
42+
Refresh();
43+
}
44+
}

Intersect.Client.Core/Core/Bootstrapper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Intersect.Core;
66
using Intersect.Factories;
77
using Intersect.Framework.Logging;
8+
using Intersect.Framework.SystemInformation;
89
using Intersect.Network;
910
using Intersect.Plugins;
1011
using Intersect.Plugins.Contexts;
@@ -43,13 +44,14 @@ public static void Start(Assembly entryAssembly, params string[] args)
4344
LoggingLevelSwitch loggingLevelSwitch =
4445
new(Debugger.IsAttached ? LogEventLevel.Debug : LogEventLevel.Information);
4546

46-
var executingAssembly = Assembly.GetExecutingAssembly();
47-
var (_, logger) = new LoggerConfiguration().CreateLoggerForIntersect(
47+
var (loggerFactory, logger) = new LoggerConfiguration().CreateLoggerForIntersect(
4848
entryAssembly,
4949
"Client",
5050
loggingLevelSwitch
5151
);
5252

53+
PlatformStatistics.Logger = loggerFactory.CreateLogger<PlatformStatistics>();
54+
5355
var packetTypeRegistry = new PacketTypeRegistry(logger, typeof(SharedConstants).Assembly);
5456
if (!packetTypeRegistry.TryRegisterBuiltIn())
5557
{

Intersect.Client.Core/Interface/Debugging/DebugWindow.cs

Lines changed: 107 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Diagnostics;
22
using Intersect.Client.Core;
33
using Intersect.Client.Framework.Content;
4-
using Intersect.Client.Framework.File_Management;
54
using Intersect.Client.Framework.GenericClasses;
65
using Intersect.Client.Framework.Graphics;
76
using Intersect.Client.Framework.Gwen;
@@ -15,8 +14,8 @@
1514
using Intersect.Client.Interface.Debugging.Providers;
1615
using Intersect.Client.Localization;
1716
using Intersect.Client.Maps;
18-
using Intersect.Client.MonoGame.NativeInterop.OpenGL;
1917
using Intersect.Framework.Reflection;
18+
using Intersect.Framework.SystemInformation;
2019
using Intersect.IO.Files;
2120
using static Intersect.Client.Framework.File_Management.GameContentManager;
2221

@@ -59,9 +58,34 @@ public DebugWindow(Base parent) : base(parent, Strings.Debug.Title, false, nameo
5958
AssetsList = CreateAssetsList(TabAssets.Page);
6059
AssetsButtonReloadAsset = CreateAssetsButtonReloadAsset(AssetsToolsTable, AssetsList);
6160

62-
TabGPU = Tabs.AddPage(Strings.Debug.TabLabelGPU, nameof(TabGPU));
63-
GPUStatisticsTable = CreateGPUStatisticsTable(TabGPU.Page);
64-
GPUAllocationsTable = CreateGPUAllocationsTable(TabGPU.Page);
61+
TabSystem = Tabs.AddPage(Strings.Debug.TabLabelSystem, nameof(TabSystem));
62+
_ = new Label(TabSystem.Page, name: "HeaderSectionSystemStatistics")
63+
{
64+
Dock = Pos.Top,
65+
Font = _defaultFont,
66+
Text = Strings.Debug.SectionSystemStatistics,
67+
TextAlign = Pos.CenterH,
68+
TextColorOverride = new Color(r: 191, g: 255, b: 191),
69+
};
70+
SystemStatisticsTable = CreateSystemStatisticsTable(TabSystem.Page);
71+
_ = new Label(TabSystem.Page, name: "HeaderSectionGPUStatistics")
72+
{
73+
Dock = Pos.Top,
74+
Font = _defaultFont,
75+
Text = Strings.Debug.SectionGPUStatistics,
76+
TextAlign = Pos.CenterH,
77+
TextColorOverride = new Color(r: 191, g: 255, b: 191),
78+
};
79+
GPUStatisticsTable = CreateGPUStatisticsTable(TabSystem.Page);
80+
_ = new Label(TabSystem.Page, name: "HeaderSectionGPUAllocations")
81+
{
82+
Dock = Pos.Top,
83+
Font = _defaultFont,
84+
Text = Strings.Debug.SectionGPUAllocations,
85+
TextAlign = Pos.CenterH,
86+
TextColorOverride = new Color(r: 191, g: 255, b: 191),
87+
};
88+
GPUAllocationsTable = CreateGPUAllocationsTable(TabSystem.Page);
6589

6690
AssetsToolsTable.SizeToChildren();
6791
}
@@ -76,6 +100,8 @@ protected override void Dispose(bool disposing)
76100

77101
private Table GPUStatisticsTable { get; }
78102

103+
private Table SystemStatisticsTable { get; }
104+
79105
private Table GPUAllocationsTable { get; }
80106

81107
private Table CreateGPUAllocationsTable(Base parent)
@@ -130,6 +156,11 @@ private Table CreateGPUAllocationsTable(Base parent)
130156
return table;
131157
}
132158

159+
private static void ResizeTableHeightToChildrenOnSizeChanged(Base sender, ValueChangedEventArgs<Point> args)
160+
{
161+
sender.SizeToChildren(resizeX: false, resizeY: true, recursive: true);
162+
}
163+
133164
private static void ResizeTableToChildrenOnSizeChanged(Base sender, ValueChangedEventArgs<Point> args)
134165
{
135166
sender.SizeToChildren(resizeX: args.Value.X > args.OldValue.X, resizeY: true, recursive: true);
@@ -253,17 +284,17 @@ private static void CopyAssetNameToClipboardOnNameCellClicked(Base sender, Mouse
253284
return node?.UserData is IGameTexture gameTexture ? gameTexture.Name : null;
254285
}
255286

256-
257287
private Table CreateGPUStatisticsTable(Base parent)
258288
{
259-
ScrollControl gpuStatisticsScroller = new(parent, nameof(gpuStatisticsScroller))
289+
ScrollControl scroller = new(parent, nameof(scroller))
260290
{
261-
Dock = Pos.Fill,
291+
Dock = Pos.Top,
292+
MinimumSize = new Point(0, 100),
262293
};
263294

264-
gpuStatisticsScroller.VerticalScrollBar.BaseNudgeAmount *= 2;
295+
scroller.VerticalScrollBar.BaseNudgeAmount *= 2;
265296

266-
var table = new Table(gpuStatisticsScroller, nameof(GPUStatisticsTable))
297+
var table = new Table(scroller, nameof(SystemStatisticsTable))
267298
{
268299
AutoSizeToContentHeightOnChildResize = true,
269300
AutoSizeToContentWidthOnChildResize = true,
@@ -273,9 +304,16 @@ private Table CreateGPUStatisticsTable(Base parent)
273304
Dock = Pos.Fill,
274305
Font = _defaultFont,
275306
};
276-
table.SizeChanged += ResizeTableToChildrenOnSizeChanged;
307+
table.SizeChanged += (sender, args) =>
308+
{
309+
ResizeTableHeightToChildrenOnSizeChanged(sender, args);
310+
var minimumSize = new Point(
311+
0,
312+
table.OuterHeight + scroller.InnerPanelPadding.Top + scroller.InnerPanelPadding.Bottom
313+
);
314+
scroller.MinimumSize = minimumSize;
315+
};
277316

278-
_ = table.AddRow(Strings.Debug.SectionGPUStatistics, columnCount: 2, name: "SectionGPU", columnIndex: 1);
279317
table.AddRow(Strings.Debug.Fps, name: "FPSRow").Listen(1, new DelegateDataProvider<int>(() => Graphics.Renderer.Fps), NoValue);
280318
// table.AddRow(Strings.Debug.Draws, name: "DrawsRow").Listen(1, new DelegateDataProvider<int>(() => Graphics.DrawCalls), NoValue);
281319

@@ -284,33 +322,54 @@ private Table CreateGPUStatisticsTable(Base parent)
284322
table.AddRow(Strings.Debug.LightsDrawn, name: "LightsDrawnRow").Listen(1, new DelegateDataProvider<int>(() => Graphics.LightsDrawn), NoValue);
285323
table.AddRow(Strings.Debug.InterfaceObjects, name: "InterfaceObjectsRow").Listen(1, new DelegateDataProvider<int?>(() => Interface.CurrentInterface?.NodeCount, delayMilliseconds: 1000), NoValue);
286324

287-
288325
table.AddRow(Strings.Debug.RenderTargetAllocations, name: "GPURenderTargetAllocations").Listen(1, new DelegateDataProvider<ulong>(() => Graphics.Renderer.RenderTargetAllocations), NoValue);
289326
table.AddRow(Strings.Debug.TextureAllocations, name: "GPUTextureAllocations").Listen(1, new DelegateDataProvider<ulong>(() => Graphics.Renderer.TextureAllocations), NoValue);
290327
table.AddRow(Strings.Debug.TextureCount, name: "GPUTextureCount").Listen(1, new DelegateDataProvider<ulong>(() => Graphics.Renderer.TextureCount), NoValue);
291328

292-
table.AddRow(Strings.Debug.FreeVRAM, name: "GPUFreeVRAM").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(Graphics.Renderer.AvailableMemory)), NoValue);
293-
table.AddRow(Strings.Debug.TotalVRAM, name: "GPUTotalVRAM").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(Graphics.Renderer.TotalMemory)), NoValue);
329+
table.AddRow(Strings.Debug.FreeVRAM, name: "GPUFreeVRAM").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.AvailableGPUMemory)), NoValue);
330+
table.AddRow(Strings.Debug.TotalVRAM, name: "GPUTotalVRAM").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.TotalGPUMemory)), NoValue);
294331

295-
table.AddRow(Strings.Debug.RenderBufferVRAMFree, name: "GPUVRAMRenderBuffers").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(GL.AvailableRenderBufferMemory)), NoValue);
296-
table.AddRow(Strings.Debug.TextureVRAMFree, name: "GPUVRAMTextures").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(GL.AvailableTextureMemory)), NoValue);
297-
table.AddRow(Strings.Debug.VBOVRAMFree, name: "GPUVRAMVBOs").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(GL.AvailableVBOMemory)), NoValue);
332+
table.PreLayout.Enqueue(t => t.SizeToChildren(recursive: true), table);
298333

299-
var rows = table.Children.OfType<TableRow>().ToArray();
300-
foreach (var row in rows)
334+
return table;
335+
}
336+
337+
private Table CreateSystemStatisticsTable(Base parent)
338+
{
339+
ScrollControl scroller = new(parent, nameof(scroller))
301340
{
302-
if (row.Name.StartsWith("Section") && row.GetCellContents(1) is Label titleLabel)
303-
{
304-
titleLabel.Padding = titleLabel.Padding with { Top = 8 };
305-
}
341+
Dock = Pos.Top,
342+
};
306343

307-
if (row.GetCellContents(0) is not Label label)
308-
{
309-
continue;
310-
}
344+
scroller.VerticalScrollBar.BaseNudgeAmount *= 2;
311345

312-
label.TextAlign = Pos.Right | Pos.CenterV;
313-
}
346+
var table = new Table(scroller, nameof(SystemStatisticsTable))
347+
{
348+
AutoSizeToContentHeightOnChildResize = true,
349+
AutoSizeToContentWidthOnChildResize = true,
350+
CellSpacing = new Point(8, 2),
351+
ColumnCount = 2,
352+
ColumnWidths = [180, null],
353+
Dock = Pos.Top,
354+
Font = _defaultFont,
355+
};
356+
table.SizeChanged += (sender, args) =>
357+
{
358+
ResizeTableHeightToChildrenOnSizeChanged(sender, args);
359+
var minimumSize = new Point(
360+
0,
361+
table.OuterHeight + scroller.InnerPanelPadding.Top + scroller.InnerPanelPadding.Bottom
362+
);
363+
scroller.MinimumSize = minimumSize;
364+
};
365+
366+
table.AddRow(Strings.Debug.FreeVirtualRAM, name: "RAMFreeVirtual").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.AvailableSystemMemory)), NoValue);
367+
table.AddRow(Strings.Debug.TotalVirtualRAM, name: "RAMTotalVirtual").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.TotalSystemMemory)), NoValue);
368+
369+
table.AddRow(Strings.Debug.FreePhysicalRAM, name: "RAMFreePhysical").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.AvailablePhysicalMemory)), NoValue);
370+
table.AddRow(Strings.Debug.TotalPhysicalRAM, name: "RAMTotalPhysical").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.TotalPhysicalMemory)), NoValue);
371+
372+
table.PreLayout.Enqueue(t => t.SizeToChildren(recursive: true), table);
314373

315374
return table;
316375
}
@@ -400,7 +459,7 @@ private void AssetListOnSelectionChanged(Base @base, EventArgs eventArgs)
400459

401460
private TabButton TabAssets { get; }
402461

403-
private TabButton TabGPU { get; }
462+
private TabButton TabSystem { get; }
404463

405464
private SearchableTree AssetsList { get; }
406465

@@ -424,9 +483,6 @@ private void AssetListOnSelectionChanged(Base @base, EventArgs eventArgs)
424483

425484
protected override void EnsureInitialized()
426485
{
427-
TableDebugStats.SizeToChildren();
428-
429-
// LoadJsonUi(UI.Debug, Graphics.Renderer?.GetResolutionString());
430486
}
431487

432488
protected override void OnAttached(Base parent)
@@ -677,20 +733,30 @@ private Table CreateInfoTableDebugStats(Base parent)
677733
table.AddRow(Strings.Debug.LightsDrawn, name: "LightsDrawnRow").Listen(1, new DelegateDataProvider<int>(() => Graphics.LightsDrawn), NoValue);
678734
table.AddRow(Strings.Debug.InterfaceObjects, name: "InterfaceObjectsRow").Listen(1, new DelegateDataProvider<int?>(() => Interface.CurrentInterface?.NodeCount, delayMilliseconds: 1000), NoValue);
679735

680-
_ = table.AddRow(Strings.Debug.SectionGPUStatistics, columnCount: 2, name: "SectionGPU", columnIndex: 1);
736+
var rowSectionGPU = table.AddRow(Strings.Debug.SectionGPUStatistics, columnCount: 2, name: "SectionGPU", columnIndex: 0);
737+
if (rowSectionGPU.GetCellContents(0) is Label labelSectionGPU)
738+
{
739+
labelSectionGPU.TextColorOverride = new Color(r: 191, g: 255, b: 191);
740+
}
681741

682742
table.AddRow(Strings.Debug.RenderTargetAllocations, name: "GPURenderTargetAllocations").Listen(1, new DelegateDataProvider<ulong>(() => Graphics.Renderer.RenderTargetAllocations), NoValue);
683743
table.AddRow(Strings.Debug.TextureAllocations, name: "GPUTextureAllocations").Listen(1, new DelegateDataProvider<ulong>(() => Graphics.Renderer.TextureAllocations), NoValue);
684744
table.AddRow(Strings.Debug.TextureCount, name: "GPUTextureCount").Listen(1, new DelegateDataProvider<ulong>(() => Graphics.Renderer.TextureCount), NoValue);
685745

686-
table.AddRow(Strings.Debug.FreeVRAM, name: "GPUFreeVRAM").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(Graphics.Renderer.AvailableMemory)), NoValue);
687-
table.AddRow(Strings.Debug.TotalVRAM, name: "GPUTotalVRAM").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(Graphics.Renderer.TotalMemory)), NoValue);
746+
table.AddRow(Strings.Debug.FreeVRAM, name: "GPUFreeVRAM").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.AvailableGPUMemory)), NoValue);
747+
table.AddRow(Strings.Debug.TotalVRAM, name: "GPUTotalVRAM").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.TotalGPUMemory)), NoValue);
688748

689-
table.AddRow(Strings.Debug.RenderBufferVRAMFree, name: "GPUVRAMRenderBuffers").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(GL.AvailableRenderBufferMemory)), NoValue);
690-
table.AddRow(Strings.Debug.TextureVRAMFree, name: "GPUVRAMTextures").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(GL.AvailableTextureMemory)), NoValue);
691-
table.AddRow(Strings.Debug.VBOVRAMFree, name: "GPUVRAMVBOs").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(GL.AvailableVBOMemory)), NoValue);
749+
table.AddRow(Strings.Debug.FreeVirtualRAM, name: "RAMFreeVirtual").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.AvailableSystemMemory)), NoValue);
750+
table.AddRow(Strings.Debug.TotalVirtualRAM, name: "RAMTotalVirtual").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.TotalSystemMemory)), NoValue);
692751

693-
// _ = table.AddRow(Strings.Debug.ControlUnderCursor, columnCount: 2, name: "SectionUI", columnIndex: 1);
752+
table.AddRow(Strings.Debug.FreePhysicalRAM, name: "RAMFreePhysical").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.AvailablePhysicalMemory)), NoValue);
753+
table.AddRow(Strings.Debug.TotalPhysicalRAM, name: "RAMTotalPhysical").Listen(1, new DelegateDataProvider<string>(() => FileSystemHelper.FormatSize(PlatformStatistics.TotalPhysicalMemory)), NoValue);
754+
755+
var rowSectionUI = table.AddRow(Strings.Debug.ControlUnderCursor, columnCount: 2, name: "SectionUI", columnIndex: 0);
756+
if (rowSectionUI.GetCellContents(0) is Label labelSectionUI)
757+
{
758+
labelSectionUI.TextColorOverride = new Color(r: 191, g: 255, b: 191);
759+
}
694760

695761
table.AddRow(Strings.Internals.Type, name: "TypeRow").Listen(1, _nodeUnderCursorProvider, (node, _) => node?.GetType().GetName(), Strings.Internals.NotApplicable);
696762
table.AddRow(Strings.Internals.Name, name: "NameRow").Listen(1, _nodeUnderCursorProvider, (node, _) => node?.ParentQualifiedName, NoValue);

0 commit comments

Comments
 (0)