summaryrefslogtreecommitdiff
path: root/rdiff-backup/rdiff_backup/statistics.py
diff options
context:
space:
mode:
authorben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-06-15 20:03:46 +0000
committerben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2002-06-15 20:03:46 +0000
commit127e5a48e7b64b5aa7c01b4ccfcc6852f31c2b20 (patch)
tree94a60eb3e0b5fdbe490b2d67e81a35b2fa04c0ed /rdiff-backup/rdiff_backup/statistics.py
parentd2943df4a4eb71162dfd3939e0c668a83d85ee4e (diff)
downloadrdiff-backup-127e5a48e7b64b5aa7c01b4ccfcc6852f31c2b20.tar.gz
Various CPU optimizations
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@126 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/rdiff_backup/statistics.py')
-rw-r--r--rdiff-backup/rdiff_backup/statistics.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/rdiff-backup/rdiff_backup/statistics.py b/rdiff-backup/rdiff_backup/statistics.py
index 4043f16..a91a681 100644
--- a/rdiff-backup/rdiff_backup/statistics.py
+++ b/rdiff-backup/rdiff_backup/statistics.py
@@ -32,21 +32,19 @@ class StatsObj:
('ChangedSourceSize', 1), ('ChangedMirrorSize', 1),
('IncrementFiles', None), ('IncrementFileSize', 1))
- # Set all stats to None, indicating info not available
- for attr in stat_attrs: locals()[attr] = None
-
# This is used in get_byte_summary_string below
byte_abbrev_list = ((1024*1024*1024*1024, "TB"),
(1024*1024*1024, "GB"),
(1024*1024, "MB"),
(1024, "KB"))
+ def __init__(self):
+ """Set attributes to None"""
+ for attr in self.stat_attrs: self.__dict__[attr] = None
+
def get_stat(self, attribute):
"""Get a statistic"""
- try: return self.__dict__[attribute]
- except KeyError:
- # this may be a hack, but seems no good way to get attrs in python
- return eval("self.%s" % attribute)
+ return self.__dict__[attribute]
def set_stat(self, attr, value):
"""Set attribute to given value"""
@@ -54,7 +52,7 @@ class StatsObj:
def increment_stat(self, attr):
"""Add 1 to value of attribute"""
- self.__dict__[attr] = self.get_stat(attr) + 1
+ self.__dict__[attr] += 1
def get_stats_line(self, index, use_repr = 1):
"""Return one line abbreviated version of full stats string"""
@@ -217,8 +215,12 @@ class StatsITR(IterTreeReducer, StatsObj):
This is subclassed by the mirroring and incrementing ITRs.
"""
- # zero out file statistics
- for attr in StatsObj.stat_file_attrs: locals()[attr] = 0
+ def __init__(self, *args):
+ """StatsITR initializer - zero out statistics"""
+ attr_dict = self.__dict__
+ for attr in StatsObj.stat_file_attrs: attr_dict[attr] = 0
+ self.ElapsedTime = self.Filename = None
+ IterTreeReducer.__init__(self, *args)
def start_stats(self, mirror_dsrp):
"""Record status of mirror dsrp
@@ -272,8 +274,7 @@ class StatsITR(IterTreeReducer, StatsObj):
def add_file_stats(self, subinstance):
"""Add all file statistics from subinstance to current totals"""
for attr in self.stat_file_attrs:
- self.set_stat(attr,
- self.get_stat(attr) + subinstance.get_stat(attr))
+ self.__dict__[attr] += subinstance.__dict__[attr]
class Stats: