diff options
author | msherbakov <msherbakov@yandex-team.ru> | 2022-02-10 16:49:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:17 +0300 |
commit | a0ffafe83b7d6229709a32fa942c71d672ac989c (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/monlib/metrics/ewma.h | |
parent | c224a621661ddd69699f9476922eb316607ef57e (diff) | |
download | ydb-a0ffafe83b7d6229709a32fa942c71d672ac989c.tar.gz |
Restoring authorship annotation for <msherbakov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/monlib/metrics/ewma.h')
-rw-r--r-- | library/cpp/monlib/metrics/ewma.h | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/library/cpp/monlib/metrics/ewma.h b/library/cpp/monlib/metrics/ewma.h index 06a2bc5058..9b2dad7cc5 100644 --- a/library/cpp/monlib/metrics/ewma.h +++ b/library/cpp/monlib/metrics/ewma.h @@ -1,47 +1,47 @@ -#pragma once - -#include <util/datetime/base.h> -#include <util/generic/ptr.h> - -#include <atomic> - -namespace NMonitoring { - class IGauge; - - class IExpMovingAverage { - public: - virtual ~IExpMovingAverage() = default; - virtual void Tick() = 0; - virtual void Update(i64 value) = 0; - virtual double Rate() const = 0; - virtual void Reset() = 0; - }; - - using IExpMovingAveragePtr = THolder<IExpMovingAverage>; - - class TEwmaMeter { - public: - // Creates a fake EWMA that will always return 0. Mostly for usage convenience - TEwmaMeter(); - explicit TEwmaMeter(IExpMovingAveragePtr&& ewma); - - TEwmaMeter(TEwmaMeter&& other); - TEwmaMeter& operator=(TEwmaMeter&& other); - - void Mark(); - void Mark(i64 value); - - double Get(); - - private: - void TickIfNeeded(); - - private: - IExpMovingAveragePtr Ewma_; - std::atomic<ui64> LastTick_{TInstant::Now().Seconds()}; - }; - - IExpMovingAveragePtr OneMinuteEwma(IGauge* gauge); - IExpMovingAveragePtr FiveMinuteEwma(IGauge* gauge); - IExpMovingAveragePtr FiveteenMinuteEwma(IGauge* gauge); -} // namespace NMonitoring +#pragma once + +#include <util/datetime/base.h> +#include <util/generic/ptr.h> + +#include <atomic> + +namespace NMonitoring { + class IGauge; + + class IExpMovingAverage { + public: + virtual ~IExpMovingAverage() = default; + virtual void Tick() = 0; + virtual void Update(i64 value) = 0; + virtual double Rate() const = 0; + virtual void Reset() = 0; + }; + + using IExpMovingAveragePtr = THolder<IExpMovingAverage>; + + class TEwmaMeter { + public: + // Creates a fake EWMA that will always return 0. Mostly for usage convenience + TEwmaMeter(); + explicit TEwmaMeter(IExpMovingAveragePtr&& ewma); + + TEwmaMeter(TEwmaMeter&& other); + TEwmaMeter& operator=(TEwmaMeter&& other); + + void Mark(); + void Mark(i64 value); + + double Get(); + + private: + void TickIfNeeded(); + + private: + IExpMovingAveragePtr Ewma_; + std::atomic<ui64> LastTick_{TInstant::Now().Seconds()}; + }; + + IExpMovingAveragePtr OneMinuteEwma(IGauge* gauge); + IExpMovingAveragePtr FiveMinuteEwma(IGauge* gauge); + IExpMovingAveragePtr FiveteenMinuteEwma(IGauge* gauge); +} // namespace NMonitoring |