userver
C++ Async Framework
Toggle main menu visibility
Documentation
API Groups
Namespaces
Reference
Class List
Class Index
File List
Macros
All
e
i
l
r
t
u
Functions
Macros
e
i
l
r
t
u
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Concepts
Loading...
Searching...
No Matches
busy.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utils/statistics/busy.hpp
4
/// @brief @copybrief utils::statistics::BusyMarker
5
6
#
include
<
memory
>
7
8
#
include
<
userver
/
utils
/
statistics
/
recentperiod
.
hpp
>
9
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
utils
::statistics {
13
14
/// Measure how much time we've spent in work recently in percents that
15
/// supports recirsive starts. Use
16
/// utils::statistics::BusyMarker for RAII time measures.
17
///
18
/// @snippet utils/statistics/busy_test.cpp busy sample
19
class
BusyStorage
final
{
20
public
:
21
using
Duration = std::chrono::steady_clock::duration;
22
23
BusyStorage(Duration epoch_duration, Duration history_period);
24
25
~BusyStorage();
26
27
/// Safe to read concurrently with calling StartWork() and StopWork()
28
double
GetCurrentLoad
()
const
;
29
30
/// Starts the time measure, if it was not already started
31
void
StartWork
();
32
33
/// Stops the time measure if the count of StopWork() invocations matches the
34
/// StartWork() invocations count.
35
void
StopWork
()
noexcept
;
36
37
/// Returns true if the time measure is active
38
bool
IsAlreadyStarted
()
const
noexcept
;
39
40
private
:
41
Duration GetNotCommittedLoad()
const
noexcept
;
42
43
struct
Impl;
44
std::unique_ptr<Impl> pimpl;
45
};
19
class
BusyStorage
final
{
…
};
46
47
/// @brief A RAII-style guard to account code block execution time in
48
/// utils::statistics::BusyStorage. Aware of recursive invocations in the same
49
/// thread.
50
///
51
/// @snippet utils/statistics/busy_test.cpp busy sample
52
class
BusyMarker
final
{
53
public
:
54
BusyMarker(BusyStorage& storage) : storage_(storage) { storage_
.
StartWork
(
)
; }
55
56
BusyMarker(
const
BusyMarker&) =
delete
;
57
BusyMarker& operator=(
const
BusyMarker&) =
delete
;
58
59
~BusyMarker() { storage_
.
StopWork
(
)
; }
60
61
private
:
62
BusyStorage& storage_;
63
};
52
class
BusyMarker
final
{
…
};
64
65
}
// namespace utils::statistics
66
67
USERVER_NAMESPACE_END
userver
utils
statistics
busy.hpp
Generated on Wed Apr 30 2025 15:55:17 for userver by
Doxygen
1.13.2