1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1991, 1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS	*/
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/errno.h>
31*7c478bd9Sstevel@tonic-gate #include <setjmp.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <rpc/types.h>
35*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
36*7c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
37*7c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
38*7c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h>
39*7c478bd9Sstevel@tonic-gate #include "snoop.h"
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate extern char *dlc_header;
42*7c478bd9Sstevel@tonic-gate extern jmp_buf xdr_err;
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate void detail_stats();		/* Version 1 */
45*7c478bd9Sstevel@tonic-gate void detail_statsswtch();	/* Version 2 */
46*7c478bd9Sstevel@tonic-gate void detail_statstime();	/* Version 3 */
47*7c478bd9Sstevel@tonic-gate void detail_statsvar();		/* Version 4 */
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate static char *procnames_short[] = {
50*7c478bd9Sstevel@tonic-gate 	"Null",			/*  0 */
51*7c478bd9Sstevel@tonic-gate 	"Get Statistics",	/*  1 */
52*7c478bd9Sstevel@tonic-gate 	"Have Disk",		/*  2 */
53*7c478bd9Sstevel@tonic-gate };
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate static char *procnames_long[] = {
56*7c478bd9Sstevel@tonic-gate 	"Null procedure",		/*  0 */
57*7c478bd9Sstevel@tonic-gate 	"Get Statistics",		/*  1 */
58*7c478bd9Sstevel@tonic-gate 	"Have Disk",			/*  2 */
59*7c478bd9Sstevel@tonic-gate };
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate #define	MAXPROC	2
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate void
interpret_rstat(flags,type,xid,vers,proc,data,len)64*7c478bd9Sstevel@tonic-gate interpret_rstat(flags, type, xid, vers, proc, data, len)
65*7c478bd9Sstevel@tonic-gate 	int flags, type, xid, vers, proc;
66*7c478bd9Sstevel@tonic-gate 	char *data;
67*7c478bd9Sstevel@tonic-gate 	int len;
68*7c478bd9Sstevel@tonic-gate {
69*7c478bd9Sstevel@tonic-gate 	char *line;
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate 	if (proc < 0 || proc > MAXPROC)
72*7c478bd9Sstevel@tonic-gate 		return;
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
75*7c478bd9Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
76*7c478bd9Sstevel@tonic-gate 			return;
77*7c478bd9Sstevel@tonic-gate 		}
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 		line = get_sum_line();
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 		if (type == CALL) {
82*7c478bd9Sstevel@tonic-gate 			(void) sprintf(line,
83*7c478bd9Sstevel@tonic-gate 				"RSTAT C %s",
84*7c478bd9Sstevel@tonic-gate 				procnames_short[proc]);
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 			check_retransmit(line, xid);
87*7c478bd9Sstevel@tonic-gate 		} else {
88*7c478bd9Sstevel@tonic-gate 			(void) sprintf(line, "RSTAT R %s ",
89*7c478bd9Sstevel@tonic-gate 				procnames_short[proc]);
90*7c478bd9Sstevel@tonic-gate 		}
91*7c478bd9Sstevel@tonic-gate 	}
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
94*7c478bd9Sstevel@tonic-gate 		show_header("RSTAT:  ", "RSTAT Get Statistics", len);
95*7c478bd9Sstevel@tonic-gate 		show_space();
96*7c478bd9Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
97*7c478bd9Sstevel@tonic-gate 			return;
98*7c478bd9Sstevel@tonic-gate 		}
99*7c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
100*7c478bd9Sstevel@tonic-gate 			"Proc = %d (%s)",
101*7c478bd9Sstevel@tonic-gate 			proc, procnames_long[proc]);
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate 		if (type == REPLY) {
104*7c478bd9Sstevel@tonic-gate 			switch (proc) {
105*7c478bd9Sstevel@tonic-gate 			case 1:
106*7c478bd9Sstevel@tonic-gate 				switch (vers) {
107*7c478bd9Sstevel@tonic-gate 				case 1:
108*7c478bd9Sstevel@tonic-gate 					detail_stats();
109*7c478bd9Sstevel@tonic-gate 					break;
110*7c478bd9Sstevel@tonic-gate 				case 2:
111*7c478bd9Sstevel@tonic-gate 					detail_statsswtch();
112*7c478bd9Sstevel@tonic-gate 					break;
113*7c478bd9Sstevel@tonic-gate 				case 3:
114*7c478bd9Sstevel@tonic-gate 					detail_statstime();
115*7c478bd9Sstevel@tonic-gate 					break;
116*7c478bd9Sstevel@tonic-gate 				case 4:
117*7c478bd9Sstevel@tonic-gate 					detail_statsvar();
118*7c478bd9Sstevel@tonic-gate 					break;
119*7c478bd9Sstevel@tonic-gate 				}
120*7c478bd9Sstevel@tonic-gate 				break;
121*7c478bd9Sstevel@tonic-gate 			case 2:
122*7c478bd9Sstevel@tonic-gate 				(void) showxdr_u_long(
123*7c478bd9Sstevel@tonic-gate 					"Result = %lu");
124*7c478bd9Sstevel@tonic-gate 				break;
125*7c478bd9Sstevel@tonic-gate 			}
126*7c478bd9Sstevel@tonic-gate 		}
127*7c478bd9Sstevel@tonic-gate 		show_trailer();
128*7c478bd9Sstevel@tonic-gate 	}
129*7c478bd9Sstevel@tonic-gate }
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate void
detail_stats()132*7c478bd9Sstevel@tonic-gate detail_stats()
133*7c478bd9Sstevel@tonic-gate {
134*7c478bd9Sstevel@tonic-gate 	show_space();
135*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "CPU Times:");
136*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (1)       = %d");
137*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (2)       = %d");
138*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (3)       = %d");
139*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (4)       = %d");
140*7c478bd9Sstevel@tonic-gate 	show_space();
141*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "Disk Transfers:");
142*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(1)   = %d");
143*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(2)   = %d");
144*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(3)   = %d");
145*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(4)   = %d");
146*7c478bd9Sstevel@tonic-gate 	show_space();
147*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Pages in         = %lu");
148*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Pages out        = %lu");
149*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Swaps in         = %lu");
150*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Swaps out        = %lu");
151*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Interrupts       = %lu");
152*7c478bd9Sstevel@tonic-gate 	show_space();
153*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Receive packets  = %d");
154*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Receive errors   = %d");
155*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Transmit packets = %d");
156*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Transmit errors  = %d");
157*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Collisions       = %d");
158*7c478bd9Sstevel@tonic-gate }
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate void
detail_statsswtch()161*7c478bd9Sstevel@tonic-gate detail_statsswtch()
162*7c478bd9Sstevel@tonic-gate {
163*7c478bd9Sstevel@tonic-gate 	show_space();
164*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "CPU Times:");
165*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (1)       = %d");
166*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (2)       = %d");
167*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (3)       = %d");
168*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (4)       = %d");
169*7c478bd9Sstevel@tonic-gate 	show_space();
170*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "Disk Transfers:");
171*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(1)   = %d");
172*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(2)   = %d");
173*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(3)   = %d");
174*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(4)   = %d");
175*7c478bd9Sstevel@tonic-gate 	show_space();
176*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Pages in         = %lu");
177*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Pages out        = %lu");
178*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Swaps in         = %lu");
179*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Swaps out        = %lu");
180*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Interrupts       = %lu");
181*7c478bd9Sstevel@tonic-gate 	show_space();
182*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Receive packets  = %d");
183*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Receive errors   = %d");
184*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Transmit packets = %d");
185*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Transmit errors  = %d");
186*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Collisions       = %d");
187*7c478bd9Sstevel@tonic-gate 	show_space();
188*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("V switch         = %lu");
189*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Average run 0    = %d");
190*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Average run 1    = %d");
191*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Average run 2    = %d");
192*7c478bd9Sstevel@tonic-gate 	show_space();
193*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Boot time:       = %s");
194*7c478bd9Sstevel@tonic-gate }
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate void
detail_statstime()197*7c478bd9Sstevel@tonic-gate detail_statstime()
198*7c478bd9Sstevel@tonic-gate {
199*7c478bd9Sstevel@tonic-gate 	show_space();
200*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "CPU Times:");
201*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (1)     = %d");
202*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (2)     = %d");
203*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (3)     = %d");
204*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Time (4)     = %d");
205*7c478bd9Sstevel@tonic-gate 	show_space();
206*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "Disk Transfers:");
207*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(1)   = %d");
208*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(2)   = %d");
209*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(3)   = %d");
210*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("  Transfers(4)   = %d");
211*7c478bd9Sstevel@tonic-gate 	show_space();
212*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Pages in         = %lu");
213*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Pages out        = %lu");
214*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Swaps in         = %lu");
215*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Swaps out        = %lu");
216*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Interrupts       = %lu");
217*7c478bd9Sstevel@tonic-gate 	show_space();
218*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Receive packets  = %d");
219*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Receive errors   = %d");
220*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Transmit packets = %d");
221*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Transmit errors  = %d");
222*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Collisions       = %d");
223*7c478bd9Sstevel@tonic-gate 	show_space();
224*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("V switch         = %lu");
225*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Average run 0    = %d");
226*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Average run 1    = %d");
227*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Average run 2    = %d");
228*7c478bd9Sstevel@tonic-gate 	show_space();
229*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Boot time:       = %s");
230*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Current time     = %s");
231*7c478bd9Sstevel@tonic-gate }
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate void
detail_statsvar()234*7c478bd9Sstevel@tonic-gate detail_statsvar()
235*7c478bd9Sstevel@tonic-gate {
236*7c478bd9Sstevel@tonic-gate 	int i, n;
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate 	show_space();
239*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "CPU Times:");
240*7c478bd9Sstevel@tonic-gate 	n = getxdr_u_long();
241*7c478bd9Sstevel@tonic-gate 	for (i = 1; i <= n; i++) {
242*7c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
243*7c478bd9Sstevel@tonic-gate 			"  Time (%2d)      = %d", i, getxdr_long());
244*7c478bd9Sstevel@tonic-gate 	}
245*7c478bd9Sstevel@tonic-gate 	show_space();
246*7c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), "Disk Transfers:");
247*7c478bd9Sstevel@tonic-gate 	n = getxdr_u_long();
248*7c478bd9Sstevel@tonic-gate 	for (i = 1; i <= n; i++) {
249*7c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
250*7c478bd9Sstevel@tonic-gate 			"  Transfers (%2d) = %d", i, getxdr_long());
251*7c478bd9Sstevel@tonic-gate 	}
252*7c478bd9Sstevel@tonic-gate 	show_space();
253*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Pages in         = %lu");
254*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Pages out        = %lu");
255*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Swaps in         = %lu");
256*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Swaps out        = %lu");
257*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("Interrupts       = %lu");
258*7c478bd9Sstevel@tonic-gate 	show_space();
259*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Receive packets  = %d");
260*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Receive errors   = %d");
261*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Transmit packets = %d");
262*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Transmit errors  = %d");
263*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Collisions       = %d");
264*7c478bd9Sstevel@tonic-gate 	show_space();
265*7c478bd9Sstevel@tonic-gate 	(void) showxdr_u_long("V switch         = %lu");
266*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Average run 0    = %d");
267*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Average run 1    = %d");
268*7c478bd9Sstevel@tonic-gate 	(void) showxdr_long("Average run 2    = %d");
269*7c478bd9Sstevel@tonic-gate 	show_space();
270*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Boot time:       = %s");
271*7c478bd9Sstevel@tonic-gate 	(void) showxdr_date("Current time     = %s");
272*7c478bd9Sstevel@tonic-gate }
273