SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Statistics.cc
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 
7 #include "swcdb/fs/Statistics.h"
8 
9 
10 namespace SWC { namespace FS {
11 
12 
13 void Statistics::Metric::add(bool err, uint64_t ns) noexcept {
14  lock();
15  if(UINT64_MAX - m_total > ns) {
16  ++m_count;
17  m_total += ns;
18  }
19  if(err)
20  ++m_error;
21  if(!m_min || m_min > ns)
22  m_min = ns;
23  if(m_max < ns)
24  m_max = ns;
25  unlock();
26 }
27 
29  lock();
30  m.m_error = m_error;
31  m.m_count = m_count;
32  m.m_total = m_total;
33  m.m_min = m_min;
34  m.m_max = m_max;
35  m_error = 0;
36  m_count = 0;
37  m_max = m_min = m_total = 0;
38  unlock();
39 }
40 
41 void Statistics::Metric::reset() noexcept {
42  lock();
43  m_error = 0;
44  m_count = 0;
45  m_max = m_min = m_total = 0;
46  unlock();
47 }
48 
49 
50 
51 SWC_SHOULD_NOT_INLINE
52 void Statistics::gather(Statistics& stats) noexcept {
53  for(uint8_t i = 0; i < Command::MAX; ++i) {
54  metrics[i].gather(stats.metrics[i]);
55  }
56 }
57 
58 void Statistics::reset() noexcept {
59  for(auto& m : metrics) {
60  m.reset();
61  }
62 }
63 
64 const char* Statistics::to_string(Command cmd) noexcept {
65  switch(cmd) {
66  case OPEN_SYNC:
67  return "OPEN_SYNC";
68  case OPEN_ASYNC:
69  return "OPEN_ASYNC";
70  case CREATE_SYNC:
71  return "CREATE_SYNC";
72  case CREATE_ASYNC:
73  return "CREATE_ASYNC";
74  case CLOSE_SYNC:
75  return "CLOSE_SYNC";
76  case CLOSE_ASYNC:
77  return "CLOSE_ASYNC";
78  case READ_SYNC:
79  return "READ_SYNC";
80  case READ_ASYNC:
81  return "READ_ASYNC";
82  case APPEND_SYNC:
83  return "APPEND_SYNC";
84  case APPEND_ASYNC:
85  return "APPEND_ASYNC";
86  case SEEK_SYNC:
87  return "SEEK_SYNC";
88  case SEEK_ASYNC:
89  return "SEEK_ASYNC";
90  case REMOVE_SYNC:
91  return "REMOVE_SYNC";
92  case REMOVE_ASYNC:
93  return "REMOVE_ASYNC";
94  case LENGTH_SYNC:
95  return "LENGTH_SYNC";
96  case LENGTH_ASYNC:
97  return "LENGTH_ASYNC";
98  case PREAD_SYNC:
99  return "PREAD_SYNC";
100  case PREAD_ASYNC:
101  return "PREAD_ASYNC";
102  case MKDIRS_SYNC:
103  return "MKDIRS_SYNC";
104  case MKDIRS_ASYNC:
105  return "MKDIRS_ASYNC";
106  case FLUSH_SYNC:
107  return "FLUSH_SYNC";
108  case FLUSH_ASYNC:
109  return "FLUSH_ASYNC";
110  case RMDIR_SYNC:
111  return "RMDIR_SYNC";
112  case RMDIR_ASYNC:
113  return "RMDIR_ASYNC";
114  case READDIR_SYNC:
115  return "READDIR_SYNC";
116  case READDIR_ASYNC:
117  return "READDIR_ASYNC";
118  case EXISTS_SYNC:
119  return "EXISTS_SYNC";
120  case EXISTS_ASYNC:
121  return "EXISTS_ASYNC";
122  case RENAME_SYNC:
123  return "RENAME_SYNC";
124  case RENAME_ASYNC:
125  return "RENAME_ASYNC";
126  case SYNC_SYNC:
127  return "SYNC_SYNC";
128  case SYNC_ASYNC:
129  return "SYNC_ASYNC";
130  case WRITE_SYNC:
131  return "WRITE_SYNC";
132  case WRITE_ASYNC:
133  return "WRITE_ASYNC";
134  case READ_ALL_SYNC:
135  return "READ_ALL_SYNC";
136  case READ_ALL_ASYNC:
137  return "READ_ALL_ASYNC";
138  case COMBI_PREAD_SYNC:
139  return "COMBI_PREAD_SYNC";
140  case COMBI_PREAD_ASYNC:
141  return "COMBI_PREAD_ASYNC";
142  default:
143  return "UNKNOWN";
144  }
145 }
146 
147 }}
SWC::FS::Statistics::FLUSH_SYNC
@ FLUSH_SYNC
Definition: Statistics.h:42
SWC::FS::Statistics::Metric::add
void add(bool err, uint64_t ns) noexcept
Definition: Statistics.cc:13
SWC::FS::Statistics::REMOVE_SYNC
@ REMOVE_SYNC
Definition: Statistics.h:34
SWC::FS::Statistics::CREATE_ASYNC
@ CREATE_ASYNC
Definition: Statistics.h:25
SWC::FS::Statistics::READDIR_SYNC
@ READDIR_SYNC
Definition: Statistics.h:46
SWC::FS::Statistics::FLUSH_ASYNC
@ FLUSH_ASYNC
Definition: Statistics.h:43
SWC::FS::Statistics::reset
void reset() noexcept
Definition: Statistics.cc:58
SWC::FS::Statistics::COMBI_PREAD_SYNC
@ COMBI_PREAD_SYNC
Definition: Statistics.h:58
SWC::FS::Statistics::CLOSE_SYNC
@ CLOSE_SYNC
Definition: Statistics.h:26
SWC::FS::Statistics::RENAME_SYNC
@ RENAME_SYNC
Definition: Statistics.h:50
SWC::FS::Statistics::RMDIR_SYNC
@ RMDIR_SYNC
Definition: Statistics.h:44
SWC::FS::Statistics::Metric::m_total
uint64_t m_total
Definition: Statistics.h:108
SWC::FS::Statistics::to_string
static const char *SWC_CONST_FUNC to_string(Command cmd) noexcept
Definition: Statistics.cc:64
SWC::FS::Statistics::WRITE_SYNC
@ WRITE_SYNC
Definition: Statistics.h:54
SWC::FS::Statistics::SYNC_SYNC
@ SYNC_SYNC
Definition: Statistics.h:52
SWC::FS::Statistics::Metric::m_error
uint24_t m_error
Definition: Statistics.h:104
SWC::FS::Statistics::WRITE_ASYNC
@ WRITE_ASYNC
Definition: Statistics.h:55
SWC::client::Query::Update::Handlers::Metric::MAX
@ MAX
Definition: Metrics.h:29
SWC::FS::Statistics::SEEK_SYNC
@ SEEK_SYNC
Definition: Statistics.h:32
SWC::FS::Statistics::OPEN_ASYNC
@ OPEN_ASYNC
Definition: Statistics.h:23
SWC::FS::Statistics::CREATE_SYNC
@ CREATE_SYNC
Definition: Statistics.h:24
SWC::FS::Statistics::SEEK_ASYNC
@ SEEK_ASYNC
Definition: Statistics.h:33
SWC::FS::Statistics::Metric::m_max
uint64_t m_max
Definition: Statistics.h:107
SWC::FS::Statistics::MKDIRS_SYNC
@ MKDIRS_SYNC
Definition: Statistics.h:40
SWC::FS::Statistics::EXISTS_SYNC
@ EXISTS_SYNC
Definition: Statistics.h:48
SWC::FS::Statistics::READDIR_ASYNC
@ READDIR_ASYNC
Definition: Statistics.h:47
SWC::Core::MutexAtomic::lock
SWC_CAN_INLINE void lock() const noexcept
Definition: MutexAtomic.h:40
SWC::FS::Statistics::Metric::gather
void gather(Metric &m) noexcept
Definition: Statistics.cc:28
SWC::FS::Statistics::Command
Command
Definition: Statistics.h:21
SWC::FS::Statistics::READ_SYNC
@ READ_SYNC
Definition: Statistics.h:28
SWC::FS::Statistics::COMBI_PREAD_ASYNC
@ COMBI_PREAD_ASYNC
Definition: Statistics.h:59
SWC::FS::Statistics::metrics
Metric metrics[Command::MAX]
Definition: Statistics.h:128
SWC::FS::Statistics::READ_ASYNC
@ READ_ASYNC
Definition: Statistics.h:29
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::FS::Statistics::LENGTH_SYNC
@ LENGTH_SYNC
Definition: Statistics.h:36
SWC::FS::Statistics::APPEND_ASYNC
@ APPEND_ASYNC
Definition: Statistics.h:31
SWC::FS::Statistics::EXISTS_ASYNC
@ EXISTS_ASYNC
Definition: Statistics.h:49
SWC::FS::Statistics::Metric::reset
void reset() noexcept
Definition: Statistics.cc:41
SWC::FS::Statistics::APPEND_SYNC
@ APPEND_SYNC
Definition: Statistics.h:30
SWC::FS::Statistics::OPEN_SYNC
@ OPEN_SYNC
Definition: Statistics.h:22
SWC::FS::Statistics::LENGTH_ASYNC
@ LENGTH_ASYNC
Definition: Statistics.h:37
SWC::Core::MutexAtomic::unlock
SWC_CAN_INLINE void unlock() const noexcept
Definition: MutexAtomic.h:72
SWC::FS::Statistics::PREAD_ASYNC
@ PREAD_ASYNC
Definition: Statistics.h:39
SWC::FS::Statistics::PREAD_SYNC
@ PREAD_SYNC
Definition: Statistics.h:38
SWC::FS::Statistics::READ_ALL_SYNC
@ READ_ALL_SYNC
Definition: Statistics.h:56
SWC::FS::Statistics::SYNC_ASYNC
@ SYNC_ASYNC
Definition: Statistics.h:53
SWC::FS::Statistics::CLOSE_ASYNC
@ CLOSE_ASYNC
Definition: Statistics.h:27
Statistics.h
SWC::FS::Statistics::RMDIR_ASYNC
@ RMDIR_ASYNC
Definition: Statistics.h:45
SWC::FS::Statistics
Definition: Statistics.h:18
SWC::FS::Statistics::Metric::m_min
uint64_t m_min
Definition: Statistics.h:106
SWC::FS::Statistics::Metric
Definition: Statistics.h:67
SWC::FS::Statistics::MKDIRS_ASYNC
@ MKDIRS_ASYNC
Definition: Statistics.h:41
SWC::FS::Statistics::Metric::m_count
uint32_t m_count
Definition: Statistics.h:105
SWC::FS::Statistics::READ_ALL_ASYNC
@ READ_ALL_ASYNC
Definition: Statistics.h:57
SWC::FS::Statistics::RENAME_ASYNC
@ RENAME_ASYNC
Definition: Statistics.h:51
SWC::FS::Statistics::REMOVE_ASYNC
@ REMOVE_ASYNC
Definition: Statistics.h:35
SWC::FS::Statistics::gather
void gather(Statistics &stats) noexcept
Definition: Statistics.cc:52