xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
core
detail
LoadEvent.cpp
1
#include <xrpl/core/LoadEvent.h>
2
3
#include <xrpl/beast/utility/instrumentation.h>
4
#include <xrpl/core/LoadMonitor.h>
5
6
#include <
chrono
>
7
#include <
string
>
8
#include <
utility
>
9
10
namespace
xrpl
{
11
12
LoadEvent::LoadEvent
(
LoadMonitor
& monitor,
std::string
name
,
bool
shouldStart)
13
:
monitor_
(monitor)
14
,
running_
(shouldStart)
15
,
name_
(
std
::move(
name
))
16
,
mark_
{
std
::chrono::steady_clock::now()}
17
,
timeWaiting_
{}
18
,
timeRunning_
{}
19
{
20
}
21
22
LoadEvent::~LoadEvent
()
23
{
24
if
(
running_
)
25
stop
();
26
}
27
28
std::string
const
&
29
LoadEvent::name
()
const
30
{
31
return
name_
;
32
}
33
34
std::chrono::steady_clock::duration
35
LoadEvent::waitTime
()
const
36
{
37
return
timeWaiting_
;
38
}
39
40
std::chrono::steady_clock::duration
41
LoadEvent::runTime
()
const
42
{
43
return
timeRunning_
;
44
}
45
46
void
47
LoadEvent::setName
(
std::string
const
&
name
)
48
{
49
name_
=
name
;
50
}
51
52
void
53
LoadEvent::start
()
54
{
55
auto
const
now =
std::chrono::steady_clock::now
();
56
57
// If we had already called start, this call will
58
// replace the previous one. Any time accumulated will
59
// be counted as "waiting".
60
timeWaiting_
+= now -
mark_
;
61
mark_
= now;
62
running_
=
true
;
63
}
64
65
void
66
LoadEvent::stop
()
67
{
68
XRPL_ASSERT(
running_
,
"xrpl::LoadEvent::stop : is running"
);
69
70
auto
const
now =
std::chrono::steady_clock::now
();
71
72
timeRunning_
+= now -
mark_
;
73
mark_
= now;
74
running_
=
false
;
75
76
monitor_
.addLoadSample(*
this
);
77
}
78
79
}
// namespace xrpl
std::string
chrono
xrpl::LoadEvent::timeRunning_
std::chrono::steady_clock::duration timeRunning_
Definition
LoadEvent.h:64
xrpl::LoadEvent::running_
bool running_
Definition
LoadEvent.h:54
xrpl::LoadEvent::mark_
std::chrono::steady_clock::time_point mark_
Definition
LoadEvent.h:60
xrpl::LoadEvent::LoadEvent
LoadEvent(LoadMonitor &monitor, std::string name, bool shouldStart)
Definition
LoadEvent.cpp:12
xrpl::LoadEvent::monitor_
LoadMonitor & monitor_
Definition
LoadEvent.h:51
xrpl::LoadEvent::waitTime
std::chrono::steady_clock::duration waitTime() const
Definition
LoadEvent.cpp:35
xrpl::LoadEvent::~LoadEvent
~LoadEvent()
Definition
LoadEvent.cpp:22
xrpl::LoadEvent::setName
void setName(std::string const &name)
Definition
LoadEvent.cpp:47
xrpl::LoadEvent::name_
std::string name_
Definition
LoadEvent.h:57
xrpl::LoadEvent::stop
void stop()
Definition
LoadEvent.cpp:66
xrpl::LoadEvent::start
void start()
Definition
LoadEvent.cpp:53
xrpl::LoadEvent::timeWaiting_
std::chrono::steady_clock::duration timeWaiting_
Definition
LoadEvent.h:63
xrpl::LoadEvent::runTime
std::chrono::steady_clock::duration runTime() const
Definition
LoadEvent.cpp:41
xrpl::LoadEvent::name
std::string const & name() const
Definition
LoadEvent.cpp:29
xrpl::LoadMonitor
Definition
LoadMonitor.h:19
std
STL namespace.
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
std::chrono::steady_clock::now
T now(T... args)
string
utility
Generated by
1.17.0