uatools 1.0.0
 
Loading...
Searching...
No Matches
Report.hpp
Go to the documentation of this file.
1
15
16#pragma once
17
18#include <array>
19#include <atomic>
20#include <chrono>
21#include <cstdint>
22#include <ostream>
23#include <string>
24
25#include <ifw/fnd/defs/iCommAdapter.hpp>
26
28
29 class Report {
30 public:
32
35 void Record(std::chrono::nanoseconds latency,
36 ifw::fnd::defs::Status status);
37
39 void RecordConnectionEvent(ifw::fnd::defs::ConnectionState state);
40
42 std::uint64_t TotalOps() const noexcept;
43
46 void Print(std::ostream& os, std::chrono::seconds duration) const;
47
48 private:
49 // ---- Per-status counters ----
50 // ifw::fnd::defs::Status is a small enum; we map each value to
51 // a fixed index so the hot path is a single fetch_add. Status
52 // values not in the enum (which shouldn't exist) bucket into
53 // index 0 ("Ok").
54 static constexpr std::size_t kStatusCount = 16;
55 std::array<std::atomic<std::uint64_t>, kStatusCount> m_status_counts{};
56
57 // ---- Connection-state counters ----
58 std::atomic<std::uint64_t> m_connected_events{0};
59 std::atomic<std::uint64_t> m_reconnecting_events{0};
60 std::atomic<std::uint64_t> m_faulted_events{0};
61 std::atomic<std::uint64_t> m_disconnected_events{0};
62
63 // ---- Latency histogram ----
64 // Log-spaced buckets covering 1 us .. ~10 s. Bucket i covers
65 // [10^((i-6)/2) seconds, 10^((i-5)/2) seconds), so e.g.:
66 // bucket 0 = [-inf, 1 us)
67 // bucket 6 = [1 us, ~3 us)
68 // bucket 18 = [~1 ms, ~3 ms)
69 // bucket 30 = [~1 s, ~3 s)
70 // Anything > 10 s lands in the final bucket as "overflow".
71 static constexpr std::size_t kBuckets = 32;
72 std::array<std::atomic<std::uint64_t>, kBuckets> m_latency_buckets{};
73
74 static std::size_t BucketIndex(std::chrono::nanoseconds latency);
75
76 // For percentile reporting.
77 std::uint64_t Percentile(double p) const;
78 double BucketUpperBoundUs(std::size_t idx) const;
79 };
80
81} // namespace eso::uatools::uastresstest
std::uint64_t TotalOps() const noexcept
Total operations recorded (success + failure).
Definition Report.cpp:104
void Print(std::ostream &os, std::chrono::seconds duration) const
Pretty-print the final report to os.
Definition Report.cpp:131
void Record(std::chrono::nanoseconds latency, ifw::fnd::defs::Status status)
Definition Report.cpp:84
void RecordConnectionEvent(ifw::fnd::defs::ConnectionState state)
Mark one connection-state event. Cheap atomic.
Definition Report.cpp:89
Definition Config.cpp:14