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 | d6d7db348c2cc64e71243cab9940ee6778f4317d (patch) | |
tree | bac67f42a02f9368eb4d329f5d79b77d0a6adc18 /library/cpp/lwtrace/perf.cpp | |
parent | 8d57b69dee81198a59c39e64704f7dc9f04b4fbf (diff) | |
download | ydb-d6d7db348c2cc64e71243cab9940ee6778f4317d.tar.gz |
Restoring authorship annotation for <serxa@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/lwtrace/perf.cpp')
-rw-r--r-- | library/cpp/lwtrace/perf.cpp | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/library/cpp/lwtrace/perf.cpp b/library/cpp/lwtrace/perf.cpp index 03b68586ea..b3f109c1be 100644 --- a/library/cpp/lwtrace/perf.cpp +++ b/library/cpp/lwtrace/perf.cpp @@ -1,84 +1,84 @@ -#include "perf.h" - +#include "perf.h" + #include "probes.h" -#include <util/system/datetime.h> -#include <util/system/hp_timer.h> - -namespace NLWTrace { - LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER); - - TCpuTracker::TCpuTracker() - : MinReportPeriod(NHPTimer::GetCyclesPerSecond()) - { - ResetStats(); - } - - void TCpuTracker::Enter() { - LastTs = GetCycleCount(); - } - - void TCpuTracker::Exit(const TProbe* probe) { - ui64 exitTs = GetCycleCount(); - if (exitTs < LastTs) { - return; // probably TSC was reset - } - ui64 cycles = exitTs - LastTs; - LastTs = exitTs; - - AddStats(probe, cycles); - } - - void TCpuTracker::AddStats(const TProbe* probe, ui64 cycles) { - if (MaxCycles < cycles) { - MaxProbe = probe; - MaxCycles = cycles; - } - if (MinCycles > cycles) { - MinCycles = cycles; - } - ProbeCycles += cycles; - Count++; - - if (LastTs - LastReportTs > MinReportPeriod) { - Report(); - } - } - - void TCpuTracker::ResetStats() { - MaxCycles = 0; - MaxProbe = nullptr; - MinCycles = ui64(-1); - ProbeCycles = 0; - Count = 0; - } - - void TCpuTracker::Report() { - if (!Reporting) { - Reporting = true; - ReportNotReentrant(); - Reporting = false; - } - } - - void TCpuTracker::ReportNotReentrant() { - if (LastReportTs && Count > 0 && LastTs > LastReportTs) { - ui64 reportPeriod = LastTs - LastReportTs; - double share = double(ProbeCycles) / reportPeriod; - double minMs = MilliSeconds(MinCycles); - double maxMs = MilliSeconds(MaxCycles); - double avgMs = MilliSeconds(ProbeCycles) / Count; - LastReportTs = LastTs; - ResetStats(); - LWPROBE(PerfReport, share, minMs, maxMs, avgMs); - } else { - LastReportTs = LastTs; - ResetStats(); - } - } - - double TCpuTracker::MilliSeconds(ui64 cycles) { - return NHPTimer::GetSeconds(cycles) * 1000.0; - } - -} +#include <util/system/datetime.h> +#include <util/system/hp_timer.h> + +namespace NLWTrace { + LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER); + + TCpuTracker::TCpuTracker() + : MinReportPeriod(NHPTimer::GetCyclesPerSecond()) + { + ResetStats(); + } + + void TCpuTracker::Enter() { + LastTs = GetCycleCount(); + } + + void TCpuTracker::Exit(const TProbe* probe) { + ui64 exitTs = GetCycleCount(); + if (exitTs < LastTs) { + return; // probably TSC was reset + } + ui64 cycles = exitTs - LastTs; + LastTs = exitTs; + + AddStats(probe, cycles); + } + + void TCpuTracker::AddStats(const TProbe* probe, ui64 cycles) { + if (MaxCycles < cycles) { + MaxProbe = probe; + MaxCycles = cycles; + } + if (MinCycles > cycles) { + MinCycles = cycles; + } + ProbeCycles += cycles; + Count++; + + if (LastTs - LastReportTs > MinReportPeriod) { + Report(); + } + } + + void TCpuTracker::ResetStats() { + MaxCycles = 0; + MaxProbe = nullptr; + MinCycles = ui64(-1); + ProbeCycles = 0; + Count = 0; + } + + void TCpuTracker::Report() { + if (!Reporting) { + Reporting = true; + ReportNotReentrant(); + Reporting = false; + } + } + + void TCpuTracker::ReportNotReentrant() { + if (LastReportTs && Count > 0 && LastTs > LastReportTs) { + ui64 reportPeriod = LastTs - LastReportTs; + double share = double(ProbeCycles) / reportPeriod; + double minMs = MilliSeconds(MinCycles); + double maxMs = MilliSeconds(MaxCycles); + double avgMs = MilliSeconds(ProbeCycles) / Count; + LastReportTs = LastTs; + ResetStats(); + LWPROBE(PerfReport, share, minMs, maxMs, avgMs); + } else { + LastReportTs = LastTs; + ResetStats(); + } + } + + double TCpuTracker::MilliSeconds(ui64 cycles) { + return NHPTimer::GetSeconds(cycles) * 1000.0; + } + +} |