#!/usr/bin/env python import sys import time try: bytes_per_chunk, = (int(arg) for arg in sys.argv[1:]) except: print >> sys.stderr, '''pull0 usage: pull0 bytes_per_chunk Repeatedly read stdin for bytes_per_chunk bytes, printing how many were read as well as 1 second timestamps.''' sys.exit(1) prog = sys.argv[0].split('/')[-1] + ':' start_time = time.time() sum = 0 secs = 1 while True: chunk = sys.stdin.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()