aboutsummaryrefslogtreecommitdiff
path: root/cddl/usr.sbin/dwatch/libexec/sched
blob: c43ad31ea2b74616037a903b637d7f2da2a11758 (plain) (blame)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- tab-width: 4 -*- ;; Emacs
# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
############################################################ IDENT(1)
#
# $Title: dwatch(8) module for dtrace_sched(4) $
# $Copyright: 2014-2018 Devin Teske. All rights reserved. $
# $FreeBSD$
#
############################################################ DESCRIPTION
#
# Display CPU scheduling activity
#
############################################################ PROBE

case "$PROFILE" in
sched)
	: ${PROBE:=sched:::} ;;
sched-cpu)
	: ${PROBE:=sched:::off-cpu, sched:::on-cpu, sched:::remain-cpu} ;;
sched-exec)
	: ${PROBE:=sched:::sleep, sched:::wakeup} ;;
sched-pri)
	: ${PROBE:=sched:::change-pri, sched:::lend-pri} ;;
sched-queue)
	: ${PROBE:=sched:::dequeue, sched:::enqueue, sched:::load-change} ;;
*)
	: ${PROBE:=sched:::${PROFILE#sched-}}
esac

############################################################ ACTIONS

exec 9<<EOF
this pid_t	pid;
this string	args;
this string	details;
this u_char	curprio;

$PROBE /* probe ID $ID */
{${TRACE:+
	printf("<$ID>");}
	this->args = this->args0;
	this->details = "";
	this->pid = this->pid0;
}

sched:::change-pri, sched:::dequeue, sched:::enqueue,
sched:::lend-pri, sched:::off-cpu, sched:::surrender,
sched:::tick, sched:::wakeup /* probe ID $(( $ID + 1 )) */
{${TRACE:+
	printf("<$(( $ID + 1 ))>");}
	this->curprio = (u_char)((struct thread *)args[0])->td_priority;

	$( pproc -P _sched "(struct proc *)args[1]" )

	this->args = this->args_sched;
	this->pid = this->pid_sched;
}

sched:::enqueue /* probe ID $(( $ID + 2 )) */
{${TRACE:+
	printf("<$(( $ID + 2 ))>");}
	/* details = "head" or "tail" */
	this->details = (int)arg3 == 0 ? "tail" : "head";
}

sched:::change-pri, sched:::lend-pri /* probe ID $(( $ID + 3 )) */
{${TRACE:+
	printf("<$(( $ID + 3 ))>");}
	/* details = "<curprio> -> arg2" */
	this->details = strjoin(lltostr(this->curprio),
		strjoin("->", lltostr((uint8_t)arg2)));
}

sched:::load-change /* probe ID $(( $ID + 4 )) */
{${TRACE:+
	printf("<$(( $ID + 4 ))>");}
	/* details = "CPU<arg0> queue <arg1>" */
	this->details = strjoin(strjoin("CPU", lltostr((int)arg0)),
		strjoin(" queue ", lltostr((int)arg1)));
}

$PROBE /* probe ID $(( $ID + 5 )) */
{${TRACE:+
	printf("<$(( $ID + 5 ))>");}
	/* details += " pid <pid> -- <proc args of pid>" */
	this->details = strjoin(this->details, this->details == "" ? "" : " ");
	this->details = strjoin(this->details, strjoin(
		strjoin("pid ", lltostr(this->pid_sched)),
		strjoin(" -- ", this->args)));
}
EOF
ACTIONS=$( cat <&9 )
ID=$(( $ID + 6 ))

############################################################ EVENT DETAILS

exec 9<<EOF
	/*
	 * Print scheduling details
	 */
	printf("%s %s", probename, this->details);
EOF
EVENT_DETAILS=$( cat <&9 )

################################################################################
# END
################################################################################