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