-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse_zsh_startup.py
executable file
·47 lines (37 loc) · 1.34 KB
/
parse_zsh_startup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
# Ref: https://kevin.burke.dev/kevin/profiling-zsh-startup-time/
# Ref: https://bitbucket.org/kevinburke/small-dotfiles/src/c09252b66f4320d85576517abb53d14a2c731766/scripts/parse_zsh_startup.py?at=master
import sys
SLOW_THRESHOLD = 7
def parse_line(raw_line):
nonewline = raw_line.strip("\n")
timestr, rest = nonewline.split(" ", 1)
return int(timestr), rest
def main(filename):
with open(filename) as f:
count = 0
start_time, rest = parse_line(f.readline())
print("0 {line}".format(line=rest))
prev_line = rest
prev_line_start = start_time
for line in f.readlines():
count += 1
if len(line) == 0 or line == "\n":
continue
if not line[0].isdigit():
continue
try:
t, rest = parse_line(line)
diff = t - prev_line_start
if diff > SLOW_THRESHOLD:
print(
"{since_start} {diff} {prev_line}".format(
since_start=t - start_time, diff=diff, prev_line=prev_line
)
)
prev_line_start = t
prev_line = rest
except ValueError:
continue
if __name__ == "__main__":
main(sys.argv[1])