Last active
September 20, 2019 11:49
-
-
Save andrewdmcleod/3b4e3c8a9fd4c927c3c54ae0361eb09d to your computer and use it in GitHub Desktop.
print n hashmarks per x seconds of time elapsed via ts w epoch time
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 python3 | |
# Takes output from "ts %s" and prints hashmark / seconds_per_hash | |
# e.g. bash_command | ts %s > outfile ; ./hashmarks.py outfile | |
import sys | |
rtime = 0 | |
line_time = 0 | |
hashstring = "" | |
seconds_per_hash = 7 | |
gapstring = "" | |
with open(str(sys.argv[1])) as file: | |
for line in file: | |
last_line_time=line_time | |
line_time=line.split(' ')[0] | |
if last_line_time == 0: | |
elapsed_time=0 | |
else: | |
elapsed_time=int(line_time) - int(last_line_time) | |
last_rtime = rtime | |
rtime = int(elapsed_time / seconds_per_hash) | |
if last_rtime != rtime: | |
for i in range(len(hashstring)): | |
gapstring = gapstring + " " | |
for i in range(rtime): | |
hashstring = hashstring + "#" | |
if '#' in hashstring: | |
print(gapstring, hashstring, end=' ') | |
line = ' '.join(line.split(' ')[1:]) | |
print(elapsed_time, line[0:200].replace("\n", "")) | |
hashstring.replace("#", "_") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment