#!/usr/bin/env python import sys import time import subprocess try: sub_command = sys.argv[1:-1] bytes_per_chunk = int(sys.argv[-1]) except: print '''pull1 usage: pull1 sub_command_and_args... bytes_per_chunk Runs sub_command_and_args in a subprocess, reads bytes_per_chunk from the subprocess, prints length read and 1 second timestamps.''' sys.exit(1) prog = sys.argv[0].split('/')[-1] + ':' proc = subprocess.Popen(sub_command, stdout=subprocess.PIPE, close_fds=True) print prog, 'pid', proc.pid start_time = time.time() sum = 0 secs = 1 while True: chunk = proc.stdout.read(bytes_per_chunk) if not chunk: break print prog, 'chunk size', len(chunk) sum += len(chunk) if time.time() - start_time >= secs: print prog, 'elapsed', secs, ' average bytes-per-sec', sum // secs secs += 1 sys.stdout.flush()