Loading...
Searching...
No Matches
statistics.hpp
Go to the documentation of this file.
//*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2025 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef STATISTICS_HPP
#define STATISTICS_HPP
#include "../my_config.h"
#include "infinint.hpp"
#include "user_interaction.hpp"
#include "deci.hpp"
extern "C"
{
#if MUTEX_WORKS
#if HAVE_PTHREAD_H
#include <pthread.h>
#endif
#endif
}
#if MUTEX_WORKS
#define LOCK_IN pthread_mutex_lock(&lock_mutex)
#define LOCK_OUT pthread_mutex_unlock(&lock_mutex)
#define LOCK_IN_CONST pthread_mutex_lock(const_cast<pthread_mutex_t *>(&lock_mutex))
#define LOCK_OUT_CONST pthread_mutex_unlock(const_cast<pthread_mutex_t *>(&lock_mutex))
#else
#define LOCK_IN //
#define LOCK_OUT //
#define LOCK_IN_CONST //
#define LOCK_OUT_CONST //
#endif
namespace libdar
{
class statistics
{
public:
statistics(bool lock = true) { init(lock); clear(); };
statistics(const statistics & ref) { copy_from(ref); };
statistics(statistics && ref) { init(false); move_from(std::move(ref)); };
statistics & operator = (const statistics & ref) { detruit(); copy_from(ref); return *this; };
statistics & operator = (statistics && ref) noexcept { move_from(std::move(ref)); return *this; };
~statistics() { detruit(); };
void clear();
infinint total() const;
void incr_treated() { (this->*increment)(&treated); };
void incr_hard_links() { (this->*increment)(&hard_links); };
void incr_skipped() { (this->*increment)(&skipped); };
void incr_inode_only() { (this->*increment)(&inode_only); };
void incr_ignored() { (this->*increment)(&ignored); };
void incr_tooold() { (this->*increment)(&tooold); };
void incr_errored() { (this->*increment)(&errored); };
void incr_deleted() { (this->*increment)(&deleted); };
void incr_ea_treated() { (this->*increment)(&ea_treated); };
void incr_fsa_treated() { (this->*increment)(&fsa_treated); };
void add_to_ignored(const infinint & val) { (this->*add_to)(&ignored, val); };
void add_to_errored(const infinint & val) { (this->*add_to)(&errored, val); };
void add_to_deleted(const infinint & val) { (this->*add_to)(&deleted, val); };
void add_to_byte_amount(const infinint & val) { (this->*add_to)(&byte_amount, val); };
void sub_from_treated(const infinint & val) { (this->*sub_from)(&treated, val); };
void sub_from_ea_treated(const infinint & val) { (this->*sub_from)(&ea_treated, val); };
void sub_from_hard_links(const infinint & val) { (this->*sub_from)(&hard_links, val); };
void sub_from_fsa_treated(const infinint & val) { (this->*sub_from)(&fsa_treated, val); };
// getting methods returning infinint
infinint get_treated() const { return (this->*returned)(&treated); };
infinint get_hard_links() const { return (this->*returned)(&hard_links); };
infinint get_skipped() const { return (this->*returned)(&skipped); };
infinint get_inode_only() const { return (this->*returned)(&inode_only); };
infinint get_ignored() const { return (this->*returned)(&ignored); };
infinint get_tooold() const { return (this->*returned)(&tooold); };
infinint get_errored() const { return (this->*returned)(&errored); };
infinint get_deleted() const { return (this->*returned)(&deleted); };
infinint get_ea_treated() const { return (this->*returned)(&ea_treated); };
infinint get_byte_amount() const { return (this->*returned)(&byte_amount); };
infinint get_fsa_treated() const { return (this->*returned)(&fsa_treated); };
// now the _str() variant returning std::string
std::string get_treated_str() const { return deci(get_treated()).human(); };
std::string get_hard_links_str() const { return deci(get_hard_links()).human(); };
std::string get_skipped_str() const { return deci(get_skipped()).human(); };
std::string get_inode_only_str() const { return deci(get_inode_only()).human(); };
std::string get_ignored_str() const { return deci(get_ignored()).human();};
std::string get_tooold_str() const { return deci(get_tooold()).human(); };
std::string get_errored_str() const { return deci(get_errored()).human(); };
std::string get_deleted_str() const { return deci(get_deleted()).human(); };
std::string get_ea_treated_str() const { return deci(get_ea_treated()).human(); };
std::string get_byte_amount_str() const { return deci(get_byte_amount()).human(); };
std::string get_fsa_treated_str() const { return deci(get_fsa_treated()).human(); };
void decr_treated() { (this->*decrement)(&treated); };
void decr_hard_links() { (this->*decrement)(&hard_links); };
void decr_skipped() { (this->*decrement)(&skipped); };
void decr_inode_only() { (this->*decrement)(&inode_only); };
void decr_ignored() { (this->*decrement)(&ignored); };
void decr_tooold() { (this->*decrement)(&tooold); };
void decr_errored() { (this->*decrement)(&errored); };
void decr_deleted() { (this->*decrement)(&deleted); };
void decr_ea_treated() { (this->*decrement)(&ea_treated); };
void decr_fsa_treated() { (this->*decrement)(&fsa_treated); }
void set_byte_amount(const infinint & val) { (this->*set_to)(&byte_amount, val); };
void dump(user_interaction & dialog) const;
private:
#if MUTEX_WORKS
pthread_mutex_t lock_mutex;
#endif
bool locking;
infinint treated;
infinint hard_links;
infinint skipped;
infinint inode_only;
infinint ignored;
infinint tooold;
infinint errored;
infinint deleted;
infinint ea_treated;
infinint byte_amount;
infinint fsa_treated;
void (statistics::*increment)(infinint * var);
void (statistics::*add_to)(infinint * var, const infinint & val);
infinint (statistics::*returned)(const infinint * var) const;
void (statistics::*decrement)(infinint * var);
void (statistics::*set_to)(infinint * var, const infinint & val);
void (statistics::*sub_from)(infinint *var, const infinint & val);
void increment_locked(infinint * var)
{
LOCK_IN;
(*var)++;
LOCK_OUT;
};
void increment_unlocked(infinint * var)
{
(*var)++;
}
void add_to_locked(infinint * var, const infinint & val)
{
LOCK_IN;
(*var) += val;
LOCK_OUT;
}
void add_to_unlocked(infinint *var, const infinint & val)
{
(*var) += val;
}
infinint returned_locked(const infinint * var) const
{
infinint ret;
LOCK_IN_CONST;
ret = *var;
LOCK_OUT_CONST;
return ret;
};
infinint returned_unlocked(const infinint * var) const
{
return *var;
};
void decrement_locked(infinint * var)
{
LOCK_IN;
(*var)--;
LOCK_OUT;
}
void decrement_unlocked(infinint * var)
{
(*var)--;
}
void set_to_locked(infinint *var, const infinint & val)
{
LOCK_IN;
(*var) = val;
LOCK_OUT;
}
void set_to_unlocked(infinint *var, const infinint & val)
{
*var = val;
}
void sub_from_unlocked(infinint *var, const infinint & val)
{
*var -= val;
}
void sub_from_locked(infinint *var, const infinint & val)
{
LOCK_IN;
*var -= val;
LOCK_OUT;
}
void init(bool lock);
void detruit();
void copy_from(const statistics & ref);
void move_from(statistics && ref) noexcept;
};
} // end of namespace
#endif
libdar::deci
decimal class, convert infinint from and to decimal represention
Definition deci.hpp:51
libdar::deci::human
std::string human() const
this produce a string from the decimal stored in the current object
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
libdar::statistics::incr_errored
void incr_errored()
increment by one the errored counter
Definition statistics.hpp:121
libdar::statistics::copy_from
void copy_from(const statistics &ref)
reset mutex and copy data from the object of reference
libdar::statistics::total
infinint total() const
total number of file treated
libdar::statistics::decr_ignored
void decr_ignored()
decrement by one the ignored counter
Definition statistics.hpp:242
libdar::statistics::decr_hard_links
void decr_hard_links()
decrement by one the hard_links counter
Definition statistics.hpp:233
libdar::statistics::decr_ea_treated
void decr_ea_treated()
decrement by one the ea_treated counter
Definition statistics.hpp:254
libdar::statistics::locking
bool locking
whether we use locking or not
Definition statistics.hpp:271
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::hard_links
infinint hard_links
number of hard linked inodes treated (including those ignored by filters)
Definition statistics.hpp:276
libdar::statistics::incr_fsa_treated
void incr_fsa_treated()
increment by one the fsa treated counter
Definition statistics.hpp:130
libdar::statistics::get_deleted
infinint get_deleted() const
returns the current value of the deleted counter
Definition statistics.hpp:181
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::statistics
statistics(const statistics &ref)
copy constructor
Definition statistics.hpp:82
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::treated
infinint treated
number of inode treated (saved, restored, etc.) [all operations]
Definition statistics.hpp:274
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::incr_deleted
void incr_deleted()
increment by one the deleted counter
Definition statistics.hpp:124
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::sub_from_treated
void sub_from_treated(const infinint &val)
substract value from the treated counter
Definition statistics.hpp:145
libdar::statistics::incr_ignored
void incr_ignored()
increment by one the ignored counter
Definition statistics.hpp:115
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::statistics::get_ignored
infinint get_ignored() const
returns the current value of the ignored counter
Definition statistics.hpp:172
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::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::ignored
infinint ignored
ignored files due to filters
Definition statistics.hpp:282
libdar::statistics::inode_only
infinint inode_only
files which operation only affected inode metadata not its data
Definition statistics.hpp:280
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::statistics::decr_deleted
void decr_deleted()
decrement by one the deleted counter
Definition statistics.hpp:251
libdar::statistics::ea_treated
infinint ea_treated
number of EA saved / number of EA restored
Definition statistics.hpp:290
libdar::statistics::incr_inode_only
void incr_inode_only()
increment by one the inode_only counter
Definition statistics.hpp:112
libdar::statistics::move_from
void move_from(statistics &&ref) noexcept
used by to implement move related operations
libdar::statistics::get_ea_treated
infinint get_ea_treated() const
returns the current value of the ea_treated counter
Definition statistics.hpp:184
libdar::statistics::get_tooold
infinint get_tooold() const
returns the current value of the tooold counter
Definition statistics.hpp:175
libdar::statistics::dump
void dump(user_interaction &dialog) const
debuging method
libdar::statistics::statistics
statistics(statistics &&ref)
move constructor
Definition statistics.hpp:85
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::tooold
infinint tooold
ignored files because less recent than the filesystem entry [restoration] / modfied during backup
Definition statistics.hpp:284
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::incr_treated
void incr_treated()
increment by one the treated counter
Definition statistics.hpp:103
libdar::statistics::incr_hard_links
void incr_hard_links()
increment by one the hard_links counter
Definition statistics.hpp:106
libdar::statistics::~statistics
~statistics()
destructor
Definition statistics.hpp:94
libdar::statistics::get_errored
infinint get_errored() const
returns the current value of the errored counter
Definition statistics.hpp:178
libdar::statistics::decr_tooold
void decr_tooold()
decrement by one the toold counter
Definition statistics.hpp:245
libdar::statistics::decr_skipped
void decr_skipped()
decrement by one the skipped counter
Definition statistics.hpp:236
libdar::statistics::deleted
infinint deleted
deleted file seen / number of files deleted during the operation [restoration]
Definition statistics.hpp:288
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::increment
void(statistics::* increment)(infinint *var)
generic method for incrementing a variable
Definition statistics.hpp:297
libdar::statistics::decr_treated
void decr_treated()
decrement by one the treated counter
Definition statistics.hpp:230
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_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::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::init
void init(bool lock)
set locking & mutex
libdar::statistics::decr_inode_only
void decr_inode_only()
decrement by one the inode_only counter
Definition statistics.hpp:239
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::fsa_treated
infinint fsa_treated
number of FSA saved / number of FSA restored
Definition statistics.hpp:294
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::get_treated
infinint get_treated() const
returns the current value of the treated counter
Definition statistics.hpp:160
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::detruit
void detruit()
release and free the mutex
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::incr_tooold
void incr_tooold()
increment by one the tooold counter
Definition statistics.hpp:118
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::decrement
void(statistics::* decrement)(infinint *var)
generic method for decrementing a variable
Definition statistics.hpp:300
libdar::statistics::decr_fsa_treated
void decr_fsa_treated()
decrement by one the fsa_treated counter
Definition statistics.hpp:257
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::operator=
statistics & operator=(const statistics &ref)
copy assignement
Definition statistics.hpp:88
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::clear
void clear()
reset counters to zero
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::add_to_deleted
void add_to_deleted(const infinint &val)
increment the deleted counter by a given value
Definition statistics.hpp:139
libdar::statistics::incr_ea_treated
void incr_ea_treated()
increment by one the ea_treated counter
Definition statistics.hpp:127
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::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
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_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::decr_errored
void decr_errored()
decrement by one the errored counter
Definition statistics.hpp:248
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::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::get_skipped
infinint get_skipped() const
returns the current value of the skipped counter
Definition statistics.hpp:166
libdar::statistics::incr_skipped
void incr_skipped()
increment by one the skipped counter
Definition statistics.hpp:109
libdar::statistics::statistics
statistics(bool lock=true)
constructor
Definition statistics.hpp:79
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:58
deci.hpp
manages the decimal representation of infinint
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
user_interaction.hpp
defines the interaction interface between libdar and users.