Add adaptive Well timing telemetry
This commit is contained in:
parent
05be4b2e44
commit
ec91c58408
8 changed files with 1166 additions and 34 deletions
|
|
@ -8,3 +8,8 @@ public interface IMimirStreamSource : IDisposable
|
|||
|
||||
bool TryRead(out MimirStreamSample sample);
|
||||
}
|
||||
|
||||
public interface IMimirMultiplexedStreamSource : IMimirStreamSource
|
||||
{
|
||||
int LogicalStreamCount { get; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public sealed record MimirAsioStreamSourceOptions(
|
|||
IReadOnlyList<string> SourceIds);
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
public sealed class MimirAsioStreamSource : IMimirStreamSource
|
||||
public sealed class MimirAsioStreamSource : IMimirMultiplexedStreamSource
|
||||
{
|
||||
private const string DefaultClsid = "{AC4D0455-50D7-4498-B3CD-9A41D130B759}";
|
||||
private const int MaxQueuedBlocks = 32768;
|
||||
|
|
@ -57,6 +57,8 @@ public sealed class MimirAsioStreamSource : IMimirStreamSource
|
|||
|
||||
public bool ExposesDescriptorBuffer => false;
|
||||
|
||||
public int LogicalStreamCount => Math.Max(1, sourceIds.Length);
|
||||
|
||||
public bool TryRead(out MimirStreamSample sample)
|
||||
{
|
||||
sample = default;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
namespace Mimir.Runtime.Synchronization;
|
||||
|
||||
public sealed class MimirCanonicalClockMapper
|
||||
{
|
||||
private readonly Dictionary<string, ClockMap> maps = new(StringComparer.Ordinal);
|
||||
|
||||
public IReadOnlyList<MimirCanonicalClockMapSnapshot> Snapshots =>
|
||||
maps
|
||||
.OrderBy(pair => pair.Key, StringComparer.Ordinal)
|
||||
.Select(pair => new MimirCanonicalClockMapSnapshot(
|
||||
pair.Key,
|
||||
pair.Value.OffsetNs,
|
||||
pair.Value.FirstSourceTimestampNs,
|
||||
pair.Value.FirstArrivalNs,
|
||||
pair.Value.LatestSourceTimestampNs,
|
||||
pair.Value.LatestCanonicalTimestampNs,
|
||||
pair.Value.SampleCount))
|
||||
.ToArray();
|
||||
|
||||
public MimirStreamSample ToCanonical(MimirStreamSample sample)
|
||||
{
|
||||
var sourceTimestampNs = sample.TimestampNs;
|
||||
if (sourceTimestampNs <= 0)
|
||||
{
|
||||
sourceTimestampNs = sample.ArrivalNs > 0 ? sample.ArrivalNs : NowNs();
|
||||
}
|
||||
|
||||
var arrivalNs = sample.ArrivalNs > 0 ? sample.ArrivalNs : NowNs();
|
||||
var key = $"{sample.Kind}:{sample.Origin}:{sample.SourceId}";
|
||||
if (!maps.TryGetValue(key, out var map))
|
||||
{
|
||||
map = new ClockMap(checked(arrivalNs - sourceTimestampNs), sourceTimestampNs, arrivalNs);
|
||||
maps.Add(key, map);
|
||||
}
|
||||
|
||||
var canonicalTimestampNs = checked(sourceTimestampNs + map.OffsetNs);
|
||||
map.LatestSourceTimestampNs = sourceTimestampNs;
|
||||
map.LatestCanonicalTimestampNs = canonicalTimestampNs;
|
||||
map.SampleCount++;
|
||||
return sample with
|
||||
{
|
||||
TimestampNs = canonicalTimestampNs,
|
||||
ArrivalNs = arrivalNs,
|
||||
};
|
||||
}
|
||||
|
||||
private static long NowNs() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1_000_000L;
|
||||
|
||||
private sealed class ClockMap(long offsetNs, long firstSourceTimestampNs, long firstArrivalNs)
|
||||
{
|
||||
public long OffsetNs { get; } = offsetNs;
|
||||
|
||||
public long FirstSourceTimestampNs { get; } = firstSourceTimestampNs;
|
||||
|
||||
public long FirstArrivalNs { get; } = firstArrivalNs;
|
||||
|
||||
public long LatestSourceTimestampNs { get; set; } = firstSourceTimestampNs;
|
||||
|
||||
public long LatestCanonicalTimestampNs { get; set; } = firstArrivalNs;
|
||||
|
||||
public long SampleCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record MimirCanonicalClockMapSnapshot(
|
||||
string StreamKey,
|
||||
long OffsetNs,
|
||||
long FirstSourceTimestampNs,
|
||||
long FirstArrivalNs,
|
||||
long LatestSourceTimestampNs,
|
||||
long LatestCanonicalTimestampNs,
|
||||
long SampleCount);
|
||||
|
|
@ -198,7 +198,14 @@ public sealed record MimirEveDashboardUiLayoutSnapshot(
|
|||
[property: Key(3)] double? Grow,
|
||||
[property: Key(4)] double? Gap,
|
||||
[property: Key(5)] double? Padding,
|
||||
[property: Key(6)] string? Overflow);
|
||||
[property: Key(6)] string? Overflow,
|
||||
[property: Key(7)] double? MinWidth = null,
|
||||
[property: Key(8)] double? MinHeight = null,
|
||||
[property: Key(9)] double? PreferredWidth = null,
|
||||
[property: Key(10)] double? PreferredHeight = null,
|
||||
[property: Key(11)] double? Priority = null,
|
||||
[property: Key(12)] string? Density = null,
|
||||
[property: Key(13)] string? ViewportMode = null);
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed record MimirEveDashboardUiStyleSnapshot(
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ public sealed class MimirSynchronizationHub : IDisposable
|
|||
private readonly MimirComplexContourRuntimeAnalyzer? complexContourSynchronization;
|
||||
private readonly MimirAudioSynchronizationStateTracker audioSynchronizationState = new();
|
||||
private readonly MimirBioacousticProbeScheduler bioacousticProbeScheduler = new();
|
||||
private readonly MimirCanonicalClockMapper clockMapper = new();
|
||||
private readonly Dictionary<string, MimirAudioSynchronizationReport> audioSynchronizationReports = new(StringComparer.Ordinal);
|
||||
private readonly Dictionary<string, MimirAudioSynchronizationReport> complexContourReports = new(StringComparer.Ordinal);
|
||||
private readonly MimirChirpBinCalibrationModel? chirpBinCalibrationModel;
|
||||
|
|
@ -44,6 +45,9 @@ public sealed class MimirSynchronizationHub : IDisposable
|
|||
public IReadOnlyList<MimirAudioSynchronizationState> AudioSynchronizationStates =>
|
||||
audioSynchronizationState.States;
|
||||
|
||||
public IReadOnlyList<MimirCanonicalClockMapSnapshot> CanonicalClockMaps =>
|
||||
clockMapper.Snapshots;
|
||||
|
||||
public IReadOnlyList<MimirAudioSynchronizationReport> AudioSynchronizationReports =>
|
||||
audioSynchronizationReports.Values.OrderBy(report => report.SourceId, StringComparer.Ordinal).ToArray();
|
||||
|
||||
|
|
@ -110,9 +114,13 @@ public sealed class MimirSynchronizationHub : IDisposable
|
|||
var consumed = 0;
|
||||
foreach (var source in sources)
|
||||
{
|
||||
for (var index = 0; index < maxSamplesPerSource && source.TryRead(out var sample); index++)
|
||||
var logicalStreamCount = source is IMimirMultiplexedStreamSource multiplexed
|
||||
? Math.Max(1, multiplexed.LogicalStreamCount)
|
||||
: 1;
|
||||
var sourceBudget = checked(Math.Max(1, maxSamplesPerSource) * logicalStreamCount);
|
||||
for (var index = 0; index < sourceBudget && source.TryRead(out var sample); index++)
|
||||
{
|
||||
Buffers.Append(sample);
|
||||
Buffers.Append(clockMapper.ToCanonical(sample));
|
||||
consumed++;
|
||||
ingestedSamples++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue