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