Debian Codegraph @

testsuite/systemtap.examples/profiling/sched_switch.stp

raw
1 #! /usr/bin/env stap
2 /* This script works similar to ftrace's sched_switch. It displays a list of
3 * processes which get switched in and out of the scheduler. The format of display
4 * is PROCESS_NAME PROCESS_PID CPU TIMESTAMP PID: PRIORITY: PROCESS STATE ->/+
5 * NEXT_PID : NEXT_PRIORITY: NEXT_STATE NEXT_PROCESS_NAME
6 * -> indicates that prev process is scheduled out and the next process is
7 * scheduled in.
8 * + indicates that prev process has woken up the next process.
9 * The usage is sched_switch.stp <"pid"/"name"> pid/name
10 */
11
12 global target_pid
13 global target_name
14
15 function state_calc(state) {
16 if(state == 0)
17 status = "R"
18 if(state == 1)
19 status = "S"
20 if(state == 2)
21 status = "D"
22 if(state == 4)
23 status = "T"
24 if(state == 8)
25 status = "T"
26 if(state == 16)
27 status = "Z"
28 if(state == 32)
29 status = "EXIT_DEAD"
30 return status
31 }
32 probe scheduler.wakeup
33 {
34 if (target_pid != 0
35 && task_pid != target_pid
36 && pid() != target_pid)
37 next
38
39 if (target_name != ""
40 && task_execname(task) != target_name
41 && execname() != target_name)
42 next
43
44 printf("%-16s%5d %5d %5d:%5d:%s + %5d:%5d:%s %-16s\n",
45 execname(), task_cpu(task), gettimeofday_ns(),
46 pid(), task_prio(task_current()), state_calc(task_state(task_current())),
47 task_pid(task), task_prio(task), state_calc(task_state(task)),
48 task_execname(task))
49 }
50 probe scheduler.ctxswitch
51 {
52 if (target_pid != 0
53 && next_pid != target_pid
54 && prev_pid != target_pid)
55 next
56
57 if (target_name != ""
58 && prev_task_name != target_name
59 && next_task_name != target_name)
60 next
61
62 printf("%-16s%5d %5d %5d:%5d:%s ==> %5d:%5d:%s %-16s\n",prev_task_name,
63 task_cpu(prev_task),gettimeofday_ns(),prev_pid,prev_priority,state_calc(prevtsk_state),next_pid,
64 next_priority,state_calc(nexttsk_state),next_task_name)
65 }
66 probe begin
67 {
68 target_pid = 0
69 target_name = ""
70
71 %( $# == 1 || $# > 2 %?
72 log("Wrong number of arguments, use none, 'pid nr' or 'name proc'")
73 exit()
74 %)
75
76 %( $# == 2 %?
77 if(@1 == "pid")
78 target_pid = strtol(@2, 10)
79 if(@1 == "name")
80 target_name = @2
81 %)
82 }