Proposed task.stp additions

Mike Mason mmlnx@us.ibm.com
Wed Jul 18 18:16:00 GMT 2007


A while back we discussed submitting changes to the list for review and ACKS.  I realize this patch is relatively minor, but thought I'd get the ball rolling.

I'd like to add these functions to task.stp.  I've found them useful in scripts I've written.

Mike Mason

--- task.stp	2007-07-18 09:57:31.000000000 -0700
+++ task.stp.new	2007-07-18 09:18:52.000000000 -0700
@@ -1,5 +1,6 @@
 // task information tapset
 // Copyright (C) 2006 Intel Corporation.
+// Copyright (C) 2007 IBM Corp.
 //
 // 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
@@ -115,3 +116,56 @@
     THIS->__retvalue = kread(&(ti->cpu));
     CATCH_DEREF_FAULT();
 %}
+
+
+// Returns total cpu time in milliseconds for the given task
+function task_cputime:long(task:long) %{ /* pure */
+    struct task_struct *t = (struct task_struct *)(long)THIS->task;
+    cputime_t stime = kread(&(t->stime));
+    cputime_t utime = kread(&(t->utime));
+    THIS->__retvalue = (long) cputime_to_msecs(stime + utime);
+    CATCH_DEREF_FAULT();
+%}
+
+
+// Return the current working directory of the given task
+function cwd:string(task:long) %{ /* pure */
+    struct task_struct *task;
+    struct fs_struct *fs;
+    struct dentry *pwd;
+    struct vfs_mount *pwdmnt;
+    char *start, buf[MAXSTRINGLEN];
+
+    task = (struct task_struct *)(long)THIS->task;
+    fs = kread(&(task->fs));
+    pwd = kread(&(fs->pwd));
+    pwdmnt = kread(&(fs->pwdmnt));
+    start = d_path(pwd, pwdmnt, buf, MAXSTRINGLEN);
+    deref_string(THIS->__retvalue, start, MAXSTRINGLEN);
+
+    CATCH_DEREF_FAULT()
+%}
+
+
+// Given a pid, return the associated task_struct
+// Returns 0 if not found
+function pid2task:long (pid:long) %{ /* pure */
+    struct task_struct *task = NULL;
+    rcu_read_lock();
+    task = find_task_by_pid (THIS->pid);
+    rcu_read_unlock();
+    THIS->__retvalue = (long) task;
+%}
+
+
+// Determines whether this is a process descriptor for a
+// kernel thread (has no user address space).
+function is_kthread:long (task:long) %{ /* pure */
+    struct task_struct *t = (struct task_struct *)(long)THIS->task;
+    struct mm_struct *mm = kread(&(t->mm));
+    if (mm == NULL)
+        THIS->__retvalue = 1;
+    else
+        THIS->__retvalue = 0;
+    CATCH_DEREF_FAULT();
+%}




More information about the Systemtap mailing list