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
8 LoadMonitor& monitor,
9 std::string const& name,
10 bool shouldStart)
11 : monitor_(monitor)
12 , running_(shouldStart)
13 , name_(name)
14 , mark_{std::chrono::steady_clock::now()}
15 , timeWaiting_{}
16 , timeRunning_{}
17{
18}
19
21{
22 if (running_)
23 stop();
24}
25
26std::string const&
28{
29 return name_;
30}
31
32std::chrono::steady_clock::duration
34{
35 return timeWaiting_;
36}
37
38std::chrono::steady_clock::duration
40{
41 return timeRunning_;
42}
43
44void
46{
47 name_ = name;
48}
49
50void
52{
53 auto const now = std::chrono::steady_clock::now();
54
55 // If we had already called start, this call will
56 // replace the previous one. Any time accumulated will
57 // be counted as "waiting".
58 timeWaiting_ += now - mark_;
59 mark_ = now;
60 running_ = true;
61}
62
63void
65{
66 XRPL_ASSERT(running_, "xrpl::LoadEvent::stop : is running");
67
68 auto const now = std::chrono::steady_clock::now();
69
70 timeRunning_ += now - mark_;
71 mark_ = now;
72 running_ = false;
73
75}
76
77} // 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:33
LoadEvent(LoadMonitor &monitor, std::string const &name, bool shouldStart)
Definition LoadEvent.cpp:7
void setName(std::string const &name)
Definition LoadEvent.cpp:45
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:39
std::string const & name() const
Definition LoadEvent.cpp:27
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