duration_counter.h 977 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include <library/cpp/monlib/dynamic_counters/counters.h>
  3. #include <util/generic/deque.h>
  4. #include <util/system/hp_timer.h>
  5. #include <util/system/mutex.h>
  6. namespace NUnifiedAgent {
  7. class TDurationUsCounter {
  8. public:
  9. class TScope {
  10. public:
  11. TScope(TDurationUsCounter& counter)
  12. : Counter(counter)
  13. , StartTime(Counter.Begin())
  14. {
  15. }
  16. ~TScope() {
  17. Counter.End(StartTime);
  18. }
  19. private:
  20. TDurationUsCounter& Counter;
  21. NHPTimer::STime* StartTime;
  22. };
  23. public:
  24. TDurationUsCounter(const TString& name, NMonitoring::TDynamicCounters& owner);
  25. NHPTimer::STime* Begin();
  26. void End(NHPTimer::STime* startTime);
  27. void Update();
  28. private:
  29. NMonitoring::TDeprecatedCounter& Counter;
  30. TDeque<NHPTimer::STime> ActiveTimers;
  31. TAdaptiveLock Lock;
  32. };
  33. }