#NEWLINE# def main( ) : #NEWLINE# #INDENT# parser = argparse . ArgumentParser ( formatter_class = argparse . RawDescriptionHelpFormatter , description = __doc__ , epilog = _USAGE_EXAMPLES ) #NEWLINE# parser . add_argument ( 'destination' , metavar = 'destination' , type = str , help = 'address of the Phabricator instance, e.g. https://secure.phabricator.com' ) #NEWLINE# parser . add_argument ( '--count' , '-c' , metavar = 'TIMES' , type = int , help = 'number of times to ping, default is unlimited' ) #NEWLINE# parser . add_argument ( '--interval' , '-i' , metavar = 'SECONDS' , type = float , default = 1.0 , help = 'wait interval seconds between sending each request, default is to wait one second. Minimum wait is 0.2 seconds.' ) #NEWLINE# args = parser . parse_args ( ) #NEWLINE# if ( args . interval < 0.2 ) : #NEWLINE# #INDENT# print ( 'interval must be at least 0.2 seconds' ) #NEWLINE# sys . exit ( 2 ) #NEWLINE# #UNINDENT# uri = phlsys_conduit . make_conduit_uri ( args . destination ) #NEWLINE# print ( ( 'conduit.ping ' + str ( uri ) ) ) #NEWLINE# if ( args . count is not None ) : #NEWLINE# #INDENT# sequence = iter ( xrange ( args . count ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sequence = itertools . count ( ) #NEWLINE# #UNINDENT# is_first = True #NEWLINE# Stats = collections . namedtuple ( 'phabping__Stats' , [ 'min' , 'max' , 'sum' , 'count' ] ) #NEWLINE# stats = None #NEWLINE# try : #NEWLINE# #INDENT# for i in sequence : #NEWLINE# #INDENT# if ( not is_first ) : #NEWLINE# #INDENT# time . sleep ( args . interval ) #NEWLINE# #UNINDENT# print ( ( ( 'request ' + str ( ( i + 1 ) ) ) + ' :' ) , end = ' ' ) #NEWLINE# conduit = phlsys_conduit . Conduit ( uri ) #NEWLINE# start = time . time ( ) #NEWLINE# result = conduit . ping ( ) #NEWLINE# end = time . time ( ) #NEWLINE# msecs = ( ( end - start ) * 1000 ) #NEWLINE# print ( result , ':' , str ( int ( msecs ) ) , 'ms' ) #NEWLINE# if ( stats is None ) : #NEWLINE# #INDENT# stats = Stats ( min = msecs , max = msecs , sum = msecs , count = ( i + 1 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# stats = Stats ( min = min ( stats . min , msecs ) , max = max ( stats . max , msecs ) , sum = ( stats . sum + msecs ) , count = ( i + 1 ) ) #NEWLINE# #UNINDENT# is_first = False #NEWLINE# #UNINDENT# #UNINDENT# except KeyboardInterrupt : #NEWLINE# #INDENT# print ( ) #NEWLINE# #UNINDENT# if ( not stats ) : #NEWLINE# #INDENT# print ( 'no requests processed.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( '---' , uri , 'conduit.ping statistics' , '---' ) #NEWLINE# print ( stats . count , 'requests processed' ) #NEWLINE# print ( 'min / mean / max =' , end = ' ' ) #NEWLINE# mean = ( stats . sum / stats . count ) #NEWLINE# vals = [ stats . min , mean , stats . max ] #NEWLINE# vals_str = ' / ' . join ( [ '{0:0.2f}' . format ( i ) for i in vals ] ) #NEWLINE# print ( vals_str , 'ms' )