rippled
Loading...
Searching...
No Matches
LoadEvent.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/core/LoadEvent.h>
21#include <xrpld/core/LoadMonitor.h>
22
23#include <xrpl/beast/utility/instrumentation.h>
24
25namespace ripple {
26
28 LoadMonitor& monitor,
29 std::string const& name,
30 bool shouldStart)
31 : monitor_(monitor)
32 , running_(shouldStart)
33 , name_(name)
34 , mark_{std::chrono::steady_clock::now()}
35 , timeWaiting_{}
36 , timeRunning_{}
37{
38}
39
41{
42 if (running_)
43 stop();
44}
45
46std::string const&
48{
49 return name_;
50}
51
52std::chrono::steady_clock::duration
54{
55 return timeWaiting_;
56}
57
58std::chrono::steady_clock::duration
60{
61 return timeRunning_;
62}
63
64void
66{
67 name_ = name;
68}
69
70void
72{
73 auto const now = std::chrono::steady_clock::now();
74
75 // If we had already called start, this call will
76 // replace the previous one. Any time accumulated will
77 // be counted as "waiting".
78 timeWaiting_ += now - mark_;
79 mark_ = now;
80 running_ = true;
81}
82
83void
85{
86 XRPL_ASSERT(running_, "ripple::LoadEvent::stop : is running");
87
88 auto const now = std::chrono::steady_clock::now();
89
90 timeRunning_ += now - mark_;
91 mark_ = now;
92 running_ = false;
93
95}
96
97} // namespace ripple
LoadMonitor & monitor_
Definition: LoadEvent.h:71
std::chrono::steady_clock::duration timeRunning_
Definition: LoadEvent.h:84
LoadEvent(LoadMonitor &monitor, std::string const &name, bool shouldStart)
Definition: LoadEvent.cpp:27
std::chrono::steady_clock::duration timeWaiting_
Definition: LoadEvent.h:83
std::string const & name() const
Definition: LoadEvent.cpp:47
std::chrono::steady_clock::duration waitTime() const
Definition: LoadEvent.cpp:53
std::chrono::steady_clock::duration runTime() const
Definition: LoadEvent.cpp:59
std::chrono::steady_clock::time_point mark_
Definition: LoadEvent.h:80
void setName(std::string const &name)
Definition: LoadEvent.cpp:65
std::string name_
Definition: LoadEvent.h:77
void addLoadSample(LoadEvent const &sample)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
STL namespace.