2 * Copyright (c) 1983, 1989, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Cursed vmstat -- from Robert Elz.
35 #include <sys/param.h>
39 #include <sys/namei.h>
40 #include <sys/sysctl.h>
41 #include <sys/vmmeter.h>
43 #include <vm/vm_param.h>
58 #include "utmpentry.h"
67 struct kinfo_cputime cp_time
;
71 struct nchstats nchstats
;
82 struct kvm_swap kvmsw
[NKVMSW
];
85 struct kinfo_cputime cp_time
, old_cp_time
;
86 struct statinfo cur
, last
, run
;
94 #define nchtotal s.nchstats
95 #define oldnchtotal s1.nchstats
97 static enum state
{ BOOT
, TIME
, RUN
} state
= TIME
;
99 static void allocinfo(struct Info
*);
100 static void copyinfo(struct Info
*, struct Info
*);
101 static void dinfo(int, int, struct statinfo
*, struct statinfo
*);
102 static void getinfo(struct Info
*);
103 static void put64(int64_t, int, int, int, int);
104 static void putfloat(double, int, int, int, int, int);
105 static void putlongdouble(long double, int, int, int, int, int);
106 static void putlongdoublez(long double, int, int, int, int, int);
107 static int ucount(void);
114 static int *intralias
;
116 static long *intrloc
;
118 static char **intrname
;
119 static int nextintsrow
;
120 static int extended_vm_stats
;
142 static struct nlist namelist
[] = {
143 #define X_BUFFERSPACE 0
144 { .n_name
= "_bufspace" },
146 { .n_name
= "_nchstats" },
147 #define X_DESIREDVNODES 2
148 { .n_name
= "_maxvnodes" },
149 #define X_CACHEDVNODES 3
150 { .n_name
= "_cachedvnodes" },
151 #define X_INACTIVEVNODES 4
152 { .n_name
= "_inactivevnodes" },
153 #define X_ACTIVEVNODES 5
154 { .n_name
= "_activevnodes" },
155 #define X_NUMDIRTYBUFFERS 6
156 { .n_name
= "_dirtybufspace" },
161 * These constants define where the major pieces are laid out
163 #define STATROW 0 /* uses 1 row and 68 cols */
165 #define MEMROW 2 /* uses 4 rows and 31 cols */
168 #define PAGEROW 2 /* uses 4 rows and 26 cols */
170 #define INTSROW 6 /* uses all rows to bottom and 17 cols */
172 #define PROCSROW 7 /* uses 2 rows and 20 cols */
174 #define GENSTATROW 7 /* uses 2 rows and 30 cols */
175 #define GENSTATCOL 16
176 #define VMSTATROW 6 /* uses 17 rows and 12 cols */
178 #define GRAPHROW 10 /* uses 3 rows and 51 cols */
180 #define NAMEIROW 14 /* uses 3 rows and 38 cols */
182 #define EXECROW 14 /* uses 2 rows and 5 cols */
184 #define DISKROW 17 /* uses 6 rows and 50 cols (for 9 drives) */
187 #define DRIVESPACE 7 /* max # for space */
189 #define MAXDRIVES DRIVESPACE /* max # to display */
193 findintralias(const char *name
, int limit
)
200 for (i
= 0; i
< limit
; ++i
) {
201 if (strcmp(name
, intrname
[i
]) == 0)
203 ilen
= strlen(intrname
[i
]);
206 strncmp(name
, intrname
[i
], nlen
- 1) == 0 &&
208 isdigit(name
[nlen
- 1]) &&
209 (isdigit(intrname
[i
][nlen
- 1]) ||
210 intrname
[i
][nlen
- 1] == '*')) {
211 intrname
[i
][nlen
- 1] = '*';
226 if (namelist
[0].n_type
== 0) {
227 if (kvm_nlist(kd
, namelist
)) {
231 if (namelist
[0].n_type
== 0) {
232 error("No namelist");
237 if ((num_devices
= getnumdevs()) < 0) {
238 warnx("%s", devstat_errbuf
);
242 cur
.dinfo
= (struct devinfo
*)malloc(sizeof(struct devinfo
));
243 last
.dinfo
= (struct devinfo
*)malloc(sizeof(struct devinfo
));
244 run
.dinfo
= (struct devinfo
*)malloc(sizeof(struct devinfo
));
245 bzero(cur
.dinfo
, sizeof(struct devinfo
));
246 bzero(last
.dinfo
, sizeof(struct devinfo
));
247 bzero(run
.dinfo
, sizeof(struct devinfo
));
249 if (dsinit(MAXDRIVES
, &cur
, &last
, &run
) != 1)
253 if (sysctlbyname("hw.intrnames", NULL
, &bytes
, NULL
, 0) == 0) {
254 intrnamebuf
= malloc(bytes
);
255 sysctlbyname("hw.intrnames", intrnamebuf
, &bytes
,
257 for (i
= 0; i
< bytes
; ++i
) {
258 if (intrnamebuf
[i
] == 0)
261 intrname
= malloc(nintr
* sizeof(char *));
262 intrloc
= malloc(nintr
* sizeof(*intrloc
));
263 lacc
= malloc(nintr
* sizeof(*lacc
));
264 intralias
= malloc(nintr
* sizeof(*intralias
));
265 intrsmp
= malloc(nintr
* sizeof(*intrsmp
));
266 bzero(intrsmp
, nintr
* sizeof(*intrsmp
));
269 for (b
= i
= 0; i
< bytes
; ++i
) {
270 if (intrnamebuf
[i
] == 0) {
271 intrname
[nintr
] = intrnamebuf
+ b
;
274 findintralias(intrname
[nintr
], nintr
);
275 ++intrsmp
[intralias
[nintr
]];
281 nextintsrow
= INTSROW
+ 2;
297 static int d_first
= -1;
300 d_first
= (*nl_langinfo(D_MD_ORDER
) == 'd');
303 tp
= localtime(&now
);
304 (void) strftime(buf
, sizeof(buf
),
305 d_first
? "%e %b %R" : "%b %e %R", tp
);
315 mvprintw(STATROW
, STATCOL
+ 4, "users Load");
316 mvprintw(MEMROW
+ 0, MEMCOLA
, "Active ");
317 mvprintw(MEMROW
+ 1, MEMCOLA
, "Kernel ");
318 mvprintw(MEMROW
+ 2, MEMCOLA
, "Free ");
319 mvprintw(MEMROW
+ 3, MEMCOLA
, "Total ");
321 mvprintw(MEMROW
+ 0, MEMCOLB
, "VM-rss");
322 mvprintw(MEMROW
+ 1, MEMCOLB
, "VM-swp");
323 mvprintw(MEMROW
+ 1, MEMCOLB
+ 15, "/");
325 mvprintw(PAGEROW
, PAGECOL
, " VN PAGER SWAP PAGER ");
326 mvprintw(PAGEROW
+ 1, PAGECOL
, " in out in out ");
327 mvprintw(PAGEROW
+ 2, PAGECOL
, "bytes");
328 mvprintw(PAGEROW
+ 3, PAGECOL
, "count");
330 mvprintw(INTSROW
, INTSCOL
+ 3, " Interrupts");
331 mvprintw(INTSROW
+ 1, INTSCOL
+ 9, "total");
333 mvprintw(VMSTATROW
+ 1, VMSTATCOL
+ 8, "cow");
334 mvprintw(VMSTATROW
+ 2, VMSTATCOL
+ 8, "wire");
335 mvprintw(VMSTATROW
+ 3, VMSTATCOL
+ 8, "act");
336 mvprintw(VMSTATROW
+ 4, VMSTATCOL
+ 8, "inact");
337 mvprintw(VMSTATROW
+ 5, VMSTATCOL
+ 8, "cache");
338 mvprintw(VMSTATROW
+ 6, VMSTATCOL
+ 8, "free");
339 mvprintw(VMSTATROW
+ 7, VMSTATCOL
+ 8, "daefr");
340 mvprintw(VMSTATROW
+ 8, VMSTATCOL
+ 8, "prcfr");
341 mvprintw(VMSTATROW
+ 9, VMSTATCOL
+ 8, "react");
342 mvprintw(VMSTATROW
+ 10, VMSTATCOL
+ 8, "pdwake");
343 mvprintw(VMSTATROW
+ 11, VMSTATCOL
+ 8, "pdpgs");
344 mvprintw(VMSTATROW
+ 12, VMSTATCOL
+ 8, "intrn");
345 mvprintw(VMSTATROW
+ 13, VMSTATCOL
+ 8, "buf");
346 mvprintw(VMSTATROW
+ 14, VMSTATCOL
+ 8, "dirtybuf");
348 mvprintw(VMSTATROW
+ 15, VMSTATCOL
+ 8, "activ-vp");
349 mvprintw(VMSTATROW
+ 16, VMSTATCOL
+ 8, "cachd-vp");
350 mvprintw(VMSTATROW
+ 17, VMSTATCOL
+ 8, "inact-vp");
352 mvprintw(GENSTATROW
, GENSTATCOL
, " Csw Trp Sys Int Sof Flt");
354 mvprintw(GRAPHROW
, GRAPHCOL
,
355 " . %%Sys . %%Intr . %%User . %%Nice . %%Idle");
356 mvprintw(PROCSROW
, PROCSCOL
, " r p d s");
357 mvprintw(GRAPHROW
+ 1, GRAPHCOL
,
358 "| | | | | | | | | | |");
360 mvprintw(NAMEIROW
, NAMEICOL
, "Path-lookups hits %% Components");
361 mvprintw(EXECROW
, EXECCOL
, "Execs");
362 mvprintw(DISKROW
, DISKCOL
, "Disks");
363 mvprintw(DISKROW
+ 1, DISKCOL
, "KB/t");
364 mvprintw(DISKROW
+ 2, DISKCOL
, "tpr/s");
365 mvprintw(DISKROW
+ 3, DISKCOL
, "MBr/s");
366 mvprintw(DISKROW
+ 4, DISKCOL
, "tpw/s");
367 mvprintw(DISKROW
+ 5, DISKCOL
, "MBw/s");
368 mvprintw(DISKROW
+ 6, DISKCOL
, "%% busy");
371 * For now, we don't support a fourth disk statistic. So there's
372 * no point in providing a label for it. If someone can think of a
373 * fourth useful disk statistic, there is room to add it.
376 for (i
= 0; i
< num_devices
&& j
< MAXDRIVES
; i
++)
377 if (dev_select
[i
].selected
) {
379 sprintf(tmpstr
, "%s%d", dev_select
[i
].device_name
,
380 dev_select
[i
].unit_number
);
381 mvprintw(DISKROW
, DISKCOL
+ 5 + 6 * j
,
388 * room for extended VM stats
390 mvprintw(VMSTATROW
+ 11, VMSTATCOL
- 6, "nzfod");
391 mvprintw(VMSTATROW
+ 12, VMSTATCOL
- 6, "ozfod");
392 mvprintw(VMSTATROW
+ 13, VMSTATCOL
- 6, "%%zslo");
393 mvprintw(VMSTATROW
+ 14, VMSTATCOL
- 6, "pgfre");
394 extended_vm_stats
= 1;
396 extended_vm_stats
= 0;
397 mvprintw(VMSTATROW
+ 0, VMSTATCOL
+ 8, "zfod");
400 for (i
= 0; i
< nintr
; i
++) {
403 mvprintw(intrloc
[i
], INTSCOL
+ 9, "%-10.10s", intrname
[i
]);
407 #define CP_UPDATE(fld) do { \
419 #define X(fld) {t=s.fld[i]; s.fld[i]-=s1.fld[i]; if(state==TIME) s1.fld[i]=t;}
420 #define Y(fld) {t = s.fld; s.fld -= s1.fld; if(state == TIME) s1.fld = t;}
421 #define Z(fld) {t = s.nchstats.fld; s.nchstats.fld -= s1.nchstats.fld; \
422 if(state == TIME) s1.nchstats.fld = t;}
423 #define PUTRATE(fld, l, c, w) \
425 put64((int64_t)((float)s.fld/etime + 0.5), l, c, w, 'D')
426 #define PUTRATE_PGTOB(fld, l, c, w) \
428 put64((int64_t)((float)s.fld/etime + 0.5) * PAGE_SIZE, l, c, w, 0)
432 static const char cpuchar
[5] = { '=' , '+', '>', '-', ' ' };
434 static const size_t cpuoffsets
[] = {
435 offsetof(struct kinfo_cputime
, cp_sys
),
436 offsetof(struct kinfo_cputime
, cp_intr
),
437 offsetof(struct kinfo_cputime
, cp_user
),
438 offsetof(struct kinfo_cputime
, cp_nice
),
439 offsetof(struct kinfo_cputime
, cp_idle
)
450 static int failcnt
= 0;
454 CP_UPDATE(cp_time
.cp_user
);
455 CP_UPDATE(cp_time
.cp_nice
);
456 CP_UPDATE(cp_time
.cp_sys
);
457 CP_UPDATE(cp_time
.cp_intr
);
458 CP_UPDATE(cp_time
.cp_idle
);
461 if (total_time
== 0.0)
464 if (etime
< 100000.0) { /* < 100ms ignore this trash */
465 if (failcnt
++ >= MAXFAIL
) {
467 mvprintw(2, 10, "The alternate system clock has died!");
468 mvprintw(3, 10, "Reverting to ``pigs'' display.");
483 bzero(lacc
, nintr
* sizeof(*lacc
));
485 for (i
= 0; i
< nintr
; i
++) {
486 if (s
.intrcnt
[i
] == 0)
489 if (intrloc
[j
] == 0) {
490 if (nextintsrow
== LINES
)
492 intrloc
[j
] = nextintsrow
++;
493 mvprintw(intrloc
[j
], INTSCOL
+ 9, "%-10.10s",
497 l
= (long)((float)s
.intrcnt
[i
]/etime
+ 0.5);
500 put64(lacc
[j
], intrloc
[j
], INTSCOL
+ 3, 5, 'D');
502 put64(inttotal
, INTSROW
+ 1, INTSCOL
+ 3, 5, 'D');
503 Z(ncs_goodhits
); Z(ncs_badhits
); Z(ncs_miss
);
504 Z(ncs_longhits
); Z(ncs_longmiss
); Z(ncs_neghits
);
505 s
.nchcount
= nchtotal
.ncs_goodhits
+ nchtotal
.ncs_badhits
+
506 nchtotal
.ncs_miss
+ nchtotal
.ncs_neghits
;
507 s
.nchpathcount
= nchtotal
.ncs_longhits
+ nchtotal
.ncs_longmiss
;
509 s1
.nchcount
= s
.nchcount
;
510 s1
.nchpathcount
= s
.nchpathcount
;
513 #define LOADCOLS 49 /* Don't but into the 'free' value */
514 #define LOADRANGE (100.0 / LOADCOLS)
518 for (lc
= 0; lc
< CPUSTATES
; lc
++) {
519 uint64_t val
= *(uint64_t *)(((uint8_t *)&s
.cp_time
) +
521 f1
= 100.0 * val
/ total_time
;
523 l
= (int)((f2
+ (LOADRANGE
/ 2.0)) / LOADRANGE
) - psiz
;
525 f1
= 99.9; /* no room to display 100.0 */
526 putfloat(f1
, GRAPHROW
, GRAPHCOL
+ 10 * lc
, 4, 1, 0);
527 move(GRAPHROW
+ 2, psiz
);
533 put64(ucount(), STATROW
, STATCOL
, 3, 'D');
534 putfloat(avenrun
[0], STATROW
, STATCOL
+ 18, 6, 2, 0);
535 putfloat(avenrun
[1], STATROW
, STATCOL
+ 25, 6, 2, 0);
536 putfloat(avenrun
[2], STATROW
, STATCOL
+ 32, 6, 2, 0);
537 mvaddstr(STATROW
, STATCOL
+ 53, buf
);
538 #define pgtokb(pg) (int64_t)((intmax_t)(pg) * vms.v_page_size / 1024)
539 #define pgtomb(pg) (int64_t)((intmax_t)(pg) * vms.v_page_size / (1024 * 1024))
540 #define pgtob(pg) (int64_t)((intmax_t)(pg) * vms.v_page_size)
542 put64(pgtob(vms
.v_active_count
), MEMROW
+ 0, MEMCOLA
+ 7, 6, 0);
543 put64(pgtob(vms
.v_wire_count
), MEMROW
+ 1, MEMCOLA
+ 7, 6, 0); /*XXX*/
544 put64(pgtob(vms
.v_inactive_count
+
546 vms
.v_free_count
), MEMROW
+ 2, MEMCOLA
+ 7, 6, 0);
547 put64(s
.physmem
, MEMROW
+ 3, MEMCOLA
+ 7, 6, 0);
548 put64(pgtob(total
.t_rm
), MEMROW
+ 0, MEMCOLB
+ 7, 6, 0);
549 put64(pgtob(total
.t_vm
- total
.t_rm
), MEMROW
+ 1, MEMCOLB
+ 7, 6, 0);
550 put64(pgtob(s
.kvmsw
[kvnsw
].ksw_total
), MEMROW
+ 1, MEMCOLB
+ 17, 6, 0);
553 put64(pgtob(total
.t_arm
), MEMROW
+ 2, MEMCOL
+ 4, 6, 0);
554 put64(pgtob(total
.t_armshr
), MEMROW
+ 2, MEMCOL
+ 11, 6, 0);
555 put64(pgtob(total
.t_avm
), MEMROW
+ 2, MEMCOL
+ 19, 6, 0);
556 put64(pgtob(total
.t_avmshr
), MEMROW
+ 2, MEMCOL
+ 26, 6, 0);
557 put64(pgtob(total
.t_rm
), MEMROW
+ 3, MEMCOL
+ 4, 6, 0);
558 put64(pgtob(total
.t_rmshr
), MEMROW
+ 3, MEMCOL
+ 11, 6, 0);
559 put64(pgtob(total
.t_vm
), MEMROW
+ 3, MEMCOL
+ 19, 6, 0);
560 put64(pgtob(total
.t_vmshr
), MEMROW
+ 3, MEMCOL
+ 26, 6, 0);
561 put64(pgtob(total
.t_free
), MEMROW
+ 2, MEMCOL
+ 34, 6, 0);
564 put64(total
.t_rq
- 1, PROCSROW
+ 1, PROCSCOL
+ 0, 4, 'D');
565 put64(total
.t_pw
, PROCSROW
+ 1, PROCSCOL
+ 4, 4, 'D');
566 put64(total
.t_dw
, PROCSROW
+ 1, PROCSCOL
+ 8, 4, 'D');
567 put64(total
.t_sl
, PROCSROW
+ 1, PROCSCOL
+ 12, 4, 'D');
568 /*put64(total.t_sw, PROCSROW + 1, PROCSCOL + 12, 3, 'D');*/
569 if (extended_vm_stats
== 0) {
570 PUTRATE_PGTOB(Vmm
.v_zfod
, VMSTATROW
+ 0, VMSTATCOL
, 7);
572 PUTRATE_PGTOB(Vmm
.v_cow_faults
, VMSTATROW
+ 1, VMSTATCOL
, 7);
573 put64(pgtob(vms
.v_wire_count
), VMSTATROW
+ 2, VMSTATCOL
, 7, 0);
574 put64(pgtob(vms
.v_active_count
), VMSTATROW
+ 3, VMSTATCOL
, 7, 0);
575 put64(pgtob(vms
.v_inactive_count
), VMSTATROW
+ 4, VMSTATCOL
, 7, 0);
576 put64(pgtob(vms
.v_cache_count
), VMSTATROW
+ 5, VMSTATCOL
, 7, 0);
577 put64(pgtob(vms
.v_free_count
), VMSTATROW
+ 6, VMSTATCOL
, 7, 0);
578 PUTRATE(Vmm
.v_dfree
, VMSTATROW
+ 7, VMSTATCOL
, 7);
579 PUTRATE(Vmm
.v_pfree
, VMSTATROW
+ 8, VMSTATCOL
, 7);
580 PUTRATE(Vmm
.v_reactivated
, VMSTATROW
+ 9, VMSTATCOL
, 7);
581 PUTRATE(Vmm
.v_pdwakeups
, VMSTATROW
+ 10, VMSTATCOL
, 7);
582 PUTRATE(Vmm
.v_pdpages
, VMSTATROW
+ 11, VMSTATCOL
, 7);
583 PUTRATE(Vmm
.v_intrans
, VMSTATROW
+ 12, VMSTATCOL
, 7);
585 if (extended_vm_stats
) {
586 int64_t orig_zfod
= s
.Vmm
.v_zfod
;
587 s
.Vmm
.v_zfod
-= s
.Vmm
.v_ozfod
;
588 PUTRATE_PGTOB(Vmm
.v_zfod
, VMSTATROW
+ 11, VMSTATCOL
- 14, 7);
589 PUTRATE_PGTOB(Vmm
.v_ozfod
, VMSTATROW
+ 12, VMSTATCOL
- 14, 7);
590 #define nz(x) ((x) ? (x) : 1)
591 put64((s
.Vmm
.v_zfod
) * 100 / nz(orig_zfod
),
592 VMSTATROW
+ 13, VMSTATCOL
- 14, 7, 'D');
594 PUTRATE_PGTOB(Vmm
.v_tfree
, VMSTATROW
+ 14, VMSTATCOL
- 14, 7);
597 put64(s
.bufspace
, VMSTATROW
+ 13, VMSTATCOL
, 7, 0);
598 put64(s
.dirtybufspace
/1024, VMSTATROW
+ 14, VMSTATCOL
, 7, 'k');
599 put64(s
.activevnodes
, VMSTATROW
+ 15, VMSTATCOL
, 7, 'D');
600 put64(s
.cachedvnodes
, VMSTATROW
+ 16, VMSTATCOL
, 7, 'D');
601 put64(s
.inactivevnodes
, VMSTATROW
+ 17, VMSTATCOL
, 7, 'D');
602 PUTRATE_PGTOB(Vmm
.v_vnodepgsin
, PAGEROW
+ 2, PAGECOL
+ 7, 5);
603 PUTRATE_PGTOB(Vmm
.v_vnodepgsout
, PAGEROW
+ 2, PAGECOL
+ 13, 5);
604 PUTRATE_PGTOB(Vmm
.v_swappgsin
, PAGEROW
+ 2, PAGECOL
+ 21, 5);
605 PUTRATE_PGTOB(Vmm
.v_swappgsout
, PAGEROW
+ 2, PAGECOL
+ 27, 5);
606 PUTRATE(Vmm
.v_vnodein
, PAGEROW
+ 3, PAGECOL
+ 7, 5);
607 PUTRATE(Vmm
.v_vnodeout
, PAGEROW
+ 3, PAGECOL
+ 13, 5);
608 PUTRATE(Vmm
.v_swapin
, PAGEROW
+ 3, PAGECOL
+ 21, 5);
609 PUTRATE(Vmm
.v_swapout
, PAGEROW
+ 3, PAGECOL
+ 27, 5);
610 PUTRATE(Vmm
.v_swtch
, GENSTATROW
+ 1, GENSTATCOL
+ 1, 4);
611 PUTRATE(Vmm
.v_trap
, GENSTATROW
+ 1, GENSTATCOL
+ 6, 4);
612 PUTRATE(Vmm
.v_syscall
, GENSTATROW
+ 1, GENSTATCOL
+ 11, 4);
613 PUTRATE(Vmm
.v_intr
, GENSTATROW
+ 1, GENSTATCOL
+ 16, 4);
614 PUTRATE(Vmm
.v_soft
, GENSTATROW
+ 1, GENSTATCOL
+ 21, 4);
615 PUTRATE(Vmm
.v_vm_faults
, GENSTATROW
+ 1, GENSTATCOL
+ 26, 4);
616 mvprintw(DISKROW
, DISKCOL
+ 5, " ");
617 for (i
= 0, lc
= 0; i
< num_devices
&& lc
< MAXDRIVES
; i
++)
618 if (dev_select
[i
].selected
) {
620 sprintf(tmpstr
, "%s%d", dev_select
[i
].device_name
,
621 dev_select
[i
].unit_number
);
622 mvprintw(DISKROW
, DISKCOL
+ 5 + 6 * lc
,
626 dinfo(i
, ++lc
, &cur
, &last
);
629 dinfo(i
, ++lc
, &cur
, &run
);
632 dinfo(i
, ++lc
, &cur
, NULL
);
636 #define nz(x) ((x) ? (x) : 1)
637 put64(s
.nchpathcount
, NAMEIROW
+ 1, NAMEICOL
+ 6, 6, 'D');
638 PUTRATE(Vmm
.v_exec
, EXECROW
+ 1, EXECCOL
, 5);
639 put64(nchtotal
.ncs_longhits
, NAMEIROW
+ 1, NAMEICOL
+ 13, 6, 'D');
640 putfloat(nchtotal
.ncs_longhits
* 100.0 / nz(s
.nchpathcount
),
641 NAMEIROW
+ 1, NAMEICOL
+ 19, 4, 0, 0);
643 putfloat((double)s
.nchcount
/ nz(s
.nchpathcount
),
644 NAMEIROW
+ 1, NAMEICOL
+ 27, 5, 2, 1);
649 cmdkre(const char *cmd
, char *args
)
653 if (prefix(cmd
, "run")) {
656 switch (getdevs(&run
)) {
658 errx(1, "%s", devstat_errbuf
);
661 num_devices
= run
.dinfo
->numdevs
;
662 generation
= run
.dinfo
->generation
;
663 retval
= dscmd("refresh", NULL
, MAXDRIVES
, &cur
);
673 if (prefix(cmd
, "boot")) {
678 if (prefix(cmd
, "time")) {
682 if (prefix(cmd
, "zero")) {
686 switch (getdevs(&run
)) {
688 errx(1, "%s", devstat_errbuf
);
691 num_devices
= run
.dinfo
->numdevs
;
692 generation
= run
.dinfo
->generation
;
693 retval
= dscmd("refresh",NULL
, MAXDRIVES
, &cur
);
703 retval
= dscmd(cmd
, args
, MAXDRIVES
, &cur
);
711 /* calculate number of users on the system */
715 struct utmpentry
*ep
= NULL
; /* avoid gcc warnings */
718 getutentries(NULL
, &ep
);
719 for (; ep
; ep
= ep
->next
)
726 put64(intmax_t n
, int l
, int lc
, int w
, int type
)
740 if (type
== 0 || type
== 'D')
741 snprintf(b
, sizeof(b
), "%*jd", w
, n
);
743 snprintf(b
, sizeof(b
), "%*jd%c", w
- 1, n
, type
);
744 if (strlen(b
) <= (size_t)w
) {
760 for (d
= 1; n
/ d
>= 1000; d
*= u
) {
787 else if (n
/ d
>= 10)
792 snprintf(b
+ 64, sizeof(b
) - 64, "%jd.%03jd%c",
793 n
/ d
, n
/ (d
/ 1000) % 1000, type
);
795 snprintf(b
+ 64, sizeof(b
) - 64, "%jd.%02jd%c",
796 n
/ d
, n
/ (d
/ 100) % 100, type
);
798 snprintf(b
+ 64, sizeof(b
) - 64, "%jd.%01jd%c",
799 n
/ d
, n
/ (d
/ 10) % 10, type
);
801 snprintf(b
+ 64, sizeof(b
) - 64, "%jd%c",
818 putfloat(double f
, int l
, int lc
, int w
, int d
, int nz
)
823 if (nz
&& f
== 0.0) {
828 snprintf(b
, sizeof(b
), "%*.*f", w
, d
, f
);
829 if (strlen(b
) > (size_t)w
)
830 snprintf(b
, sizeof(b
), "%*.0f", w
, f
);
831 if (strlen(b
) > (size_t)w
) {
840 putlongdouble(long double f
, int l
, int lc
, int w
, int d
, int nz
)
845 if (nz
&& f
== 0.0) {
850 sprintf(b
, "%*.*Lf", w
, d
, f
);
851 if (strlen(b
) > (size_t)w
)
852 sprintf(b
, "%*.0Lf", w
, f
);
853 if (strlen(b
) > (size_t)w
) {
862 putlongdoublez(long double f
, int l
, int lc
, int w
, int d
, int nz
)
868 sprintf(b
, "%*.*s", w
, w
, "");
871 putlongdouble(f
, l
, lc
, w
, d
, nz
);
876 getinfo(struct Info
*ls
)
878 struct devinfo
*tmp_dinfo
;
879 struct nchstats
*nch_tmp
;
881 size_t vms_size
= sizeof(ls
->Vms
);
882 size_t vmm_size
= sizeof(ls
->Vmm
);
883 size_t nch_size
= sizeof(ls
->nchstats
) * SMP_MAXCPU
;
884 size_t phys_size
= sizeof(ls
->physmem
);
886 kvnsw
= kvm_getswapinfo(kd
, ls
->kvmsw
, NKVMSW
, 0);
888 if (sysctlbyname("vm.vmstats", &ls
->Vms
, &vms_size
, NULL
, 0)) {
889 perror("sysctlbyname: vm.vmstats");
892 if (sysctlbyname("vm.vmmeter", &ls
->Vmm
, &vmm_size
, NULL
, 0)) {
893 perror("sysctlbyname: vm.vmstats");
896 if (sysctlbyname("hw.physmem", &ls
->physmem
, &phys_size
, NULL
, 0)) {
897 perror("sysctlbyname: hw.physmem");
901 if (kinfo_get_sched_cputime(&ls
->cp_time
))
902 err(1, "kinfo_get_sched_cputime");
903 if (kinfo_get_sched_cputime(&cp_time
))
904 err(1, "kinfo_get_sched_cputime");
905 NREAD(X_BUFFERSPACE
, &ls
->bufspace
, sizeof(ls
->bufspace
));
906 NREAD(X_DESIREDVNODES
, &ls
->maxvnodes
, sizeof(ls
->maxvnodes
));
907 NREAD(X_CACHEDVNODES
, &ls
->cachedvnodes
, sizeof(ls
->cachedvnodes
));
908 NREAD(X_INACTIVEVNODES
, &ls
->inactivevnodes
,
909 sizeof(ls
->inactivevnodes
));
910 NREAD(X_ACTIVEVNODES
, &ls
->activevnodes
, sizeof(ls
->activevnodes
));
911 NREAD(X_NUMDIRTYBUFFERS
, &ls
->dirtybufspace
, sizeof(ls
->dirtybufspace
));
914 size
= nintr
* sizeof(ls
->intrcnt
[0]);
915 sysctlbyname("hw.intrcnt_all", ls
->intrcnt
, &size
, NULL
, 0);
917 size
= sizeof(ls
->Total
);
918 if (sysctlbyname("vm.vmtotal", &ls
->Total
, &size
, NULL
, 0) < 0) {
919 error("Can't get kernel info: %s\n", strerror(errno
));
920 bzero(&ls
->Total
, sizeof(ls
->Total
));
923 if ((nch_tmp
= malloc(nch_size
)) == NULL
) {
927 if (sysctlbyname("vfs.cache.nchstats", nch_tmp
, &nch_size
, NULL
, 0)) {
928 perror("sysctlbyname vfs.cache.nchstats");
932 if ((nch_tmp
= realloc(nch_tmp
, nch_size
)) == NULL
) {
939 if (kinfo_get_cpus(&ncpu
))
940 err(1, "kinfo_get_cpus");
941 kvm_nch_cpuagg(nch_tmp
, &ls
->nchstats
, ncpu
);
944 tmp_dinfo
= last
.dinfo
;
945 last
.dinfo
= cur
.dinfo
;
946 cur
.dinfo
= tmp_dinfo
;
948 last
.busy_time
= cur
.busy_time
;
949 switch (getdevs(&cur
)) {
951 errx(1, "%s", devstat_errbuf
);
954 num_devices
= cur
.dinfo
->numdevs
;
955 generation
= cur
.dinfo
->generation
;
956 cmdkre("refresh", NULL
);
964 allocinfo(struct Info
*ls
)
966 ls
->intrcnt
= (long *) calloc(nintr
, sizeof(long));
967 if (ls
->intrcnt
== NULL
)
968 errx(2, "out of memory");
972 copyinfo(struct Info
*from
, struct Info
*to
)
977 * time, wds, seek, and xfer are malloc'd so we have to
978 * save the pointers before the structure copy and then
981 intrcnt
= to
->intrcnt
;
984 bcopy(from
->intrcnt
, to
->intrcnt
= intrcnt
, nintr
* sizeof (int));
988 dinfo(int dn
, int lc
, struct statinfo
*now
, struct statinfo
*then
)
990 long double kb_per_transfer
;
991 long double transfers_per_secondr
;
992 long double transfers_per_secondw
;
993 long double mb_per_secondr
;
994 long double mb_per_secondw
;
995 long double elapsed_time
, device_busy
;
998 di
= dev_select
[dn
].position
;
1000 elapsed_time
= compute_etime(now
->busy_time
, then
?
1002 now
->dinfo
->devices
[di
].dev_creation_time
);
1004 device_busy
= compute_etime(now
->dinfo
->devices
[di
].busy_time
, then
?
1005 then
->dinfo
->devices
[di
].busy_time
:
1006 now
->dinfo
->devices
[di
].dev_creation_time
);
1009 &now
->dinfo
->devices
[di
],
1010 (then
? &then
->dinfo
->devices
[di
] : NULL
),
1017 errx(1, "%s", devstat_errbuf
);
1019 if (compute_stats_read(
1020 &now
->dinfo
->devices
[di
],
1021 (then
? &then
->dinfo
->devices
[di
] : NULL
),
1025 &transfers_per_secondr
,
1028 errx(1, "%s", devstat_errbuf
);
1030 if (compute_stats_write(
1031 &now
->dinfo
->devices
[di
],
1032 (then
? &then
->dinfo
->devices
[di
] : NULL
),
1036 &transfers_per_secondw
,
1039 errx(1, "%s", devstat_errbuf
);
1043 * Remove this hack, it no longer works properly and will
1044 * report 100% busy in situations where the device is able
1045 * to respond to the requests faster than the busy counter's
1048 if ((device_busy
== 0) &&
1049 (transfers_per_secondr
> 5 || transfers_per_secondw
> 5)) {
1050 /* the device has been 100% busy, fake it because
1051 * as long as the device is 100% busy the busy_time
1052 * field in the devstat struct is not updated */
1053 device_busy
= elapsed_time
;
1056 if (device_busy
> elapsed_time
) {
1057 /* this normally happens after one or more periods
1058 * where the device has been 100% busy, correct it */
1059 device_busy
= elapsed_time
;
1062 lc
= DISKCOL
+ lc
* 6;
1063 putlongdoublez(kb_per_transfer
, DISKROW
+ 1, lc
, 5, 2, 0);
1064 putlongdoublez(transfers_per_secondr
, DISKROW
+ 2, lc
, 5, 0, 0);
1065 putlongdoublez(mb_per_secondr
, DISKROW
+ 3, lc
, 5, 2, 0);
1066 putlongdoublez(transfers_per_secondw
, DISKROW
+ 4, lc
, 5, 0, 0);
1067 putlongdoublez(mb_per_secondw
, DISKROW
+ 5, lc
, 5, 2, 0);
1068 putlongdouble(device_busy
* 100 / elapsed_time
,
1069 DISKROW
+ 6, lc
, 5, 0, 0);