summaryrefslogtreecommitdiffstats
path: root/tapset/task.stp
blob: a15888f871eaa4d4a944ea8b4f0c324903bfc810 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// task information tapset
// Copyright (C) 2006 Intel Corporation.
//
// This file is part of systemtap, and is free software.  You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.

%{
#include <linux/version.h>
#include <linux/file.h>
%}

// Return the task_struct representing the current process
function task_current:long () %{ /* pure */
    THIS->__retvalue = (long)current;
%}


// Return the parent task_struct of the given task
function task_parent:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue = (long)kread(&(t->parent));
    CATCH_DEREF_FAULT();
%}


// Return the state of the given task, one of:
//   TASK_RUNNING           0
//   TASK_INTERRUPTIBLE     1
//   TASK_UNINTERRUPTIBLE   2
//   TASK_STOPPED           4
//   TASK_TRACED            8
//   EXIT_ZOMBIE           16
//   EXIT_DEAD             32
function task_state:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue = kread(&(t->state));
    CATCH_DEREF_FAULT();
%}


// Return the name of the given task
function task_execname:string (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    deref_string(THIS->__retvalue, t->comm, MAXSTRINGLEN);
    CATCH_DEREF_FAULT();
%}


// Return the process id of the given task
function task_pid:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue = kread(&(t->tgid));
    CATCH_DEREF_FAULT();
%}


// Return the thread id of the given task
function task_tid:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue = kread(&(t->pid));
    CATCH_DEREF_FAULT();
%}


// Return the group id of the given task
function task_gid:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue = kread(&(t->gid));
    CATCH_DEREF_FAULT();
%}


// Return the effective group id of the given task
function task_egid:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue = kread(&(t->egid));
    CATCH_DEREF_FAULT();
%}


// Return the user id of the given task
function task_uid:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue = kread(&(t->uid));
    CATCH_DEREF_FAULT();
%}


// Return the effective user id of the given task
function task_euid:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue = kread(&(t->euid));
    CATCH_DEREF_FAULT();
%}


// Return the priority value of the given task
function task_prio:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue =  kread(&(t->prio)) - MAX_RT_PRIO;
    CATCH_DEREF_FAULT();
%}


// Return the nice value of the given task
function task_nice:long (task:long) %{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    THIS->__retvalue = kread(&(t->static_prio)) - MAX_RT_PRIO - 20;
    CATCH_DEREF_FAULT();
%}


// Return the scheduled cpu for the given task
function task_cpu:long (task:long)
%( kernel_v >= "2.6.22" %? 
%{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    struct thread_info *ti = kread(&(t->stack));
    THIS->__retvalue = kread(&(ti->cpu));
    CATCH_DEREF_FAULT();
%}
%:
%{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    struct thread_info *ti = kread(&(t->thread_info));
    THIS->__retvalue = kread(&(ti->cpu));
    CATCH_DEREF_FAULT();
%}
%)


// Return the number of open file handlers for the given task
function task_open_file_handles:long (task:long)
%( kernel_v >= "2.6.15" %?
%{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    struct files_struct *fs = kread(&(t->files));
    struct fdtable *f = kread(&(fs->fdt));
    unsigned int count=0, fd, max;
    rcu_read_lock();
    max = kread(&(f->max_fds));
    for (fd = 0; fd < max; fd++) {
                if ( kread(&(f->fd[fd])) != NULL)
                        count ++;
        }
    rcu_read_unlock();
    THIS->__retvalue = count;
    CATCH_DEREF_FAULT();
%}
%:
%{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    struct files_struct *f = kread(&(t->files));
    unsigned int count=0, fd, max;
    rcu_read_lock();
    max = kread(&(f->max_fds));
    for (fd = 0; fd < max; fd++) {
                if ( kread(&(f->fd[fd])) != NULL)
                        count ++;
        }
    rcu_read_unlock();
    THIS->__retvalue = count;
    CATCH_DEREF_FAULT();
%}
%)


// Return the maximum number of file handlers for the given task
function task_max_file_handles:long (task:long)
%( kernel_v >= "2.6.15" %?
%{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    struct files_struct *fs = kread (&(t->files));
    struct fdtable *f = kread(&(fs->fdt));
    rcu_read_lock();
    THIS->__retvalue = kread(&(f->max_fds));
    rcu_read_unlock();
    CATCH_DEREF_FAULT();
%}
%:
%{ /* pure */
    struct task_struct *t = (struct task_struct *)(long)THIS->task;
    struct files_struct *f = kread(&(t->files));
    rcu_read_lock();
    THIS->__retvalue = kread(&(f->max_fds));
    rcu_read_unlock();
    CATCH_DEREF_FAULT();
%}
%)