diff options
-rw-r--r-- | rdiff-backup/rdiff_backup/statistics.py | 43 | ||||
-rw-r--r-- | rdiff-backup/src/statistics.py | 43 | ||||
-rw-r--r-- | rdiff-backup/src/ttime.py | 16 |
3 files changed, 92 insertions, 10 deletions
diff --git a/rdiff-backup/rdiff_backup/statistics.py b/rdiff-backup/rdiff_backup/statistics.py index a121591..e0b19bf 100644 --- a/rdiff-backup/rdiff_backup/statistics.py +++ b/rdiff-backup/rdiff_backup/statistics.py @@ -17,7 +17,7 @@ class StatsObj: 'ChangedFiles', 'ChangedSourceSize', 'ChangedMirrorSize', 'IncrementFileSize') - stat_time_attrs = ('StartTime', 'EndTime') + stat_time_attrs = ('StartTime', 'EndTime', 'ElapsedTime') stat_attrs = stat_time_attrs + stat_file_attrs # Set all stats to None, indicating info not available @@ -36,10 +36,23 @@ class StatsObj: def get_stats_string(self): """Return string printing out statistics""" - slist = ["%s %s" % (attr, self.get_stat(attr)) - for attr in self.stat_attrs - if self.get_stat(attr) is not None] - return "\n".join(slist) + timelist = [] + if self.StartTime is not None: + timelist.append("StartTime %s (%s)" % + (self.StartTime, Time.timetopretty(self.StartTime))) + if self.EndTime is not None: + timelist.append("EndTime %s (%s)" % + (self.EndTime, Time.timetopretty(self.EndTime))) + if self.StartTime is not None and self.EndTime is not None: + if self.ElapsedTime is None: + self.ElapsedTime = self.EndTime - self.StartTime + timelist.append("ElapsedTime %s (%s)" % + (self.ElapsedTime, Time.inttopretty(self.ElapsedTime))) + + filelist = ["%s %s" % (attr, self.get_stat(attr)) + for attr in self.stat_file_attrs + if self.get_stat(attr) is not None] + return "\n".join(timelist + filelist) def init_stats_from_string(self, s): """Initialize attributes from string, return self for convenience""" @@ -78,6 +91,26 @@ class StatsObj: if self.get_stat(attr) != s.get_stat(attr): return None return 1 + def set_to_average(self, statobj_list): + """Set self's attributes to average of those in statobj_list""" + for attr in self.stat_attrs: self.set_stat(attr, 0) + for statobj in statobj_list: + for attr in self.stat_attrs: + if statobj.get_stat(attr) is None: self.set_stat(attr, None) + elif self.get_stat(attr) is not None: + self.set_stat(attr, statobj.get_stat(attr) + + self.get_stat(attr)) + + # Don't compute average starting/stopping time + self.StartTime = None + self.EndTime = None + + for attr in self.stat_attrs: + if self.get_stat(attr) is not None: + self.set_stat(attr, + self.get_stat(attr)/float(len(statobj_list))) + return self + class StatsITR(IterTreeReducer, StatsObj): """Keep track of per directory statistics diff --git a/rdiff-backup/src/statistics.py b/rdiff-backup/src/statistics.py index a121591..e0b19bf 100644 --- a/rdiff-backup/src/statistics.py +++ b/rdiff-backup/src/statistics.py @@ -17,7 +17,7 @@ class StatsObj: 'ChangedFiles', 'ChangedSourceSize', 'ChangedMirrorSize', 'IncrementFileSize') - stat_time_attrs = ('StartTime', 'EndTime') + stat_time_attrs = ('StartTime', 'EndTime', 'ElapsedTime') stat_attrs = stat_time_attrs + stat_file_attrs # Set all stats to None, indicating info not available @@ -36,10 +36,23 @@ class StatsObj: def get_stats_string(self): """Return string printing out statistics""" - slist = ["%s %s" % (attr, self.get_stat(attr)) - for attr in self.stat_attrs - if self.get_stat(attr) is not None] - return "\n".join(slist) + timelist = [] + if self.StartTime is not None: + timelist.append("StartTime %s (%s)" % + (self.StartTime, Time.timetopretty(self.StartTime))) + if self.EndTime is not None: + timelist.append("EndTime %s (%s)" % + (self.EndTime, Time.timetopretty(self.EndTime))) + if self.StartTime is not None and self.EndTime is not None: + if self.ElapsedTime is None: + self.ElapsedTime = self.EndTime - self.StartTime + timelist.append("ElapsedTime %s (%s)" % + (self.ElapsedTime, Time.inttopretty(self.ElapsedTime))) + + filelist = ["%s %s" % (attr, self.get_stat(attr)) + for attr in self.stat_file_attrs + if self.get_stat(attr) is not None] + return "\n".join(timelist + filelist) def init_stats_from_string(self, s): """Initialize attributes from string, return self for convenience""" @@ -78,6 +91,26 @@ class StatsObj: if self.get_stat(attr) != s.get_stat(attr): return None return 1 + def set_to_average(self, statobj_list): + """Set self's attributes to average of those in statobj_list""" + for attr in self.stat_attrs: self.set_stat(attr, 0) + for statobj in statobj_list: + for attr in self.stat_attrs: + if statobj.get_stat(attr) is None: self.set_stat(attr, None) + elif self.get_stat(attr) is not None: + self.set_stat(attr, statobj.get_stat(attr) + + self.get_stat(attr)) + + # Don't compute average starting/stopping time + self.StartTime = None + self.EndTime = None + + for attr in self.stat_attrs: + if self.get_stat(attr) is not None: + self.set_stat(attr, + self.get_stat(attr)/float(len(statobj_list))) + return self + class StatsITR(IterTreeReducer, StatsObj): """Keep track of per directory statistics diff --git a/rdiff-backup/src/ttime.py b/rdiff-backup/src/ttime.py index 166c3f8..bfa3c6f 100644 --- a/rdiff-backup/src/ttime.py +++ b/rdiff-backup/src/ttime.py @@ -82,6 +82,22 @@ class Time: """Return pretty version of time given w3 time string""" return cls.timetopretty(cls.stringtotime(timestring)) + def inttopretty(cls, seconds): + """Convert num of seconds to readable string like "2 hours".""" + partlist = [] + hours, seconds = divmod(seconds, 3600) + if hours > 1: partlist.append("%d hours" % hours) + elif hours == 1: partlist.append("1 hour") + + minutes, seconds = divmod(seconds, 60) + if minutes > 1: partlist.append("%d minutes" % minutes) + elif minutes == 1: partlist.append("1 minute") + + if seconds == 1: partlist.append("1 second") + elif not partlist or seconds > 1: + partlist.append("%s seconds" % seconds) + return " ".join(partlist) + def intstringtoseconds(cls, interval_string): """Convert a string expressing an interval (e.g. "4D2s") to seconds""" def error(): |