#!/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..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()