File: task_ancestry.stp

package info (click to toggle)
systemtap 4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,436 kB
  • sloc: cpp: 72,388; ansic: 58,430; xml: 47,797; exp: 40,417; sh: 10,793; python: 2,759; perl: 2,252; tcl: 1,305; makefile: 1,119; lisp: 105; java: 102; awk: 101; asm: 91; sed: 16
file content (43 lines) | stat: -rw-r--r-- 1,621 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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.
 */
@__private30 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]
}