Nothing calls it yet: no Agent code composes the reader, so nothing a user sees or records changes. - Application.Advanced: the port IAdvancedHardware (Acquire, Latest, ReadSessionFacts), AdvancedSnapshot, AdvancedSources and the status of each source - Reading, NotPresent, NotElevated, PawnIoMissing, Faulted. A source that is not there is a state, never an exception and never a value in its place. - Infrastructure: AdvancedHardwareHub - one reader for the whole Agent on a thread of its own (fl-advanced), started by the first holder and closed a linger after the last lets go (D107), so a PC idling with FrameLedger in the tray reads nothing for this. AdvancedHardwareReader - one tick of NVAPI and of LibreHardwareMonitor. LhmAdvancedReader over a Computer of its own: every sensor of the graphics card, and as administrator with PawnIO the processor, memory and motherboard groups (D103). LhmGroups has a member for those four and no other. - Storage is not opened (D103's outcome, written before any run): LibreHardwareMonitor 0.9.6's StorageGroup lists every drive through DiskInfoToolkit with no filter by bus and follows drives plugged in later. lhm.storage.* is Deferred in the catalog; a drive's temperature will read N/A with that reason. - A device that throws twice is left alone and the others go on; NVAPI answering with no field twice running, after it had answered, is released and initialised again once (20_OPEN_QUESTIONS M12). - FrameLedger.CaptureHost probe-advanced (unshipped): runs that reader on the caller's own rights and prints what it read and what it cost. On the dev box (RTX 5080, unelevated): 35 facts, 58 readings a tick; one NVAPI live read 0.4 ms of processor time; one refresh of the sensor library's graphics-card group 14 ms (62 ms elapsed) - 1.4% of one core at one a second, above NFR-2. So NVAPI is read every tick and the sensor library every fifth (0.28%), with no value repeated between. - The same refresh is what the L2 telemetry layer does once a second in every session. That cost is not this train's: recorded as 20_OPEN_QUESTIONS M16, with the owner's choices. - PrivilegeFootprintTests: opening every group this project can name enables no powerful privilege (the real thing on the elevated CI runner). - docs: 18_GPU_VENDOR_APIS (the reader, D103 as found, L2's line), 20_OPEN_QUESTIONS (M13 half answered, M16 new), HANDOFF, CLAUDE.md, CHANGELOG. Hook overhead: not applicable - nothing in code loaded into a game changes. Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
78 lines
3.4 KiB
C#
78 lines
3.4 KiB
C#
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
|
|
|
using FrameLedger.Infrastructure.Telemetry;
|
|
using LibreHardwareMonitor.Hardware;
|
|
using NSubstitute;
|
|
|
|
namespace FrameLedger.Infrastructure.Tests.Telemetry;
|
|
|
|
/// <summary>
|
|
/// A LibreHardwareMonitor tree made of substitutes, and an <see cref="ILhmComputer"/> over it, so the advanced
|
|
/// readers are tested with no sensor in the room — which is what CI is.
|
|
/// </summary>
|
|
internal static class FakeSensorTree
|
|
{
|
|
public static IHardware Device(HardwareType type, string name, params ISensor[] sensors)
|
|
{
|
|
IHardware h = Substitute.For<IHardware>();
|
|
h.HardwareType.Returns(type);
|
|
h.Name.Returns(name);
|
|
h.Sensors.Returns(sensors);
|
|
h.SubHardware.Returns([]);
|
|
h.Parent.Returns((IHardware?)null);
|
|
foreach (ISensor s in sensors)
|
|
{
|
|
s.Hardware.Returns(h);
|
|
}
|
|
|
|
return h;
|
|
}
|
|
|
|
public static IHardware WithSub(this IHardware parent, params IHardware[] subs)
|
|
{
|
|
parent.SubHardware.Returns(subs);
|
|
foreach (IHardware sub in subs)
|
|
{
|
|
sub.Parent.Returns(parent);
|
|
}
|
|
|
|
return parent;
|
|
}
|
|
|
|
/// <summary>A sensor whose identifier is <paramref name="path"/>, e.g. <c>/gpu-nvidia/0/temperature/0</c>.</summary>
|
|
public static ISensor Sensor(SensorType type, string path, string name, float? value)
|
|
{
|
|
ISensor s = Substitute.For<ISensor>();
|
|
s.SensorType.Returns(type);
|
|
s.Name.Returns(name);
|
|
s.Value.Returns(value);
|
|
s.Identifier.Returns(new Identifier(path.Split('/', StringSplitOptions.RemoveEmptyEntries)));
|
|
return s;
|
|
}
|
|
|
|
/// <summary>A graphics card, a processor, a motherboard with its sensor chip, and a memory device.</summary>
|
|
public static IHardware[] WholePc()
|
|
{
|
|
IHardware gpu = Device(HardwareType.GpuNvidia, "NVIDIA GeForce RTX 5080",
|
|
Sensor(SensorType.Temperature, "/gpu-nvidia/0/temperature/0", "GPU Core", 61f),
|
|
Sensor(SensorType.Control, "/gpu-nvidia/0/control/1", "GPU Fan 1", 42f),
|
|
Sensor(SensorType.Voltage, "/gpu-nvidia/0/voltage/0", "GPU Core", 1.05f),
|
|
Sensor(SensorType.Throughput, "/gpu-nvidia/0/throughput/0", "GPU PCIe Rx", 2048f));
|
|
IHardware cpu = Device(HardwareType.Cpu, "Intel Core i7-14700K",
|
|
Sensor(SensorType.Temperature, "/intelcpu/0/temperature/0", "CPU Package", 71f),
|
|
Sensor(SensorType.Temperature, "/intelcpu/0/temperature/3", "CPU Core #3", 68f),
|
|
Sensor(SensorType.Load, "/intelcpu/0/load/0", "CPU Total", 37f),
|
|
Sensor(SensorType.Power, "/intelcpu/0/power/0", "CPU Package", 96.5f));
|
|
IHardware chip = Device(HardwareType.SuperIO, "Nuvoton NCT6798D",
|
|
Sensor(SensorType.Voltage, "/lpc/nct6798d/0/voltage/7", "-12V", -11.97f),
|
|
Sensor(SensorType.Fan, "/lpc/nct6798d/0/fan/1", "Fan #2", 940f),
|
|
Sensor(SensorType.Temperature, "/lpc/nct6798d/0/temperature/2", "Temperature #3", 38f));
|
|
IHardware board = Device(HardwareType.Motherboard, "ASUS ROG STRIX Z790-E").WithSub(chip);
|
|
IHardware memory = Device(HardwareType.Memory, "Total Memory",
|
|
Sensor(SensorType.Load, "/ram/load/0", "Memory", 44f),
|
|
Sensor(SensorType.Data, "/ram/data/0", "Memory Used", 14.1f));
|
|
return [gpu, cpu, board, memory];
|
|
}
|
|
}
|