This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: [RFC] [PATCH] tapset to count number open file handlers and max file handlers for a process
Frank Ch. Eigler wrote:
>
> Thanks, but not quite: *every link* needs to be protected. For
> example, this expression has three, so you'll need temporary variables
> or more nesting/casting:
>
>> THIS->__retvalue = kread(&(t->files->fdt->max_fds));
Done
>>> Finally, for a real check-in, one would need documentation in stapfuncs
>>> and at least a buildok item in the test suite.
>> I am ready to work on this.
>
> Great.
Iam attching tapset function and testcase(I have just extended the
buildok/task_test.stp). I didn't find documentation for tapsets(present
in tapset/task.stp) in src/man dir, Shall I write a new man page for
all the functions in task.stp?
Signed-off-by: Srinivasa DS <srinivasa@in.ibm.com>
---
tapset/task.stp | 31 +++++++++++++++++++++++++++++++
testsuite/buildok/task_test.stp | 2 ++
2 files changed, 33 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,30 @@ function task_cpu:long (task:long)
CATCH_DEREF_FAULT();
%}
%)
+
+
+// Return the number of open file handlers for the given task
+function task_open_file_handler:long (task:long) %{
+ struct task_struct *t = (struct task_struct *)(long)THIS->task;
+ struct fdtable *fdt = kread(&(t->files->fdt));
+ unsigned int count=0, fd;
+ rcu_read_lock();
+ for (fd = 0; fd < kread(&(fdt->max_fds)); 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_handler:long (task:long) %{
+ struct task_struct *t = (struct task_struct *)(long)THIS->task;
+ struct files_struct *f = kread (&(t->files));
+ rcu_read_lock();
+ THIS->__retvalue = kread(&(f->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_handler(c)))
+ log(sprint(task_max_file_handler(c)))
exit()
}