userver: utils::statistics::BusyStorage Class Reference
Loading...
Searching...
No Matches
utils::statistics::BusyStorage Class Referencefinal

#include <userver/utils/statistics/busy.hpp>

Detailed Description

Measure how much time we've spent in work recently in percents that supports recirsive starts. Use utils::statistics::BusyMarker for RAII time measures.

EXPECT_FLOAT_EQ(0, storage.GetCurrentLoad());
{
if (some_heavy_task_that_takes_1s()) {
some_heavy_task_that_takes_3s();
// 4 seconds out of 5 were consumed -> 80%
EXPECT_FLOAT_EQ(0.8, storage.GetCurrentLoad());
}
}
EXPECT_LE(0.2, storage.GetCurrentLoad());
sleep_for_more_than_5s();
// No workload measured in last 5 seconds
EXPECT_FLOAT_EQ(0, storage.GetCurrentLoad());

Definition at line 19 of file busy.hpp.

Public Types

using Duration = std::chrono::steady_clock::duration
 

Public Member Functions

 BusyStorage (Duration epoch_duration, Duration history_period)
 
double GetCurrentLoad () const
 Safe to read concurrently with calling StartWork() and StopWork()
 
void StartWork ()
 Starts the time measure, if it was not already started.
 
void StopWork () noexcept
 
bool IsAlreadyStarted () const noexcept
 Returns true if the time measure is active.
 

Member Typedef Documentation

◆ Duration

using utils::statistics::BusyStorage::Duration = std::chrono::steady_clock::duration

Definition at line 21 of file busy.hpp.

Member Function Documentation

◆ StopWork()

void utils::statistics::BusyStorage::StopWork ( )
noexcept

Stops the time measure if the count of StopWork() invocations matches the StartWork() invocations count.


The documentation for this class was generated from the following file: