xref: /netbsd-src/usr.bin/systat/cmdtab.c (revision 5a5cdfa229a4a633b28890bfe4f9dfcc4909f9b5)
1*5a5cdfa2Ssevan /*	$NetBSD: cmdtab.c,v 1.26 2018/12/26 01:47:37 sevan Exp $	*/
22f3cb7aeSjtc 
312749a2aSjtc /*-
412749a2aSjtc  * Copyright (c) 1980, 1992, 1993
512749a2aSjtc  *	The Regents of the University of California.  All rights reserved.
612749a2aSjtc  *
712749a2aSjtc  * Redistribution and use in source and binary forms, with or without
812749a2aSjtc  * modification, are permitted provided that the following conditions
912749a2aSjtc  * are met:
1012749a2aSjtc  * 1. Redistributions of source code must retain the above copyright
1112749a2aSjtc  *    notice, this list of conditions and the following disclaimer.
1212749a2aSjtc  * 2. Redistributions in binary form must reproduce the above copyright
1312749a2aSjtc  *    notice, this list of conditions and the following disclaimer in the
1412749a2aSjtc  *    documentation and/or other materials provided with the distribution.
1589aaa1bbSagc  * 3. Neither the name of the University nor the names of its contributors
1612749a2aSjtc  *    may be used to endorse or promote products derived from this software
1712749a2aSjtc  *    without specific prior written permission.
1812749a2aSjtc  *
1912749a2aSjtc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2012749a2aSjtc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2112749a2aSjtc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2212749a2aSjtc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2312749a2aSjtc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2412749a2aSjtc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2512749a2aSjtc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2612749a2aSjtc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2712749a2aSjtc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2812749a2aSjtc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2912749a2aSjtc  * SUCH DAMAGE.
3012749a2aSjtc  */
3112749a2aSjtc 
3259413993Smrg #include <sys/cdefs.h>
3312749a2aSjtc #ifndef lint
342f3cb7aeSjtc #if 0
3512749a2aSjtc static char sccsid[] = "@(#)cmdtab.c	8.1 (Berkeley) 6/6/93";
362f3cb7aeSjtc #endif
37*5a5cdfa2Ssevan __RCSID("$NetBSD: cmdtab.c,v 1.26 2018/12/26 01:47:37 sevan Exp $");
3812749a2aSjtc #endif /* not lint */
3912749a2aSjtc 
4012749a2aSjtc #include "systat.h"
4112749a2aSjtc #include "extern.h"
4212749a2aSjtc 
43ad285dbfSjwise /*
44ad285dbfSjwise  * NOTE: if one command is a substring of another, the shorter string
45ad285dbfSjwise  * MUST come first, or it will be shadowed by the longer
46ad285dbfSjwise  */
47ad285dbfSjwise 
484c0fbd4cSjwise struct	command global_commands[] = {
494c0fbd4cSjwise 	{ "help",	global_help,		"show help"},
504c0fbd4cSjwise 	{ "interval",	global_interval,	"set update interval"},
514c0fbd4cSjwise 	{ "load",	global_load,		"show system load averages"},
524c0fbd4cSjwise 	{ "quit",	global_quit,		"exit systat"},
534c0fbd4cSjwise 	{ "start",	global_interval,	"restart updating display"},
544c0fbd4cSjwise 	{ "stop",	global_stop,		"stop updating display"},
55*5a5cdfa2Ssevan 	{ "?",		global_help,		"show help"},
568a3920f2Schristos 	{ .c_name = NULL }
574c0fbd4cSjwise };
584c0fbd4cSjwise 
59756c7041Shubertf struct command	df_commands[] = {
60756c7041Shubertf 	{ "all",	df_all,         "show all filesystems"},
61756c7041Shubertf 	{ "some",	df_some,        "show only some filesystems"},
628a3920f2Schristos 	{ .c_name = NULL }
63756c7041Shubertf };
64756c7041Shubertf 
65fc391547Sad struct command	icmp_commands[] = {
66fc391547Sad 	{ "boot",	icmp_boot,	"show total stats since boot"},
67fc391547Sad 	{ "run",	icmp_run,	"show running total stats"},
68fc391547Sad 	{ "time",	icmp_time,	"show stats for each sample time"},
69fc391547Sad 	{ "zero",	icmp_zero,	"re-zero running totals"},
708a3920f2Schristos 	{ .c_name = NULL }
71fc391547Sad };
72fc391547Sad 
73bd7662dcSscole struct command ifstat_commands[] = {
74bd7662dcSscole 	{ "scale",	ifstat_scale,	"modify scale of display"},
75bd7662dcSscole 	{ "pps",	ifstat_pps, 	"toggle packets per second display"},
76bd7662dcSscole 	{ "match",	ifstat_match,   "display matching interfaces"},
77bd7662dcSscole 	{ .c_name = NULL }
78bd7662dcSscole };
79bd7662dcSscole 
804c0fbd4cSjwise struct command	iostat_commands[] = {
814c0fbd4cSjwise 	{ "bars",	iostat_bars,	"show io stats as a bar graph"},
824c0fbd4cSjwise 	{ "numbers",	iostat_numbers,	"show io stats numerically"},
834c0fbd4cSjwise 	{ "secs",	iostat_secs,	"include time statistics"},
843cf4c73dSmrg 	{ "rw",		iostat_rw,	"show read/write disk stats"},
855af29647Sdsl 	{ "all",	iostat_all,	"show combined disk stats"},
864c0fbd4cSjwise 	/* from disks.c */
870e1a71bbSmycroft 	{ "display",	disks_add,	"add a disk to displayed disks"},
880e1a71bbSmycroft 	{ "ignore",	disks_remove,	"remove a disk from displayed disks"},
890e1a71bbSmycroft 	{ "drives",	disks_drives,	"list all disks/set disk list"},
908a3920f2Schristos 	{ .c_name = NULL }
914c0fbd4cSjwise };
924c0fbd4cSjwise 
93fc391547Sad struct command	ip_commands[] = {
94fc391547Sad 	{ "boot",	ip_boot,	"show total stats since boot"},
95fc391547Sad 	{ "run",	ip_run,		"show running total stats"},
96fc391547Sad 	{ "time",	ip_time,	"show stats for each sample time"},
97fc391547Sad 	{ "zero",	ip_zero,	"re-zero running totals"},
988a3920f2Schristos 	{ .c_name = NULL }
99fc391547Sad };
100fc391547Sad 
101fc391547Sad #ifdef INET6
102fc391547Sad struct command	ip6_commands[] = {
103fc391547Sad 	{ "boot",	ip6_boot,	"show total stats since boot"},
104fc391547Sad 	{ "run",	ip6_run,	"show running total stats"},
105fc391547Sad 	{ "time",	ip6_time,	"show stats for each sample time"},
106fc391547Sad 	{ "zero",	ip6_zero,	"re-zero running totals"},
1078a3920f2Schristos 	{ .c_name = NULL }
108fc391547Sad };
109fc391547Sad #endif
110fc391547Sad 
1114c0fbd4cSjwise struct command netstat_commands[] = {
1124c0fbd4cSjwise 	{ "all",	netstat_all,	 "include server sockets"},
1134c0fbd4cSjwise 	{ "display",	netstat_display, "show specified hosts or ports"},
1144c0fbd4cSjwise 	{ "ignore",	netstat_ignore,	 "hide specified hosts or ports"},
1154c0fbd4cSjwise 	{ "names",	netstat_names,	 "show names instead of addresses"},
1164c0fbd4cSjwise 	{ "numbers",	netstat_numbers, "show addresses instead of names"},
1174c0fbd4cSjwise 	{ "reset",	netstat_reset,	 "return to default display"},
1184c0fbd4cSjwise 	{ "show",	netstat_show,	 "show current display/ignore settings"},
1194c0fbd4cSjwise 	{ "tcp",	netstat_tcp,	 "show only tcp connections"},
1204c0fbd4cSjwise 	{ "udp",	netstat_udp,	 "show only udp connections"},
1218a3920f2Schristos 	{ .c_name = NULL }
1224c0fbd4cSjwise };
1234c0fbd4cSjwise 
124c23c312aSkleink struct command ps_commands[] = {
125c23c312aSkleink 	{ "user",	ps_user,	"limit displayed processes to a user"},
1268a3920f2Schristos 	{ .c_name = NULL }
127c23c312aSkleink };
128c23c312aSkleink 
129fc391547Sad struct command	tcp_commands[] = {
130fc391547Sad 	{ "boot",	tcp_boot,	"show total stats since boot"},
131fc391547Sad 	{ "run",	tcp_run,	"show running total stats"},
132fc391547Sad 	{ "time",	tcp_time,	"show stats for each sample time"},
133fc391547Sad 	{ "zero",	tcp_zero,	"re-zero running totals"},
1348a3920f2Schristos 	{ .c_name = NULL }
135fc391547Sad };
136fc391547Sad 
1374c0fbd4cSjwise struct command	vmstat_commands[] = {
1384c0fbd4cSjwise 	{ "boot",	vmstat_boot,	"show total vm stats since boot"},
1394c0fbd4cSjwise 	{ "run",	vmstat_run,	"show running total vm stats"},
1404c0fbd4cSjwise 	{ "time",	vmstat_time,	"show vm stats for each sample time"},
1414c0fbd4cSjwise 	{ "zero",	vmstat_zero,	"re-zero running totals"},
1424c0fbd4cSjwise 	/* from disks.c */
1430e1a71bbSmycroft 	{ "display",	disks_add,	"add a disk to displayed disks"},
1440e1a71bbSmycroft 	{ "ignore",	disks_remove,	"remove a disk from displayed disks"},
1450e1a71bbSmycroft 	{ "drives",	disks_drives,	"list all disks/set disk list"},
1468a3920f2Schristos 	{ .c_name = NULL }
1474c0fbd4cSjwise };
1484c0fbd4cSjwise 
14949c5f0e9Sdsl struct command	syscall_commands[] = {
15049c5f0e9Sdsl 	{ "boot",	syscall_boot,	"show total syscall stats since boot"},
15149c5f0e9Sdsl 	{ "run",	syscall_run,	"show running total syscall stats"},
15249c5f0e9Sdsl 	{ "time",	syscall_time,	"show syscall stats for each sample time"},
15349c5f0e9Sdsl 	{ "zero",	syscall_zero,	"re-zero running totals"},
15449c5f0e9Sdsl 	{ "sort",	syscall_order,	"sort by [name|count|syscall]"},
15549c5f0e9Sdsl 	{ "show",	syscall_show,	"show [count|time]"},
15649c5f0e9Sdsl 	{ .c_name = NULL }
15749c5f0e9Sdsl };
15849c5f0e9Sdsl 
15906f37661Sjwise struct mode modes[] = {
160b80f4eafSsimonb 	/* "pigs" is the default, it must be first. */
16112749a2aSjtc 	{ "pigs",	showpigs,	fetchpigs,	labelpigs,
16212749a2aSjtc 	  initpigs,	openpigs,	closepigs,	0,
16312749a2aSjtc 	  CF_LOADAV },
164b80f4eafSsimonb 	{ "bufcache",	showbufcache,	fetchbufcache,	labelbufcache,
165b80f4eafSsimonb 	  initbufcache,	openbufcache,	closebufcache,	0,
16612749a2aSjtc 	  CF_LOADAV },
167756c7041Shubertf 	{ "df",         showdf,  	fetchdf,	labeldf,
168756c7041Shubertf 	  initdf,	opendf,		closedf,	df_commands,
169756c7041Shubertf 	  CF_LOADAV },
170bd7662dcSscole 	{ "ifstat",	showifstat,	fetchifstat,	labelifstat,
171bd7662dcSscole 	  initifstat,	openifstat,	closeifstat,	ifstat_commands,
172bd7662dcSscole 	  CF_LOADAV },
173b80f4eafSsimonb 	{ "inet.icmp",	showicmp,	fetchicmp,	labelicmp,
174fc391547Sad 	  initicmp,	openicmp,	closeicmp,	icmp_commands,
17512749a2aSjtc 	  CF_LOADAV },
176b80f4eafSsimonb 	{ "inet.ip",	showip,		fetchip,	labelip,
177fc391547Sad 	  initip,	openip,		closeip,	ip_commands,
178cfb46b6fSjwise 	  CF_LOADAV },
1791a9ae67fSjwise 	{ "inet.tcp",	showtcp,	fetchtcp,	labeltcp,
180fc391547Sad 	  inittcp,	opentcp,	closetcp,	tcp_commands,
18100116cf5Sad 	  CF_LOADAV },
1821a9ae67fSjwise 	{ "inet.tcpsyn",showtcpsyn,	fetchtcp,	labeltcpsyn,
183fc391547Sad 	  inittcp,	opentcp,	closetcp,	tcp_commands,
18400116cf5Sad 	  CF_LOADAV },
185d7b4ec92Sitojun #ifdef INET6
186d7b4ec92Sitojun 	{ "inet6.ip6",	showip6,	fetchip6,	labelip6,
187fc391547Sad 	  initip6,	openip6,	closeip6,	ip6_commands,
188d7b4ec92Sitojun 	  CF_LOADAV },
189d7b4ec92Sitojun #endif
190b80f4eafSsimonb 	{ "iostat",	showiostat,	fetchiostat,	labeliostat,
1914c0fbd4cSjwise 	  initiostat,	openiostat,	closeiostat,	iostat_commands,
19200116cf5Sad 	  CF_LOADAV },
193b80f4eafSsimonb 	{ "mbufs",	showmbufs,	fetchmbufs,	labelmbufs,
194b80f4eafSsimonb 	  initmbufs,	openmbufs,	closembufs,	0,
19500116cf5Sad 	  CF_LOADAV },
196b80f4eafSsimonb 	{ "netstat",	shownetstat,	fetchnetstat,	labelnetstat,
1974c0fbd4cSjwise 	  initnetstat,	opennetstat,	closenetstat,	netstat_commands,
198b80f4eafSsimonb 	  CF_LOADAV },
199b80f4eafSsimonb 	{ "ps",		showps,		fetchpigs,	labelps,
200c23c312aSkleink 	  initpigs,	openpigs,	closepigs,	ps_commands,
201b80f4eafSsimonb 	  CF_LOADAV },
202b80f4eafSsimonb 	{ "swap",	showswap,	fetchswap,	labelswap,
203b80f4eafSsimonb 	  initswap,	openswap,	closeswap,	0,
204b80f4eafSsimonb 	  CF_LOADAV },
205fc391547Sad 	{ "vmstat",	showvmstat,	fetchvmstat,	labelvmstat,
206fc391547Sad 	  initvmstat,	openvmstat,	closevmstat,	vmstat_commands,
207b80f4eafSsimonb 	  0 },
20849c5f0e9Sdsl 	{ "syscall",	showsyscall,	fetchsyscall,	labelsyscall,
20949c5f0e9Sdsl 	  initsyscall,	opensyscall,	closesyscall,	syscall_commands,
21049c5f0e9Sdsl 	  0 },
2118a3920f2Schristos 	{ .c_name = NULL }
21212749a2aSjtc };
21306f37661Sjwise struct  mode *curmode = &modes[0];
214