5#include <userver/utils/statistics/recentperiod.hpp>
9namespace utils::statistics {
11using Duration = std::chrono::steady_clock::duration;
14
15class BusyStorage
final {
17 BusyStorage(Duration epoch_duration, Duration history_period,
18 size_t max_workers = 1);
22 double GetCurrentLoad()
const;
24 using WorkerId = size_t;
28 void StopWork(WorkerId worker_id);
31 WorkerId PopWorkerId();
33 Duration GetNotCommittedLoad(WorkerId worker_id)
const;
35 bool IsAlreadyStarted()
const;
37 bool UpdateCurrentWorkerLoad(std::vector<Duration>& load)
const;
40 std::unique_ptr<Impl> pimpl;
42 friend class BusyMarker;
46
47
48
49
50class BusyMarker
final {
52 BusyMarker(BusyStorage& storage)
53 : storage_(storage), worker_id_(storage.StartWork()) {}
55 BusyMarker(
const BusyMarker&) =
delete;
56 BusyMarker& operator=(
const BusyMarker&) =
delete;
58 ~BusyMarker() { storage_.StopWork(worker_id_); }
61 BusyStorage& storage_;
62 BusyStorage::WorkerId worker_id_;