This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] [PATCH] tapset to count number open file handlers and max file handlers for a process


Stone, Joshua I wrote:
> Srinivasa Ds wrote:
> [...]
>> +// Return the number of open file handlers for the given task
> Please split this into two kreads, f->fdt and fdt->max_fds.
> 
> Otherwise, it looks good.
> 

Thanks for reviewing. I have incorporated those changes. Attaching the patch.

Signed-off-by: Srinivasa DS <srinivasa@in.ibm.com>




---
 man/stapprobes.task.5.in        |  207 ++++++++++++++++++++++++++++++++++++++++
 tapset/task.stp                 |   34 ++++++
 testsuite/buildok/task_test.stp |    2 
 3 files changed, 243 insertions(+)

Index: src/tapset/task.stp
===================================================================
--- src.orig/tapset/task.stp
+++ src/tapset/task.stp
@@ -6,6 +6,10 @@
 // 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 */
@@ -125,3 +129,33 @@ function task_cpu:long (task:long)
     CATCH_DEREF_FAULT();
 %}
 %)
+
+
+// Return the number of open file handlers for the given task
+function task_open_file_handles:long (task:long) %{
+    struct task_struct *t = (struct task_struct *)(long)THIS->task;
+    struct files_struct *f = kread(&(t->files));
+    struct fdtable *fdt = kread(&(f->fdt));
+    unsigned int count=0, fd, max;
+    rcu_read_lock();
+    max = kread(&(fdt->max_fds));
+    for (fd = 0; fd < max; fd++) {
+                if ( kread(&(fdt->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) %{
+    struct task_struct *t = (struct task_struct *)(long)THIS->task;
+    struct files_struct *f = kread (&(t->files));
+    struct fdtable *fdt = kread(&(f->fdt));
+    rcu_read_lock();
+    THIS->__retvalue = kread(&(fdt->max_fds));
+    rcu_read_unlock();
+    CATCH_DEREF_FAULT();
+%}
Index: src/testsuite/buildok/task_test.stp
===================================================================
--- src.orig/testsuite/buildok/task_test.stp
+++ src/testsuite/buildok/task_test.stp
@@ -14,5 +14,7 @@ probe begin {
   log(sprint(task_prio(c)))
   log(sprint(task_nice(c)))
   log(sprint(task_cpu(c)))
+  log(sprint(task_open_file_handles(c)))
+  log(sprint(task_max_file_handles(c)))
   exit()
 }
Index: src/man/stapprobes.task.5.in
===================================================================
--- /dev/null
+++ src/man/stapprobes.task.5.in
@@ -0,0 +1,207 @@
+.\" -*- nroff -*-
+.TH STAPPROBES.TASK 5 @DATE@ "IBM"
+.SH NAME
+stapprobes.task \- systemtap task information
+
+.\" macros
+.de SAMPLE
+.br
+.RS
+.nf
+.nh
+..
+.de ESAMPLE
+.hy
+.fi
+.RE
+..
+
+.SH DESCRIPTION
+
+This family of tapset functions is used to collect information about tasks.
+It contains the following functions.
+
+.P
+.TP
+.B task_current:long()
+
+Return the task_struct of the current process.
+
+.P
+.TP
+.B task_parent:long(task:long)
+
+Return the parent task_struct of the given task.
+
+.B Arguments:
+
+.I task
+   task_struct of the task.
+
+.P
+.TP
+.B task_state:long(task:long)
+
+Return the state of the given task. State of the task could be, one among the following.
+
+   TASK_RUNNING           0
+   TASK_INTERRUPTIBLE     1
+   TASK_UNINTERRUPTIBLE   2
+   TASK_STOPPED           4
+   TASK_TRACED            8
+   EXIT_ZOMBIE           16
+   EXIT_DEAD             32
+
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+.B task_execname:string(task:long)
+
+Return the name of the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+
+.P
+.TP
+.B task_pid:long(task:long)
+
+Return the process id of the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+.B task_tid:long(task:long)
+
+Return the thread id of the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+
+.B task_gid:long(task:long)
+
+Return the group id of the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+
+.B task_egid:long(task:long)
+
+Return the effective group id of the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+
+.B task_uid:long(task:long)
+
+Return the user id of the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+
+.B task_euid:long(task:long)
+
+Return the effective user id of the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+
+.B task_prio:long(task:long)
+
+Return the priority of the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+
+.B task_nice:long(task:long)
+
+Return the nice value of the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+
+.B task_cpu:long(task:long)
+
+Return the scheduled cpu for the  given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+
+.B task_open_file_handles:long(task:long)
+
+Return the number of open file handles for the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+.P
+.TP
+
+.B task_max_file_handles:long(task:long)
+
+Return the maximum number of file handles for the given task.
+
+.B Arguments:
+
+.I task
+  task_struct of the task.
+
+
+.SH SEE ALSO
+.IR stap (1),
+.IR stapprobes (5),
+


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]