Wire M10.7b interpolation and the stale loss view into the client
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m55s
Foundation / checks (client) (push) Successful in 12m27s
Foundation / checks (network) (push) Successful in 12m46s
Foundation / checks (tsan) (push) Successful in 7m59s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 25m13s
Foundation / checks (postgres) (push) Canceled after 12m48s

ADR-0095. The engineering client times presentation with the tick clock:
its own marker between ticks, other markers interpolated a few ticks behind
(grey when stale). Silence beyond 3 ticks and long-gap holds are stale. A lost
session leaves its last view frozen and labelled stale until the reconnect's
fresh baseline; nothing is predicted or sent meanwhile.

evo-motion-trace --remote measures remote-marker error between two clients
through the relay, with a 1.5 s outage (motion-trace-remote-smoke CTest).
Prediction errors are recorded only for ticks inputs are scheduled for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-06 17:50:41 -04:00
co-authored by Claude Opus 5.5
parent 90cdb61e30
commit 5728e7682e
17 changed files with 651 additions and 210 deletions
+352 -169
View File
@@ -1,17 +1,23 @@
// M10.6c probe-marker prediction traces (ADR-0094). Development measurement, not a test of
// game behaviour: the engineering client's own session code (apps/evo-client
// remote_session.hpp) against a loopback region that simulates at 50 ms in real time, through
// the owned UDP impairment relay. Each profile scripts WASD-like movement, then stops and
// requires the prediction to converge on the authority.
// M10.6c/M10.7b probe-marker traces (ADR-0094, ADR-0095). Development measurement, not a
// test of game behaviour: the engineering client's own session code (apps/evo-client
// remote_session.hpp) against a loopback region that simulates at 50 ms in real time,
// through the owned UDP impairment relay (one relay per client).
//
// evo-motion-trace [--seconds S] [--profile NAME] [--smoke]
// evo-motion-trace [--seconds S] [--profile NAME] [--remote] [--smoke]
//
// One line per profile:
// Prediction (default): one client scripts WASD-like movement, then stops and requires its
// prediction to converge on the authority. One line per profile:
// motion PROFILE rtt=MS jitter=MS loss=% samples=N exact=% p50/p95/p99/max=MM corrections=N
// snaps=N refused=N dropped=N resends=N lead=TICKS max_pending=N converged=0|1
// and for the restart profile: restart resync_ms=MS converged=0|1.
// --smoke runs one short impaired profile plus the restart and exits 1 unless both converge,
// the input list stayed bounded and most predictions were exact (the CTest).
// Remote (--remote): client A moves, client B shows A's marker interpolated; every 10 ms
// B's presented position is compared with A's authoritative path at B's render tick. Midway,
// B's link is cut for 1.5 s (outage). One line per profile:
// remote PROFILE rtt=MS jitter=MS loss=% samples=N p50/p95/p99/max=MM
// current_p99/max=MM (markers not shown stale) extrapolated=% stale=% delay=TICKS
// outage_stale=% recovered_ms=MS
// --smoke runs one short impaired profile (prediction: plus a restart) and exits 1 unless
// its bounds hold (the CTests).
#include "evo/client/session_host.hpp"
#include "evo/network/dev_credentials.hpp"
#include "evo/network/session_grant.hpp"
@@ -27,6 +33,7 @@
#include <filesystem>
#include <fstream>
#include <functional>
#include <map>
#include <optional>
#include <string>
#include <string_view>
@@ -38,6 +45,7 @@ using namespace evo;
using namespace evo::network;
using Clock = std::chrono::steady_clock;
using std::chrono::milliseconds;
using Host = client::SessionHost<client_app::RemoteSession>;
constexpr std::string_view server_name = "dev-region.evolution.test";
constexpr world::WorldIdentity world_id{9, 2};
constexpr std::uint64_t region = 21;
@@ -48,17 +56,12 @@ struct Profile {
milliseconds one_way{}, jitter{};
double loss{};
};
struct Result {
std::vector<std::uint64_t> errors;
client_app::RemoteStatus status;
bool converged{};
double resync_ms{};
};
std::uint64_t now_seconds() {
return static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch())
.count());
}
// Nearest-rank percentile of micrometre samples, in millimetres.
double percentile_mm(std::vector<std::uint64_t> v, double p) {
if (v.empty())
return 0;
@@ -66,6 +69,9 @@ double percentile_mm(std::vector<std::uint64_t> v, double p) {
const auto rank = static_cast<std::size_t>(p / 100 * static_cast<double>(v.size() - 1));
return static_cast<double>(v.at(rank)) / 1000;
}
double share(std::uint64_t part, std::uint64_t whole) {
return whole == 0 ? 0.0 : 100.0 * static_cast<double>(part) / static_cast<double>(whole);
}
struct Files {
std::filesystem::path dir, ca, certificate, key;
@@ -99,194 +105,357 @@ std::array<std::uint8_t, grant_private_key_bytes> scalar() {
s.back() = 0x2C;
return s;
}
impair::Impairment impairment(const Profile& p) {
impair::Impairment way;
way.delay = p.one_way;
way.jitter = p.jitter;
way.loss = p.loss;
return way;
}
// One profile: a fresh region, relay and client session.
class Trace {
// WASD-like movement: a new direction every 0.4-1.1 s (seeded), held in between.
class Script {
public:
Trace(const Files& f, const Profile& p) : files_{f}, profile_{p} {}
std::optional<Result> run(std::chrono::seconds moving, bool restart) {
void step(client::Intention& intention) {
if (Clock::now() < change_)
return;
static constexpr std::array<std::pair<std::int16_t, std::int16_t>, 9> directions{
{{1000, 0},
{-1000, 0},
{0, 1000},
{0, -1000},
{707, 707},
{-707, 707},
{707, -707},
{-707, -707},
{0, 0}}};
const auto d = directions.at(next() % directions.size());
intention.move_x = d.first;
intention.move_y = d.second;
change_ = Clock::now() + milliseconds{400 + static_cast<int>(next() % 700)};
}
private:
std::uint64_t next() {
seed_ = ((seed_ ^ (seed_ >> 31)) * 0xBF58'476D'1CE4'E5B9ULL) + 1;
return seed_;
}
std::uint64_t seed_{0x9E37'79B9'7F4A'7C15ULL};
Clock::time_point change_{};
};
// A loopback region on real 50 ms ticks with probe markers, and clients behind relays.
class Bench {
public:
explicit Bench(const Files& f) : files_{f} {}
bool start() {
auto key = GrantSigningKey::import(DeploymentEnvironment::dev, 1, scalar());
if (!key)
return std::nullopt;
return false;
key_.emplace(std::move(*key));
server::RegionSessionsConfig c;
c.transport.certificate_pem_file = files_.certificate.string();
c.transport.key_pem_file = files_.key.string();
c.control.environment = DeploymentEnvironment::dev;
c.control.world = world_id;
c.control.region = region;
c.control.epoch = epoch_;
c.issuer_keys.push_back({1, *key->public_key()});
c.control.epoch = epoch;
c.issuer_keys.push_back({1, *key_->public_key()});
auto sessions = server::RegionSessions::create(std::move(c));
if (!sessions)
return std::nullopt;
return false;
sessions_ = std::move(*sessions);
sessions_->set_default_interest({0, 0, 0, 7});
if (!sessions_->set_motion_area({-20'000'000, -20'000'000, 20'999'999, 20'999'999, 0},
500'000, 500'000))
return sessions_->set_motion_area({-20'000'000, -20'000'000, 20'999'999, 20'999'999, 0},
500'000, 500'000);
}
// A client session behind its own relay, with `grants` single-use grants.
std::optional<std::pair<std::unique_ptr<impair::UdpRelay>, std::unique_ptr<Host>>>
client(std::uint8_t account, const Profile& p, std::uint64_t grants) {
auto relay = impair::UdpRelay::start(sessions_->port(), impairment(p), impairment(p),
0xE6 + account);
if (!relay)
return std::nullopt;
impair::Impairment way;
way.delay = profile_.one_way;
way.jitter = profile_.jitter;
way.loss = profile_.loss;
relay_ = impair::UdpRelay::start(sessions_->port(), way, way, 0xE6);
if (!relay_)
return std::nullopt;
std::vector<WireGrant> grants;
for (std::uint64_t serial = 1; serial <= 4; ++serial) {
std::vector<WireGrant> bundle;
for (std::uint64_t serial = 1; serial <= grants; ++serial) {
GrantClaims g;
g.grant_id = 700 + serial;
g.account.bytes.fill(0x5A);
g.grant_id = (std::uint64_t{account} << 16) + serial;
g.account.bytes.fill(account);
g.serial = serial;
g.world = world_id;
g.region = region;
g.issued_at = now_seconds();
g.expires_at = g.issued_at + 300;
const auto signed_grant = key->sign(g);
if (!key_)
return std::nullopt;
const auto signed_grant = key_->sign(g);
if (!signed_grant)
return std::nullopt;
grants.push_back(*signed_grant);
bundle.push_back(*signed_grant);
}
client::SessionHost<client_app::RemoteSession> host;
if (!host.connect(client_app::RemoteSession::open({{"127.0.0.1", relay_->port()},
std::string{server_name},
files_.ca_pem,
files_.ca.string(),
std::move(grants)})))
auto host = std::make_unique<Host>();
if (!host->connect(client_app::RemoteSession::open({{"127.0.0.1", relay->port()},
std::string{server_name},
files_.ca_pem,
files_.ca.string(),
std::move(bundle)})))
return std::nullopt;
client::UiState ui;
client::Intention intention;
auto* session = host.session();
const auto connected = [&] { return session && session->status().phase == "connected"; };
if (!pump(host, ui, intention, connected, std::chrono::seconds{10}))
return std::nullopt;
Result r;
// Movement: a new direction every 0.4-1.1 s (seeded), held in between.
std::uint64_t seed = 0x9E37'79B9'7F4A'7C15ULL;
const auto next = [&] {
seed = (seed ^ (seed >> 31)) * 0xBF58'476D'1CE4'E5B9ULL + 1;
return seed;
};
const std::array<std::pair<std::int16_t, std::int16_t>, 9> directions{{{1000, 0},
{-1000, 0},
{0, 1000},
{0, -1000},
{707, 707},
{-707, 707},
{707, -707},
{-707, -707},
{0, 0}}};
const auto end = Clock::now() + moving;
auto change = Clock::now();
while (Clock::now() < end) {
if (Clock::now() >= change) {
const auto d = directions.at(next() % directions.size());
intention.move_x = d.first;
intention.move_y = d.second;
change = Clock::now() + milliseconds{400 + static_cast<int>(next() % 700)};
}
if (!pump(
host, ui, intention, [] { return false; }, milliseconds{10}) &&
!host.session())
return std::nullopt;
collect(r, *host.session());
}
// Stop and require convergence: no input in flight, prediction equal to the authority.
intention.move_x = intention.move_y = 0;
r.converged = pump(
host, ui, intention, [&] { return settled(*host.session()); }, std::chrono::seconds{5});
collect(r, *host.session());
if (restart) {
// A restart: the epoch advances, the session reconnects with its next grant and the
// marker is respawned; resync is the time until the prediction matches again.
const auto before = host.session()->status().session;
++epoch_;
const auto start = Clock::now();
const bool back = pump(
host, ui, intention,
[&] {
const auto s = host.session()->status();
return s.phase == "connected" && s.session != before && s.marker &&
settled(*host.session());
},
std::chrono::seconds{15});
r.resync_ms = std::chrono::duration<double, std::milli>(Clock::now() - start).count();
r.converged = r.converged && back;
collect(r, *host.session());
}
r.status = host.session()->status();
return r;
return std::pair{std::move(relay), std::move(host)};
}
private:
// Region ticks every 50 ms of real time; the client steps every millisecond.
bool pump(client::SessionHost<client_app::RemoteSession>& host, client::UiState& ui,
const client::Intention& intention, const std::function<bool()>& done,
std::chrono::milliseconds limit) {
// One server iteration: a new tick every 50 ms of real time, then poll and replicate.
void serve() {
const auto now = Clock::now();
if (now >= next_tick_) {
++tick;
next_tick_ = std::max(next_tick_ + tick_period, now - tick_period);
}
sessions_->poll({true, epoch, tick}, now_seconds(), now);
if (tick != replicated_) {
replicated_ = tick;
sessions_->replicate(tick, [](const SessionInterest&) {
ReplicationSource s;
s.identity = world_id;
return s;
});
}
static_cast<void>(sessions_->take_events());
}
// Steps the region and the clients (each with its intention) until `done` or `limit`.
bool pump(const std::vector<std::pair<Host*, client::Intention*>>& clients,
const std::function<bool()>& done, std::chrono::milliseconds limit) {
client::UiState ui;
const auto end = Clock::now() + limit;
while (Clock::now() < end) {
const auto now = Clock::now();
if (now >= next_tick_) {
++tick_;
next_tick_ = std::max(next_tick_ + tick_period, now - tick_period);
serve();
for (const auto& [host, intention] : clients) {
host->step(Clock::now(), *intention, ui);
if (!host->session())
return false;
}
sessions_->poll({true, epoch_, tick_}, now_seconds(), now);
if (tick_ != replicated_) {
replicated_ = tick_;
sessions_->replicate(tick_, [](const SessionInterest&) {
ReplicationSource s;
s.identity = world_id;
return s;
});
}
static_cast<void>(sessions_->take_events());
host.step(Clock::now(), intention, ui);
if (!host.session())
return false;
if (done())
return true;
std::this_thread::sleep_for(milliseconds{1});
}
return done();
}
// Nothing in flight and the presented (smoothed) marker on the authoritative position.
bool settled(client_app::RemoteSession& s) {
const auto status = s.status();
const auto* m = sessions_->markers().of(status.session);
return status.marker && m != nullptr && status.inputs_pending == 0 &&
m->state.vector == motion::Vector{} &&
std::llround(status.marker_x_mm * 1000) == m->state.x &&
std::llround(status.marker_y_mm * 1000) == m->state.y;
}
static void collect(Result& r, client_app::RemoteSession& s) {
for (const auto e : s.take_prediction_errors())
r.errors.push_back(e);
[[nodiscard]] const motion::Marker* marker(std::uint64_t session) const {
return sessions_->markers().of(session);
}
std::uint64_t epoch{1}, tick{1};
private:
const Files& files_;
Profile profile_;
std::optional<GrantSigningKey> key_;
std::unique_ptr<server::RegionSessions> sessions_;
std::unique_ptr<impair::UdpRelay> relay_;
std::uint64_t epoch_{1}, tick_{1}, replicated_{};
std::uint64_t replicated_{};
Clock::time_point next_tick_{Clock::now()};
};
void report(const Profile& p, const Result& r) {
const auto exact = std::ranges::count(r.errors, std::uint64_t{0});
const auto share = r.errors.empty() ? 0.0
: 100.0 * static_cast<double>(exact) /
static_cast<double>(r.errors.size());
bool connected(Host& h) {
return h.session() && h.session()->status().phase == "connected";
}
// Nothing in flight and the presented (smoothed) own marker on the authoritative position.
bool settled(const Bench& bench, client_app::RemoteSession& s) {
const auto status = s.status();
const auto* m = bench.marker(status.session);
return status.marker && m != nullptr && status.inputs_pending == 0 &&
m->state.vector == motion::Vector{} &&
std::llround(status.marker_x_mm * 1000) == m->state.x &&
std::llround(status.marker_y_mm * 1000) == m->state.y;
}
struct PredictionResult {
std::vector<std::uint64_t> errors;
client_app::RemoteStatus status;
bool converged{};
double resync_ms{};
};
std::optional<PredictionResult> prediction(const Files& files, const Profile& p,
std::chrono::seconds moving, bool restart) {
Bench bench{files};
if (!bench.start())
return std::nullopt;
auto made = bench.client(0x5A, p, 4);
if (!made)
return std::nullopt;
auto& host = *made->second;
client::Intention intention;
const std::vector<std::pair<Host*, client::Intention*>> one{{&host, &intention}};
if (!bench.pump(one, [&] { return connected(host); }, std::chrono::seconds{10}))
return std::nullopt;
PredictionResult r;
const auto collect = [&] {
for (const auto e : host.session()->take_prediction_errors())
r.errors.push_back(e);
};
Script script;
const auto end = Clock::now() + moving;
while (Clock::now() < end) {
script.step(intention);
if (!bench.pump(one, [] { return false; }, milliseconds{10}) && !host.session())
return std::nullopt;
collect();
}
// Stop and require convergence on the authority.
intention = {};
r.converged =
bench.pump(one, [&] { return settled(bench, *host.session()); }, std::chrono::seconds{5});
collect();
if (restart) {
// The epoch advances: the session reconnects with its next grant and the marker is
// respawned; resync is the time until the prediction matches again.
const auto before = host.session()->status().session;
++bench.epoch;
const auto start = Clock::now();
const bool back = bench.pump(
one,
[&] {
const auto s = host.session()->status();
return s.phase == "connected" && s.session != before && s.marker &&
settled(bench, *host.session());
},
std::chrono::seconds{15});
r.resync_ms = std::chrono::duration<double, std::milli>(Clock::now() - start).count();
r.converged = r.converged && back;
collect();
}
r.status = host.session()->status();
return r;
}
struct RemoteResult {
std::vector<std::uint64_t> errors; // Outside the outage.
std::vector<std::uint64_t> current; // The same, for markers not shown as stale.
std::uint64_t samples{}, extrapolated{}, stale{}, outage_samples{}, outage_stale{};
double delay_sum{}, recovered_ms{-1};
};
std::optional<RemoteResult> remote(const Files& files, const Profile& p,
std::chrono::seconds moving) {
Bench bench{files};
if (!bench.start())
return std::nullopt;
auto a = bench.client(0x61, p, 2);
auto b = bench.client(0x62, p, 2);
if (!a || !b)
return std::nullopt;
auto& ha = *a->second;
auto& hb = *b->second;
client::Intention ia, ib;
const std::vector<std::pair<Host*, client::Intention*>> both{{&ha, &ia}, {&hb, &ib}};
if (!bench.pump(
both,
[&] {
return connected(ha) && connected(hb) && hb.session()->status().other_markers == 1;
},
std::chrono::seconds{10}))
return std::nullopt;
const auto session_a = ha.session()->status().session;
// A's authoritative path by tick (state after the tick).
std::map<std::uint64_t, std::pair<double, double>> path;
const auto record = [&] {
if (const auto* m = bench.marker(session_a))
path[bench.tick] = {static_cast<double>(m->state.x), static_cast<double>(m->state.y)};
};
const auto truth = [&](double t) -> std::optional<std::pair<double, double>> {
const auto lo = static_cast<std::uint64_t>(std::floor(t));
const auto from = path.find(lo), to = path.find(lo + 1);
if (from == path.end() || to == path.end())
return std::nullopt;
const auto f = t - static_cast<double>(lo);
return std::pair{from->second.first + ((to->second.first - from->second.first) * f),
from->second.second + ((to->second.second - from->second.second) * f)};
};
RemoteResult r;
Script script;
const auto start = Clock::now();
const auto outage_from = start + (moving / 2), outage_to = outage_from + milliseconds{1500};
bool cut = false;
const auto end = start + moving;
while (Clock::now() < end) {
const auto now = Clock::now();
if (!cut && now >= outage_from && now < outage_to) {
impair::Impairment dead = impairment(p);
dead.loss = 1.0;
b->first->set(dead, dead);
cut = true;
} else if (cut && now >= outage_to) {
b->first->set(impairment(p), impairment(p));
cut = false;
}
script.step(ia);
if (!bench.pump(
both,
[&] {
record();
return false;
},
milliseconds{10}) &&
(!ha.session() || !hb.session()))
return std::nullopt;
const auto s = hb.session()->status();
const auto& markers = hb.session()->markers();
const auto it = std::ranges::find_if(markers, [](const auto& m) { return !m.own; });
if (it == markers.end())
continue;
const bool in_outage = Clock::now() >= outage_from && Clock::now() < outage_to;
if (in_outage) {
++r.outage_samples;
r.outage_stale += it->stale ? 1 : 0;
continue;
}
if (Clock::now() >= outage_to && r.recovered_ms < 0 && !it->stale)
r.recovered_ms =
std::chrono::duration<double, std::milli>(Clock::now() - outage_to).count();
const auto t = truth(s.remote_render_tick);
if (!t)
continue;
++r.samples;
r.extrapolated += it->extrapolated ? 1 : 0;
r.stale += it->stale ? 1 : 0;
r.delay_sum += s.interpolation_delay;
const auto dx = (it->x_mm * 1000) - t->first, dy = (it->y_mm * 1000) - t->second;
const auto error = static_cast<std::uint64_t>(std::llround(std::hypot(dx, dy)));
r.errors.push_back(error);
if (!it->stale)
r.current.push_back(error);
}
return r;
}
void report(const Profile& p, const PredictionResult& r) {
const auto exact = static_cast<std::uint64_t>(std::ranges::count(r.errors, std::uint64_t{0}));
const auto& s = r.status;
std::printf(
"motion %s rtt=%lld jitter=%lld loss=%.1f samples=%zu exact=%.1f "
"p50/p95/p99/max=%.1f/%.1f/%.1f/%.1f corrections=%llu snaps=%llu refused=%llu "
"dropped=%llu resends=%llu lead=%llu max_pending=%llu converged=%d\n",
p.name.c_str(), 2 * static_cast<long long>(p.one_way.count()),
static_cast<long long>(p.jitter.count()), p.loss * 100, r.errors.size(), share,
percentile_mm(r.errors, 50), percentile_mm(r.errors, 95), percentile_mm(r.errors, 99),
percentile_mm(r.errors, 100), static_cast<unsigned long long>(s.corrections),
static_cast<unsigned long long>(s.snaps), static_cast<unsigned long long>(s.refused_inputs),
static_cast<unsigned long long>(s.dropped_inputs),
static_cast<unsigned long long>(s.resends), static_cast<unsigned long long>(s.lead),
static_cast<unsigned long long>(s.max_pending), r.converged ? 1 : 0);
std::printf("motion %s rtt=%lld jitter=%lld loss=%.1f samples=%zu exact=%.1f "
"p50/p95/p99/max=%.1f/%.1f/%.1f/%.1f corrections=%llu snaps=%llu refused=%llu "
"dropped=%llu resends=%llu lead=%llu max_pending=%llu converged=%d\n",
p.name.c_str(), 2 * static_cast<long long>(p.one_way.count()),
static_cast<long long>(p.jitter.count()), p.loss * 100, r.errors.size(),
share(exact, r.errors.size()), percentile_mm(r.errors, 50),
percentile_mm(r.errors, 95), percentile_mm(r.errors, 99),
percentile_mm(r.errors, 100), static_cast<unsigned long long>(s.corrections),
static_cast<unsigned long long>(s.snaps),
static_cast<unsigned long long>(s.refused_inputs),
static_cast<unsigned long long>(s.dropped_inputs),
static_cast<unsigned long long>(s.resends), static_cast<unsigned long long>(s.lead),
static_cast<unsigned long long>(s.max_pending), r.converged ? 1 : 0);
if (r.resync_ms > 0)
std::printf("restart %s resync_ms=%.0f converged=%d\n", p.name.c_str(), r.resync_ms,
r.converged ? 1 : 0);
std::fflush(stdout);
}
void report(const Profile& p, const RemoteResult& r) {
std::printf("remote %s rtt=%lld jitter=%lld loss=%.1f samples=%llu "
"p50/p95/p99/max=%.1f/%.1f/%.1f/%.1f current_p99/max=%.1f/%.1f extrapolated=%.1f "
"stale=%.1f delay=%.2f outage_stale=%.1f recovered_ms=%.0f\n",
p.name.c_str(), 2 * static_cast<long long>(p.one_way.count()),
static_cast<long long>(p.jitter.count()), p.loss * 100,
static_cast<unsigned long long>(r.samples), percentile_mm(r.errors, 50),
percentile_mm(r.errors, 95), percentile_mm(r.errors, 99),
percentile_mm(r.errors, 100), percentile_mm(r.current, 99),
percentile_mm(r.current, 100), share(r.extrapolated, r.samples),
share(r.stale, r.samples),
r.samples == 0 ? 0.0 : r.delay_sum / static_cast<double>(r.samples),
share(r.outage_stale, r.outage_samples), r.recovered_ms);
std::fflush(stdout);
}
} // namespace
@@ -294,17 +463,20 @@ void report(const Profile& p, const Result& r) {
int main(int argc, char** argv) {
std::chrono::seconds seconds{20};
std::string only;
bool smoke = false;
bool smoke = false, remote_mode = false;
for (int i = 1; i < argc; ++i) {
const std::string_view a = argv[i];
if (a == "--smoke")
smoke = true;
else if (a == "--remote")
remote_mode = true;
else if (a == "--seconds" && i + 1 < argc)
seconds = std::chrono::seconds{std::max(1, std::atoi(argv[++i]))};
else if (a == "--profile" && i + 1 < argc)
only = argv[++i];
else {
std::fputs("usage: evo-motion-trace [--seconds S] [--profile NAME] [--smoke]\n",
std::fputs("usage: evo-motion-trace [--seconds S] [--profile NAME] [--remote] "
"[--smoke]\n",
stderr);
return 2;
}
@@ -319,23 +491,34 @@ int main(int argc, char** argv) {
{"rtt200-loss5", milliseconds{100}, milliseconds{20}, 0.05}};
if (smoke) {
profiles = {{"rtt60-loss2", milliseconds{30}, milliseconds{5}, 0.02}};
seconds = std::chrono::seconds{6};
seconds = std::chrono::seconds{remote_mode ? 8 : 6};
}
int code = 0;
for (const auto& p : profiles) {
if (!only.empty() && p.name != only)
continue;
Trace t{*files, p};
const auto r = t.run(seconds, smoke || p.name == "rtt120-loss2");
if (remote_mode) {
const auto r = remote(*files, p, seconds);
if (!r) {
std::printf("remote %s setup-failed\n", p.name.c_str());
code = 1;
continue;
}
report(p, *r);
// Bounds: errors within a metre at the 95th percentile, the outage shown stale,
// recovery after it.
if (smoke && (r->samples == 0 || percentile_mm(r->current, 95) > 1000 ||
share(r->outage_stale, r->outage_samples) < 50 || r->recovered_ms < 0))
code = 1;
continue;
}
const auto r = prediction(*files, p, seconds, smoke || p.name == "rtt120-loss2");
if (!r) {
std::printf("motion %s setup-failed\n", p.name.c_str());
code = 1;
continue;
}
report(p, *r);
if (r->resync_ms > 0)
std::printf("restart %s resync_ms=%.0f converged=%d\n", p.name.c_str(), r->resync_ms,
r->converged ? 1 : 0);
const auto exact = std::ranges::count(r->errors, std::uint64_t{0});
if (smoke && (!r->converged || r->status.max_pending > 32 || r->errors.empty() ||
exact * 2 < static_cast<std::ptrdiff_t>(r->errors.size())))