source: strace-plot/parse_strace.py@ 1161

Last change on this file since 1161 was 1066, checked in by slederer, on Aug 16, 2012 at 11:27:02 AM

Skript zur Visualisierung von Startvorgängen (z.B. KDE-Anmeldung) mit Hilfe von strace und gnuplot

File size: 1.3 KB
RevLine 
[1066]1#!/usr/bin/python
2
3import sys
4import time
5
6pids={}
7
8def parse_execve(syscall):
9 i=syscall.find('"')
10 if i<0:
11 return None
12 name=syscall[i+1:]
13 i=name.find('"')
14 if i<0:
15 return None
16 name=name[:i]
17 return name
18
19def parse_exit(syscall):
20 i=syscall.find(',')
21 retcode=syscall[len('_exit('):i]
22 return retcode
23
24def parse_waitpid(syscall):
25 i=syscall.rfind('=')
26 if i<0:
27 return None
28 else:
29 pid=syscall[i+1:].strip()
30 pid=pid.split(' ')[0]
31 return pid
32
33def process_syscall(pid,t,syscall):
34 if syscall.startswith('execve') and not "ENOENT" in syscall:
35 name=parse_execve(syscall)
36 i=name.rfind('/')
37 if i>0:
38 name=name[i+1:]
39 pids[pid]=[ name,t ]
40 elif syscall.startswith('_exit'):
41 if pids.has_key(pid):
42 name,start=pids[pid]
43 pids[pid]=[ name,start,t ]
44 elif 'waitpid' in syscall:
45 pid=parse_waitpid(syscall)
46 if pids.has_key(pid):
47 name,start=pids[pid]
48 pids[pid]=[ name,start,t]
49
50if __name__=="__main__":
51 for l in sys.stdin.readlines():
52 parts=l.split(" ")
53 pid=parts[0]
54 t=parts[1]
55 syscall=''.join(parts[2:])
56
57 process_syscall(pid,t,syscall)
58
59
60 for p in sorted(pids):
61 tup=pids[p]
62 if len(tup)==2:
63 name,start=tup
64 print name+"*",start,start
65 else:
66 name,start,end=tup
67 print name,start,end
Note: See TracBrowser for help on using the repository browser.