Created
January 24, 2020 00:35
-
-
Save bryant1410/fa9c595c599afa763f055ee72b2f7944 to your computer and use it in GitHub Desktop.
Profile a slow bash load. See https://www.rosipov.com/blog/profiling-slow-bashrc/
This file contains hidden or 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 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