SWC-DB  v0.5.11 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Profiling.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 #ifndef swcdb_db_client_Query_Profiling_h
7 #define swcdb_db_client_Query_Profiling_h
8 
9 
11 #include "swcdb/db/Types/Range.h"
12 
13 
14 namespace SWC { namespace client {
15 
16 
18 namespace Query {
19 
20 
22 
23 
24 struct Profiling {
27 
28  Profiling() noexcept
29  : ts_start(Time::now_ns()),
31  }
32 
33  struct Component {
34 
39 
40  Component() noexcept : time(0), count(0), cache(0), error(0) { }
41 
42  Component& operator+=(const Component& other) noexcept {
43  time.fetch_add(other.time);
44  count.fetch_add(other.count);
45  cache.fetch_add(other.cache);
46  error.fetch_add(other.error);
47  return *this;
48  }
49 
50  struct Start {
52  const int64_t ts;
53 
55  Start(Component& m) noexcept
56  : _m(m), ts(Time::now_ns()) {
57  }
58 
60  void add(bool err) const noexcept {
61  _m.add(ts, err);
62  }
63 
65  void add_cached(bool err) const noexcept {
66  _m.add_cached(ts, err);
67  }
68  };
69 
71  Start start() noexcept {
72  return Start(*this);
73  }
74 
76  void add(uint64_t ts, bool err) noexcept {
77  time.fetch_add(Time::now_ns() - ts);
78  count.fetch_add(1);
79  if(err)
80  error.fetch_add(1);
81  }
82 
84  void add_cached(uint64_t ts, bool err) noexcept {
85  add(ts, err);
86  cache.fetch_add(1);
87  }
88 
89  void reset() noexcept {
90  time.store(0);
91  count.store(0);
92  cache.store(0);
93  error.store(0);
94  }
95 
96  void print(std::ostream& out) const {
97  out << "(time=" << time.load() << "ns"
98  << " count=" << count.load()
99  << " cached=" << cache.load()
100  << " errors=" << error.load()
101  << ')';
102  }
103 
104  void display(std::ostream& out) const {
105  out << time.load() << "ns"
106  << ' ' << count.load()
107  << '/' << cache.load()
108  << '/' << error.load()
109  << '\n';
110  }
111  };
112 
119 
121  void finished() noexcept {
123  }
124 
128  }
129 
132  return Component::Start(_mngr_res);
133  }
134 
137  switch(type) {
138  case DB::Types::Range::MASTER:
140  default:
142  }
143  }
144 
147  return Component::Start(_rgr_data);
148  }
149 
151  Component::Start bkr() noexcept {
152  return Component::Start(_bkr);
153  }
154 
155  Profiling& operator+=(const Profiling& other) noexcept {
156  _mngr_locate += other._mngr_locate;
157  _mngr_res += other._mngr_res;
158  _rgr_locate_master += other._rgr_locate_master;
159  _rgr_locate_meta += other._rgr_locate_meta;
160  _rgr_data += other._rgr_data;
161  _bkr += other._bkr;
162  return *this;
163  }
164 
165  void reset() noexcept {
167  _mngr_res.reset();
170  _rgr_data.reset();
171  _bkr.reset();
174  }
175 
176  void display(std::ostream& out) const {
177  if(_mngr_locate.time)
179  out << " Mngr Locate: ");
180  if(_mngr_res.time)
182  out << " Mngr Resolve: ");
185  out << " Rgr Locate Master: ");
188  out << " Rgr Locate Meta: ");
189  if(_rgr_data.time)
191  out << " Rgr Data: ");
192  if(_bkr.time)
193  _bkr.display(
194  out << " Bkr: ");
195  out << std::flush;
196  }
197 
198  void print(std::ostream& out) const {
199  out << "Profile(took=" << (ts_finish - ts_start) << "ns";
201  out << " mngr[";
202  if(_mngr_locate.time)
203  _mngr_locate.print(out << "locate");
204  if(_mngr_res.time)
205  _mngr_res.print(out << " res");
206  out << ']';
207  }
209  out << " rgr[";
211  _rgr_locate_master.print(out << "locate-master");
213  _rgr_locate_meta.print(out << " locate-meta");
214  if(_rgr_data.time)
215  _rgr_data.print(out << " data");
216  out << ']';
217  }
218  if(_bkr.time)
219  _bkr.print(out << " bkr");
220  out << ')';
221  }
222 
224  std::string to_string() const {
225  std::string s;
226  {
227  std::stringstream ss;
228  print(ss);
229  s = ss.str();
230  }
231  return s;
232  }
233 
234 };
235 
236 
237 }}}
238 
239 #endif // swcdb_db_client_Query_Profiling_h
SWC::client::Query::Profiling::Component::add
SWC_CAN_INLINE void add(uint64_t ts, bool err) noexcept
Definition: Profiling.h:76
SWC::Time::now_ns
SWC_CAN_INLINE int64_t now_ns() noexcept
Definition: Time.h:43
SWC::client::Query::Profiling::_bkr
Component _bkr
Definition: Profiling.h:118
SWC::Core::Atomic< int64_t >
SWC::client::Query::Profiling::_mngr_locate
Component _mngr_locate
Definition: Profiling.h:113
SWC::Common::Files::Schema::load
void load(int &err, const std::string &filepath, DB::Schema::Ptr &schema)
Definition: Schema.h:87
SWC::Comm::client::ConnQueueReqBase
Definition: ClientConnQueue.h:22
SWC::Comm::client::ConnQueue::ReqBase
ConnQueueReqBase ReqBase
Definition: ClientConnQueue.h:62
SWC::client::Query::Profiling::display
void display(std::ostream &out) const
Definition: Profiling.h:176
SWC::client::Query::Profiling::Component::Start::Start
SWC_CAN_INLINE Start(Component &m) noexcept
Definition: Profiling.h:55
SWC::client::Query::Profiling::Component::operator+=
Component & operator+=(const Component &other) noexcept
Definition: Profiling.h:42
SWC::client::Query::Profiling::reset
void reset() noexcept
Definition: Profiling.h:165
SWC::client::Query::Profiling::Component::Start::ts
const int64_t ts
Definition: Profiling.h:52
SWC::client::Query::Profiling::ts_finish
Core::Atomic< int64_t > ts_finish
Definition: Profiling.h:26
SWC::Core::AtomicBase::store
constexpr SWC_CAN_INLINE void store(T v) noexcept
Definition: Atomic.h:37
SWC::client::Query::Profiling::_rgr_data
Component _rgr_data
Definition: Profiling.h:117
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::client::Query::Profiling::rgr_locate
SWC_CAN_INLINE Component::Start rgr_locate(DB::Types::Range type) noexcept
Definition: Profiling.h:136
Range.h
SWC::client::Query::Profiling::Component
Definition: Profiling.h:33
SWC::client::Query::Profiling::Component::display
void display(std::ostream &out) const
Definition: Profiling.h:104
SWC::client::Query::Profiling::Component::Start::_m
Component & _m
Definition: Profiling.h:51
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::client::Query::Profiling::Component::print
void print(std::ostream &out) const
Definition: Profiling.h:96
SWC::client::Query::Profiling::ts_start
Core::Atomic< int64_t > ts_start
Definition: Profiling.h:25
SWC::client::Query::Profiling::operator+=
Profiling & operator+=(const Profiling &other) noexcept
Definition: Profiling.h:155
ClientConnQueue.h
SWC::client::Query::Profiling::finished
SWC_CAN_INLINE void finished() noexcept
Definition: Profiling.h:121
SWC::client::Query::Profiling::Component::count
Core::Atomic< uint64_t > count
Definition: Profiling.h:36
SWC::client::Query::Profiling::_rgr_locate_master
Component _rgr_locate_master
Definition: Profiling.h:115
SWC::client::Query::Profiling::Component::reset
void reset() noexcept
Definition: Profiling.h:89
SWC::client::Query::Profiling::_mngr_res
Component _mngr_res
Definition: Profiling.h:114
SWC::client::Query::Profiling
Definition: Profiling.h:24
SWC::client::Query::Profiling::bkr
SWC_CAN_INLINE Component::Start bkr() noexcept
Definition: Profiling.h:151
SWC::Core::AtomicBase::load
constexpr SWC_CAN_INLINE T load() const noexcept
Definition: Atomic.h:42
SWC::client::Query::Profiling::Component::start
SWC_CAN_INLINE Start start() noexcept
Definition: Profiling.h:71
SWC::client::Query::Profiling::Component::add_cached
SWC_CAN_INLINE void add_cached(uint64_t ts, bool err) noexcept
Definition: Profiling.h:84
SWC::client::Query::Profiling::Component::error
Core::Atomic< uint64_t > error
Definition: Profiling.h:38
SWC::client::Query::Profiling::to_string
SWC_CAN_INLINE std::string to_string() const
Definition: Profiling.h:224
SWC::Comm::Protocol::FsBroker::Handler::flush
void flush(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: Flush.h:17
SWC::client::Query::Profiling::mngr_res
SWC_CAN_INLINE Component::Start mngr_res() noexcept
Definition: Profiling.h:131
SWC::client::Query::Profiling::rgr_data
SWC_CAN_INLINE Component::Start rgr_data() noexcept
Definition: Profiling.h:146
SWC::client::Query::Profiling::Component::Start
Definition: Profiling.h:50
SWC::client::Query::Profiling::_rgr_locate_meta
Component _rgr_locate_meta
Definition: Profiling.h:116
SWC::client::Query::Profiling::Component::Component
Component() noexcept
Definition: Profiling.h:40
SWC::client::Query::Profiling::Profiling
Profiling() noexcept
Definition: Profiling.h:28
SWC::client::Query::Profiling::Component::cache
Core::Atomic< uint64_t > cache
Definition: Profiling.h:37
SWC::client::Query::Profiling::Component::Start::add_cached
SWC_CAN_INLINE void add_cached(bool err) const noexcept
Definition: Profiling.h:65
SWC::Core::Atomic::fetch_add
constexpr SWC_CAN_INLINE T fetch_add(T v) noexcept
Definition: Atomic.h:93
SWC::client::Query::Profiling::mngr_locate
SWC_CAN_INLINE Component::Start mngr_locate() noexcept
Definition: Profiling.h:126
SWC::client::Query::Profiling::print
void print(std::ostream &out) const
Definition: Profiling.h:198
SWC::DB::Types::Range
Range
Definition: Range.h:14
SWC::client::Query::Profiling::Component::Start::add
SWC_CAN_INLINE void add(bool err) const noexcept
Definition: Profiling.h:60
SWC::client::Query::Profiling::Component::time
Core::Atomic< uint64_t > time
Definition: Profiling.h:35