Skip to content

Instantly share code, notes, and snippets.

@bryant1410
Created January 24, 2020 00:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bryant1410/fa9c595c599afa763f055ee72b2f7944 to your computer and use it in GitHub Desktop.
Save bryant1410/fa9c595c599afa763f055ee72b2f7944 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import argparse
import heapq
def parse_args():
parser = argparse.ArgumentParser(description="Analyze bashstart log for speed.")
parser.add_argument('filename', help="often /tmp/bashstart.<PID>.log")
parser.add_argument('-n', default=20, help="number of results to show")
return parser.parse_args()
def main():
args = parse_args()
filename, n = args.filename, int(args.n)
with open(filename) as f:
q = []
prev_time = None
for line in f.readlines():
line = line.split()
if not line or '+' not in line[0] or len(line) < 3:
continue
text = ' '.join(line[2:])
seconds, nanoseconds = line[1].split('.')
time = int(nanoseconds)
diff = time - prev_time if prev_time is not None else 0
prev_time = time
heapq.heappush(q, (diff, text))
for diff, text in heapq.nlargest(n, q):
print(diff / 1000000000, 's:', text)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment