Last active
December 10, 2015 09:29
-
-
Save scoates/4414560 to your computer and use it in GitHub Desktop.
Times each line of stdin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
from sys import stdin, stdout, argv, exit | |
try: | |
if argv[1] == 'help' or argv[1] == '--help' or argv[1] == '-h': | |
print "%s: times each line of stdin.\n Optional parameter is a float of a threshold. (defaults to 2.0)" % argv[0] | |
exit(255); | |
else: | |
threshold = argv[1] | |
except IndexError: | |
threshold = 2.0 | |
timeline_last = time.time() | |
while 1: | |
try: | |
line = stdin.readline() | |
except KeyboardInterrupt: | |
break | |
if not line: | |
break | |
diff = time.time() - timeline_last | |
if diff > threshold: | |
indicator = '!' | |
else: | |
indicator = ' ' | |
print "[%s%0.2f] %s" % (indicator, diff, line.rstrip()) | |
timeline_last = time.time() | |
stdout.flush() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage example:
puppet agent … | /path/to/timeline | tee /path/to/file.log