Debian Codegraph @

testsuite/systemtap.examples/process/plimit.stp

raw
1 # plimit.stp
2 # Copyright (C) 2006 Red Hat, Inc., Eugene Teo <[email protected]>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 2 as
6 # published by the Free Software Foundation.
7 #
8
9 # Example:
10 # $ stap -g plimit.stp `pgrep udevd`
11 # OR
12 # $ stap -g plimit.stp -x `pgrep udevd`
13
14 #
15 # plimit.stp prints a variety of resource limits for a given pid.
16 #
17
18 %{
19 #include <linux/sched.h>
20 #include <linux/list.h>
21 %}
22
23 function getrlimit:string (rlim:long, pid:long) %{ /* pure */
24 struct task_struct *p;
25 struct list_head *_p, *_n;
26 static char cur_buf[24], max_buf[24];
27 long int cur, max;
28
29 list_for_each_safe(_p, _n, &current->tasks) {
30 p = list_entry(_p, struct task_struct, tasks);
31
32 cur = p->signal->rlim[STAP_ARG_rlim].rlim_cur;
33 max = p->signal->rlim[STAP_ARG_rlim].rlim_max;
34
35 if (p->pid == (int)STAP_ARG_pid) {
36 if (cur == -1 && max == -1)
37 strcat(STAP_RETVALUE, "unlimited unlimited");
38 else if (cur == -1)
39 snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%-9s %-9ld",
40 "unlimited", max);
41 else if (max == -1)
42 snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%-9ld %-9s",
43 cur, "unlimited");
44 else
45 snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%-9ld %-9ld",
46 cur, max);
47 }
48 }
49 %}
50
51 function task_execname_by_pid:string (pid:long) %{ /* pure */
52 struct task_struct *p;
53 struct list_head *_p, *_n;
54 list_for_each_safe(_p, _n, &current->tasks) {
55 p = list_entry(_p, struct task_struct, tasks);
56 if (p->pid == (int)STAP_ARG_pid)
57 snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%s", p->comm);
58 }
59 %}
60
61 probe begin {
62 %( $# < 1
63 %? pid = target()
64 %: pid = $1
65 %)
66
67 if (pid == 0) error ("Please provide valid target process-id as $1 or -x PID");
68
69 printf("%d: -%s\n", pid, task_execname_by_pid(pid))
70 /* include/asm-generic/resource.h */
71 printf(" resource current maximum\n")
72 printf("coredump(blocks) %s\n", getrlimit(4, pid))
73 printf("data(bytes) %s\n", getrlimit(2, pid))
74 printf("max nice %s\n", getrlimit(13, pid))
75 printf("file size(blocks) %s\n", getrlimit(1, pid))
76 printf("pending signals %s\n", getrlimit(11, pid))
77 printf("max locked memory(bytes) %s\n", getrlimit(8, pid))
78 printf("max memory size(bytes) %s\n", getrlimit(5, pid))
79 printf("open files %s\n", getrlimit(7, pid))
80 printf("POSIX message queues(bytes) %s\n", getrlimit(12, pid))
81 printf("max rt priority %s\n", getrlimit(14, pid))
82 printf("stack size(bytes) %s\n", getrlimit(3, pid))
83 printf("cpu time(seconds) %s\n", getrlimit(0, pid))
84 printf("max user processes %s\n", getrlimit(6, pid))
85 printf("virtual memory(bytes) %s\n", getrlimit(9, pid))
86 printf("file locks %s\n", getrlimit(10, pid))
87
88 exit()
89 }