Disk ARchive 2.7.14
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
dar64-2.7.14-win64/include/dar/statistics.hpp
Go to the documentation of this file.
1//*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2024 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, see the AUTHOR file
20/*********************************************************************/
21
25
26#ifndef STATISTICS_HPP
27#define STATISTICS_HPP
28
29#include "//include/dar/libdar_my_config.h"
30
31#include "//include/dar/infinint.hpp"
32#include "//include/dar/user_interaction.hpp"
33#include "//include/dar/deci.hpp"
34
35extern "C"
36{
37#if LIBDAR_MUTEX_WORKS
38#if LIBDAR_HAS_PTHREAD_H
39#include <pthread.h>
40#endif
41#endif
42}
43
44
45#if LIBDAR_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
57namespace libdar
58{
59
62
64
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) { 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
95
97 void clear();
98
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
258
260 void set_byte_amount(const infinint & val) { (this->*set_to)(&byte_amount, val); };
261
264
265 private:
266#if LIBDAR_MUTEX_WORKS
269#endif
272
295
296
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
decimal class, convert infinint from and to decimal represention
std::string human() const
this produce a string from the decimal stored in the current object
the arbitrary large positive integer class
class used by libdar::archive class to give a summary of treated file during and after an operation
void(statistics::* set_to)(infinint *var, const infinint &val)
generic method for setting a variable to a given value
void incr_errored()
increment by one the errored counter
void copy_from(const statistics &ref)
reset mutex and copy data from the object of reference
infinint total() const
total number of file treated
void decr_ignored()
decrement by one the ignored counter
void decr_hard_links()
decrement by one the hard_links counter
void decr_ea_treated()
decrement by one the ea_treated counter
bool locking
whether we use locking or not
infinint errored
files that could not be saved / files that could not be restored (filesystem access right)
infinint hard_links
number of hard linked inodes treated (including those ignored by filters)
void(statistics::* decrement)(infinint *var)
generic method for decrementing a variable
void incr_fsa_treated()
increment by one the fsa treated counter
infinint get_deleted() const
returns the current value of the deleted counter
void add_to_ignored(const infinint &val)
increment the ignored counter by a given value
statistics(const statistics &ref)
copy constructor
infinint skipped
files not changed since last backup / file not restored because not saved in backup
infinint treated
number of inode treated (saved, restored, etc.) [all operations]
infinint get_inode_only() const
returns the current value of the inode_only counter
void incr_deleted()
increment by one the deleted counter
std::string get_byte_amount_str() const
returns the current value of the byte_amount counter as a std::string
void sub_from_treated(const infinint &val)
substract value from the treated counter
void incr_ignored()
increment by one the ignored counter
void(statistics::* sub_from)(infinint *var, const infinint &val)
generic method for substracting to a variable
void sub_from_ea_treated(const infinint &val)
substract value to the ea_treated counter
infinint get_ignored() const
returns the current value of the ignored counter
void sub_from_fsa_treated(const infinint &val)
substract value to the fsa_treated counter
std::string get_hard_links_str() const
returns the current value of the hard_links counter as a std::string;
infinint ignored
ignored files due to filters
infinint inode_only
files which operation only affected inode metadata not its data
void decr_deleted()
decrement by one the deleted counter
infinint ea_treated
number of EA saved / number of EA restored
void incr_inode_only()
increment by one the inode_only counter
void move_from(statistics &&ref) noexcept
used by to implement move related operations
infinint get_ea_treated() const
returns the current value of the ea_treated counter
infinint get_tooold() const
returns the current value of the tooold counter
void dump(user_interaction &dialog) const
debuging method
statistics(statistics &&ref)
move constructor
infinint byte_amount
auxilliary counter, holds the wasted bytes due to repeat on change feature for example.
infinint tooold
ignored files because less recent than the filesystem entry [restoration] / modfied during backup
std::string get_ea_treated_str() const
returns the current value of the ea_treated counter as a std::string
void incr_treated()
increment by one the treated counter
void incr_hard_links()
increment by one the hard_links counter
infinint get_errored() const
returns the current value of the errored counter
void decr_tooold()
decrement by one the toold counter
void decr_skipped()
decrement by one the skipped counter
infinint deleted
deleted file seen / number of files deleted during the operation [restoration]
infinint get_fsa_treated() const
returns the current value of the fsa_treated counter
void decr_treated()
decrement by one the treated counter
std::string get_inode_only_str() const
returns the current value of the inode_only counter as a std::string
std::string get_ignored_str() const
returns the current value of the ignored counter as a std::string
void(statistics::* add_to)(infinint *var, const infinint &val)
generic method for add a value to a variable
std::string get_skipped_str() const
returns the current value of the skipped counter as a std::string
void init(bool lock)
set locking & mutex
void decr_inode_only()
decrement by one the inode_only counter
void sub_from_hard_links(const infinint &val)
substract value to the hard_links counter
infinint fsa_treated
number of FSA saved / number of FSA restored
infinint get_byte_amount() const
returns the current value of the byte_amount counter
infinint get_treated() const
returns the current value of the treated counter
infinint get_hard_links() const
returns the current value of the hard_links counter
void detruit()
release and free the mutex
void(statistics::* increment)(infinint *var)
generic method for incrementing a variable
void incr_tooold()
increment by one the tooold counter
void decr_fsa_treated()
decrement by one the fsa_treated counter
std::string get_errored_str() const
returns the current value of the errored counter as a std::string
statistics & operator=(const statistics &ref)
copy assignement
void clear()
reset counters to zero
void add_to_errored(const infinint &val)
increment the errored counter by a given value
void add_to_deleted(const infinint &val)
increment the deleted counter by a given value
void incr_ea_treated()
increment by one the ea_treated counter
std::string get_deleted_str() const
returns the current value of the deleted counter as a std::string
void add_to_byte_amount(const infinint &val)
increment the byte amount counter by a given value
std::string get_fsa_treated_str() const
returns the current value of the fsa_treated counter as a std::string
std::string get_treated_str() const
returns the current value of the treated counter as a std::string
infinint(statistics::* returned)(const infinint *var) const
generic method for obtaining the value of a variable
void decr_errored()
decrement by one the errored counter
void set_byte_amount(const infinint &val)
set to the given value the byte_amount counter
std::string get_tooold_str() const
returns the current value of the tooold counter as a std::string
infinint get_skipped() const
returns the current value of the skipped counter
void incr_skipped()
increment by one the skipped counter
This is a pure virtual class that is used by libdar when interaction with the user is required.
libdar namespace encapsulate all libdar symbols