Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddc7517492
|
||
|
|
63af4eb38c
|
||
|
|
be10e68506
|
||
|
|
0058b7c167
|
||
|
|
a936466f5f
|
||
|
|
a0690a4bc2
|
No files matched your search
@@ -67,6 +67,14 @@ numeric core and does not move; the heading is the full version — corrected 20
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Sensors were read less often than the setting says** (owner decision D146). With the sensor interval at
|
||||
1000 ms, nearly every session on the owner's PC got a sample every 1.3 seconds: the Agent waited the whole
|
||||
interval *after* each reading, and a reading there takes about a third of a second (what in it does is not
|
||||
established; on a PC where the Agent is not run as administrator it takes a millisecond, and the samples were
|
||||
already a second apart). It now keeps the period. No chart was wrong — every sample is stored with its own time — but a session
|
||||
has about a third more samples now, and about a quarter of the readings of NVIDIA's latency report no longer
|
||||
fall between two samples. For developers: `sensor_blobs.hz` was the constant 1 and is now the rate the
|
||||
session's samples had.
|
||||
- **A session could start with the last read of the session before it.** In a game that kept running between two
|
||||
sessions, a read of the driver's latency report that ended after the first session's last tick was taken as the
|
||||
second session's first point. A new session now drops it.
|
||||
|
||||
@@ -131,6 +131,7 @@ shown is recorded too, from outside the game. ([Capture](docs/04_CAPTURE.md))
|
||||
second. They are the driver's numbers, not FrameLedger's measurement. **The stages overlap and do not add up to
|
||||
the total**, and the graphics card's stage includes the time the card waited — in one game it is longer than the
|
||||
whole frame; the driver's own figure for the card's active time is shown beside it where the driver gives one.
|
||||
One point is one reading; with the sensor interval set above one second, some readings are not stored.
|
||||
FrameLedger asks the driver for them from inside the game; a read that is slow or faults is switched off until the game is closed, and the session says so.
|
||||
([Advanced metrics](guide/12-advanced-metrics.md))
|
||||
|
||||
|
||||
@@ -496,6 +496,22 @@ Because Tier-1 and Tier-2 sessions carry different fields, every query that comp
|
||||
> Sensor series are aligned to `t_ms` (milliseconds from `qpc_epoch`) and a tick with no reading is stored as
|
||||
> **−1** — never 0, which would be a reading — because temperatures, loads, power and memory are never negative.
|
||||
>
|
||||
> **`t_ms` is the time axis; `hz` is the fallback** (written here 2026-11-14, owner decision D146 — the code cited
|
||||
> this rule before the page had it). Every series of a session is stored beside `t_ms`, which carries each
|
||||
> sample's own time, and the App draws against it; `hz` is read only for a row that has no `t_ms`
|
||||
> (`SessionSeriesLoader`). **Until 0.1.0-beta.48 `hz` was the constant 1**, whatever the samples did — and they
|
||||
> were not one second apart: the poller waited its whole interval *after* a poll's work. In the owner's ledger of
|
||||
> 2026-11-14, under a setting of 1000 ms, 180 of the 186 sessions long enough to tell have a median of 1.32 s
|
||||
> between samples; six have 1.0 s. **What takes the third of a second is not established.** Unelevated — the layers
|
||||
> composed as the Agent composes them, each read under a stopwatch — a poll takes about a millisecond. The two
|
||||
> sessions with no `cpu_temp` series (an Agent that was not elevated) are among the six, which points at the
|
||||
> sensor library's processor update, run on the poll's thread as administrator with PawnIO; but four sessions
|
||||
> that have the series kept one second, and the call itself was not timed (it needs elevation). Since 0.1.0-beta.48 the poller keeps a fixed period
|
||||
> (`TelemetryPoller.UntilNextTick`) and `hz` is the rate the session's samples had, measured from the samples
|
||||
> (`SessionFinalizer.SampleRate`: the gaps between the first and the last over the time between them, to a
|
||||
> thousandth; 1 for fewer than two) — so it is right for a session recovered from a `.partial` file as well.
|
||||
> Rows written before keep their 1.
|
||||
>
|
||||
> **The advanced series are the exception, and say so by their name (schema 0023, owner decision D102).** A series
|
||||
> whose name starts with `adv.` stores **NaN** for a tick with no reading: a motherboard's −12 V rail is negative, so
|
||||
> −1 cannot mark a gap, and most of its ticks are gaps — the sensor library is read every fifth. They go through a
|
||||
|
||||
+11
-2
@@ -204,8 +204,17 @@ is [`17_HOOK_ENGINE.md`](17_HOOK_ENGINE.md) §Calls the Overlay makes into a dri
|
||||
brought up to date with the next release, as beta.46's pages were.
|
||||
- **In Phantom Blade Zero the driver's *GPU render* span is longer than its total** (item 45): shown as reported,
|
||||
not explained. In Cyberpunk 2077 it is not. The owner's answer: read the driver's active time (NEXT 2).
|
||||
- **The Agent's samples are 1.32 s apart while `sensor_blobs.hz` says 1.0** (seen 2026-11-14 in the `t_ms` series,
|
||||
in sessions back to beta.42). Not looked into: whether anything reads `hz` as the spacing.
|
||||
- ~~**The Agent's samples are 1.32 s apart while `sensor_blobs.hz` says 1.0**~~ (seen 2026-11-14 in the `t_ms`
|
||||
series). **Looked into the same day (D146)**: the poller waited its whole interval after a poll's work; only
|
||||
the App's series loader reads `hz`, and only where a row has no `t_ms`, so no chart was wrong. The poller now
|
||||
keeps a fixed period and `hz` is measured from the samples (`06_DATA_MODEL` §sensor_blobs) — in no release yet.
|
||||
- **Where the third of a second goes is not established.** Unelevated, a poll takes about a millisecond (the
|
||||
layers composed as the Agent composes them, each read under a stopwatch). In the owner's ledger 180 of 186
|
||||
sessions are 1.32 s apart and six are 1.0 s: the two with no `cpu_temp` series (an Agent not elevated) are among
|
||||
the six — which points at the sensor library's processor update, run on the poll's thread as administrator
|
||||
with PawnIO — **but four sessions that have the series kept one second** (22, 72, 73, 136). **Not measured**:
|
||||
that call itself (it needs elevation), and whether it is processor time or waiting. Not changed; the period no
|
||||
longer depends on it. The owner's to say whether it is worth timing on their PC and moving off the poll's thread.
|
||||
- **No test runs the whole path through the real Agent**: the injected tests stop at the shared memory and the
|
||||
sampler's start from it; no end-to-end case loads the stand-in module under an Agent session.
|
||||
- **Two install batches of beta.46 took 0.61 s and 1.26 s and nothing explains them** (Hogwarts Legacy, Cyberpunk
|
||||
|
||||
@@ -20,7 +20,7 @@ The link under them, *Read what the hook does and does not do*, opens the safety
|
||||
| Setting | What it does | Default |
|
||||
|---|---|---|
|
||||
| **Minimum session length (s)** | A shorter session is not kept. 5 to 600 seconds. *Agent.* | 30 |
|
||||
| **Sensor interval (ms)** | How often the PC's sensors are read during a session. 500 to 2000 ms. *Agent.* | 1000 |
|
||||
| **Sensor interval (ms)** | How often the PC's sensors are read during a session. 500 to 2000 ms. With a value above 1000, not every reading of NVIDIA's latency report — made about once a second inside the game — becomes a point: each point is still one reading ([Advanced metrics](12-advanced-metrics.md)). *Agent.* | 1000 |
|
||||
| **Raw series kept per game** | How many of each game's newest sessions keep their per-frame data; older ones keep their statistics. 0 keeps everything. *Agent.* | 20 |
|
||||
| **Advanced metrics** | Reads more from the graphics driver and the hardware sensors during a session — the graphics card's memory and load in detail, each fan and voltage, what your display can do, the driver's settings for the game — and stores it with the session. In a game FrameLedger measures from inside it also reads what the game tells DLSS, Streamline and FSR, and — on an NVIDIA card, in a Direct3D 12 game that uses NVIDIA's library — asks the graphics driver about once a second how long each stage of a frame took ([Advanced metrics](12-advanced-metrics.md)). Off: nothing more is read or stored. It applies from the next session; a session recorded while it was off is not filled in later. While it is on, the **Advanced** page is in the list on the left ([Advanced metrics](12-advanced-metrics.md)). *Agent.* | Off |
|
||||
|
||||
|
||||
@@ -33,7 +33,12 @@ public static class AdvancedSessionBuilder
|
||||
/// </summary>
|
||||
public const int MaxSeries = 256;
|
||||
|
||||
public static (IReadOnlyList<SensorBlob> Blobs, AdvancedSessionRow? Row) Build(IReadOnlyList<TelemetrySample> sensors, AdvancedSessionData? data, ISeriesCodec codec)
|
||||
/// <summary>The session's advanced series as blobs, and its <c>session_advanced</c> row — nothing when there is neither a series nor data.</summary>
|
||||
/// <param name="sensors">The session's samples, in order.</param>
|
||||
/// <param name="data">What the session knew of the machine and itself, or null when the option was off.</param>
|
||||
/// <param name="codec">How a series is encoded.</param>
|
||||
/// <param name="hz">The rate the samples had (<see cref="SessionFinalizer.SampleRate"/>): stored with each series as the fallback for a reader with no <c>t_ms</c>.</param>
|
||||
public static (IReadOnlyList<SensorBlob> Blobs, AdvancedSessionRow? Row) Build(IReadOnlyList<TelemetrySample> sensors, AdvancedSessionData? data, ISeriesCodec codec, double hz = 1)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(sensors);
|
||||
ArgumentNullException.ThrowIfNull(codec);
|
||||
@@ -48,7 +53,7 @@ public static class AdvancedSessionBuilder
|
||||
var stats = new Dictionary<string, SensorSeriesStats>(StringComparer.Ordinal);
|
||||
for (int s = 0; s < names.Count; s++)
|
||||
{
|
||||
blobs.Add(new SensorBlob { Series = names[s], Hz = 1, Codec = codec.Tag, Data = codec.EncodeSparseFloat32(columns[s]) });
|
||||
blobs.Add(new SensorBlob { Series = names[s], Hz = hz, Codec = codec.Tag, Data = codec.EncodeSparseFloat32(columns[s]) });
|
||||
SeriesAggregates aggregates = SeriesAggregates.Of(columns[s].Select(static v => float.IsNaN(v) ? (double?)null : v));
|
||||
if (aggregates.Count > 0)
|
||||
{
|
||||
|
||||
@@ -59,7 +59,8 @@ public sealed class SessionFinalizer
|
||||
|
||||
// Advanced metrics (D102), both tiers: they are read by the Agent, not by a hook, so a session that was not
|
||||
// hooked has them all the same. Nothing when the option was off - no series, no row.
|
||||
(IReadOnlyList<SensorBlob> advancedBlobs, AdvancedSessionRow? advanced) = AdvancedSessionBuilder.Build(input.Sensors, input.Advanced, _codec);
|
||||
double hz = SampleRate(input.Sensors, row.QpcFrequency);
|
||||
(IReadOnlyList<SensorBlob> advancedBlobs, AdvancedSessionRow? advanced) = AdvancedSessionBuilder.Build(input.Sensors, input.Advanced, _codec, hz);
|
||||
if (input.Hooked is null)
|
||||
{
|
||||
// A Tier-2 row has no frames and every sensor the machine provided (2026-09-22): the same averages a
|
||||
@@ -67,7 +68,7 @@ public sealed class SessionFinalizer
|
||||
return new FinalizedSession
|
||||
{
|
||||
Row = SessionAggregator.WithSensorAggregates(row with { Tier = CaptureTier.NotHooked }, input.Sensors),
|
||||
Sensors = [.. EncodeSensors(input.Sensors, row.QpcEpoch, row.QpcFrequency), .. advancedBlobs],
|
||||
Sensors = [.. EncodeSensors(input.Sensors, row.QpcEpoch, row.QpcFrequency, hz), .. advancedBlobs],
|
||||
Advanced = advanced,
|
||||
};
|
||||
}
|
||||
@@ -82,11 +83,32 @@ public sealed class SessionFinalizer
|
||||
{
|
||||
FirstPresentMs = FirstPresentMs(r.Dominant, row.QpcEpoch, row.QpcFrequency),
|
||||
},
|
||||
Sensors = [.. EncodeSensors(input.Sensors, row.QpcEpoch, row.QpcFrequency), .. advancedBlobs],
|
||||
Sensors = [.. EncodeSensors(input.Sensors, row.QpcEpoch, row.QpcFrequency, hz), .. advancedBlobs],
|
||||
Advanced = advanced,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The rate the session's samples had, a second (owner decision D146): the gaps between the first and the last
|
||||
/// over the time between them, to a thousandth. 1 where there are fewer than two samples or no time between them.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Measured, not the configured interval: it is then right for a session recovered from a <c>.partial</c> file,
|
||||
/// which never knew the setting, and for one whose poller could not keep its period. It is the FALLBACK for a
|
||||
/// reader: every series is stored beside <c>t_ms</c>, which carries each sample's own time.
|
||||
/// </remarks>
|
||||
public static double SampleRate(IReadOnlyList<TelemetrySample> sensors, long qpcFrequency)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(sensors);
|
||||
if (sensors.Count < 2 || qpcFrequency <= 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
long span = sensors[^1].QpcTicks - sensors[0].QpcTicks;
|
||||
return span <= 0 ? 1 : Math.Round((sensors.Count - 1) * (double)qpcFrequency / span, 3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The discard rule, the owner, then step 5: one transaction, then the retention sweep.
|
||||
/// </summary>
|
||||
@@ -248,7 +270,7 @@ public sealed class SessionFinalizer
|
||||
}
|
||||
|
||||
/// <summary><c>t_ms</c> plus one series per field any sample carried, aligned to <c>t_ms</c>, −1 where a tick had no reading.</summary>
|
||||
private List<SensorBlob> EncodeSensors(IReadOnlyList<TelemetrySample> sensors, ulong qpcEpoch, long qpcFrequency)
|
||||
private List<SensorBlob> EncodeSensors(IReadOnlyList<TelemetrySample> sensors, ulong qpcEpoch, long qpcFrequency, double hz)
|
||||
{
|
||||
if (sensors.Count == 0)
|
||||
{
|
||||
@@ -257,34 +279,34 @@ public sealed class SessionFinalizer
|
||||
|
||||
var blobs = new List<SensorBlob>
|
||||
{
|
||||
Blob("t_ms", sensors, s => (float)((s.QpcTicks - (long)qpcEpoch) * 1000.0 / qpcFrequency)),
|
||||
Blob("t_ms", sensors, hz, s => (float)((s.QpcTicks - (long)qpcEpoch) * 1000.0 / qpcFrequency)),
|
||||
};
|
||||
// One list (SensorSeriesCatalog) for the blobs and for sensor_stats_json; the game process's memory joined it in
|
||||
// beta.12 (D43) — five series, MiB, both tiers.
|
||||
foreach ((string name, Func<TelemetrySample, double?> select) in SensorSeriesCatalog.All)
|
||||
{
|
||||
AddIfAny(blobs, name, sensors, select);
|
||||
AddIfAny(blobs, name, sensors, hz, select);
|
||||
}
|
||||
|
||||
return blobs;
|
||||
}
|
||||
|
||||
private void AddIfAny(List<SensorBlob> into, string series, IReadOnlyList<TelemetrySample> sensors, Func<TelemetrySample, double?> field)
|
||||
private void AddIfAny(List<SensorBlob> into, string series, IReadOnlyList<TelemetrySample> sensors, double hz, Func<TelemetrySample, double?> field)
|
||||
{
|
||||
if (sensors.Any(s => field(s) is not null))
|
||||
{
|
||||
into.Add(Blob(series, sensors, s => field(s) is { } v ? (float)v : SensorMissing));
|
||||
into.Add(Blob(series, sensors, hz, s => field(s) is { } v ? (float)v : SensorMissing));
|
||||
}
|
||||
}
|
||||
|
||||
private SensorBlob Blob(string series, IReadOnlyList<TelemetrySample> sensors, Func<TelemetrySample, float> value) => new()
|
||||
private SensorBlob Blob(string series, IReadOnlyList<TelemetrySample> sensors, double hz, Func<TelemetrySample, float> value) => new()
|
||||
{
|
||||
Series = series,
|
||||
|
||||
// Nominal: the poller ticks once a second by default (TelemetryPollerOptions). The t_ms series stored beside every
|
||||
// series carries each tick's real time, and that is what the App draws against; Hz is only its fallback for a row
|
||||
// written without t_ms (06_DATA_MODEL §sensor_blobs).
|
||||
Hz = 1,
|
||||
// The rate the samples had (SampleRate; it was the constant 1 until 0.1.0-beta.48, whatever the samples did).
|
||||
// The t_ms series stored beside every series carries each tick's real time, and that is what the App draws
|
||||
// against; Hz is only its fallback for a row written without t_ms (06_DATA_MODEL §sensor_blobs).
|
||||
Hz = hz,
|
||||
Codec = _codec.Tag,
|
||||
Data = _codec.EncodeFloat32([.. sensors.Select(value)]),
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
using FrameLedger.Application.Advanced;
|
||||
using FrameLedger.Application.Telemetry;
|
||||
|
||||
@@ -205,12 +206,34 @@ public sealed class TelemetryPoller : ITelemetryPoller
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How long to wait for the next tick of a fixed period (owner decision D146): ticks are due at whole intervals
|
||||
/// from the loop's start, so the answer is what is left of the interval now running - more than nothing, at most
|
||||
/// a whole interval. A poll that overran one or more periods is followed by the next tick still to come: the
|
||||
/// ticks it missed are skipped, never run in a burst.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Until 0.1.0-beta.48 the loop waited the whole interval AFTER a poll's work. In the owner's ledger nearly
|
||||
/// every session has its samples 1.32 s apart under a setting of one second - so the part inside a game, which
|
||||
/// reads the driver's latency report once a second, had a quarter of its reads fall between two samples. What
|
||||
/// takes the third of a second is not established (06_DATA_MODEL §sensor_blobs): unelevated, a poll takes about
|
||||
/// a millisecond. Whatever a poll costs, the period no longer depends on it.
|
||||
/// </remarks>
|
||||
public static TimeSpan UntilNextTick(TimeSpan elapsed, TimeSpan interval)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(interval, TimeSpan.Zero);
|
||||
long into = elapsed <= TimeSpan.Zero ? 0 : elapsed.Ticks % interval.Ticks;
|
||||
return TimeSpan.FromTicks(interval.Ticks - into);
|
||||
}
|
||||
|
||||
private void Loop()
|
||||
{
|
||||
// The stopwatch, not the injected clock: this is about waiting, and a test's clock stands still.
|
||||
long started = Stopwatch.GetTimestamp();
|
||||
do
|
||||
{
|
||||
PollOnce();
|
||||
}
|
||||
while (!_stop.Wait(_options.Interval));
|
||||
while (!_stop.Wait(UntilNextTick(Stopwatch.GetElapsedTime(started), _options.Interval)));
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,10 @@ public sealed class AdvancedSessionBuilderTests
|
||||
|
||||
blobs.Select(static b => b.Series).Should().Equal("adv.nvapi.pstate", "adv.lhm.board.voltage.lpc_0_7");
|
||||
blobs.Should().OnlyContain(static b => b.Hz == 1 && string.Equals(b.Codec, "raw-le-test", StringComparison.Ordinal));
|
||||
|
||||
// The rate the session's samples had is the caller's to say (D146); 1 is only what is assumed without it.
|
||||
AdvancedSessionBuilder.Build(Samples(), _data, new RawSeriesCodec(), hz: 0.758).Blobs
|
||||
.Should().OnlyContain(static b => b.Hz == 0.758);
|
||||
float[] pstate = Decode(blobs[0]);
|
||||
float[] rail = Decode(blobs[1]);
|
||||
pstate.Should().HaveCount(5);
|
||||
|
||||
@@ -118,6 +118,32 @@ public sealed class SessionFinalizerTests
|
||||
built.Sensors.Should().AllSatisfy(s => s.Hz.Should().Be(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheRateStoredWithASeriesIsTheOneTheSamplesHad()
|
||||
{
|
||||
// D146: it was the constant 1. Samples 1.32 s apart - what a poller that waited its whole interval after its
|
||||
// work made of "once a second" - are 0.758 a second, and are stored as that.
|
||||
SessionFinalizer.SampleRate(SessionFixtures.Sensors(3), SessionFixtures.QpcFrequency).Should().Be(1);
|
||||
List<Application.Telemetry.TelemetrySample> slow = SessionFixtures.Sensors(5);
|
||||
for (int i = 0; i < slow.Count; i++)
|
||||
{
|
||||
slow[i] = slow[i] with { QpcTicks = (long)SessionFixtures.QpcEpoch + (i * SessionFixtures.QpcFrequency * 132 / 100) };
|
||||
}
|
||||
|
||||
SessionFinalizer.SampleRate(slow, SessionFixtures.QpcFrequency).Should().Be(0.758);
|
||||
|
||||
(SessionFinalizer finalizer, _) = Make();
|
||||
FinalizedSession built = finalizer.Build(new FinalizeInput { Skeleton = SessionFixtures.Skeleton(tier: CaptureTier.NotHooked), Sensors = slow });
|
||||
built.Sensors.Should().NotBeEmpty();
|
||||
built.Sensors.Should().AllSatisfy(s => s.Hz.Should().Be(0.758));
|
||||
|
||||
// Fewer than two samples, or no time between them, have no rate to measure: 1, as before.
|
||||
SessionFinalizer.SampleRate([], SessionFixtures.QpcFrequency).Should().Be(1);
|
||||
SessionFinalizer.SampleRate(SessionFixtures.Sensors(1), SessionFixtures.QpcFrequency).Should().Be(1);
|
||||
SessionFinalizer.SampleRate([slow[0], slow[0]], SessionFixtures.QpcFrequency).Should().Be(1);
|
||||
SessionFinalizer.SampleRate(slow, 0).Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheMachinesReadingsBecomeTheCpuAndMemorySeriesTheSchemaAlwaysAllowed()
|
||||
{
|
||||
|
||||
@@ -231,6 +231,56 @@ public sealed class TelemetryPollerTests
|
||||
empty.Should().Throw<ArgumentOutOfRangeException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheNextTickIsDueAtAWholeIntervalFromTheStartHoweverLongThePollTook()
|
||||
{
|
||||
TimeSpan second = TimeSpan.FromSeconds(1);
|
||||
|
||||
// D146: a poll that took 320 ms is followed 680 ms later, not a whole second later.
|
||||
TelemetryPoller.UntilNextTick(TimeSpan.FromMilliseconds(320), second).Should().Be(TimeSpan.FromMilliseconds(680));
|
||||
TelemetryPoller.UntilNextTick(TimeSpan.FromMilliseconds(5320), second).Should().Be(TimeSpan.FromMilliseconds(680));
|
||||
|
||||
// A poll that overran two periods: the next tick still to come, and the two it missed are not made up.
|
||||
TelemetryPoller.UntilNextTick(TimeSpan.FromMilliseconds(2500), second).Should().Be(TimeSpan.FromMilliseconds(500));
|
||||
|
||||
// On the boundary, and before any time has passed: a whole interval - never nothing, never more.
|
||||
TelemetryPoller.UntilNextTick(second, second).Should().Be(second);
|
||||
TelemetryPoller.UntilNextTick(TimeSpan.Zero, second).Should().Be(second);
|
||||
TelemetryPoller.UntilNextTick(TimeSpan.FromSeconds(-3), second).Should().Be(second);
|
||||
for (int ms = 0; ms < 5000; ms += 37)
|
||||
{
|
||||
TelemetryPoller.UntilNextTick(TimeSpan.FromMilliseconds(ms), TimeSpan.FromMilliseconds(500))
|
||||
.Should().BeGreaterThan(TimeSpan.Zero).And.BeLessThanOrEqualTo(TimeSpan.FromMilliseconds(500));
|
||||
}
|
||||
|
||||
Action none = () => TelemetryPoller.UntilNextTick(second, TimeSpan.Zero);
|
||||
none.Should().Throw<ArgumentOutOfRangeException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheThreadKeepsItsPeriodWhenAPollTakesTime()
|
||||
{
|
||||
// A layer that takes 300 ms to answer, polled every 500 ms: the samples are 500 ms apart, where waiting the
|
||||
// whole interval after the work made them 800 ms apart.
|
||||
using var layer = new FakeLayer(TelemetryLayer.Lhm);
|
||||
GpuSample sample = layer.Sample(_t0, load: 1);
|
||||
layer.Script(() =>
|
||||
{
|
||||
Thread.Sleep(300);
|
||||
return sample;
|
||||
});
|
||||
var poller = new TelemetryPoller(layer, new TelemetryPollerOptions { Interval = TelemetryPollerOptions.MinimumInterval }, TimeProvider.System);
|
||||
|
||||
poller.Start();
|
||||
SpinWait.SpinUntil(() => poller.Queued >= 7, TimeSpan.FromSeconds(20)).Should().BeTrue("seven ticks, half a second apart");
|
||||
poller.Dispose();
|
||||
|
||||
var samples = new List<TelemetrySample>();
|
||||
poller.Drain(samples);
|
||||
double apart = TimeProvider.System.GetElapsedTime(samples[0].QpcTicks, samples[6].QpcTicks).TotalMilliseconds / 6;
|
||||
apart.Should().BeLessThan(700, "the period is the interval (500 ms), not the interval plus the work (800 ms)");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheThreadPollsAtItsIntervalAndReturnsOnDispose()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user