Rev 2: Switch to using a BlackHole file. in http://bzr.arbash-meinel.com/plugins/dummy_request
John Arbash Meinel
john at arbash-meinel.com
Sat Dec 12 20:56:23 GMT 2009
At http://bzr.arbash-meinel.com/plugins/dummy_request
------------------------------------------------------------
revno: 2
revision-id: john at arbash-meinel.com-20091212205615-hjkcmgy621n9fmjx
parent: john at arbash-meinel.com-20091212204332-00g8lyfngbi4cnru
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dummy_request
timestamp: Sat 2009-12-12 14:56:15 -0600
message:
Switch to using a BlackHole file.
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2009-12-12 20:43:32 +0000
+++ b/__init__.py 2009-12-12 20:56:15 +0000
@@ -32,6 +32,7 @@
graph,
remote,
transport,
+ ui,
)
from bzrlib.repofmt import (
groupcompress_repo,
@@ -56,6 +57,28 @@
# time
+class BlackHoleFile(object):
+
+ def __init__(self, pb=None):
+ self.bytes_written = 0
+ self.pb = pb
+
+ def write(self, bytes):
+ self.bytes_written += len(bytes)
+ ui.ui_factory.report_transport_activity(None, len(bytes), None)
+ if self.pb is not None:
+ self.pb.tick()
+
+ def tell(self):
+ return self.bytes_written
+
+ def flush(self):
+ pass # no-op
+
+ def close(self):
+ ui.ui_factory.report_transport_activity(None, 0, None)
+
+
class cmd_test_stream(commands.Command):
"""Make a stream request.
@@ -66,14 +89,17 @@
def run(self, keep=False):
b = branch.Branch.open('.')
req_fn, req_name = tempfile.mkstemp(prefix='bzr-request-')
- resp_fn, resp_name = tempfile.mkstemp(prefix='bzr-response-')
+ # resp_fn, resp_name = tempfile.mkstemp(prefix='bzr-response-')
self.outf.write('Request file: %s\n' % req_name)
- self.outf.write('Response file: %s\n' % resp_name)
+ #self.outf.write('Response file: %s\n' % resp_name)
req_f = os.fdopen(req_fn, 'wb+')
# TODO: Make the resp_f a wrapper that tracks throughput,
# alternatively, we could also wrap it around a simple list
# structure, so that we avoid any sort of disk I/O limitations
- resp_f = os.fdopen(resp_fn, 'wb+')
+ # resp_f = os.fdopen(resp_fn, 'wb+')
+ pb = ui.ui_factory.nested_progress_bar()
+ resp_f = BlackHoleFile(pb)
+
# We don't have the client ever read the response, we just place the
# request into the temp file
t = b.repository.bzrdir.root_transport
@@ -93,9 +119,11 @@
req_f.seek(0)
# This should trigger a single request, and then stop, putting the
# output int othe response file
+ pb.tick()
start_time = time.clock()
server.serve()
delta_time = time.clock() - start_time
+ pb.finished()
bytes_written = resp_f.tell()
mb_written = bytes_written / 1024. / 1024
self.outf.write('Wrote %d bytes (%.1f MiB) in %.3fs, %.3fMiB/s\n'
@@ -105,6 +133,6 @@
resp_f.close()
if not keep:
os.remove(req_name)
- os.remove(resp_name)
+ # os.remove(resp_name)
commands.register_command(cmd_test_stream)
More information about the bazaar-commits
mailing list