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.4 1994/06/08 00:38:49 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>
52 #include <net/if_ppp.h>
56 #define PPP_STATS 1 /* should be defined iff it is in ppp_if.c */
57 #include <sys/stream.h>
58 #include <net/ppp_str.h>
67 #include <machine/pte.h>
69 #include <machine/cpu.h>
74 char *kmemf = "/dev/kmem";
107 char *system = "/vmunix";
110 char *system = _PATH_UNIX;
115 unsigned interval = 5;
118 extern char *malloc();
126 if (strcmp(argv[0], "-v") == 0) {
131 if (strcmp(argv[0], "-i") == 0 && argv[1] &&
132 isdigit(argv[1][0])) {
133 interval = atoi(argv[1]);
140 if (isdigit(argv[0][0])) {
141 unit = atoi(argv[0]);
159 if (nlist(system, nl) < 0 || nl[0].n_type == 0) {
160 fprintf(stderr, "%s: no namelist\n", system);
163 kmem = open(kmemf, O_RDONLY);
172 Sysmap = (struct pte *)
173 malloc((u_int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
175 fputs("netstat: can't get memory for Sysmap.\n", stderr);
178 off = nl[N_SYSMAP].n_value & ~KERNBASE;
179 (void)lseek(kmem, off, L_SET);
180 (void)read(kmem, (char *)Sysmap,
181 (int)(nl[N_SYSSIZE].n_value * sizeof(struct pte)));
187 if ((kd = kvm_open(system, kmemf, (char *)0, O_RDONLY, NULL)) == NULL) {
193 if (kvm_openfiles(system, kmemf, (char *)0) == -1) {
194 fprintf(stderr, "kvm_openfiles: %s", kvm_geterr());
199 if (kvm_nlist(KDARG nl)) {
200 fprintf(stderr, "pppstats: can't find symbols in nlist\n");
210 * Seek into the kernel for a value.
213 klseek(fd, base, off)
219 base = K0_TO_PHYS(base);
223 base = ctob(Sysmap[btop(base)].pg_pfnum) + (base & PGOFSET);
226 return (lseek(fd, base, off));
232 fprintf(stderr,"usage: pppstats [-i interval] [-v] [unit] [system] [core]\n");
236 u_char signalled; /* set if alarm goes off "early" */
238 #define V(offset) ((line % 20)? sc->offset - osc->offset : sc->offset)
241 #define STRUCT struct ppp_if_info
242 #define COMP pii_sc_comp
243 #define STATS pii_ifnet
245 #define STRUCT struct ppp_softc
251 * Print a running summary of interface statistics.
252 * Repeat display every interval seconds, showing statistics
253 * collected over that interval. Assumes that interval is non-zero.
254 * First line printed at top of screen is always cumulative.
258 register int line = 0;
261 void catchalarm(int);
268 nl[N_SOFTC].n_value += unit * sizeof(STRUCT);
269 sc = (STRUCT *)malloc(sizeof(STRUCT));
270 osc = (STRUCT *)malloc(sizeof(STRUCT));
272 bzero((char *)osc, sizeof(STRUCT));
276 if (klseek(kmem, (off_t)nl[N_SOFTC].n_value, 0) == -1) {
280 if (read(kmem, (char *)sc, sizeof(STRUCT)) <= 0) {
285 if (kvm_read(KDARG nl[N_SOFTC].n_value, sc,
286 sizeof(STRUCT)) != sizeof(STRUCT)) {
292 (void)signal(SIGALRM, catchalarm);
294 (void)alarm(interval);
296 if ((line % 20) == 0) {
297 printf("%6.6s %6.6s %6.6s %6.6s %6.6s",
298 "in", "pack", "comp", "uncomp", "err");
300 printf(" %6.6s %6.6s", "toss", "ip");
301 printf(" | %6.6s %6.6s %6.6s %6.6s %6.6s",
302 "out", "pack", "comp", "uncomp", "ip");
304 printf(" %6.6s %6.6s", "search", "miss");
308 printf("%6d %6d %6d %6d %6d",
316 V(pii_stats.ppp_ibytes),
322 V(STATS.if_ipackets),
323 V(COMP.sls_compressedin),
324 V(COMP.sls_uncompressedin),
325 V(COMP.sls_errorin));
329 V(STATS.if_ipackets) - V(COMP.sls_compressedin) -
330 V(COMP.sls_uncompressedin) - V(COMP.sls_errorin));
331 printf(" | %6d %6d %6d %6d %6d",
339 V(pii_stats.ppp_obytes),
345 V(STATS.if_opackets),
346 V(COMP.sls_compressed),
347 V(COMP.sls_packets) - V(COMP.sls_compressed),
348 V(STATS.if_opackets) - V(COMP.sls_packets));
351 V(COMP.sls_searches),
358 oldmask = sigblock(sigmask(SIGALRM));
364 (void)alarm(interval);
365 bcopy((char *)sc, (char *)osc, sizeof(STRUCT));
370 * Called if an interval expires before sidewaysintpr has completed a loop.
371 * Sets a flag to not wait for the alarm.