diff options
author | serxa <serxa@yandex-team.ru> | 2022-02-10 16:49:08 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:08 +0300 |
commit | e5d4696304c6689379ac7ce334512404d4b7836c (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/lwtrace/perf.h | |
parent | d6d7db348c2cc64e71243cab9940ee6778f4317d (diff) | |
download | ydb-e5d4696304c6689379ac7ce334512404d4b7836c.tar.gz |
Restoring authorship annotation for <serxa@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/lwtrace/perf.h')
-rw-r--r-- | library/cpp/lwtrace/perf.h | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/library/cpp/lwtrace/perf.h b/library/cpp/lwtrace/perf.h index 03564eeb3f..d535247196 100644 --- a/library/cpp/lwtrace/perf.h +++ b/library/cpp/lwtrace/perf.h @@ -1,63 +1,63 @@ -#pragma once - -#include <util/system/types.h> -#include <util/thread/singleton.h> - -namespace NLWTrace { - struct TProbe; - - class TCpuTracker { - private: - const ui64 MinReportPeriod; - - // State - bool Reporting = false; - ui64 LastTs = 0; - ui64 LastReportTs = 0; - - // Statistics - ui64 MaxCycles; - const TProbe* MaxProbe; - ui64 MinCycles; - ui64 ProbeCycles; - ui64 Count; - - public: - TCpuTracker(); - void Enter(); - void Exit(const TProbe* Probe); - static TCpuTracker* TlsInstance() { - struct TCpuTrackerkHolder { - TCpuTracker Tracker; - }; - return &FastTlsSingletonWithPriority<TCpuTrackerkHolder, 4>()->Tracker; - } - - private: - void AddStats(const TProbe* probe, ui64 cycles); - void ResetStats(); - void Report(); - void ReportNotReentrant(); - static double MilliSeconds(ui64 cycles); - }; - - class TScopedThreadCpuTracker { - private: - const TProbe* Probe; - TCpuTracker* Tracker; - - public: - template <class T> - explicit TScopedThreadCpuTracker(const T& probe) - : Probe(&probe.Probe) - , Tracker(TCpuTracker::TlsInstance()) - { - Tracker->Enter(); - } - - ~TScopedThreadCpuTracker() { - Tracker->Exit(Probe); - } - }; - -} +#pragma once + +#include <util/system/types.h> +#include <util/thread/singleton.h> + +namespace NLWTrace { + struct TProbe; + + class TCpuTracker { + private: + const ui64 MinReportPeriod; + + // State + bool Reporting = false; + ui64 LastTs = 0; + ui64 LastReportTs = 0; + + // Statistics + ui64 MaxCycles; + const TProbe* MaxProbe; + ui64 MinCycles; + ui64 ProbeCycles; + ui64 Count; + + public: + TCpuTracker(); + void Enter(); + void Exit(const TProbe* Probe); + static TCpuTracker* TlsInstance() { + struct TCpuTrackerkHolder { + TCpuTracker Tracker; + }; + return &FastTlsSingletonWithPriority<TCpuTrackerkHolder, 4>()->Tracker; + } + + private: + void AddStats(const TProbe* probe, ui64 cycles); + void ResetStats(); + void Report(); + void ReportNotReentrant(); + static double MilliSeconds(ui64 cycles); + }; + + class TScopedThreadCpuTracker { + private: + const TProbe* Probe; + TCpuTracker* Tracker; + + public: + template <class T> + explicit TScopedThreadCpuTracker(const T& probe) + : Probe(&probe.Probe) + , Tracker(TCpuTracker::TlsInstance()) + { + Tracker->Enter(); + } + + ~TScopedThreadCpuTracker() { + Tracker->Exit(Probe); + } + }; + +} |