| 1 |
// task information tapset |
| 2 |
// Copyright (C) 2014 Red Hat Inc. |
| 3 |
// |
| 4 |
// This file is part of systemtap, and is free software. You can |
| 5 |
// redistribute it and/or modify it under the terms of the GNU General |
| 6 |
// Public License (GPL); either version 2, or (at your option) any |
| 7 |
// later version. |
| 8 |
|
| 9 |
/* We remember the ancestry of a task in __task_ancestry_memo using the task |
| 10 |
* address as key. Since different task_structs can re-use the same addresses, |
| 11 |
* we also remember the start_time in __task_ancestry_times to check for expired |
| 12 |
* memo entries. |
| 13 |
*/ |
| 14 |
@__private30 global __task_ancestry_memo, __task_ancestry_times |
| 15 |
|
| 16 |
/** |
| 17 |
* sfunction task_ancestry - The ancestry of the given task |
| 18 |
* |
| 19 |
* @task: task_struct pointer |
| 20 |
* @with_time: set to 1 to also print the start time of processes (given as a |
| 21 |
* delta from boot time) |
| 22 |
* |
| 23 |
* Description: Return the ancestry of the given task in the form of |
| 24 |
* "grandparent_process=>parent_process=>process". |
| 25 |
*/ |
| 26 |
function task_ancestry:string (task:long, with_time:long) { |
| 27 |
stime = task_start_time(task_pid(task)) |
| 28 |
if (__task_ancestry_memo[task] == "" |
| 29 |
|| __task_ancestry_times[task] != stime) { |
| 30 |
ptask = task_parent(task) |
| 31 |
name = task_execname(task) |
| 32 |
__task_ancestry_times[task] = stime |
| 33 |
if (with_time) |
| 34 |
stamp = sprintf("(%s)", nsecs_to_string(stime)) |
| 35 |
if (ptask == task) /* tree root */ |
| 36 |
__task_ancestry_memo[task] = sprintf("%s%s", name, stamp) |
| 37 |
else |
| 38 |
__task_ancestry_memo[task] = task_ancestry(ptask, with_time) . "=>" |
| 39 |
. sprintf("%s%s", name, stamp) |
| 40 |
} |
| 41 |
return __task_ancestry_memo[task] |
| 42 |
} |
| 43 |
|