This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[RFC] [PATCH] tapset to count number open file handlers and max file handlers for a process
- From: Srinivasa Ds <srinivasa at in dot ibm dot com>
- To: SystemTAP <systemtap at sources dot redhat dot com>
- Date: Thu, 30 Aug 2007 15:38:52 +0530
- Subject: [RFC] [PATCH] tapset to count number open file handlers and max file handlers for a process
Hi
I have developed a small tapset that caluculates number of opened file
handlers for a process as well as maximum file hanlders for a
process.
Since Iam new to this, I might have done some mistakes. Please
let me know comments, So that I can improve on it.
=========================================================
Signed-off-by: Srinivasa DS <srinivasa@in.ibm.com>
--- tapset/task.stp.orig 2007-08-30 15:04:43.000000000 +0530
+++ tapset/task.stp 2007-08-30 15:11:12.000000000 +0530
@@ -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 */
@@ -83,6 +87,23 @@ function task_uid:long (task:long) %{ /*
CATCH_DEREF_FAULT();
%}
+function task_open_file_handler:long (task:long) %{
+ struct task_struct *t = (struct task_struct *)(long)THIS->task;
+ struct fdtable *fdt = t->files->fdt;
+ unsigned int count=0, fd;
+ for (fd = 0; fd < fdt->max_fds; fd++) {
+ if (fdt->fd[fd] != NULL)
+ count ++;
+ }
+ THIS->__retvalue = count;
+ CATCH_DEREF_FAULT();
+%}
+
+function task_max_file_handler:long (task:long) %{
+ struct task_struct *t = (struct task_struct *)(long)THIS->task;
+ THIS->__retvalue = t->files->fdt->max_fds;
+ CATCH_DEREF_FAULT();
+%}
// Return the effective user id of the given task
function task_euid:long (task:long) %{ /* pure */