Debian Codegraph @

testsuite/systemtap.examples/profiling/timeout.stp

raw
1 #! /usr/bin/env stap
2 # Copyright (C) 2009-2018 Red Hat, Inc.
3 # Written by Ulrich Drepper <[email protected]>
4 # Modified by William Cohen <[email protected]>
5
6 global process, timeout_count, to
7 global poll_timeout, epoll_timeout, select_timeout, itimer_timeout
8 global nanosleep_timeout, futex_timeout, signal_timeout
9
10 probe syscall.{poll,epoll_wait} {
11 if (timeout) to[pid()]=timeout
12 }
13
14 probe syscall.poll.return {
15 if (retval == 0 && to[pid()] > 0 ) {
16 poll_timeout[pid()]++
17 timeout_count[pid()]++
18 process[pid()] = execname()
19 delete to[pid()]
20 }
21 }
22
23 probe syscall.epoll_wait.return {
24 if (retval == 0 && to[pid()] > 0 ) {
25 epoll_timeout[pid()]++
26 timeout_count[pid()]++
27 process[pid()] = execname()
28 delete to[pid()]
29 }
30 }
31
32 probe syscall.select.return {
33 if (retval == 0) {
34 select_timeout[pid()]++
35 timeout_count[pid()]++
36 process[pid()] = execname()
37 }
38 }
39
40 probe syscall.futex.return {
41 if (errno_str(retval) == "ETIMEDOUT") {
42 futex_timeout[pid()]++
43 timeout_count[pid()]++
44 process[pid()] = execname()
45 }
46 }
47
48 probe syscall.nanosleep.return {
49 if (retval == 0) {
50 nanosleep_timeout[pid()]++
51 timeout_count[pid()]++
52 process[pid()] = execname()
53 }
54 }
55
56 probe kernel.function("it_real_fn") {
57 itimer_timeout[pid()]++
58 timeout_count[pid()]++
59 process[pid()] = execname()
60 }
61
62 probe syscall.rt_sigtimedwait.return {
63 if (errno_str(retval) == "EAGAIN") {
64 signal_timeout[pid()]++
65 timeout_count[pid()]++
66 process[pid()] = execname()
67 }
68 }
69
70 probe syscall.exit {
71 if (pid() in process) {
72 delete process[pid()]
73 delete timeout_count[pid()]
74 delete poll_timeout[pid()]
75 delete epoll_timeout[pid()]
76 delete select_timeout[pid()]
77 delete itimer_timeout[pid()]
78 delete futex_timeout[pid()]
79 delete nanosleep_timeout[pid()]
80 delete signal_timeout[pid()]
81 }
82 }
83
84 probe timer.s(1) {
85 ansi_clear_screen()
86 printf (" pid | poll select epoll itimer futex nanosle signal| process\n")
87 foreach (p in timeout_count- limit 20) {
88 printf ("%5d |%7d %7d %7d %7d %7d %7d %7d| %-.38s\n", p,
89 poll_timeout[p], select_timeout[p],
90 epoll_timeout[p], itimer_timeout[p],
91 futex_timeout[p], nanosleep_timeout[p],
92 signal_timeout[p], process[p])
93 }
94 }
95
96 global prom_arr
97
98 probe prometheus {
99 foreach (p in timeout_count- limit 20) {
100 prom_arr[poll_timeout[p], select_timeout[p],
101 epoll_timeout[p], itimer_timeout[p],
102 futex_timeout[p], nanosleep_timeout[p],
103 signal_timeout[p]] = process[p]
104 }
105
106 @prometheus_dump_array7(prom_arr, "process_timeouts", "poll_timeout", "select_timeout",
107 "epoll_timeout", "itimer_timeout",
108 "futex_timeout", "nanosleep_timeout",
109 "signal_timeout")
110 delete prom_arr
111 }