Skip to content

Commit fbb4773

Browse files
committed
fix: Only display CPU/GPU memory details when we can load them
1 parent 624f7cb commit fbb4773

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

Source/Launcher/app.manifest

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
33
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
4+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
5+
<application>
6+
<!-- Windows 10 and Windows 11 -->
7+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
8+
<!-- Windows 7 -->
9+
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
10+
</application>
11+
</compatibility>
412
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
513
<security>
614
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">

Source/RunActivity/Viewer3D/Popups/HUDWindow.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ public class HUDWindow : LayeredWindow
4848

4949
readonly int ProcessorCount = System.Environment.ProcessorCount;
5050

51+
readonly Version Windows10 = new Version(10, 0);
5152
const int PerformanceCounterUpdateTimeS = 10;
52-
float PerformanceCounterElapsedTimeS;
53+
float PerformanceCounterElapsedTimeS = PerformanceCounterUpdateTimeS;
5354

5455
readonly PerformanceCounter CLRMemoryAllocatedBytesPerSecCounter; // \.NET CLR Memory(*)\Allocated Bytes/sec
5556
float CLRMemoryAllocatedBytesPerSec;
@@ -154,25 +155,28 @@ public HUDWindow(WindowManager owner)
154155
Trace.TraceWarning("Unable to access Windows Process performance counters. This may be resolved by following the instructions at http://support.microsoft.com/kb/300956");
155156
}
156157

157-
try
158+
if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version >= Windows10)
158159
{
159-
var instancePrefix = $"pid_{Process.GetCurrentProcess().Id}_";
160-
var counterProcess = new PerformanceCounterCategory("GPU Process Memory");
161-
foreach (var process in counterProcess.GetInstanceNames())
160+
try
162161
{
163-
if (process.StartsWith(instancePrefix))
162+
var instancePrefix = $"pid_{Process.GetCurrentProcess().Id}_";
163+
var counterProcess = new PerformanceCounterCategory("GPU Process Memory");
164+
foreach (var process in counterProcess.GetInstanceNames())
164165
{
165-
GPUMemoryCommittedCounters.Add(new PerformanceCounter("GPU Process Memory", "Total Committed", process));
166-
GPUMemoryDedicatedCounters.Add(new PerformanceCounter("GPU Process Memory", "Dedicated Usage", process));
167-
GPUMemorySharedCounters.Add(new PerformanceCounter("GPU Process Memory", "Shared Usage", process));
168-
Trace.TraceInformation($"Found Windows GPU Process Memory performance counter {process}");
166+
if (process.StartsWith(instancePrefix))
167+
{
168+
GPUMemoryCommittedCounters.Add(new PerformanceCounter("GPU Process Memory", "Total Committed", process));
169+
GPUMemoryDedicatedCounters.Add(new PerformanceCounter("GPU Process Memory", "Dedicated Usage", process));
170+
GPUMemorySharedCounters.Add(new PerformanceCounter("GPU Process Memory", "Shared Usage", process));
171+
Trace.TraceInformation($"Found Windows GPU Process Memory performance counter {process}");
172+
}
169173
}
170174
}
171-
}
172-
catch (Exception error)
173-
{
174-
Trace.WriteLine(error);
175-
Trace.TraceWarning("Unable to access Windows GPU Process Memory performance counters. This may be resolved by following the instructions at http://support.microsoft.com/kb/300956");
175+
catch (Exception error)
176+
{
177+
Trace.WriteLine(error);
178+
Trace.TraceWarning("Unable to access Windows GPU Process Memory performance counters. This may be resolved by following the instructions at http://support.microsoft.com/kb/300956");
179+
}
176180
}
177181

