2 * print PPP statistics:
3 * pppstats [-i interval] [-v] [interface] [system] [core]
5 * Brad Parker (brad@cayman.com) 6/92
7 * from the original "slstats" by Van Jaconson
9 * Copyright (c) 1989 Regents of the University of California.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms are permitted
13 * provided that the above copyright notice and this paragraph are
14 * duplicated in all such forms and that any documentation,
15 * advertising materials, and other materials related to such
16 * distribution and use acknowledge that the software was developed
17 * by the University of California, Berkeley. The name of the
18 * University may not be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
25 * - Initial distribution.
29 static char rcsid[] = "$Id: pppstats.c,v 1.3 1994/04/21 03:11:03 paulus Exp $";
37 #include <sys/param.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/ip.h>
46 #include <netinet/ip_var.h>
49 #include <net/slcompress.h>
50 #include <net/if_ppp.h>
53 #define PPP_STATS 1 /* should be defined iff it is in ppp_if.c */
54 #include <sys/stream.h>
55 #include <net/ppp_str.h>
64 #include <machine/pte.h>
66 #include <machine/cpu.h>
71 char *kmemf = "/dev/kmem";
104 char *system = "/vmunix";
107 char *system = _PATH_UNIX;
112 unsigned interval = 5;
115 extern char *malloc();
123 if (strcmp(argv[0], "-v") == 0) {
128 if (strcmp(argv[0], "-i") == 0 && argv[1] &&
129 isdigit(argv[1][0])) {
130 interval = atoi(argv[1]);
137 if (isdigit(argv[0][0])) {
138 unit = atoi(argv[0]);
156 if (nlist(system, nl) < 0 || nl[0].n_type == 0) {
157 fprintf(stderr, "%s: no namelist\n", system);
160 kmem = open(kmemf, O_RDONLY);
169 Sysmap = (struct pte *)
170 malloc((u_int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
172 fputs("netstat: can't get memory for Sysmap.\n", stderr);
175 off = nl[N_SYSMAP].n_value & ~KERNBASE;
176 (void)lseek(kmem, off, L_SET);
177 (void)read(kmem, (char *)Sysmap,
178 (int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
184 if ((kd = kvm_open(system, kmemf, (char *)0, O_RDONLY, NULL)) == NULL) {
190 if (kvm_openfiles(system, kmemf, (char *)0) == -1) {
191 fprintf(stderr, "kvm_openfiles: %s", kvm_geterr());
196 if (kvm_nlist(KDARG nl)) {
197 fprintf(stderr, "pppstats: can't find symbols in nlist\n");
207 * Seek into the kernel for a value.
210 klseek(fd, base, off)
216 base = K0_TO_PHYS(base);
220 base = ctob(Sysmap[btop(base)].pg_pfnum) + (base & PGOFSET);
223 return (lseek(fd, base, off));
229 fprintf(stderr,"usage: pppstats [-i interval] [-v] [unit] [system] [core]\n");
233 u_char signalled; /* set if alarm goes off "early" */
235 #define V(offset) ((line % 20)? sc->offset - osc->offset : sc->offset)
238 #define STRUCT struct ppp_if_info
239 #define COMP pii_sc_comp
240 #define STATS pii_ifnet
242 #define STRUCT struct ppp_softc
248 * Print a running summary of interface statistics.
249 * Repeat display every interval seconds, showing statistics
250 * collected over that interval. Assumes that interval is non-zero.
251 * First line printed at top of screen is always cumulative.
255 register int line = 0;
258 void catchalarm(int);
265 nl[N_SOFTC].n_value += unit * sizeof(STRUCT);
266 sc = (STRUCT *)malloc(sizeof(STRUCT));
267 osc = (STRUCT *)malloc(sizeof(STRUCT));
269 bzero((char *)osc, sizeof(STRUCT));
273 if (klseek(kmem, (off_t)nl[N_SOFTC].n_value, 0) == -1) {
277 if (read(kmem, (char *)sc, sizeof(STRUCT)) <= 0) {
282 if (kvm_read(KDARG nl[N_SOFTC].n_value, sc,
283 sizeof(STRUCT)) != sizeof(STRUCT)) {
289 (void)signal(SIGALRM, catchalarm);
291 (void)alarm(interval);
293 if ((line % 20) == 0) {
294 printf("%6.6s %6.6s %6.6s %6.6s %6.6s",
295 "in", "pack", "comp", "uncomp", "err");
297 printf(" %6.6s %6.6s", "toss", "ip");
298 printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s",
299 "out", "pack", "comp", "uncomp", "ip");
301 printf(" %6.6s %6.6s", "search", "miss");
305 printf("%6d %6d %6d %6d %6d",
313 V(pii_stats.ppp_ibytes),
319 V(STATS.if_ipackets),
320 V(COMP.sls_compressedin),
321 V(COMP.sls_uncompressedin),
322 V(COMP.sls_errorin));
326 V(STATS.if_ipackets) - V(COMP.sls_compressedin) -
327 V(COMP.sls_uncompressedin) - V(COMP.sls_errorin));
328 printf(" | %6d %6d %6d %6d %6d",
336 V(pii_stats.ppp_obytes),
342 V(STATS.if_opackets),
343 V(COMP.sls_compressed),
344 V(COMP.sls_packets) - V(COMP.sls_compressed),
345 V(STATS.if_opackets) - V(COMP.sls_packets));
348 V(COMP.sls_searches),
355 oldmask = sigblock(sigmask(SIGALRM));
361 (void)alarm(interval);
362 bcopy((char *)sc, (char *)osc, sizeof(STRUCT));
367 * Called if an interval expires before sidewaysintpr has completed a loop.
368 * Sets a flag to not wait for the alarm.