Debian Codegraph @

testsuite/systemtap.examples/process/rlimit_nofile.stp

raw
1 ############################################################
2 # rlimit_nofile.stp
3 # Author: Robin Hack <[email protected]>
4 # This script watches processes being scheduled and which
5 # try to allocate a file descriptor without luck.
6 ############################################################
7
8 global failed_calls
9
10 probe kernel.trace("sched_wakeup")
11 {
12 pid = task_pid($p);
13 name = task_execname($p);
14 open_ds = task_open_file_handles($p);
15 max_ds = task_rlimit_nofile($p);
16 if (failed_calls[name, pid] == "EMFILE") {
17 printf ("%s %s(%d) open: %d - max: %d Hit: %s\n",
18 ctime(gettimeofday_s()), name, pid, open_ds, max_ds,
19 failed_calls[name, pid]);
20 }
21 }
22
23 probe kernel.trace("sched_process_exit")
24 {
25 pid = task_pid($p);
26 name = task_execname($p);
27 delete failed_calls[name, pid];
28 }
29
30 # This is exactly point where all the fun happens
31 # This function returns only EMFILE errno.
32 probe kernel.function("__alloc_fd@fs/file.c").return !,
33 kernel.function("alloc_fd").return
34 {
35 if (errno_str($return) == "EMFILE")
36 {
37 failed_calls[execname(), pid()] = errno_str($return);
38 }
39 }