Debian Codegraph @

testsuite/systemtap.examples/process/spawn_seeker.stp

raw
1 #! /usr/bin/env stap
2 # Copyright (C) 2014 Red Hat, Inc.
3 # Written by William Cohen <[email protected]>
4 #
5 # spawn_seeker provides a breakdown of which processes and children
6 # are spawning new processes. To provide better information about
7 # short-lived process, when a child exits the child's spawns are
8 # added to its parent.
9 #
10 # control-c to exit data collection
11
12 global pid_name, fork_by_pid, fork_by_name, fork_count
13
14 probe kprocess.create {
15 pid_name[pid()] = execname()
16 fork_by_pid[pid()]++
17 fork_by_name[execname()]++
18 fork_count++
19 }
20
21 probe kprocess.exit {
22 # take the fork count info for this pid and add it to the parent pid
23 if (fork_by_pid[pid()]) {
24 fork_by_pid[ppid()] += fork_by_pid[pid()]
25 pid_name[ppid()] = pexecname()
26 delete fork_by_pid[pid()]
27 delete pid_name[pid()]
28 }
29 }
30
31 # every minute print info
32 probe timer.s(60), end
33 {
34 printf("\n%s\n", tz_ctime(gettimeofday_s()))
35 if (fork_count == 0) next
36
37 # print out the data by pid
38 printf("\n%16s(%6s) %10s (percent)\n", "execname", "PID", "spawned")
39 foreach (p in fork_by_pid-) {
40 printf("%16s(%6d) %10d (%3d%%)\n", pid_name[p], p, fork_by_pid[p],
41 (fork_by_pid[p]*100)/fork_count)
42 }
43
44 # print out the data by execname
45 printf("\n%16s %10s (percent)\n", "execname", "spawned")
46 foreach (n in fork_by_name-) {
47 printf("%16s %10d (%3d%%)\n", n, fork_by_name[n],
48 (fork_by_name[n]*100)/fork_count)
49 }
50
51 # reset for the next interval
52 delete fork_by_pid
53 delete fork_by_name
54 fork_count = 0
55 }
56