rippled
Loading...
Searching...
No Matches
LoadEvent.h
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#ifndef RIPPLE_CORE_LOADEVENT_H_INCLUDED
21#define RIPPLE_CORE_LOADEVENT_H_INCLUDED
22
23#include <chrono>
24#include <string>
25
26namespace ripple {
27
28class LoadMonitor;
29
30// VFALCO NOTE What is the difference between a LoadEvent and a LoadMonitor?
31// VFALCO TODO Rename LoadEvent to ScopedLoadSample
32//
33// This looks like a scoped elapsed time measuring class
34//
36{
37public:
38 // VFALCO TODO remove the dependency on LoadMonitor. Is that possible?
39 LoadEvent(LoadMonitor& monitor, std::string const& name, bool shouldStart);
40 LoadEvent(LoadEvent const&) = delete;
41
42 ~LoadEvent();
43
44 std::string const&
45 name() const;
46
47 // The time spent waiting.
48 std::chrono::steady_clock::duration
49 waitTime() const;
50
51 // The time spent running.
52 std::chrono::steady_clock::duration
53 runTime() const;
54
55 void
56 setName(std::string const& name);
57
58 // Start the measurement. If already started, then
59 // restart, assigning the elapsed time to the "waiting"
60 // state.
61 void
62 start();
63
64 // Stop the measurement and report the results. The
65 // time reported is measured from the last call to
66 // start.
67 void
68 stop();
69
70private:
72
73 // Represents our current state
75
76 // The name associated with this event, if any.
78
79 // Represents the time we last transitioned states
80 std::chrono::steady_clock::time_point mark_;
81
82 // The time we spent waiting and running respectively
83 std::chrono::steady_clock::duration timeWaiting_;
84 std::chrono::steady_clock::duration timeRunning_;
85};
86
87} // namespace ripple
88
89#endif
LoadMonitor & monitor_
Definition LoadEvent.h:71
std::chrono::steady_clock::duration timeRunning_
Definition LoadEvent.h:84
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
LoadEvent(LoadEvent const &)=delete
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
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25