- FrameLedger.ProcessStats.dll (C++20, loaded by the Agent, never into a game): the game process's dedicated and shared
GPU memory from the documented `GPU Process Memory` performance counters (no handle to the game, every instance of the
pid summed) and its private working set / working set / commit from GetProcessMemoryInfo (EX2, falling back to EX)
through PROCESS_QUERY_LIMITED_INFORMATION only (a sentinel refuses an EX2 answer whose private working set was not
filled). Not D3DKMTQueryStatistics ("Reserved for system use").
ctest fl_process_stats (GPU_INSTANCE on a hardware adapter, NO_GPU_INSTANCE on CI) and fl-probe-processstats.
- Measured first, decision table in spike-notes §16 written before the runs: +512.0 MiB for a 512 MiB buffer,
private working set equal to Windows' own counter, 0.1 ms per read, nothing leaked over 600 reads; dedicated reads a
constant 4.5 MiB above DXGI's local usage, so it is never compared with a budget.
- NativeProcessStats (third facade), GameMemoryReader: a pinned session reads through its held handle; an unpinned
Tier-2 hold opens each process of the executable for the read, refuses a reused pid, sums. CaptureSession tells the
observer which process (ICaptureObserver.Measuring), the recorder forwards it to the poller (ITelemetryPoller.Follow).
- TelemetrySample.Game; five sensor series; schema 0018 (game_vram_dedicated_*, game_ram_private_*, ..., sensor_stats_json);
SeriesAggregates gains Median and Min; a wide .partial sensors chunk (type 8) with type 4 still read; SessionProgress
and SessionHeld carry the game's memory live.
- notice-check accepts a contributor's own copyright line in the same form.
- Tests: the two classes that open a LibreHardwareMonitor Computer run one at a time - GenericCpu.Update threw a
NullReferenceException in the local gate when they ran in parallel (the Agent's own read is already contained).
- Docs corrected in place: 03_METRICS, 18_GPU_VENDOR_APIS, 17_HOOK_ENGINE, 20_OPEN_QUESTIONS (§M7, §H10, new §M11),
04_CAPTURE, 19_SAFETY, 06_DATA_MODEL, 07_IPC, 02_SPEC, 01_ARCHITECTURE, 12_BUILD, CLAUDE.md; the accuracy block and
LIMITATIONS.md.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.7 KiB
C#
61 lines
2.7 KiB
C#
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
|
|
|
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
using FluentAssertions;
|
|
using FrameLedger.Application.Telemetry;
|
|
using FrameLedger.Infrastructure.Telemetry;
|
|
|
|
namespace FrameLedger.Infrastructure.Tests.Telemetry;
|
|
|
|
/// <summary>
|
|
/// The managed mirror of <c>FlPsSample</c> against <c>FrameLedger.ProcessStats.dll</c>'s own size and ABI version (beta.12,
|
|
/// D43), and one real read of this test's own process through the real DLL. Fails rather than skips when the DLL is not
|
|
/// staged: a mirror test that quietly does nothing is a gate that cannot fail.
|
|
/// </summary>
|
|
public sealed class ProcessStatsMirrorTests
|
|
{
|
|
[Fact]
|
|
public void TheMirrorIsTheSizeTheDllAnswersAndTheAbiVersionIsTheOneWeWroteAgainst()
|
|
{
|
|
NativeProcessStats.IsPresent.Should().BeTrue("FrameLedger.ProcessStats.dll must be staged beside the test binary (FrameLedger.ProcessStats.targets)");
|
|
NativeProcessStats.LoadedAbiVersion.Should().Be(NativeProcessStats.AbiVersion);
|
|
((uint)Marshal.SizeOf<ProcessStatsSample>()).Should().Be(NativeProcessStats.LoadedSampleSize);
|
|
Marshal.SizeOf<ProcessStatsSample>().Should().Be(88);
|
|
NativeProcessStats.LoadedBuildId.Should().NotBeNullOrEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void ThisProcessesOwnMemoryReadsThroughTheRealDllWithTheLeastRight()
|
|
{
|
|
using var reader = new GameMemoryReader(new NativeProcessStats());
|
|
using var self = Process.GetCurrentProcess();
|
|
reader.Follow(GameProcess.Unpinned([new GameProcessId(self.Id, new DateTimeOffset(self.StartTime))]));
|
|
|
|
reader.TryRead(out ProcessReading r).Should().BeTrue("a process may always read its own counters");
|
|
|
|
r.Processes.Should().Be(1);
|
|
r.RamWorkingSetMb.Should().BePositive();
|
|
r.CommitMb.Should().BePositive();
|
|
if (r.RamPrivateMb is { } privateWs)
|
|
{
|
|
privateWs.Should().BePositive().And.BeLessThanOrEqualTo(r.RamWorkingSetMb!.Value);
|
|
}
|
|
|
|
// The video half depends on the machine: a test host that made no GPU allocation has no counter instance (N/A).
|
|
r.Sources.Should().HaveFlag(ProcessReadingSources.TransientHandle);
|
|
}
|
|
|
|
[Fact]
|
|
public void AReusedPidIsRefusedRatherThanReadOffAStranger()
|
|
{
|
|
using var reader = new GameMemoryReader(new NativeProcessStats());
|
|
using var self = Process.GetCurrentProcess();
|
|
reader.Follow(GameProcess.Unpinned([new GameProcessId(self.Id, new DateTimeOffset(self.StartTime).AddSeconds(-5))]));
|
|
|
|
reader.TryRead(out ProcessReading r).Should().BeFalse("the creation time is not this process's");
|
|
r.IsEmpty.Should().BeTrue();
|
|
}
|
|
}
|