File: sched_switch.stp

package info (click to toggle)
systemtap 5.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 47,964 kB
  • sloc: cpp: 80,838; ansic: 54,757; xml: 49,725; exp: 43,665; sh: 11,527; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (82 lines) | stat: -rwxr-xr-x 2,132 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/bin/env stap
/* This script works similar to ftrace's sched_switch. It displays a list of
 * processes which get switched in and out of the scheduler. The format of display
 * is PROCESS_NAME PROCESS_PID CPU TIMESTAMP PID: PRIORITY: PROCESS STATE ->/+
 *    NEXT_PID : NEXT_PRIORITY: NEXT_STATE NEXT_PROCESS_NAME 
 * -> indicates that prev process is scheduled out and the next process is 
 *    scheduled in.
 * + indicates that prev process has woken up the next process.
 * The usage is sched_switch.stp <"pid"/"name"> pid/name
 */

global target_pid
global target_name

function state_calc(state) {
	if(state == 0)
	status = "R"
	if(state == 1)
	status = "S"
	if(state == 2)
	status = "D"
	if(state == 4)
	status = "T"
	if(state == 8)
	status = "T"
	if(state == 16)
	status = "Z"
	if(state == 32)
	status = "EXIT_DEAD"
	return status
}
probe scheduler.wakeup
{
	if (target_pid != 0
	    && task_pid != target_pid
	    && pid() != target_pid)
			next

	if (target_name != ""
	    && task_execname(task) != target_name
	    && execname() != target_name)
			next

	printf("%-16s%5d %5d %5d:%5d:%s +   %5d:%5d:%s %-16s\n",
                execname(), task_cpu(task), gettimeofday_ns(),
                pid(), task_prio(task_current()), state_calc(task_state(task_current())),
                task_pid(task), task_prio(task), state_calc(task_state(task)),
                task_execname(task))
}
probe scheduler.ctxswitch
{
	if (target_pid != 0
	    && next_pid != target_pid
	    && prev_pid != target_pid)
			next

	if (target_name != ""
	    && prev_task_name != target_name
	    && next_task_name != target_name)
			next

	printf("%-16s%5d %5d %5d:%5d:%s ==> %5d:%5d:%s %-16s\n",prev_task_name,
		task_cpu(prev_task),gettimeofday_ns(),prev_pid,prev_priority,state_calc(prevtsk_state),next_pid,
		next_priority,state_calc(nexttsk_state),next_task_name)
}
probe begin
{
	target_pid = 0
	target_name = ""

	%( $# == 1 || $# > 2 %?
		log("Wrong number of arguments, use none, 'pid nr' or 'name proc'")
		exit()
	%)

	%( $# == 2 %?
		if(@1 == "pid") 
			target_pid = strtol(@2, 10)
		if(@1 == "name")
			target_name = @2
	%)
}