rippled
JobTypeData.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_JOBTYPEDATA_H_INCLUDED
21 #define RIPPLE_CORE_JOBTYPEDATA_H_INCLUDED
22 
23 #include <ripple/basics/Log.h>
24 #include <ripple/beast/insight/Collector.h>
25 #include <ripple/core/JobTypeInfo.h>
26 
27 namespace ripple {
28 
30 {
31 private:
33 
34  /* Support for insight */
36 
37 public:
38  /* The job category which we represent */
39  JobTypeInfo const& info;
40 
41  /* The number of jobs waiting */
42  int waiting;
43 
44  /* The number presently running */
45  int running;
46 
47  /* And the number we deferred executing because of job limits */
48  int deferred;
49 
50  /* Notification callbacks */
53 
55  JobTypeInfo const& info_,
56  beast::insight::Collector::ptr const& collector,
57  Logs& logs) noexcept
58  : m_load(logs.journal("LoadMonitor"))
59  , m_collector(collector)
60  , info(info_)
61  , waiting(0)
62  , running(0)
63  , deferred(0)
64  {
67 
68  if (!info.special())
69  {
70  dequeue = m_collector->make_event(info.name() + "_q");
71  execute = m_collector->make_event(info.name());
72  }
73  }
74 
75  /* Not copy-constructible or assignable */
76  JobTypeData(JobTypeData const& other) = delete;
78  operator=(JobTypeData const& other) = delete;
79 
81  name() const
82  {
83  return info.name();
84  }
85 
86  JobType
87  type() const
88  {
89  return info.type();
90  }
91 
93  load()
94  {
95  return m_load;
96  }
97 
100  {
101  return m_load.getStats();
102  }
103 };
104 
105 } // namespace ripple
106 
107 #endif
ripple::JobTypeData::info
JobTypeInfo const & info
Definition: JobTypeData.h:39
std::string
STL class.
std::shared_ptr< Collector >
ripple::Logs
Manages partitions for logging.
Definition: Log.h:48
ripple::JobTypeData::execute
beast::insight::Event execute
Definition: JobTypeData.h:52
ripple::JobTypeData::load
LoadMonitor & load()
Definition: JobTypeData.h:93
ripple::JobTypeData::deferred
int deferred
Definition: JobTypeData.h:48
ripple::LoadMonitor::getStats
Stats getStats()
Definition: LoadMonitor.cpp:177
ripple::JobTypeData::JobTypeData
JobTypeData(JobTypeInfo const &info_, beast::insight::Collector::ptr const &collector, Logs &logs) noexcept
Definition: JobTypeData.h:54
ripple::JobTypeData::dequeue
beast::insight::Event dequeue
Definition: JobTypeData.h:51
ripple::LoadMonitor::Stats
Definition: LoadMonitor.h:56
ripple::JobTypeInfo::getAverageLatency
std::chrono::milliseconds getAverageLatency() const
Definition: JobTypeInfo.h:88
ripple::JobTypeInfo::type
JobType type() const
Definition: JobTypeInfo.h:64
ripple::JobTypeInfo
Holds all the 'static' information about a job, which does not change.
Definition: JobTypeInfo.h:28
ripple::JobTypeData::waiting
int waiting
Definition: JobTypeData.h:42
beast::insight::Event
A metric for reporting event timing.
Definition: Event.h:40
ripple::JobTypeData
Definition: JobTypeData.h:29
ripple::JobTypeData::type
JobType type() const
Definition: JobTypeData.h:87
ripple::LoadMonitor
Definition: LoadMonitor.h:36
ripple::JobTypeData::m_collector
beast::insight::Collector::ptr m_collector
Definition: JobTypeData.h:35
ripple::JobTypeInfo::name
std::string const & name() const
Definition: JobTypeInfo.h:70
ripple::LoadMonitor::setTargetLatency
void setTargetLatency(std::chrono::milliseconds avg, std::chrono::milliseconds pk)
Definition: LoadMonitor.cpp:143
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::JobTypeData::m_load
LoadMonitor m_load
Definition: JobTypeData.h:32
ripple::JobTypeData::running
int running
Definition: JobTypeData.h:45
ripple::JobTypeData::operator=
JobTypeData & operator=(JobTypeData const &other)=delete
ripple::JobTypeData::stats
LoadMonitor::Stats stats()
Definition: JobTypeData.h:99
ripple::JobType
JobType
Definition: Job.h:35
ripple::JobTypeInfo::special
bool special() const
Definition: JobTypeInfo.h:82
ripple::JobTypeInfo::getPeakLatency
std::chrono::milliseconds getPeakLatency() const
Definition: JobTypeInfo.h:94
ripple::JobTypeData::name
std::string name() const
Definition: JobTypeData.h:81