diff options
Diffstat (limited to 'zencore/include')
| -rw-r--r-- | zencore/include/zencore/stats.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/zencore/include/zencore/stats.h b/zencore/include/zencore/stats.h index f61184ced..dfa8dac34 100644 --- a/zencore/include/zencore/stats.h +++ b/zencore/include/zencore/stats.h @@ -180,6 +180,46 @@ private: std::atomic<int64_t> m_Count{0}; }; +/** Track timing and frequency of some operation + + Example usage would be to track frequency and duration of network + requests, or function calls. + + */ +class OperationTiming +{ +public: + OperationTiming(int32_t SampleCount = 514); + ~OperationTiming(); + + void Update(int64_t Duration); + int64_t Max() const; + int64_t Min() const; + double Mean() const; + uint64_t Count() const; + SampleSnapshot Snapshot() const { return m_Histogram.Snapshot(); } + + double Rate1() { return m_Meter.Rate1(); } + double Rate5() { return m_Meter.Rate5(); } + double Rate15() { return m_Meter.Rate15(); } + double MeanRate() const { return m_Meter.MeanRate(); } + + struct Scope + { + Scope(OperationTiming& Outer); + ~Scope(); + + private: + OperationTiming& m_Outer; + uint64_t m_StartTick; + }; + +private: + Meter m_Meter; + Histogram m_Histogram; +}; + +void EmitSnapshot(std::string_view Tag, OperationTiming& Stat, CbObjectWriter& Cbo); void EmitSnapshot(std::string_view Tag, const Histogram& Stat, CbObjectWriter& Cbo); void EmitSnapshot(std::string_view Tag, Meter& Stat, CbObjectWriter& Cbo); |