%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/usr/share/doc/systemtap-client-2.9/examples/process/
Upload File :
Create Path :
Current File : //proc/self/root/usr/share/doc/systemtap-client-2.9/examples/process/pstree.stp

#!/usr/bin/stap
# Copyright (C) 2014 Red Hat, Inc.
# by Josh Stone <jistone@redhat.com>
#
# pstree.stp generates a process diagram in DOT form.  For instance, it may be
# useful on a 'make' command to see all the processes that are started.
#
# Run the script with:
#   stap pstree.stp -c 'command_to_watch' -o output.dot
#
# Render the diagram with:
#   dot -Tsvg output.dot >output.svg

probe begin
{
  printf("digraph pstree {\n")
  printf("rankdir=\"LR\"\n")
}

function dot_escape(str)
{
  # In DOT double-quoted strings, the only escape is " to \"
  return str_replace(str, "\"", "\\\"")
}

global depth
probe process.begin
{
  if (!(pid() in depth)) {
    depth[pid()] = 1
    if (pid() != target())
      printf("PID%d_%d -> PID%d_1\n", ppid(), depth[ppid()], pid())
    printf("PID%d_1 [ label=\"(%d) %s\" tooltip=\"forked from %d\" ];\n",
           pid(), pid(), dot_escape(execname()), ppid())
  }
}

probe syscall.execve.return
{
  if ($return == 0 && pid() in depth) {
    d = ++depth[pid()]
    printf("PID%d_%d -> PID%d_%d [ style=\"dashed\" ];\n",
           pid(), d-1, pid(), d)
    printf("PID%d_%d [ label=\"(%d) %s\" tooltip=\"%s\" ];\n",
           pid(), d, pid(),
           dot_escape(@entry(user_string($filename))),
           dot_escape(cmdline_str()))
  }
}

probe end
{
  printf("}\n")
}

Zerion Mini Shell 1.0