xref: /freebsd/cddl/usr.sbin/dwatch/libexec/sched (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
1# -*- tab-width: 4 -*- ;; Emacs
2# vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
3############################################################ IDENT(1)
4#
5# $Title: dwatch(8) module for dtrace_sched(4) $
6# $Copyright: 2014-2018 Devin Teske. All rights reserved. $
7# $FreeBSD$
8#
9############################################################ DESCRIPTION
10#
11# Display CPU scheduling activity
12#
13############################################################ PROBE
14
15case "$PROFILE" in
16sched)
17	: ${PROBE:=sched:::} ;;
18sched-cpu)
19	: ${PROBE:=sched:::off-cpu, sched:::on-cpu, sched:::remain-cpu} ;;
20sched-exec)
21	: ${PROBE:=sched:::sleep, sched:::wakeup} ;;
22sched-pri)
23	: ${PROBE:=sched:::change-pri, sched:::lend-pri} ;;
24sched-queue)
25	: ${PROBE:=sched:::dequeue, sched:::enqueue, sched:::load-change} ;;
26*)
27	: ${PROBE:=sched:::${PROFILE#sched-}}
28esac
29
30############################################################ ACTIONS
31
32exec 9<<EOF
33this pid_t	pid;
34this string	args;
35this string	details;
36this u_char	curprio;
37
38$PROBE /* probe ID $ID */
39{${TRACE:+
40	printf("<$ID>");}
41	this->args = this->args0;
42	this->details = "";
43	this->pid = this->pid0;
44}
45
46sched:::change-pri, sched:::dequeue, sched:::enqueue,
47sched:::lend-pri, sched:::off-cpu, sched:::surrender,
48sched:::tick, sched:::wakeup /* probe ID $(( $ID + 1 )) */
49{${TRACE:+
50	printf("<$(( $ID + 1 ))>");}
51	this->curprio = (u_char)((struct thread *)args[0])->td_priority;
52
53	$( pproc -P _sched "(struct proc *)args[1]" )
54
55	this->args = this->args_sched;
56	this->pid = this->pid_sched;
57}
58
59sched:::enqueue /* probe ID $(( $ID + 2 )) */
60{${TRACE:+
61	printf("<$(( $ID + 2 ))>");}
62	/* details = "head" or "tail" */
63	this->details = (int)arg3 == 0 ? "tail" : "head";
64}
65
66sched:::change-pri, sched:::lend-pri /* probe ID $(( $ID + 3 )) */
67{${TRACE:+
68	printf("<$(( $ID + 3 ))>");}
69	/* details = "<curprio> -> <arg2>" */
70	this->details = strjoin(lltostr(this->curprio),
71		strjoin("->", lltostr((uint8_t)arg2)));
72}
73
74sched:::load-change /* probe ID $(( $ID + 4 )) */
75{${TRACE:+
76	printf("<$(( $ID + 4 ))>");}
77	/* details = "CPU<arg0> queue <arg1>" */
78	this->details = strjoin(strjoin("CPU", lltostr((int)arg0)),
79		strjoin(" queue ", lltostr((int)arg1)));
80}
81
82$PROBE /* probe ID $(( $ID + 5 )) */
83{${TRACE:+
84	printf("<$(( $ID + 5 ))>");}
85	/* details += " pid <pid> -- <proc args of pid>" */
86	this->details = strjoin(this->details, this->details == "" ? "" : " ");
87	this->details = strjoin(this->details, strjoin(
88		strjoin("pid ", lltostr(this->pid)),
89		strjoin(" -- ", this->args)));
90}
91EOF
92ACTIONS=$( cat <&9 )
93ID=$(( $ID + 6 ))
94
95############################################################ EVENT DETAILS
96
97if [ ! "$CUSTOM_DETAILS" ]; then
98exec 9<<EOF
99	/*
100	 * Print scheduling details
101	 */
102	printf("%s %s", probename, this->details);
103EOF
104EVENT_DETAILS=$( cat <&9 )
105fi
106
107################################################################################
108# END
109################################################################################
110