diff options
| author | Stefan Boberg <[email protected]> | 2021-09-30 11:52:05 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-30 11:52:05 +0200 |
| commit | 8a48929c2212c830cf54d2c874e1a55a8f68e09e (patch) | |
| tree | 4822d0f33a3f86d993e534cb862103605e9e1b4e /zencore/stats.cpp | |
| parent | structured cache: Added stats test code (needs additional work / metrics) (diff) | |
| download | zen-8a48929c2212c830cf54d2c874e1a55a8f68e09e.tar.xz zen-8a48929c2212c830cf54d2c874e1a55a8f68e09e.zip | |
stats: Added EmitSnapshot functions to emit metrics into CbObjects
Diffstat (limited to 'zencore/stats.cpp')
| -rw-r--r-- | zencore/stats.cpp | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/zencore/stats.cpp b/zencore/stats.cpp index 2a9b0a06f..53086f3ec 100644 --- a/zencore/stats.cpp +++ b/zencore/stats.cpp @@ -1,6 +1,8 @@ // Copyright Epic Games, Inc. All Rights Reserved. #include "zencore/stats.h" + +#include <zencore/compactbinarybuilder.h> #include "zencore/intmath.h" #include "zencore/thread.h" #include "zencore/timer.h" @@ -79,18 +81,18 @@ Meter::TickIfNecessary() if (m_LastTick.compare_exchange_strong(OldTick, NewTick)) { - m_Remain.fetch_add(Age); + m_Remainder.fetch_add(Age); do { - int64_t Remain = m_Remain.load(std::memory_order_relaxed); + int64_t Remain = m_Remainder.load(std::memory_order_relaxed); if (Remain < 0) { return; } - if (m_Remain.compare_exchange_strong(Remain, Remain - CountPerTick)) + if (m_Remainder.compare_exchange_strong(Remain, Remain - CountPerTick)) { Tick(); } @@ -140,7 +142,7 @@ Meter::Rate15() } double -Meter::MeanRate() +Meter::MeanRate() const { const uint64_t Count = m_TotalCount.load(std::memory_order_relaxed); @@ -222,7 +224,7 @@ UniformSample::Update(int64_t Value) SampleSnapshot UniformSample::Snapshot() const { - uint64_t ValuesSize = Size(); + uint64_t ValuesSize = Size(); std::vector<double> Values(ValuesSize); for (int i = 0; i < ValuesSize; ++i) @@ -336,8 +338,8 @@ SampleSnapshot::GetQuantileValue(double Quantile) } const int32_t Index = (int32_t)Pos; - const double Lower = m_Values[Index - 1]; - const double Upper = m_Values[Index]; + const double Lower = m_Values[Index - 1]; + const double Upper = m_Values[Index]; // Lerp return Lower + (Pos - std::floor(Pos)) * (Upper - Lower); @@ -351,6 +353,34 @@ SampleSnapshot::GetValues() const ////////////////////////////////////////////////////////////////////////// +void +EmitSnapshot(std::string_view Tag, const Histogram& Stat, CbObjectWriter& Cbo) +{ + Cbo.BeginObject(Tag); + + SampleSnapshot Snap = Stat.Snapshot(); + + Cbo << "count" << Stat.Count() << "avg" << Stat.Mean(); + Cbo << "min" << Stat.Min() << "max" << Stat.Max(); + Cbo << "p75" << Snap.Get75Percentile() << "p95" << Snap.Get95Percentile() << "p99" << Snap.Get99Percentile() << "p999" + << Snap.Get999Percentile(); + + Cbo.EndObject(); +} + +void +EmitSnapshot(std::string_view Tag, Meter& Stat, CbObjectWriter& Cbo) +{ + Cbo.BeginObject(Tag); + + Cbo << "count" << Stat.Count() << "rate_mean" << Stat.MeanRate(); + Cbo << "rate_1" << Stat.Rate1() << "rate_5" << Stat.Rate5() << "rate_15" << Stat.Rate15(); + + Cbo.EndObject(); +} + +////////////////////////////////////////////////////////////////////////// + #if ZEN_WITH_TESTS TEST_CASE("Core.Stats.Histogram") @@ -378,7 +408,7 @@ TEST_CASE("Core.Stats.Histogram") Histo.Update(-2); CHECK_EQ(Histo.Min(), -2); CHECK_EQ(Histo.Max(), 2); - CHECK_EQ(Histo.Mean(), 1/3.0); + CHECK_EQ(Histo.Mean(), 1 / 3.0); SampleSnapshot Snap4 = Histo.Snapshot(); CHECK_EQ(Snap4.Size(), 3); |