xrpld
Loading...
Searching...
No Matches
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
10namespace xrpl {
11
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
23{
24 if (running_)
25 stop();
26}
27
28std::string const&
30{
31 return name_;
32}
33
34std::chrono::steady_clock::duration
36{
37 return timeWaiting_;
38}
39
40std::chrono::steady_clock::duration
42{
43 return timeRunning_;
44}
45
46void
51
52void
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
65void
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::chrono::steady_clock::duration timeRunning_
Definition LoadEvent.h:64
std::chrono::steady_clock::time_point mark_
Definition LoadEvent.h:60
LoadEvent(LoadMonitor &monitor, std::string name, bool shouldStart)
Definition LoadEvent.cpp:12
LoadMonitor & monitor_
Definition LoadEvent.h:51
std::chrono::steady_clock::duration waitTime() const
Definition LoadEvent.cpp:35
void setName(std::string const &name)
Definition LoadEvent.cpp:47
std::string name_
Definition LoadEvent.h:57
std::chrono::steady_clock::duration timeWaiting_
Definition LoadEvent.h:63
std::chrono::steady_clock::duration runTime() const
Definition LoadEvent.cpp:41
std::string const & name() const
Definition LoadEvent.cpp:29
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5