1 /* 2 * Copyright (c) 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)intr.c 8.1 (Berkeley) 06/06/93"; 10 #endif /* not lint */ 11 12 #include <sys/types.h> 13 14 #include <errno.h> 15 #include <kvm.h> 16 #include <nlist.h> 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <string.h> 20 21 #include "extern.h" 22 23 static struct nlist nl[] = { 24 { "_intrcnt" }, 25 #define X_INTRCNT 0 26 { "_eintrcnt" }, 27 #define X_EINTRCNT 1 28 { "_intrnames" }, 29 #define X_INTRNAMES 2 30 { "_eintrnames" }, 31 #define X_EINTRNAMES 3 32 0 33 }; 34 35 void 36 dointr() 37 { 38 register long *intrcnt, inttotal, uptime; 39 register int nintr, inamlen; 40 register char *intrname; 41 42 knlist(nl); 43 uptime = getuptime(); 44 nintr = nl[X_EINTRCNT].n_value - nl[X_INTRCNT].n_value; 45 inamlen = nl[X_EINTRNAMES].n_value - nl[X_INTRNAMES].n_value; 46 intrcnt = malloc((size_t)nintr); 47 intrname = malloc((size_t)inamlen); 48 if (intrcnt == NULL || intrname == NULL) 49 errexit("malloc: %s\n", strerror(errno)); 50 kread(nl[X_INTRCNT].n_value, intrcnt, nintr, "intrcnt"); 51 kread(nl[X_INTRNAMES].n_value, intrname, inamlen, "intrnames"); 52 (void)printf("interrupt total rate\n"); 53 inttotal = 0; 54 nintr /= sizeof(long); 55 while (--nintr >= 0) { 56 if (*intrcnt) 57 (void)printf("%-12s %8ld %8ld\n", intrname, 58 *intrcnt, *intrcnt / uptime); 59 intrname += strlen(intrname) + 1; 60 inttotal += *intrcnt++; 61 } 62 (void)printf("Total %8ld %8ld\n", inttotal, inttotal / uptime); 63 } 64