From 222a9a0336b9e8cf961a672470f3fd9f9a70712c Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 13 Jan 2014 16:03:02 -0500 Subject: [PATCH] tapset/linux: add task_ancestry.stp --- doc/SystemTap_Tapset_Reference/tapsets.tmpl | 1 + tapset/linux/task_ancestry.stp | 43 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tapset/linux/task_ancestry.stp diff --git a/doc/SystemTap_Tapset_Reference/tapsets.tmpl b/doc/SystemTap_Tapset_Reference/tapsets.tmpl index 3a2711fb7..27b16909e 100644 --- a/doc/SystemTap_Tapset_Reference/tapsets.tmpl +++ b/doc/SystemTap_Tapset_Reference/tapsets.tmpl @@ -126,6 +126,7 @@ !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 index 000000000..9d8234154 --- /dev/null +++ b/tapset/linux/task_ancestry.stp @@ -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] +} + -- 2.43.5