okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221engine: opt-in batch telemetry (STRATA_BATCH_TELEMETRY=1 prints BSTAT/PSTAT lines)79d8ea066

main
2.8 KiB50 linesraw
1#include "strata/core/batch_telemetry.hpp"
2
3#include <chrono>
4#include <cstdio>
5
6int main() {
7    using Sampler = strata::core::BatchWindowSampler;
8    const auto t0 = Sampler::Clock::time_point{};
9    Sampler disabled(false);
10    if (disabled.complete(4, 2, true, t0, t0)) return 1;
11
12    Sampler sampler(true);
13    if (sampler.complete(4, 2, false, t0, t0)) return 2;
14    if (sampler.complete(6, 3, false, t0 + std::chrono::milliseconds(490),
15                         t0 + std::chrono::milliseconds(500))) return 3;
16    const auto first = sampler.complete(8, 4, false, t0 + std::chrono::milliseconds(990),
17                                        t0 + std::chrono::milliseconds(1000));
18    if (!first || first->windows != 3 || first->processed_rows != 18 ||
19        first->active_rows != 9 || first->elapsed_ms != 1000) return 4;
20    if (sampler.complete(0, 0, true, t0, t0 + std::chrono::milliseconds(1001))) return 5;
21    const auto last = sampler.complete(2, 1, true, t0 + std::chrono::milliseconds(1001),
22                                       t0 + std::chrono::milliseconds(1002));
23    if (!last || last->windows != 1 || last->processed_rows != 2 ||
24        last->active_rows != 1 || last->elapsed_ms != 1) return 6;
25    Sampler pipelined(true);
26    if (pipelined.complete(4, 2, false, t0 + std::chrono::milliseconds(500),
27                           t0 + std::chrono::milliseconds(900))) return 7;
28    const auto overlap = pipelined.complete(4, 1, true, t0 + std::chrono::milliseconds(200),
29                                            t0 + std::chrono::milliseconds(1000));
30    if (!overlap || overlap->windows != 2 || overlap->processed_rows != 8 ||
31        overlap->active_rows != 3 || overlap->elapsed_ms != 800) return 8;
32    using StageSampler = strata::core::StageInFlightSampler;
33    StageSampler stages(4, true);
34    stages.launch(0, t0);
35    stages.launch(1, t0 + std::chrono::milliseconds(200));
36    stages.complete(0, t0 + std::chrono::milliseconds(800));
37    if (stages.sample(t0 + std::chrono::milliseconds(999), false)) return 9;
38    const auto first_stages = stages.sample(t0 + std::chrono::milliseconds(1000), false);
39    if (!first_stages || first_stages->elapsed_us != 1000000 ||
40        first_stages->in_flight_us != std::vector<int64_t>({800000, 800000, 0, 0})) return 10;
41    stages.complete(1, t0 + std::chrono::milliseconds(1200));
42    const auto last_stages = stages.sample(t0 + std::chrono::milliseconds(1200), true);
43    if (!last_stages || last_stages->elapsed_us != 200000 ||
44        last_stages->in_flight_us != std::vector<int64_t>({0, 200000, 0, 0})) return 11;
45    StageSampler disabled_stages(4, false);
46    disabled_stages.launch(0, t0);
47    if (disabled_stages.sample(t0 + std::chrono::seconds(2), true)) return 12;
48    std::puts("batch telemetry sampler: OK");
49    return 0;
50}