178182
Debug.Assert(GC.MaxGeneration == 2, "Runtime is expected to have a MaxGeneration of 2.");
@@ -1382,8 +1386,8 @@ void TextPageDebugInfo(TableData table)
13821386
TableAddLabelValue(table, Viewer.Catalog.GetString("CPU"), Viewer.Catalog.GetStringFmt("{0:F0}% ({1})", (Viewer.RenderProcess.Profiler.CPU.SmoothedValue + Viewer.UpdaterProcess.Profiler.CPU.SmoothedValue + Viewer.LoaderProcess.Profiler.CPU.SmoothedValue + Viewer.SoundProcess.Profiler.CPU.SmoothedValue) / ProcessorCount, Viewer.Catalog.GetPluralStringFmt("{0} logical processor", "{0} logical processors", ProcessorCount)));
13831387
TableAddLabelValue(table, Viewer.Catalog.GetString("GPU"), Viewer.Catalog.GetStringFmt("{0:F0} FPS (50th/95th/99th percentiles {1:F1} / {2:F1} / {3:F1} ms, DirectX feature level >= {4})", Viewer.RenderProcess.FrameRate.SmoothedValue, Viewer.RenderProcess.FrameTime.SmoothedP50 * 1000, Viewer.RenderProcess.FrameTime.SmoothedP95 * 1000, Viewer.RenderProcess.FrameTime.SmoothedP99 * 1000, Viewer.Settings.DirectXFeatureLevel));
13841388
TableAddLabelValue(table, Viewer.Catalog.GetString("Memory"), Viewer.Catalog.GetStringFmt("{3}, {4}, {5}, {6} ({7:F0} kB/frame allocated, {0:F0}/{1:F0}/{2:F0} GCs)", GC.CollectionCount(0), GC.CollectionCount(1), GC.CollectionCount(2), Viewer.TextureManager.GetStatus(), Viewer.MaterialManager.GetStatus(), Viewer.ShapeManager.GetStatus(), Viewer.World.Terrain.GetStatus(), CLRMemoryAllocatedBytesPerSec / Viewer.RenderProcess.FrameRate.SmoothedValue / 1024));
1385-
TableAddLabelValue(table, Viewer.Catalog.GetString("CPU Memory"), Viewer.Catalog.GetStringFmt("{0:F0} MB private, {1:F0} MB working set, {2:F0} MB private working set, {3:F0} MB managed, {4:F0} MB virtual", CPUMemoryPrivate / 1024 / 1024, CPUMemoryWorkingSet / 1024 / 1024, CPUMemoryWorkingSetPrivate / 1024 / 1024, GC.GetTotalMemory(false) / 1024 / 1024, CPUMemoryVirtual / 1024 / 1024));
1386-
TableAddLabelValue(table, Viewer.Catalog.GetString("GPU Memory"), Viewer.Catalog.GetStringFmt("{0:F0} MB committed, {1:F0} MB dedicated, {2:F0} MB shared", GPUMemoryCommitted / 1024 / 1024, GPUMemoryDedicated / 1024 / 1024, GPUMemoryShared / 1024 / 1024));
1389+
if (CPUMemoryPrivate > 0) TableAddLabelValue(table, Viewer.Catalog.GetString("CPU Memory"), Viewer.Catalog.GetStringFmt("{0:F0} MB private, {1:F0} MB working set, {2:F0} MB private working set, {3:F0} MB managed, {4:F0} MB virtual", CPUMemoryPrivate / 1024 / 1024, CPUMemoryWorkingSet / 1024 / 1024, CPUMemoryWorkingSetPrivate / 1024 / 1024, GC.GetTotalMemory(false) / 1024 / 1024, CPUMemoryVirtual / 1024 / 1024));
1390+
if (GPUMemoryCommitted > 0) TableAddLabelValue(table, Viewer.Catalog.GetString("GPU Memory"), Viewer.Catalog.GetStringFmt("{0:F0} MB committed, {1:F0} MB dedicated, {2:F0} MB shared", GPUMemoryCommitted / 1024 / 1024, GPUMemoryDedicated / 1024 / 1024, GPUMemoryShared / 1024 / 1024));
13871391
TableAddLabelValue(table, Viewer.Catalog.GetString("Adapter"), Viewer.Catalog.GetStringFmt("{0} ({1:F0} MB)", Viewer.AdapterDescription, Viewer.AdapterMemory / 1024 / 1024));
13881392
if (Viewer.Settings.DynamicShadows)
13891393
{

0 commit comments

Comments
 (0)