]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/usr.sbin/dwatch/libexec/sched
Update OpenZFS to 2.0.0-rc3-gfc5966
[FreeBSD/FreeBSD.git] / cddl / usr.sbin / dwatch / libexec / sched
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
15 case "$PROFILE" in
16 sched)
17         : ${PROBE:=sched:::} ;;
18 sched-cpu)
19         : ${PROBE:=sched:::off-cpu, sched:::on-cpu, sched:::remain-cpu} ;;
20 sched-exec)
21         : ${PROBE:=sched:::sleep, sched:::wakeup} ;;
22 sched-pri)
23         : ${PROBE:=sched:::change-pri, sched:::lend-pri} ;;
24 sched-queue)
25         : ${PROBE:=sched:::dequeue, sched:::enqueue, sched:::load-change} ;;
26 *)
27         : ${PROBE:=sched:::${PROFILE#sched-}}
28 esac
29
30 ############################################################ ACTIONS
31
32 exec 9<<EOF
33 this pid_t      pid;
34 this string     args;
35 this string     details;
36 this 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
46 sched:::change-pri, sched:::dequeue, sched:::enqueue,
47 sched:::lend-pri, sched:::off-cpu, sched:::surrender,
48 sched:::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
59 sched:::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
66 sched:::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
74 sched:::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 }
91 EOF
92 ACTIONS=$( cat <&9 )
93 ID=$(( $ID + 6 ))
94
95 ############################################################ EVENT DETAILS
96
97 if [ ! "$CUSTOM_DETAILS" ]; then
98 exec 9<<EOF
99         /*
100          * Print scheduling details
101          */
102         printf("%s %s", probename, this->details);
103 EOF
104 EVENT_DETAILS=$( cat <&9 )
105 fi
106
107 ################################################################################
108 # END
109 ################################################################################