SWC-DB  v0.5.12 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  _mngr_locate(),
32  _mngr_res(),
35  _rgr_data(),
36  _bkr() {
37  }
38 
39  struct Component {
40 
45 
46  Component() noexcept : time(0), count(0), cache(0), error(0) { }
47 
48  Component& operator+=(const Component& other) noexcept {
49  time.fetch_add(other.time);
50  count.fetch_add(other.count);
51  cache.fetch_add(other.cache);
52  error.fetch_add(other.error);
53  return *this;
54  }
55 
56  struct Start {
58  const int64_t ts;
59 
61  Start(Component& m) noexcept
62  : _m(m), ts(Time::now_ns()) {
63  }
64 
66  void add(bool err) const noexcept {
67  _m.add(ts, err);
68  }
69 
71  void add_cached(bool err) const noexcept {
72  _m.add_cached(ts, err);
73  }
74  };
75 
77  Start start() noexcept {
78  return Start(*this);
79  }
80 
82  void add(uint64_t ts, bool err) noexcept {
83  time.fetch_add(Time::now_ns() - ts);
84  count.fetch_add(1);
85  if(err)
86  error.fetch_add(1);
87  }
88 
90  void add_cached(uint64_t ts, bool err) noexcept {
91  add(ts, err);
92  cache.fetch_add(1);
93  }
94 
95  void reset() noexcept {
96  time.store(0);
97  count.store(0);
98  cache.store(0);
99  error.store(0);
100  }
101 
102  void print(std::ostream& out) const {
103  out << "(time=" << time.load() << "ns"
104  << " count=" << count.load()
105  << " cached=" << cache.load()
106  << " errors=" << error.load()
107  << ')';
108  }
109 
110  void display(std::ostream& out) const {
111  out << time.load() << "ns"
112  << ' ' << count.load()
113  << '/' << cache.load()
114  << '/' << error.load()
115  << '\n';
116  }
117  };
118 
125 
127  void finished() noexcept {
129  }
130 
134  }
135 
138  return Component::Start(_mngr_res);
139  }
140 
143  switch(type) {
144  case DB::Types::Range::MASTER:
146  default:
148  }
149  }
150 
153  return Component::Start(_rgr_data);
154  }
155 
157  Component::Start bkr() noexcept {
158  return Component::Start(_bkr);
159  }
160 
161  Profiling& operator+=(const Profiling& other) noexcept {
162  _mngr_locate += other._mngr_locate;
163  _mngr_res += other._mngr_res;
164  _rgr_locate_master += other._rgr_locate_master;
165  _rgr_locate_meta += other._rgr_locate_meta;
166  _rgr_data += other._rgr_data;
167  _bkr += other._bkr;
168  return *this;
169  }
170 
171  void reset() noexcept {
173  _mngr_res.reset();
176  _rgr_data.reset();
177  _bkr.reset();
180  }
181 
182  void display(std::ostream& out) const {
183  if(_mngr_locate.time)
185  out << " Mngr Locate: ");
186  if(_mngr_res.time)
188  out << " Mngr Resolve: ");
191  out << " Rgr Locate Master: ");
194  out << " Rgr Locate Meta: ");
195  if(_rgr_data.time)
197  out << " Rgr Data: ");
198  if(_bkr.time)
199  _bkr.display(
200  out << " Bkr: ");
201  out << std::flush;
202  }
203 
204  void print(std::ostream& out) const {
205  out << "Profile(took=" << (ts_finish - ts_start) << "ns";
207  out << " mngr[";
208  if(_mngr_locate.time)
209  _mngr_locate.print(out << "locate");
210  if(_mngr_res.time)
211  _mngr_res.print(out << " res");
212  out << ']';
213  }
215  out << " rgr[";
217  _rgr_locate_master.print(out << "locate-master");
219  _rgr_locate_meta.print(out << " locate-meta");
220  if(_rgr_data.time)
221  _rgr_data.print(out << " data");
222  out << ']';
223  }
224  if(_bkr.time)
225  _bkr.print(out << " bkr");
226  out << ')';
227  }
228 
230  std::string to_string() const {
231  std::string s;
232  {
233  std::stringstream ss;
234  print(ss);
235  s = ss.str();
236  }
237  return s;
238  }
239 
240 };
241 
242 
243 }}}
244 
245 #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:82
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:124
SWC::Core::Atomic< int64_t >
SWC::client::Query::Profiling::_mngr_locate
Component _mngr_locate
Definition: Profiling.h:119
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:182
SWC::client::Query::Profiling::Component::Start::Start
SWC_CAN_INLINE Start(Component &m) noexcept
Definition: Profiling.h:61
SWC::client::Query::Profiling::Component::operator+=
Component & operator+=(const Component &other) noexcept
Definition: Profiling.h:48
SWC::client::Query::Profiling::reset
void reset() noexcept
Definition: Profiling.h:171
SWC::client::Query::Profiling::Component::Start::ts
const int64_t ts
Definition: Profiling.h:58
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:123
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:142
Range.h
SWC::client::Query::Profiling::Component
Definition: Profiling.h:39
SWC::client::Query::Profiling::Component::display
void display(std::ostream &out) const
Definition: Profiling.h:110
SWC::client::Query::Profiling::Component::Start::_m
Component & _m
Definition: Profiling.h:57
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:102
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:161
ClientConnQueue.h
SWC::client::Query::Profiling::finished
SWC_CAN_INLINE void finished() noexcept
Definition: Profiling.h:127
SWC::client::Query::Profiling::Component::count
Core::Atomic< uint64_t > count
Definition: Profiling.h:42
SWC::client::Query::Profiling::_rgr_locate_master
Component _rgr_locate_master
Definition: Profiling.h:121
SWC::client::Query::Profiling::Component::reset
void reset() noexcept
Definition: Profiling.h:95
SWC::client::Query::Profiling::_mngr_res
Component _mngr_res
Definition: Profiling.h:120
SWC::client::Query::Profiling
Definition: Profiling.h:24
SWC::client::Query::Profiling::bkr
SWC_CAN_INLINE Component::Start bkr() noexcept
Definition: Profiling.h:157
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:77
SWC::client::Query::Profiling::Component::add_cached
SWC_CAN_INLINE void add_cached(uint64_t ts, bool err) noexcept
Definition: Profiling.h:90
SWC::client::Query::Profiling::Component::error
Core::Atomic< uint64_t > error
Definition: Profiling.h:44
SWC::client::Query::Profiling::to_string
SWC_CAN_INLINE std::string to_string() const
Definition: Profiling.h:230
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:137
SWC::client::Query::Profiling::rgr_data
SWC_CAN_INLINE Component::Start rgr_data() noexcept
Definition: Profiling.h:152
SWC::client::Query::Profiling::Component::Start
Definition: Profiling.h:56
SWC::client::Query::Profiling::_rgr_locate_meta
Component _rgr_locate_meta
Definition: Profiling.h:122
SWC::client::Query::Profiling::Component::Component
Component() noexcept
Definition: Profiling.h:46
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:43
SWC::client::Query::Profiling::Component::Start::add_cached
SWC_CAN_INLINE void add_cached(bool err) const noexcept
Definition: Profiling.h:71
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:132
SWC::client::Query::Profiling::print
void print(std::ostream &out) const
Definition: Profiling.h:204
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:66
SWC::client::Query::Profiling::Component::time
Core::Atomic< uint64_t > time
Definition: Profiling.h:41