/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
library/cpp/unified_agent_client/duration_counter.cpp
41 строка
1 KB
qkrorlqr
Initial NBS OpenSource export
28 апр 2023, 21:54
28 апр 2023, 21:54
783a858
Код
Авторство
О чём код?
#include "duration_counter.h" namespace NUnifiedAgent { using namespace NMonitoring; TDurationUsCounter::TDurationUsCounter(const TString& name, TDynamicCounters& owner) : Counter(*owner.GetCounter(name, true)) , ActiveTimers() , Lock() { } NHPTimer::STime* TDurationUsCounter::Begin() { with_lock (Lock) { ActiveTimers.push_back(0); auto& result = ActiveTimers.back(); NHPTimer::GetTime(&result); return &result; } } void TDurationUsCounter::End(NHPTimer::STime* startTime) { with_lock (Lock) { Counter += static_cast<ui64>(NHPTimer::GetTimePassed(startTime) * 1000000); *startTime = 0; while (!ActiveTimers.empty() && ActiveTimers.front() == 0) { ActiveTimers.pop_front(); } } } void TDurationUsCounter::Update() { with_lock (Lock) { for (auto& startTime : ActiveTimers) { if (startTime != 0) { Counter += static_cast<ui64>(NHPTimer::GetTimePassed(&startTime) * 1000000); } } } } }