4.4BSD snapshot (revision 8.1)
[unix-history] / usr / src / usr.bin / vmstat.sparc / sum.c
CommitLineData
e08a6384
CT
1/*
2 * Copyright (c) 1992 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#ifndef lint
9static char sccsid[] = "@(#)sum.c 5.1 (Berkeley) %G%";
10#endif /* not lint */
11
12#include <sys/param.h>
13#include <sys/uio.h>
14#include <sys/namei.h>
15
16#include <errno.h>
17#include <kvm.h>
18#include <limits.h>
19#include <nlist.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23
24#include <vm/vm.h>
25
26#ifdef tahoe
27#include <machine/cpu.h>
28#endif
29
30#include "extern.h"
31
32int pct __P((long, long));
33
34#define PCT(top, bot) pct((long)(top), (long)(bot))
35
36static struct nlist nl[] = {
37#define X_CNT 0
38 { "_cnt" },
39#define X_NCHSTATS 1
40 { "_nchstats" },
41#ifdef tahoe /* XXX */
42#define X_CKEYSTATS 2
43 { "_ckeystats" },
44#define X_DKEYSTATS 3
45 { "_dkeystats" },
46#endif
47 0
48};
49
50void
51dosum()
52{
53 long nchtotal;
54 struct nchstats nchstats;
55 struct vmmeter cnt;
56#ifdef tahoe
57 struct keystats keystats;
58#endif
59
60 knlist(nl);
61 kread(nl[X_CNT].n_value, &cnt, sizeof cnt, "cnt");
62 (void)printf("%9u cpu context switches\n", cnt.v_swtch);
63 (void)printf("%9u device interrupts\n", cnt.v_intr);
64 (void)printf("%9u software interrupts\n", cnt.v_soft);
65#ifdef vax
66 (void)printf("%9u pseudo-dma dz interrupts\n", cnt.v_pdma);
67#endif
68 (void)printf("%9u traps\n", cnt.v_trap);
69 (void)printf("%9u system calls\n", cnt.v_syscall);
70 (void)printf("%9u total faults taken\n", cnt.v_faults);
71 (void)printf("%9u swap ins\n", cnt.v_swpin);
72 (void)printf("%9u swap outs\n", cnt.v_swpout);
73 (void)printf("%9u pages swapped in\n", cnt.v_pswpin / CLSIZE);
74 (void)printf("%9u pages swapped out\n", cnt.v_pswpout / CLSIZE);
75 (void)printf("%9u page ins\n", cnt.v_pageins);
76 (void)printf("%9u page outs\n", cnt.v_pageouts);
77 (void)printf("%9u pages paged in\n", cnt.v_pgpgin);
78 (void)printf("%9u pages paged out\n", cnt.v_pgpgout);
79 (void)printf("%9u pages reactivated\n", cnt.v_reactivated);
80 (void)printf("%9u intransit blocking page faults\n", cnt.v_intrans);
81 (void)printf("%9u zero fill pages created\n", cnt.v_nzfod / CLSIZE);
82 (void)printf("%9u zero fill page faults\n", cnt.v_zfod / CLSIZE);
83 (void)printf("%9u pages examined by the clock daemon\n", cnt.v_scan);
84 (void)printf("%9u revolutions of the clock hand\n", cnt.v_rev);
85 (void)printf("%9u VM object cache lookups\n", cnt.v_lookups);
86 (void)printf("%9u VM object hits\n", cnt.v_hits);
87 (void)printf("%9u total VM faults taken\n", cnt.v_vm_faults);
88 (void)printf("%9u copy-on-write faults\n", cnt.v_cow_faults);
89 (void)printf("%9u pages freed by daemon\n", cnt.v_dfree);
90 (void)printf("%9u pages freed by exiting processes\n", cnt.v_pfree);
91 (void)printf("%9u pages free\n", cnt.v_free_count);
92 (void)printf("%9u pages wired down\n", cnt.v_wire_count);
93 (void)printf("%9u pages active\n", cnt.v_active_count);
94 (void)printf("%9u pages inactive\n", cnt.v_inactive_count);
95 (void)printf("%9u bytes per page\n", cnt.v_page_size);
96 kread(nl[X_NCHSTATS].n_value, &nchstats, sizeof nchstats, "nchstats");
97 nchtotal = nchstats.ncs_goodhits + nchstats.ncs_neghits +
98 nchstats.ncs_badhits + nchstats.ncs_falsehits +
99 nchstats.ncs_miss + nchstats.ncs_long;
100 (void)printf("%9ld total name lookups\n", nchtotal);
101 (void)printf(
102 "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n",
103 "", PCT(nchstats.ncs_goodhits, nchtotal),
104 PCT(nchstats.ncs_neghits, nchtotal),
105 PCT(nchstats.ncs_pass2, nchtotal));
106 (void)printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "",
107 PCT(nchstats.ncs_badhits, nchtotal),
108 PCT(nchstats.ncs_falsehits, nchtotal),
109 PCT(nchstats.ncs_long, nchtotal));
110#if defined(tahoe)
111 kread(nl[X_CKEYSTATS].n_value, &keystats, sizeof keystats, "ckeystats");
112 (void)printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n",
113 keystats.ks_allocs, "code cache keys allocated",
114 PCT(keystats.ks_allocfree, keystats.ks_allocs),
115 PCT(keystats.ks_norefs, keystats.ks_allocs),
116 PCT(keystats.ks_taken, keystats.ks_allocs),
117 PCT(keystats.ks_shared, keystats.ks_allocs));
118 kread(nl[X_DKEYSTATS].n_value, &keystats, sizeof keystats, "ckeystats");
119 (void)printf("%9d %s (free %d%% norefs %d%% taken %d%% shared %d%%)\n",
120 keystats.ks_allocs, "data cache keys allocated",
121 PCT(keystats.ks_allocfree, keystats.ks_allocs),
122 PCT(keystats.ks_norefs, keystats.ks_allocs),
123 PCT(keystats.ks_taken, keystats.ks_allocs),
124 PCT(keystats.ks_shared, keystats.ks_allocs));
125#endif
126}
127
128int
129pct(top, bot)
130 long top, bot;
131{
132 if (bot == 0)
133 return (0);
134 if (bot > (LONG_MAX / 100))
135 return (top / (bot / 100));
136 return ((top * 100) / bot);
137}