File: rlimit_nofile.stp

package info (click to toggle)
systemtap 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,436 kB
  • sloc: cpp: 72,388; ansic: 58,430; xml: 47,797; exp: 40,417; sh: 10,793; python: 2,759; perl: 2,252; tcl: 1,305; makefile: 1,119; lisp: 105; java: 102; awk: 101; asm: 91; sed: 16
file content (39 lines) | stat: -rwxr-xr-x 1,151 bytes parent folder | download | duplicates (7)
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
############################################################
# rlimit_nofile.stp
# Author: Robin Hack <rhack@redhat.com>
# This script watches processes being scheduled and which
# try to allocate a file descriptor without luck.
############################################################

global failed_calls

probe kernel.trace("sched_wakeup")
{
    pid = task_pid($p);
    name = task_execname($p);
    open_ds = task_open_file_handles($p);
    max_ds = task_rlimit_nofile($p);
    if (failed_calls[name, pid] == "EMFILE") {
        printf ("%s %s(%d) open: %d - max: %d Hit: %s\n",
                ctime(gettimeofday_s()), name, pid, open_ds, max_ds,
                failed_calls[name, pid]);
    }
}

probe kernel.trace("sched_process_exit")
{
    pid = task_pid($p);
    name = task_execname($p);
    delete failed_calls[name, pid];
}

# This is exactly point where all the fun happens
# This function returns only EMFILE errno.
probe kernel.function("__alloc_fd@fs/file.c").return !,
      kernel.function("alloc_fd").return
{
    if (errno_str($return) == "EMFILE")
    {
        failed_calls[execname(), pid()] = errno_str($return);
    }
}