From 8a48929c2212c830cf54d2c874e1a55a8f68e09e Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Thu, 30 Sep 2021 11:52:05 +0200 Subject: stats: Added EmitSnapshot functions to emit metrics into CbObjects --- zencore/include/zencore/stats.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'zencore/include') diff --git a/zencore/include/zencore/stats.h b/zencore/include/zencore/stats.h index 7665d0cf5..f61184ced 100644 --- a/zencore/include/zencore/stats.h +++ b/zencore/include/zencore/stats.h @@ -7,6 +7,10 @@ #include #include +namespace zen { +class CbObjectWriter; +} + namespace zen::metrics { template @@ -77,18 +81,19 @@ public: Meter(); ~Meter(); - double Rate1(); // One-minute rate - double Rate5(); // Five-minute rate - double Rate15(); // Fifteen-minute rate - double MeanRate(); // Mean rate since instantiation of this meter - void Mark(uint64_t Count = 1); // Register one or more events + inline uint64_t Count() const { return m_TotalCount; } + double Rate1(); // One-minute rate + double Rate5(); // Five-minute rate + double Rate15(); // Fifteen-minute rate + double MeanRate() const; // Mean rate since instantiation of this meter + void Mark(uint64_t Count = 1); // Register one or more events private: std::atomic m_TotalCount{0}; // Accumulator counting number of marks since beginning std::atomic m_PendingCount{0}; // Pending EWMA update accumulator std::atomic m_StartTick{0}; // Time this was instantiated (for mean) std::atomic m_LastTick{0}; // Timestamp of last EWMA tick - std::atomic m_Remain{0}; // Tracks the "modulo" of tick time + std::atomic m_Remainder{0}; // Tracks the "modulo" of tick time bool m_IsFirstTick = true; RawEWMA m_RateM1; RawEWMA m_RateM5; @@ -175,6 +180,9 @@ private: std::atomic m_Count{0}; }; +void EmitSnapshot(std::string_view Tag, const Histogram& Stat, CbObjectWriter& Cbo); +void EmitSnapshot(std::string_view Tag, Meter& Stat, CbObjectWriter& Cbo); + } // namespace zen::metrics namespace zen { -- cgit v1.2.3