Created
August 8, 2018 21:29
-
-
Save jerroydmoore/3c59107f6c21f29be5691018b5b741b2 to your computer and use it in GitHub Desktop.
Add linenumbers to the output of http://www.rosipov.com/blog/profiling-slow-bashrc/
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
import argparse | |
import heapq | |
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') | |
args = parser.parse_args() | |
filename, n = args.filename, int(args.n) | |
with open(filename, 'r') as f: | |
q = [] | |
prev_time = None | |
for lineno, line in enumerate(f, 1): | |
# for line in f.readlines(): | |
line = line.rstrip() | |
# print "line ", line | |
if not line or line[0] != '+': | |
print "IGNORE1 ", line | |
continue | |
plus,time,cmd = line.split(None, 2); | |
# print "time ", time | |
# print "cmd ", cmd | |
seconds, nanoseconds = time.split('.') | |
time = int(nanoseconds) | |
diff = time - prev_time if prev_time is not None else 0 | |
prev_time = time | |
heapq.heappush(q, (diff, cmd, lineno)) | |
for diff, cmd, lineno in heapq.nlargest(n, q): | |
print float(diff) / 1000000000, 's, lineno', lineno, ':', cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment