Disk ARchive  2.6.8
Full featured and portable backup and archiving tool
statistics.hpp
Go to the documentation of this file.
1 //*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2020 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
25 
26 #ifndef STATISTICS_HPP
27 #define STATISTICS_HPP
28 
29 #include "../my_config.h"
30 
31 #include "infinint.hpp"
32 #include "user_interaction.hpp"
33 #include "deci.hpp"
34 
35 extern "C"
36 {
37 #if MUTEX_WORKS
38 #if HAVE_PTHREAD_H
39 #include <pthread.h>
40 #endif
41 #endif
42 }
43 
44 
45 #if MUTEX_WORKS
46 #define LOCK_IN pthread_mutex_lock(&lock_mutex)
47 #define LOCK_OUT pthread_mutex_unlock(&lock_mutex)
48 #define LOCK_IN_CONST pthread_mutex_lock(const_cast<pthread_mutex_t *>(&lock_mutex))
49 #define LOCK_OUT_CONST pthread_mutex_unlock(const_cast<pthread_mutex_t *>(&lock_mutex))
50 #else
51 #define LOCK_IN //
52 #define LOCK_OUT //
53 #define LOCK_IN_CONST //
54 #define LOCK_OUT_CONST //
55 #endif
56 
57 namespace libdar
58 {
59 
62 
64 
69  class statistics
70  {
71  public:
73 
79  statistics(bool lock = true) { init(lock); clear(); };
80 
82  statistics(const statistics & ref) { copy_from(ref); };
83 
85  statistics(statistics && ref) noexcept { init(false); move_from(std::move(ref)); };
86 
88  statistics & operator = (const statistics & ref) { detruit(); copy_from(ref); return *this; };
89 
91  statistics & operator = (statistics && ref) noexcept { move_from(std::move(ref)); return *this; };
92 
94  ~statistics() { detruit(); };
95 
97  void clear();
98 
100  infinint total() const;
101 
103  void incr_treated() { (this->*increment)(&treated); };
104 
106  void incr_hard_links() { (this->*increment)(&hard_links); };
107 
109  void incr_skipped() { (this->*increment)(&skipped); };
110 
112  void incr_inode_only() { (this->*increment)(&inode_only); };
113 
115  void incr_ignored() { (this->*increment)(&ignored); };
116 
118  void incr_tooold() { (this->*increment)(&tooold); };
119 
121  void incr_errored() { (this->*increment)(&errored); };
122 
124  void incr_deleted() { (this->*increment)(&deleted); };
125 
127  void incr_ea_treated() { (this->*increment)(&ea_treated); };
128 
130  void incr_fsa_treated() { (this->*increment)(&fsa_treated); };
131 
133  void add_to_ignored(const infinint & val) { (this->*add_to)(&ignored, val); };
134 
136  void add_to_errored(const infinint & val) { (this->*add_to)(&errored, val); };
137 
139  void add_to_deleted(const infinint & val) { (this->*add_to)(&deleted, val); };
140 
142  void add_to_byte_amount(const infinint & val) { (this->*add_to)(&byte_amount, val); };
143 
145  void sub_from_treated(const infinint & val) { (this->*sub_from)(&treated, val); };
146 
148  void sub_from_ea_treated(const infinint & val) { (this->*sub_from)(&ea_treated, val); };
149 
151  void sub_from_hard_links(const infinint & val) { (this->*sub_from)(&hard_links, val); };
152 
154  void sub_from_fsa_treated(const infinint & val) { (this->*sub_from)(&fsa_treated, val); };
155 
157  // getting methods returning infinint
158 
160  infinint get_treated() const { return (this->*returned)(&treated); };
161 
163  infinint get_hard_links() const { return (this->*returned)(&hard_links); };
164 
166  infinint get_skipped() const { return (this->*returned)(&skipped); };
167 
169  infinint get_inode_only() const { return (this->*returned)(&inode_only); };
170 
172  infinint get_ignored() const { return (this->*returned)(&ignored); };
173 
175  infinint get_tooold() const { return (this->*returned)(&tooold); };
176 
178  infinint get_errored() const { return (this->*returned)(&errored); };
179 
181  infinint get_deleted() const { return (this->*returned)(&deleted); };
182 
184  infinint get_ea_treated() const { return (this->*returned)(&ea_treated); };
185 
187  infinint get_byte_amount() const { return (this->*returned)(&byte_amount); };
188 
190  infinint get_fsa_treated() const { return (this->*returned)(&fsa_treated); };
191 
193  // now the _str() variant returning std::string
194 
196  std::string get_treated_str() const { return deci(get_treated()).human(); };
197 
199  std::string get_hard_links_str() const { return deci(get_hard_links()).human(); };
200 
202  std::string get_skipped_str() const { return deci(get_skipped()).human(); };
203 
205  std::string get_inode_only_str() const { return deci(get_inode_only()).human(); };
206 
208  std::string get_ignored_str() const { return deci(get_ignored()).human();};
209 
211  std::string get_tooold_str() const { return deci(get_tooold()).human(); };
212 
214  std::string get_errored_str() const { return deci(get_errored()).human(); };
215 
217  std::string get_deleted_str() const { return deci(get_deleted()).human(); };
218 
220  std::string get_ea_treated_str() const { return deci(get_ea_treated()).human(); };
221 
223  std::string get_byte_amount_str() const { return deci(get_byte_amount()).human(); };
224 
226  std::string get_fsa_treated_str() const { return deci(get_fsa_treated()).human(); };
227 
228 
230  void decr_treated() { (this->*decrement)(&treated); };
231 
233  void decr_hard_links() { (this->*decrement)(&hard_links); };
234 
236  void decr_skipped() { (this->*decrement)(&skipped); };
237 
239  void decr_inode_only() { (this->*decrement)(&inode_only); };
240 
242  void decr_ignored() { (this->*decrement)(&ignored); };
243 
245  void decr_tooold() { (this->*decrement)(&tooold); };
246 
248  void decr_errored() { (this->*decrement)(&errored); };
249 
251  void decr_deleted() { (this->*decrement)(&deleted); };
252 
254  void decr_ea_treated() { (this->*decrement)(&ea_treated); };
255 
257  void decr_fsa_treated() { (this->*decrement)(&fsa_treated); }
258 
260  void set_byte_amount(const infinint & val) { (this->*set_to)(&byte_amount, val); };
261 
263  void dump(user_interaction & dialog) const;
264 
265  private:
266 #if MUTEX_WORKS
267  pthread_mutex_t lock_mutex;
269 #endif
270  bool locking;
272 
295 
296 
297  void (statistics::*increment)(infinint * var);
298  void (statistics::*add_to)(infinint * var, const infinint & val);
299  infinint (statistics::*returned)(const infinint * var) const;
300  void (statistics::*decrement)(infinint * var);
301  void (statistics::*set_to)(infinint * var, const infinint & val);
302  void (statistics::*sub_from)(infinint *var, const infinint & val);
303 
304  void increment_locked(infinint * var)
305  {
306  LOCK_IN;
307  (*var)++;
308  LOCK_OUT;
309  };
310 
311  void increment_unlocked(infinint * var)
312  {
313  (*var)++;
314  }
315 
316  void add_to_locked(infinint * var, const infinint & val)
317  {
318  LOCK_IN;
319  (*var) += val;
320  LOCK_OUT;
321  }
322 
323  void add_to_unlocked(infinint *var, const infinint & val)
324  {
325  (*var) += val;
326  }
327 
328  infinint returned_locked(const infinint * var) const
329  {
330  infinint ret;
331 
332  LOCK_IN_CONST;
333  ret = *var;
334  LOCK_OUT_CONST;
335 
336  return ret;
337  };
338 
339  infinint returned_unlocked(const infinint * var) const
340  {
341  return *var;
342  };
343 
344  void decrement_locked(infinint * var)
345  {
346  LOCK_IN;
347  (*var)--;
348  LOCK_OUT;
349  }
350 
351  void decrement_unlocked(infinint * var)
352  {
353  (*var)--;
354  }
355 
356  void set_to_locked(infinint *var, const infinint & val)
357  {
358  LOCK_IN;
359  (*var) = val;
360  LOCK_OUT;
361  }
362 
363  void set_to_unlocked(infinint *var, const infinint & val)
364  {
365  *var = val;
366  }
367 
368  void sub_from_unlocked(infinint *var, const infinint & val)
369  {
370  *var -= val;
371  }
372 
373  void sub_from_locked(infinint *var, const infinint & val)
374  {
375  LOCK_IN;
376  *var -= val;
377  LOCK_OUT;
378  }
379 
381  void init(bool lock);
382 
384  void detruit();
385 
387  void copy_from(const statistics & ref);
388 
390  void move_from(statistics && ref) noexcept;
391 
392  };
393 
395 
396 
397 } // end of namespace
398 
399 #endif
libdar::statistics::inode_only
infinint inode_only
files which operation only affected inode metadata not its data
Definition: statistics.hpp:280
libdar::statistics::get_hard_links
infinint get_hard_links() const
returns the current value of the hard_links counter
Definition: statistics.hpp:163
libdar::statistics::byte_amount
infinint byte_amount
auxilliary counter, holds the wasted bytes due to repeat on change feature for example.
Definition: statistics.hpp:292
libdar::statistics::statistics
statistics(const statistics &ref)
copy constructor
Definition: statistics.hpp:82
libdar::statistics::incr_skipped
void incr_skipped()
increment by one the skipped counter
Definition: statistics.hpp:109
libdar::statistics::get_ignored_str
std::string get_ignored_str() const
returns the current value of the ignored counter as a std::string
Definition: statistics.hpp:208
libdar::statistics::set_to
void(statistics::* set_to)(infinint *var, const infinint &val)
generic method for setting a variable to a given value
Definition: statistics.hpp:301
libdar::user_interaction
This is a pure virtual class that is used by libdar when interaction with the user is required.
Definition: user_interaction.hpp:46
libdar::statistics::add_to
void(statistics::* add_to)(infinint *var, const infinint &val)
generic method for add a value to a variable
Definition: statistics.hpp:298
libdar::statistics::decr_fsa_treated
void decr_fsa_treated()
decrement by one the fsa_treated counter
Definition: statistics.hpp:257
libdar::statistics::tooold
infinint tooold
ignored files because less recent than the filesystem entry [restoration] / modfied during backup
Definition: statistics.hpp:284
libdar::statistics::add_to_deleted
void add_to_deleted(const infinint &val)
increment the deleted counter by a given value
Definition: statistics.hpp:139
libdar::statistics::get_inode_only_str
std::string get_inode_only_str() const
returns the current value of the inode_only counter as a std::string
Definition: statistics.hpp:205
libdar::statistics::get_byte_amount
infinint get_byte_amount() const
returns the current value of the byte_amount counter
Definition: statistics.hpp:187
libdar::statistics::dump
void dump(user_interaction &dialog) const
debuging method
user_interaction.hpp
defines the interaction interface between libdar and users.
libdar::statistics::get_tooold_str
std::string get_tooold_str() const
returns the current value of the tooold counter as a std::string
Definition: statistics.hpp:211
libdar::statistics::hard_links
infinint hard_links
number of hard linked inodes treated (including those ignored by filters)
Definition: statistics.hpp:276
libdar::statistics::incr_ea_treated
void incr_ea_treated()
increment by one the ea_treated counter
Definition: statistics.hpp:127
libdar::statistics::operator=
statistics & operator=(const statistics &ref)
copy assignement
Definition: statistics.hpp:88
libdar::statistics::add_to_byte_amount
void add_to_byte_amount(const infinint &val)
increment the byte amount counter by a given value
Definition: statistics.hpp:142
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:61
libdar::statistics::move_from
void move_from(statistics &&ref) noexcept
used by to implement move related operations
libdar::statistics::incr_tooold
void incr_tooold()
increment by one the tooold counter
Definition: statistics.hpp:118
libdar::statistics::returned
infinint(statistics::* returned)(const infinint *var) const
generic method for obtaining the value of a variable
Definition: statistics.hpp:299
libdar::statistics::statistics
statistics(statistics &&ref) noexcept
move constructor
Definition: statistics.hpp:85
libdar::statistics::get_errored_str
std::string get_errored_str() const
returns the current value of the errored counter as a std::string
Definition: statistics.hpp:214
libdar::statistics::increment
void(statistics::* increment)(infinint *var)
generic method for incrementing a variable
Definition: statistics.hpp:297
libdar::statistics::decr_ea_treated
void decr_ea_treated()
decrement by one the ea_treated counter
Definition: statistics.hpp:254
libdar::statistics::get_treated_str
std::string get_treated_str() const
returns the current value of the treated counter as a std::string
Definition: statistics.hpp:196
libdar::statistics::errored
infinint errored
files that could not be saved / files that could not be restored (filesystem access right)
Definition: statistics.hpp:286
libdar::statistics::fsa_treated
infinint fsa_treated
number of FSA saved / number of FSA restored
Definition: statistics.hpp:294
libdar::statistics::incr_treated
void incr_treated()
increment by one the treated counter
Definition: statistics.hpp:103
libdar::statistics::incr_errored
void incr_errored()
increment by one the errored counter
Definition: statistics.hpp:121
libdar::statistics::decr_skipped
void decr_skipped()
decrement by one the skipped counter
Definition: statistics.hpp:236
libdar::statistics::decr_inode_only
void decr_inode_only()
decrement by one the inode_only counter
Definition: statistics.hpp:239
libdar::statistics::sub_from_fsa_treated
void sub_from_fsa_treated(const infinint &val)
substract value to the fsa_treated counter
Definition: statistics.hpp:154
libdar::statistics::decr_deleted
void decr_deleted()
decrement by one the deleted counter
Definition: statistics.hpp:251
libdar::statistics::incr_fsa_treated
void incr_fsa_treated()
increment by one the fsa treated counter
Definition: statistics.hpp:130
libdar::statistics::get_ignored
infinint get_ignored() const
returns the current value of the ignored counter
Definition: statistics.hpp:172
libdar::statistics::detruit
void detruit()
release and free the mutex
libdar::statistics::get_skipped
infinint get_skipped() const
returns the current value of the skipped counter
Definition: statistics.hpp:166
libdar::statistics
class used by libdar::archive class to give a summary of treated file during and after an operation
Definition: statistics.hpp:69
libdar::statistics::ea_treated
infinint ea_treated
number of EA saved / number of EA restored
Definition: statistics.hpp:290
libdar::statistics::get_hard_links_str
std::string get_hard_links_str() const
returns the current value of the hard_links counter as a std::string;
Definition: statistics.hpp:199
libdar::statistics::get_ea_treated
infinint get_ea_treated() const
returns the current value of the ea_treated counter
Definition: statistics.hpp:184
libdar::deci
decimal class, convert infinint from and to decimal represention
Definition: deci.hpp:50
libdar::statistics::incr_inode_only
void incr_inode_only()
increment by one the inode_only counter
Definition: statistics.hpp:112
libdar::statistics::deleted
infinint deleted
deleted file seen / number of files deleted during the operation [restoration]
Definition: statistics.hpp:288
libdar::statistics::sub_from
void(statistics::* sub_from)(infinint *var, const infinint &val)
generic method for substracting to a variable
Definition: statistics.hpp:302
libdar::statistics::~statistics
~statistics()
destructor
Definition: statistics.hpp:94
libdar::statistics::get_deleted_str
std::string get_deleted_str() const
returns the current value of the deleted counter as a std::string
Definition: statistics.hpp:217
libdar::statistics::get_ea_treated_str
std::string get_ea_treated_str() const
returns the current value of the ea_treated counter as a std::string
Definition: statistics.hpp:220
libdar::statistics::sub_from_ea_treated
void sub_from_ea_treated(const infinint &val)
substract value to the ea_treated counter
Definition: statistics.hpp:148
libdar::deci::human
std::string human() const
this produce a string from the decimal stored in the current object
libdar::statistics::ignored
infinint ignored
ignored files due to filters
Definition: statistics.hpp:282
libdar::statistics::decr_ignored
void decr_ignored()
decrement by one the ignored counter
Definition: statistics.hpp:242
libdar::statistics::get_fsa_treated
infinint get_fsa_treated() const
returns the current value of the fsa_treated counter
Definition: statistics.hpp:190
libdar::statistics::add_to_errored
void add_to_errored(const infinint &val)
increment the errored counter by a given value
Definition: statistics.hpp:136
libdar::statistics::incr_deleted
void incr_deleted()
increment by one the deleted counter
Definition: statistics.hpp:124
libdar::statistics::copy_from
void copy_from(const statistics &ref)
reset mutex and copy data from the object of reference
libdar::statistics::decrement
void(statistics::* decrement)(infinint *var)
generic method for decrementing a variable
Definition: statistics.hpp:300
libdar::statistics::sub_from_hard_links
void sub_from_hard_links(const infinint &val)
substract value to the hard_links counter
Definition: statistics.hpp:151
libdar::statistics::decr_tooold
void decr_tooold()
decrement by one the toold counter
Definition: statistics.hpp:245
libdar::statistics::get_tooold
infinint get_tooold() const
returns the current value of the tooold counter
Definition: statistics.hpp:175
libdar::statistics::decr_hard_links
void decr_hard_links()
decrement by one the hard_links counter
Definition: statistics.hpp:233
libdar::statistics::decr_treated
void decr_treated()
decrement by one the treated counter
Definition: statistics.hpp:230
libdar::statistics::add_to_ignored
void add_to_ignored(const infinint &val)
increment the ignored counter by a given value
Definition: statistics.hpp:133
libdar::statistics::get_deleted
infinint get_deleted() const
returns the current value of the deleted counter
Definition: statistics.hpp:181
libdar::statistics::init
void init(bool lock)
set locking & mutex
libdar::statistics::clear
void clear()
reset counters to zero
libdar::statistics::statistics
statistics(bool lock=true)
constructor
Definition: statistics.hpp:79
libdar::statistics::sub_from_treated
void sub_from_treated(const infinint &val)
substract value from the treated counter
Definition: statistics.hpp:145
libdar::statistics::get_fsa_treated_str
std::string get_fsa_treated_str() const
returns the current value of the fsa_treated counter as a std::string
Definition: statistics.hpp:226
libdar::statistics::get_errored
infinint get_errored() const
returns the current value of the errored counter
Definition: statistics.hpp:178
libdar::statistics::treated
infinint treated
number of inode treated (saved, restored, etc.) [all operations]
Definition: statistics.hpp:274
deci.hpp
manages the decimal representation of infinint
libdar::statistics::get_skipped_str
std::string get_skipped_str() const
returns the current value of the skipped counter as a std::string
Definition: statistics.hpp:202
libdar::statistics::incr_ignored
void incr_ignored()
increment by one the ignored counter
Definition: statistics.hpp:115
libdar::statistics::get_inode_only
infinint get_inode_only() const
returns the current value of the inode_only counter
Definition: statistics.hpp:169
libdar::statistics::get_byte_amount_str
std::string get_byte_amount_str() const
returns the current value of the byte_amount counter as a std::string
Definition: statistics.hpp:223
libdar::statistics::skipped
infinint skipped
files not changed since last backup / file not restored because not saved in backup
Definition: statistics.hpp:278
libdar::statistics::total
infinint total() const
total number of file treated
libdar::statistics::get_treated
infinint get_treated() const
returns the current value of the treated counter
Definition: statistics.hpp:160
libdar::statistics::incr_hard_links
void incr_hard_links()
increment by one the hard_links counter
Definition: statistics.hpp:106
libdar::statistics::decr_errored
void decr_errored()
decrement by one the errored counter
Definition: statistics.hpp:248
libdar::statistics::locking
bool locking
whether we use locking or not
Definition: statistics.hpp:271
libdar::statistics::set_byte_amount
void set_byte_amount(const infinint &val)
set to the given value the byte_amount counter
Definition: statistics.hpp:260
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46