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