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