Rev 20: Add 'verbose' to ts-display to list all issued calls. in file:///v/home/vila/.bazaar/plugins/transportstats/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Oct 9 08:11:10 BST 2007


At file:///v/home/vila/.bazaar/plugins/transportstats/

------------------------------------------------------------
revno: 20
revision-id: v.ladeuil+lp at free.fr-20071009071109-mlxeus44re2b2bo0
parent: v.ladeuil+lp at free.fr-20071008155333-4nxooaszwpob174u
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: transportstats
timestamp: Tue 2007-10-09 09:11:09 +0200
message:
  Add 'verbose' to ts-display to list all issued calls.
  
  * stats.py:
  (StatsPart.__init__): Add the name of the stat itself as an
  attribute.
  (Stats.collect): Deleted, not our job, we already provide the
  iterator.
  
  * decorator.py:
  (StatsCollector.__collect): Use _decorated.base not .base.
  
  * commands.py:
  (cmd_ts_display.run): Iterate stats ourselves. Add verbose option
  to list all issued calls.
modified:
  commands.py                    commands.py-20070927123419-zy82qayy9xzwxvzi-1
  decorator.py                   decorator.py-20070926152401-52kuiex1mu755ajk-1
  stats.py                       stats.py-20070928061304-7i3r2h4gg6rbi03e-1
-------------- next part --------------
=== modified file 'commands.py'
--- a/commands.py	2007-10-08 15:53:33 +0000
+++ b/commands.py	2007-10-09 07:11:09 +0000
@@ -50,14 +50,34 @@
 class cmd_ts_display(bzrlib.commands.Command):
     """Display the statistics collected via the 'stats+' decorator."""
 
+    takes_options = ['verbose']
     _see_also = ['ts-reset']
 
     @bzrlib.commands.display_command
-    def run(self):
+    def run(self, verbose=False):
         from bzrlib.plugins.transportstats import stats
         mystats = stats.get_stats()
         mystats.start_exploiting()
-        (requests, bytes_read, bytes_written, avg_latency) = mystats.collect()
+
+        requests = 0
+        bytes_read = 0
+        bytes_written = 0
+        latency_count = 0
+        total_latency = 0
+        for stat in mystats:
+            if verbose:
+                print '%s: %s%s' % (stat.name, stat.base, stat.relpath)
+            bytes_read += getattr(stat, 'bytes_read', 0)
+            bytes_written += getattr(stat, 'bytes_written', 0)
+            latency = getattr(stat, 'latency', None)
+            if latency is not None:
+                total_latency += latency
+                latency_count += 1
+            requests += getattr(stat, 'requests', 0)
+        avg_latency = 0
+        if latency_count:
+            avg_latency = total_latency / latency_count
+
         print '# requests: %d' % requests
         print 'Bytes read: %d' % bytes_read
         print 'Bytes written: %d' % bytes_written

=== modified file 'decorator.py'
--- a/decorator.py	2007-10-08 14:19:14 +0000
+++ b/decorator.py	2007-10-09 07:11:09 +0000
@@ -54,7 +54,7 @@
         self.__start_time = 0
 
     def __collect(self, name, *args):
-        self._stats.write_stat(name, self.base, *args)
+        self._stats.write_stat(name, self._decorated.base, *args)
 
     def __start(self):
         self.__start_time = time.time()

=== modified file 'stats.py'
--- a/stats.py	2007-10-08 14:19:14 +0000
+++ b/stats.py	2007-10-09 07:11:09 +0000
@@ -41,7 +41,8 @@
 
 class StatsPart(object):
 
-    def __init__(self, format, *args):
+    def __init__(self, name, format, *args):
+        self.name = name
         for fmt_spec, value in map(None, format.parts, args):
             object.__setattr__(self, fmt_spec.name, value)
 
@@ -231,26 +232,7 @@
                 trace.warning('Unknown method in stats file: %s' % name)
             else:
                 body = self._sfile.read_stat_body(body_file, stat_format)
-                yield stat_class(stat_format, *body)
-
-    def collect(self):
-        requests = 0
-        bytes_read = 0
-        bytes_written = 0
-        latency_count = 0
-        total_latency = 0
-        for stat in self:
-            bytes_read += getattr(stat, 'bytes_read', 0)
-            bytes_written += getattr(stat, 'bytes_written', 0)
-            latency = getattr(stat, 'latency', None)
-            if latency is not None:
-                total_latency += latency
-                latency_count += 1
-            requests += getattr(stat, 'requests', 0)
-        avg_latency = 0
-        if latency_count:
-            avg_latency = total_latency / latency_count
-        return requests, bytes_read, bytes_written, avg_latency
+                yield stat_class(name, stat_format, *body)
 
 
 _stats = None



More information about the bazaar-commits mailing list