xref: /freebsd/cddl/usr.sbin/dwatch/libexec/systop (revision 7ab1a32cd43cbae61ad4dd435d6a482bbf61cb52)
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) profile for top-like syscall $
6# $Copyright: 2014-2018 Devin Teske. All rights reserved. $
7#
8############################################################ DESCRIPTION
9#
10# Every 3 seconds update the screen with syscall consumers.
11#
12############################################################ PRAGMAS
13
14# Optional: You can override the default pragmas (shown below)
15
16DTRACE_PRAGMA="
17	option quiet
18	option aggsortrev
19" # END-QUOTE
20
21############################################################ PROBE
22
23: ${PROBE:=profile:::tick-3s}
24
25############################################################ ACTIONS
26
27exec 9<<EOF
28BEGIN { printf("Sampling ...") } /* probe ID $ID */
29
30syscall:::entry /* probe ID $(( $ID + 1 )) */
31{
32	@num[probefunc,execname] = count();
33}
34
35END { trunc(@num) } /* probe ID $(( $ID + 2 )) */
36EOF
37ACTIONS=$( cat <&9 )
38ID=$(( $ID + 3 ))
39
40############################################################ EVENT TAG
41
42# The EVENT_TAG is run inside the print action after the timestamp has been
43# printed. By default, `UID.GID CMD[PID]: ' of the process is printed.
44#
45# Here we override the default EVENT_TAG to include ANSI cursor-homing and
46# screen-clearing codes.
47
48size=$( stty size 2> /dev/null )
49rows="${size%% *}"
50cols="${size#* }"
51
52exec 9<<EOF
53	printf("\033[H"); /* Position the cursor at top-left */
54	printf("\033[J"); /* Clear display from cursor to end */
55
56	/* Header line containing probe (left) and date (right) */
57	printf("%-*s%s%Y%s\n",
58		$(( ${cols:-80} - 20 )), "$PROBE",
59		console ? "\033[32m" : "",
60		walltimestamp,
61		console ? "\033[39m" : "");
62
63	/* Column headers */
64	printf("%s%8s %-20s %s%s\n",
65		console ? "\033[1m" : "",
66		"COUNT",
67		"SYSCALL",
68		"EXECNAME",
69		console ? "\033[22m" : "");
70EOF
71EVENT_TAG=$( cat <&9 )
72
73############################################################ EVENT DETAILS
74
75exec 9<<EOF
76	printa("%@8u %-20s %s\n", @num);
77	trunc(@num);
78EOF
79EVENT_DETAILS=$( cat <&9 )
80
81################################################################################
82# END
83################################################################################
84