-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrace_summary.py
More file actions
executable file
·84 lines (67 loc) · 2.15 KB
/
strace_summary.py
File metadata and controls
executable file
·84 lines (67 loc) · 2.15 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import re
import sys
PID_SYSCALL_MAP = {}
# "syscall":
# "count":
# "time":
SYSCALL_STATS = {}
def parse_syscall_name(line):
match = re.search('(.*)\\(', line)
if match:
return f"{match.group(1)}"
else:
return None
def parse_time_spent(line):
time_column = line.split()[-1]
time_string = time_column[1:-1]
return time_string
def account_syscall(syscall, time):
if syscall == "exit_group" or syscall == "exit":
return
try:
if syscall in SYSCALL_STATS:
SYSCALL_STATS[syscall]["count"] += 1
SYSCALL_STATS[syscall]["time"] += float(time)
elif syscall:
SYSCALL_STATS[syscall] = {}
SYSCALL_STATS[syscall]["count"] = 1
SYSCALL_STATS[syscall]["time"] = float(time)
except KeyError:
print(f"ERROR: {syscall} {time} in? {syscall in SYSCALL_STATS}")
def process_line(line):
columns = line.split(" ")
if "?" in columns[-1]:
return
pid = columns[0]
syscall = parse_syscall_name(columns[2])
try:
if "unfinished" in line:
PID_SYSCALL_MAP[pid] = syscall
elif "resumed" in line and pid in PID_SYSCALL_MAP:
account_syscall(PID_SYSCALL_MAP[pid], parse_time_spent(line))
elif syscall:
account_syscall(syscall, parse_time_spent(line))
except ValueError:
print(f"ERROR: {line}")
return
def main():
file = open(sys.argv[1], "r")
line = file.readline()
while line != '':
process_line(line)
line = file.readline()
sorted_syscalls = sorted(SYSCALL_STATS.items(),
key=lambda x: x[1]["time"],
reverse=True)
print(f"{'Syscall':>20s} {'Count':>8s} {'Time':>15s} {'Time per call':>15s}")
for syscall in sorted_syscalls:
try:
count = syscall[1]["count"]
time = syscall[1]["time"]
print(f"{syscall[0]:>20} {count:>8} {time:>15.6f} {time/count:>15.6f}")
except KeyError:
print(syscall)
except TypeError:
print(syscall)
if __name__ == "__main__":
main()