Rev 3: more simplification. in http://bzr.arbash-meinel.com/plugins/hello
John Arbash Meinel
john at arbash-meinel.com
Fri Oct 26 17:38:33 BST 2007
At http://bzr.arbash-meinel.com/plugins/hello
------------------------------------------------------------
revno: 3
revision-id:john at arbash-meinel.com-20071026163831-8xb7o8t4ss9s6jc3
parent: john at arbash-meinel.com-20071026162507-2wayirmfu66cie3k
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: hello
timestamp: Fri 2007-10-26 11:38:31 -0500
message:
more simplification.
Start printing earlier
use self.outf instead of plain print.
write something so we don't just sit there with no output.
modified:
__init__.py __init__.py-20071026162324-fyzesbthcgxhqy4b-1
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2007-10-26 16:25:07 +0000
+++ b/__init__.py 2007-10-26 16:38:31 +0000
@@ -17,6 +17,7 @@
"""Connect to a Bazaar smart server, and just say hello.
"""
+import sys
import time
from bzrlib import (
@@ -32,37 +33,36 @@
"""
takes_args = ['location']
- takes_options = [option.Option('ping',
- help='Test the round trip time to the server.'),
- ]
+ takes_options = []
- def run(self, location=None, ping=False):
+ def run(self, location=None):
from bzrlib.smart import client
start = time.time()
t = transport.get_transport(location)
t_time = time.time()
+ self.outf.write("get_transport: %.3fs\n" % (t_time - start,))
medium = t.get_shared_medium()
medium_time = time.time()
the_client = client._SmartClient(medium)
+ self.outf.write('connecting ... ')
+ self.outf.flush()
client_time = time.time()
hello_response = the_client.call('hello')
hello_time = time.time()
- print 'response: %s' % (hello_response,)
- print "get_transport: %.3fs" % (t_time - start,)
- print "first hello: %.3fs" % (hello_time - client_time,)
+ self.outf.write('response: %s\n' % (hello_response,))
+ hello_delta = hello_time - client_time
+ self.outf.write("first hello: %.3fs\n" % (hello_delta,))
- if ping:
- total_time = 0.0
- n_count = 20
- for i in xrange(n_count):
- base_time = time.time()
- the_client.call('hello')
- cur_time = time.time()
- total_time += cur_time - base_time
- print 'hello: %.3fs\r' % (cur_time - base_time,),
- avg_time = total_time / n_count
- print 'Average ping: %.1fms' % (avg_time * 1000.0)
- hello_delta = hello_time - client_time
- print 'Connect time: %.3fs' % (hello_delta - avg_time,)
+ total_time = 0.0
+ n_count = 20
+ for i in xrange(n_count):
+ base_time = time.time()
+ the_client.call('hello')
+ cur_time = time.time()
+ total_time += cur_time - base_time
+ self.outf.write('hello: %.3fs\r' % (cur_time - base_time,))
+ avg_time = total_time / n_count
+ self.outf.write('Average ping: %.1fms\n' % (avg_time * 1000.0))
+ self.outf.write('Connect time: %.3fs' % (hello_delta - avg_time,))
commands.register_command(cmd_hello)
More information about the bazaar-commits
mailing list