aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-30 14:44:32 +0200
committerStefan Boberg <[email protected]>2021-09-30 14:44:32 +0200
commitdda5004708497e54bca99d72cf707ba63b6d7fb6 (patch)
tree2fd5a08f23b005a7831899ea718cf6d4e95267cd /zencore/include
parentMerge branch 'main' of https://github.com/EpicGames/zen (diff)
downloadzen-dda5004708497e54bca99d72cf707ba63b6d7fb6.tar.xz
zen-dda5004708497e54bca99d72cf707ba63b6d7fb6.zip
metrics: added OperationTiming which is a useful combination of a Meter and a Histogram, intended to track frequency and duration of certain operations
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/stats.h40
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);