Skip to content

Instantly share code, notes, and snippets.

@andrewdmcleod
Last active September 20, 2019 11:49
Show Gist options
  • Save andrewdmcleod/3b4e3c8a9fd4c927c3c54ae0361eb09d to your computer and use it in GitHub Desktop.
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
#!/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