Rev 4911: Include the KiB/s for the transfer. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-dbytes

John Arbash Meinel john at arbash-meinel.com
Fri Dec 18 17:58:11 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-dbytes

------------------------------------------------------------
revno: 4911
revision-id: john at arbash-meinel.com-20091218175810-07kjs6e20i30acob
parent: john at arbash-meinel.com-20091218174230-2xrmkkbw4f5idufr
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0rc1-dbytes
timestamp: Fri 2009-12-18 11:58:10 -0600
message:
  Include the KiB/s for the transfer.
-------------- next part --------------
=== modified file 'bzrlib/tests/per_uifactory/__init__.py'
--- a/bzrlib/tests/per_uifactory/__init__.py	2009-12-18 17:42:30 +0000
+++ b/bzrlib/tests/per_uifactory/__init__.py	2009-12-18 17:58:10 +0000
@@ -167,9 +167,9 @@
     def _check_log_transport_activity_display(self):
         self.assertEqual('', self.stdout.getvalue())
         # Displaying the result should write to the progress stream
-        self.assertEqual('Transferred: 0.007MiB'
-                         ' (r:0.002MiB w:0.001MiB u:0.004MiB)\n',
-                         self.stderr.getvalue())
+        self.assertContainsRe(self.stderr.getvalue(),
+            r'Transferred: 0\.007MiB'
+            r' \(\d+\.\dKiB/s r:0\.002MiB w:0\.001MiB u:0\.004MiB\)')
 
 
 class TestSilentUIFactory(tests.TestCase, UIFactoryTestMixin):

=== modified file 'bzrlib/ui/text.py'
--- a/bzrlib/ui/text.py	2009-12-18 17:42:30 +0000
+++ b/bzrlib/ui/text.py	2009-12-18 17:58:10 +0000
@@ -265,6 +265,7 @@
         self._total_byte_count = 0
         self._bytes_since_update = 0
         self._bytes_by_direction = {'unknown': 0, 'read': 0, 'write': 0}
+        self._first_byte_time = None
         self._fraction = 0
         # force the progress bar to be off, as at the moment it doesn't 
         # correspond reliably to overall command progress
@@ -382,6 +383,11 @@
         # here.
         self._total_byte_count += byte_count
         self._bytes_since_update += byte_count
+        if self._first_byte_time is None:
+            # Note that this isn't great, as technically it should be the time
+            # when the bytes started transferring, not when they completed.
+            # However, we usually start with a small request anyway.
+            self._first_byte_time = time.time()
         if direction in self._bytes_by_direction:
             self._bytes_by_direction[direction] += byte_count
         else:
@@ -414,9 +420,18 @@
             self._repaint()
 
     def _format_bytes_by_direction(self):
+        if self._first_byte_time is None:
+            bps = 0.0
+        else:
+            transfer_time = time.time() - self._first_byte_time
+            if transfer_time < 0.001:
+                transfer_time = 0.001
+            bps = self._total_byte_count / transfer_time
+
         msg = ('Transferred: %.3fMiB'
-               ' (r:%.3fMiB w:%.3fMiB'
+               ' (%.1fKiB/s r:%.3fMiB w:%.3fMiB'
                % (self._total_byte_count / 1024. / 1024.,
+                  bps / 1024.,
                   self._bytes_by_direction['read'] / 1024. / 1024.,
                   self._bytes_by_direction['write'] / 1024. / 1024.,
                  ))



More information about the bazaar-commits mailing list