SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
FlowRate.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_common_Stats_FlowRate_h
7 #define swcdb_common_Stats_FlowRate_h
8 
9 
10 
11 namespace SWC { namespace Common { namespace Stats { namespace FlowRate {
12 
13 static const size_t KB = 1024;
14 static const size_t MB = KB * 1024;
15 static const size_t GB = MB * 1024;
16 static const size_t TB = GB * 1024;
17 static const size_t PB = TB * 1024;
18 
19 struct Data {
20  double bytes = 0;
21  const char* bytes_base = "";
22  double time = 0;
23  const char* time_base = "";
24 
25  Data(size_t in_bytes, size_t in_ns) {
26  // size_t epochs_bytes = 0, size_t epochs_ns = 0
27 
28  if(in_ns < 100000) {
29  time = in_ns;
30  time_base = "nanosecond";
31  } else if(in_ns < 10000000) {
32  time = double(in_ns)/1000;
33  time_base = "microsecond";
34  } else if(in_ns <= 10000000000) {
35  time = (double(in_ns)/1000)/1000;
36  time_base = "millisecond";
37  } else if(in_ns <= 3600000000000) {
38  time = (double(in_ns)/1000000)/1000;
39  time_base = "second";
40  } else if(in_ns <= 86400000000000) {
41  time = (double(in_ns)/60000000)/1000;
42  time_base = "minute";
43  } else {
44  time = (double(in_ns)/3600000000)/1000;
45  time_base = "hour";
46  }
47 
48  if(in_bytes <= MB) {
49  bytes = in_bytes;
50  bytes_base = "B";
51  } else if(in_bytes <= GB ) {
52  bytes = double(in_bytes)/KB;
53  bytes_base = "KB";
54  } else if(in_bytes <= TB) {
55  bytes = (double(in_bytes)/KB)/KB;
56  bytes_base = "MB";
57  } else if(in_bytes <= PB) {
58  bytes = (double(in_bytes)/MB)/KB;
59  bytes_base = "GB";
60  } else {
61  bytes = (double(in_bytes)/GB)/KB;
62  bytes_base = "TB";
63  }
64 
65  }
66 
67  //~Data() noexcept { }
68 
69  void print_cells_statistics(std::ostream& out, size_t cells_count,
70  size_t resend_cells) const {
71  out << "Statistics:\n"
72  << " Total Time Took: " << time << " " << time_base << "s\n"
73  << " Total Cells Count: " << cells_count << "\n"
74  << " Total Cells Size: " << bytes << " " << bytes_base << "\n";
75 
76  if(resend_cells)
77  out << " Resend Cells Count: " << resend_cells << "\n";
78 
79  out << " Average Transfer Rate: " << bytes/time << " "
80  << bytes_base <<"/"<< time_base << "\n"
81  << " Average Cells Rate: " << (cells_count ? cells_count/time : 0)
82  << " cell/" << time_base << "\n"
83  << std::flush;
84  }
85 };
86 
87 
88 }}}} // namespace SWC::Common::Stats
89 
90 
91 #endif // swcdb_common_Stats_FlowRate_h
SWC::Common::Stats::FlowRate::KB
static const size_t KB
Definition: FlowRate.h:13
SWC::Common::Stats::FlowRate::Data
Definition: FlowRate.h:19
SWC::Common::Stats::FlowRate::Data::bytes
double bytes
Definition: FlowRate.h:20
SWC::Common::Stats::FlowRate::Data::time
double time
Definition: FlowRate.h:22
SWC::Common::Stats::FlowRate::MB
static const size_t MB
Definition: FlowRate.h:14
SWC::Common::Stats::FlowRate::PB
static const size_t PB
Definition: FlowRate.h:17
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Common::Stats::FlowRate::Data::print_cells_statistics
void print_cells_statistics(std::ostream &out, size_t cells_count, size_t resend_cells) const
Definition: FlowRate.h:69
SWC::Common::Stats::FlowRate::Data::bytes_base
const char * bytes_base
Definition: FlowRate.h:21
SWC::Common::Stats::FlowRate::GB
static const size_t GB
Definition: FlowRate.h:15
SWC::Comm::Protocol::FsBroker::Handler::flush
void flush(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: Flush.h:17
SWC::Common::Stats::FlowRate::Data::Data
Data(size_t in_bytes, size_t in_ns)
Definition: FlowRate.h:25
SWC::Common::Stats::FlowRate::TB
static const size_t TB
Definition: FlowRate.h:16
SWC::Common::Stats::FlowRate::Data::time_base
const char * time_base
Definition: FlowRate.h:23