]> sourceware.org Git - systemtap.git/commitdiff
tapset/linux: add task_ancestry.stp
authorJonathan Lebon <jlebon@redhat.com>
Mon, 13 Jan 2014 21:03:02 +0000 (16:03 -0500)
committerJonathan Lebon <jlebon@redhat.com>
Tue, 14 Jan 2014 20:20:23 +0000 (15:20 -0500)
doc/SystemTap_Tapset_Reference/tapsets.tmpl
tapset/linux/task_ancestry.stp [new file with mode: 0644]

index 3a2711fb71fa2b2779481f7a231b9912db62ba34..27b16909e29e864a1b956d0830c0f6e8f0574124 100644 (file)
 !Itapset/linux/context-caller.stp
 !Itapset/linux/ucontext-unwind.stp
 !Itapset/linux/task.stp
+!Itapset/linux/task_ancestry.stp
 !Itapset/pn.stp
 !Itapset/linux/pstrace.stp
 !Itapset/registers.stp
diff --git a/tapset/linux/task_ancestry.stp b/tapset/linux/task_ancestry.stp
new file mode 100644 (file)
index 0000000..9d82341
--- /dev/null
@@ -0,0 +1,43 @@
+// task information tapset
+// Copyright (C) 2014 Red Hat Inc.
+//
+// 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.
+
+/* We remember the ancestry of a task in __task_ancestry_memo using the task
+ * address as key. Since different task_structs can re-use the same addresses,
+ * we also remember the start_time in __task_ancestry_times to check for expired
+ * memo entries.
+ */
+global __task_ancestry_memo, __task_ancestry_times
+
+/**
+ * sfunction task_ancestry - The ancestry of the given task
+ *
+ * @task: task_struct pointer
+ * @with_time: set to 1 to also print the start time of processes (given as a
+ * delta from boot time)
+ *
+ * Description: Return the ancestry of the given task in the form of
+ * "grandparent_process=>parent_process=>process".
+ */
+function task_ancestry:string (task:long, with_time:long) {
+   stime = task_start_time(task_pid(task))
+   if (__task_ancestry_memo[task] == ""
+    || __task_ancestry_times[task] != stime) {
+      ptask = task_parent(task)
+      name = task_execname(task)
+      __task_ancestry_times[task] = stime
+      if (with_time)
+         stamp = sprintf("(%s)", nsecs_to_string(stime))
+      if (ptask == task) /* tree root */
+         __task_ancestry_memo[task] = sprintf("%s%s", name, stamp)
+      else
+         __task_ancestry_memo[task] = task_ancestry(ptask, with_time) . "=>"
+                                    . sprintf("%s%s", name, stamp)
+   }
+   return __task_ancestry_memo[task]
+}
+
This page took 0.032118 seconds and 5 git commands to generate.