Debian Codegraph @

testsuite/systemtap.examples/process/strace.stp

raw
1 #! /bin/sh
2
3 # suppress some run-time errors here for cleaner output
4 //bin/true && exec stap --suppress-handler-errors --skip-badvars $0 ${1+"$@"}
5
6
7 /* configuration options; set these with stap -G */
8 global follow_fork = 0 /* -Gfollow_fork=1 means trace descendant processes too */
9 global timestamp = 1 /* -Gtimestamp=0 means don't print a syscall timestamp */
10 global elapsed_time = 0 /* -Gelapsed_time=1 means print a syscall duration too */
11
12 global thread_argstr%
13 global thread_time%
14
15 global syscalls_nonreturn[2]
16 probe begin
17 {
18 /* list those syscalls that never .return */
19 syscalls_nonreturn["exit"]=1
20 syscalls_nonreturn["exit_group"]=1
21 }
22
23
24
25 function filter_p()
26 {
27 if (target() == 0) return 0; /* system-wide */
28 if (!follow_fork && pid() != target()) return 1; /* single-process */
29 if (follow_fork && !target_set_pid(pid())) return 1; /* multi-process */
30 return 0;
31 }
32
33 probe nd_syscall.*
34 {
35 if (filter_p()) next;
36
37 thread_argstr[tid()]=argstr
38 if (timestamp || elapsed_time)
39 thread_time[tid()]=gettimeofday_us()
40
41 if (name in syscalls_nonreturn)
42 report(name,argstr,"")
43 }
44
45 probe nd_syscall.*.return
46 {
47 if (filter_p()) next;
48
49 report(name,thread_argstr[tid()],retstr)
50 }
51
52
53
54 function report(syscall_name, syscall_argstr, syscall_retstr)
55 {
56 if (timestamp || elapsed_time)
57 {
58 now = gettimeofday_us()
59 then = thread_time[tid()]
60
61 if (timestamp)
62 prefix=sprintf("%s.%06d ", ctime(then/1000000), then%1000000)
63
64 if (elapsed_time && (now>then)) {
65 diff = now-then
66 suffix=sprintf(" <%d.%06d>", diff/1000000, diff%1000000)
67 }
68
69 delete thread_time[tid()]
70 }
71
72 /* add a thread-id string in lots of cases, except if
73 stap strace.stp -c SINGLE_THREADED_CMD */
74 if (tid() != target()) {
75 prefix .= sprintf("%s[%d] ", execname(), tid())
76 }
77
78 printf("%s%s(%s) = %s%s\n",
79 prefix,
80 syscall_name, syscall_argstr, syscall_retstr,
81 suffix)
82
83 delete thread_argstr[tid()]
84 }