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