Home | History | Annotate | Line # | Download | only in systat
syscall.c revision 1.1.2.1
      1  1.1.2.1  chap /*	$NetBSD: syscall.c,v 1.1.2.1 2006/06/19 04:17:07 chap Exp $	*/
      2      1.1   dsl 
      3      1.1   dsl /*-
      4      1.1   dsl  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5      1.1   dsl  * All rights reserved.
      6      1.1   dsl  *
      7      1.1   dsl  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1   dsl  * by David Laight.
      9      1.1   dsl  *
     10      1.1   dsl  * Redistribution and use in source and binary forms, with or without
     11      1.1   dsl  * modification, are permitted provided that the following conditions
     12      1.1   dsl  * are met:
     13      1.1   dsl  * 1. Redistributions of source code must retain the above copyright
     14      1.1   dsl  *    notice, this list of conditions and the following disclaimer.
     15      1.1   dsl  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1   dsl  *    notice, this list of conditions and the following disclaimer in the
     17      1.1   dsl  *    documentation and/or other materials provided with the distribution.
     18      1.1   dsl  * 3. Neither the name of The NetBSD Foundation nor the names of its
     19      1.1   dsl  *    contributors may be used to endorse or promote products derived
     20      1.1   dsl  *    from this software without specific prior written permission.
     21      1.1   dsl  *
     22      1.1   dsl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23      1.1   dsl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24      1.1   dsl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25      1.1   dsl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26      1.1   dsl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27      1.1   dsl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28      1.1   dsl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29      1.1   dsl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30      1.1   dsl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31      1.1   dsl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32      1.1   dsl  * POSSIBILITY OF SUCH DAMAGE.
     33      1.1   dsl  */
     34      1.1   dsl 
     35      1.1   dsl #include <sys/cdefs.h>
     36      1.1   dsl __RCSID("$NetBSD: syscall.c,v 1.1.2.1 2006/06/19 04:17:07 chap Exp $");
     37      1.1   dsl 
     38      1.1   dsl /* System call stats */
     39      1.1   dsl 
     40      1.1   dsl #include <sys/param.h>
     41      1.1   dsl #include <sys/user.h>
     42      1.1   dsl #include <sys/namei.h>
     43      1.1   dsl #include <sys/sysctl.h>
     44      1.1   dsl #include <sys/device.h>
     45      1.1   dsl 
     46      1.1   dsl #include <uvm/uvm_extern.h>
     47      1.1   dsl 
     48  1.1.2.1  chap #include <errno.h>
     49      1.1   dsl #include <stdlib.h>
     50      1.1   dsl #include <string.h>
     51      1.1   dsl #include <util.h>
     52      1.1   dsl 
     53      1.1   dsl #include "systat.h"
     54      1.1   dsl #include "extern.h"
     55  1.1.2.1  chap #include "drvstats.h"
     56      1.1   dsl #include "utmpentry.h"
     57      1.1   dsl #include "vmstat.h"
     58      1.1   dsl 
     59      1.1   dsl #include <sys/syscall.h>
     60      1.1   dsl #include <../../sys/kern/syscalls.c>
     61      1.1   dsl 
     62      1.1   dsl #define nelem(x) (sizeof (x) / sizeof *(x))
     63      1.1   dsl 
     64      1.1   dsl static struct Info {
     65  1.1.2.1  chap 	struct	 uvmexp_sysctl uvmexp;
     66  1.1.2.1  chap 	struct	 vmtotal Total;
     67  1.1.2.1  chap 	uint64_t counts[SYS_NSYSENT];
     68  1.1.2.1  chap 	uint64_t times[SYS_NSYSENT];
     69      1.1   dsl } s, s1, s2, irf;
     70      1.1   dsl 
     71      1.1   dsl int syscall_sort[SYS_NSYSENT];
     72      1.1   dsl 
     73      1.1   dsl static	enum sort_order { UNSORTED, NAMES, COUNTS } sort_order = NAMES;
     74      1.1   dsl 
     75  1.1.2.1  chap #define	SHOW_COUNTS	1
     76  1.1.2.1  chap #define	SHOW_TIMES	2
     77  1.1.2.1  chap static int show = SHOW_COUNTS;
     78  1.1.2.1  chap 
     79  1.1.2.1  chap static void getinfo(struct Info *, int);
     80      1.1   dsl 
     81      1.1   dsl static	char buf[26];
     82      1.1   dsl static	float hertz;
     83      1.1   dsl 
     84  1.1.2.1  chap static size_t counts_mib_len, times_mib_len;
     85  1.1.2.1  chap static int counts_mib[4], times_mib[4];
     86      1.1   dsl 
     87      1.1   dsl WINDOW *
     88      1.1   dsl opensyscall(void)
     89      1.1   dsl {
     90      1.1   dsl 	return (stdscr);
     91      1.1   dsl }
     92      1.1   dsl 
     93      1.1   dsl void
     94      1.1   dsl closesyscall(WINDOW *w)
     95      1.1   dsl {
     96      1.1   dsl 
     97      1.1   dsl 	if (w == NULL)
     98      1.1   dsl 		return;
     99      1.1   dsl 	wclear(w);
    100      1.1   dsl 	wrefresh(w);
    101      1.1   dsl }
    102      1.1   dsl 
    103      1.1   dsl 
    104      1.1   dsl /*
    105      1.1   dsl  * These constants define where the major pieces are laid out
    106      1.1   dsl  */
    107      1.1   dsl #define SYSCALLROW	9	/* Below the vmstat header */
    108      1.1   dsl 
    109      1.1   dsl int
    110      1.1   dsl initsyscall(void)
    111      1.1   dsl {
    112      1.1   dsl 	static char name[] = "name";
    113      1.1   dsl 
    114      1.1   dsl 	hertz = stathz ? stathz : hz;
    115      1.1   dsl 
    116      1.1   dsl 	syscall_order(name);
    117      1.1   dsl 
    118  1.1.2.1  chap 	/* drvinit gets number of cpus! */
    119  1.1.2.1  chap 	drvinit(1);
    120      1.1   dsl 
    121  1.1.2.1  chap 	counts_mib_len = nelem(counts_mib);
    122  1.1.2.1  chap 	if (sysctlnametomib("kern.syscalls.counts", counts_mib, &counts_mib_len))
    123  1.1.2.1  chap 		counts_mib_len = 0;
    124  1.1.2.1  chap 
    125  1.1.2.1  chap 	times_mib_len = nelem(times_mib);
    126  1.1.2.1  chap 	if (sysctlnametomib("kern.syscalls.times", times_mib, &times_mib_len))
    127  1.1.2.1  chap 		times_mib_len = 0;
    128      1.1   dsl 
    129  1.1.2.1  chap 	getinfo(&s2, SHOW_COUNTS | SHOW_TIMES);
    130      1.1   dsl 	s1 = s2;
    131  1.1.2.1  chap 
    132      1.1   dsl 	return(1);
    133      1.1   dsl }
    134      1.1   dsl 
    135      1.1   dsl void
    136      1.1   dsl fetchsyscall(void)
    137      1.1   dsl {
    138      1.1   dsl 	time_t now;
    139      1.1   dsl 
    140      1.1   dsl 	time(&now);
    141      1.1   dsl 	strlcpy(buf, ctime(&now), sizeof(buf));
    142      1.1   dsl 	buf[19] = '\0';
    143  1.1.2.1  chap 	getinfo(&s, show);
    144      1.1   dsl }
    145      1.1   dsl 
    146      1.1   dsl void
    147      1.1   dsl labelsyscall(void)
    148      1.1   dsl {
    149      1.1   dsl 	labelvmstat_top();
    150      1.1   dsl }
    151      1.1   dsl 
    152      1.1   dsl #define MAXFAIL 5
    153      1.1   dsl 
    154      1.1   dsl static int
    155      1.1   dsl compare_counts(const void *a, const void *b)
    156      1.1   dsl {
    157      1.1   dsl 	int ia = *(const int *)a, ib = *(const int *)b;
    158  1.1.2.1  chap 	int64_t delta;
    159      1.1   dsl 
    160      1.1   dsl 	if (display_mode == TIME)
    161  1.1.2.1  chap 		delta = irf.counts[ib] - irf.counts[ia];
    162  1.1.2.1  chap 	else
    163  1.1.2.1  chap 		delta = s.counts[ib] - s1.counts[ib]
    164  1.1.2.1  chap 		    - (s.counts[ia] - s1.counts[ia]);
    165  1.1.2.1  chap 	return delta ? delta < 0 ? -1 : 1 : 0;
    166  1.1.2.1  chap }
    167  1.1.2.1  chap 
    168  1.1.2.1  chap static int
    169  1.1.2.1  chap compare_times(const void *a, const void *b)
    170  1.1.2.1  chap {
    171  1.1.2.1  chap 	int ia = *(const int *)a, ib = *(const int *)b;
    172  1.1.2.1  chap 	int64_t delta;
    173      1.1   dsl 
    174  1.1.2.1  chap 	if (display_mode == TIME)
    175  1.1.2.1  chap 		delta = irf.times[ib] - irf.times[ia];
    176  1.1.2.1  chap 	else
    177  1.1.2.1  chap 		delta = s.times[ib] - s1.times[ib] - s.times[ia] + s1.times[ia];
    178  1.1.2.1  chap 	return delta ? delta < 0 ? -1 : 1 : 0;
    179      1.1   dsl }
    180      1.1   dsl 
    181      1.1   dsl void
    182      1.1   dsl showsyscall(void)
    183      1.1   dsl {
    184      1.1   dsl 	int i, ii, l, c;
    185  1.1.2.1  chap 	uint64_t val;
    186      1.1   dsl 	static int failcnt = 0;
    187      1.1   dsl 	static int relabel = 0;
    188      1.1   dsl 	static char pigs[] = "pigs";
    189      1.1   dsl 
    190      1.1   dsl 	if (relabel) {
    191      1.1   dsl 		labelsyscall();
    192      1.1   dsl 		relabel = 0;
    193      1.1   dsl 	}
    194      1.1   dsl 
    195      1.1   dsl 	cpuswap();
    196      1.1   dsl 	if (display_mode == TIME) {
    197      1.1   dsl 		etime = cur.cp_etime;
    198      1.1   dsl 		/* < 5 ticks - ignore this trash */
    199      1.1   dsl 		if ((etime * hertz) < 1.0) {
    200      1.1   dsl 			if (failcnt++ > MAXFAIL)
    201      1.1   dsl 				return;
    202      1.1   dsl 			failcnt = 0;
    203      1.1   dsl 			clear();
    204      1.1   dsl 			mvprintw(2, 10, "The alternate system clock has died!");
    205      1.1   dsl 			mvprintw(3, 10, "Reverting to ``pigs'' display.");
    206      1.1   dsl 			move(CMDLINE, 0);
    207      1.1   dsl 			refresh();
    208      1.1   dsl 			failcnt = 0;
    209      1.1   dsl 			sleep(5);
    210      1.1   dsl 			command(pigs);
    211      1.1   dsl 			return;
    212      1.1   dsl 		}
    213      1.1   dsl 	} else
    214      1.1   dsl 		etime = 1.0;
    215      1.1   dsl 
    216      1.1   dsl 	failcnt = 0;
    217      1.1   dsl 
    218      1.1   dsl 	show_vmstat_top(&s.Total, &s.uvmexp, &s1.uvmexp);
    219      1.1   dsl 
    220      1.1   dsl 	if (sort_order == COUNTS) {
    221      1.1   dsl 		/*
    222      1.1   dsl 		 * We use an 'infinite response filter' in a vague
    223      1.1   dsl 		 * attempt to stop the data leaping around too much.
    224      1.1   dsl 		 * I suspect there are other/better methods in use.
    225      1.1   dsl 		 */
    226  1.1.2.1  chap 		if (show & SHOW_COUNTS) {
    227  1.1.2.1  chap 			for (i = 0; i < nelem(s.counts); i++) {
    228  1.1.2.1  chap 				val = s.counts[i] - s1.counts[i];
    229  1.1.2.1  chap 				if (irf.counts[i] > 0xfffffff)
    230  1.1.2.1  chap 				    irf.counts[i] = irf.counts[i] / 8 * 7 + val;
    231  1.1.2.1  chap 				else
    232  1.1.2.1  chap 				    irf.counts[i] = irf.counts[i] * 7 / 8 + val;
    233  1.1.2.1  chap 			}
    234  1.1.2.1  chap 		}
    235  1.1.2.1  chap 		if (show & SHOW_TIMES) {
    236  1.1.2.1  chap 			for (i = 0; i < nelem(s.times); i++) {
    237  1.1.2.1  chap 				val = s.times[i] - s1.times[i];
    238  1.1.2.1  chap 				if (irf.times[i] > 0xfffffff)
    239  1.1.2.1  chap 				    irf.times[i] = irf.times[i] / 8 * 7 + val;
    240  1.1.2.1  chap 				else
    241  1.1.2.1  chap 				    irf.times[i] = irf.times[i] * 7 / 8 + val;
    242  1.1.2.1  chap 			}
    243      1.1   dsl 		}
    244      1.1   dsl 
    245      1.1   dsl 		/* mergesort() doesn't swap equal values about... */
    246      1.1   dsl 		mergesort(syscall_sort, nelem(syscall_sort),
    247  1.1.2.1  chap 			sizeof syscall_sort[0],
    248  1.1.2.1  chap 			show & SHOW_COUNTS ? compare_counts : compare_times);
    249      1.1   dsl 	}
    250      1.1   dsl 
    251      1.1   dsl 	l = SYSCALLROW;
    252      1.1   dsl 	c = 0;
    253      1.1   dsl 	move(l, c);
    254  1.1.2.1  chap 	for (ii = 0; ii < nelem(s.counts); ii++) {
    255      1.1   dsl 		i = syscall_sort[ii];
    256  1.1.2.1  chap 		switch (show) {
    257  1.1.2.1  chap 		default:
    258  1.1.2.1  chap 		case SHOW_COUNTS:
    259  1.1.2.1  chap 			val = s.counts[i] - s1.counts[i];
    260  1.1.2.1  chap 			break;
    261  1.1.2.1  chap 		case SHOW_TIMES:
    262  1.1.2.1  chap 			val = s.times[i] - s1.times[i];
    263  1.1.2.1  chap 			break;
    264  1.1.2.1  chap 		case SHOW_COUNTS | SHOW_TIMES:
    265  1.1.2.1  chap 			val = s.counts[i] - s1.counts[i];
    266  1.1.2.1  chap 			if (val != 0)
    267  1.1.2.1  chap 				val = (s.times[i] - s1.times[i]) / val;
    268  1.1.2.1  chap 		}
    269  1.1.2.1  chap 		if (val == 0 && irf.counts[i] == 0 && irf.times[i] == 0)
    270      1.1   dsl 			continue;
    271      1.1   dsl 
    272      1.1   dsl 		if (i < nelem(syscallnames)) {
    273      1.1   dsl 			const char *name = syscallnames[i];
    274      1.1   dsl 			while (name[0] == '_')
    275      1.1   dsl 				name++;
    276      1.1   dsl 			if (name[0] == 'c' && !strcmp(name + 1, "ompat_"))
    277      1.1   dsl 				name += 7;
    278      1.1   dsl 			mvprintw(l, c, "%17.17s", name);
    279      1.1   dsl 		} else
    280      1.1   dsl 			mvprintw(l, c, "syscall #%d       ", i);
    281      1.1   dsl 
    282  1.1.2.1  chap 		putint((unsigned int)((double)val/etime + 0.5), l, c + 17, 9);
    283      1.1   dsl 		c += 27;
    284      1.1   dsl 		if (c + 26 > COLS) {
    285      1.1   dsl 			c = 0;
    286      1.1   dsl 			l++;
    287      1.1   dsl 			if (l >= LINES - 1)
    288      1.1   dsl 				break;
    289      1.1   dsl 		}
    290      1.1   dsl 	}
    291  1.1.2.1  chap 	if (display_mode == TIME) {
    292  1.1.2.1  chap 		memcpy(s1.counts, s.counts, sizeof s1.counts);
    293  1.1.2.1  chap 		memcpy(s1.times, s.times, sizeof s1.times);
    294  1.1.2.1  chap 	}
    295      1.1   dsl 	while (l < LINES - 1) {
    296      1.1   dsl 	    clrtoeol();
    297      1.1   dsl 	    move(++l, 0);
    298      1.1   dsl 	}
    299      1.1   dsl }
    300      1.1   dsl 
    301      1.1   dsl void
    302      1.1   dsl syscall_boot(char *args)
    303      1.1   dsl {
    304      1.1   dsl 	memset(&s1, 0, sizeof s1);
    305      1.1   dsl 	display_mode = BOOT;
    306      1.1   dsl }
    307      1.1   dsl 
    308      1.1   dsl void
    309      1.1   dsl syscall_run(char *args)
    310      1.1   dsl {
    311      1.1   dsl 	s1 = s2;
    312      1.1   dsl 	display_mode = RUN;
    313      1.1   dsl }
    314      1.1   dsl 
    315      1.1   dsl void
    316      1.1   dsl syscall_time(char *args)
    317      1.1   dsl {
    318      1.1   dsl 	display_mode = TIME;
    319      1.1   dsl }
    320      1.1   dsl 
    321      1.1   dsl void
    322      1.1   dsl syscall_zero(char *args)
    323      1.1   dsl {
    324      1.1   dsl 	s1 = s;
    325      1.1   dsl }
    326      1.1   dsl 
    327      1.1   dsl static int
    328      1.1   dsl compare_names(const void *a, const void *b)
    329      1.1   dsl {
    330      1.1   dsl 	const char *name_a = syscallnames[*(const int *)a];
    331      1.1   dsl 	const char *name_b = syscallnames[*(const int *)b];
    332      1.1   dsl 
    333      1.1   dsl 	while (*name_a == '_')
    334      1.1   dsl 		name_a++;
    335      1.1   dsl 	while (*name_b == '_')
    336      1.1   dsl 		name_b++;
    337      1.1   dsl 
    338      1.1   dsl 	return strcmp(name_a, name_b);
    339      1.1   dsl }
    340      1.1   dsl 
    341      1.1   dsl void
    342      1.1   dsl syscall_order(char *args)
    343      1.1   dsl {
    344      1.1   dsl 	int i, len;
    345      1.1   dsl 
    346      1.1   dsl 	if (args == NULL)
    347      1.1   dsl 		goto usage;
    348      1.1   dsl 
    349      1.1   dsl 	len = strcspn(args, " \t\r\n");
    350      1.1   dsl 
    351      1.1   dsl 	if (args[len + strspn(args + len, " \t\r\n")])
    352      1.1   dsl 		goto usage;
    353      1.1   dsl 
    354  1.1.2.1  chap 	if (memcmp(args, "count", len) == 0) {
    355      1.1   dsl 		sort_order = COUNTS;
    356  1.1.2.1  chap 		memset(&irf, 0, sizeof irf);
    357  1.1.2.1  chap 	} else if (memcmp(args, "name", len) == 0)
    358      1.1   dsl 		sort_order = NAMES;
    359      1.1   dsl 	else if (memcmp(args, "syscall", len) == 0)
    360      1.1   dsl 		sort_order = UNSORTED;
    361      1.1   dsl 	else
    362      1.1   dsl 		goto usage;
    363      1.1   dsl 
    364      1.1   dsl 	/* Undo all the sorting */
    365      1.1   dsl 	for (i = 0; i < nelem(syscall_sort); i++)
    366      1.1   dsl 		syscall_sort[i] = i;
    367      1.1   dsl 
    368      1.1   dsl 	if (sort_order == NAMES) {
    369      1.1   dsl 		/* Only sort the entries we have names for */
    370      1.1   dsl 		qsort(syscall_sort, nelem(syscallnames), sizeof syscall_sort[0],
    371      1.1   dsl 			compare_names);
    372      1.1   dsl 	}
    373      1.1   dsl 	return;
    374      1.1   dsl 
    375      1.1   dsl     usage:
    376      1.1   dsl 	error("Usage: sort [count|name|syscall]");
    377      1.1   dsl }
    378      1.1   dsl 
    379  1.1.2.1  chap void
    380  1.1.2.1  chap syscall_show(char *args)
    381  1.1.2.1  chap {
    382  1.1.2.1  chap 	int len;
    383  1.1.2.1  chap 
    384  1.1.2.1  chap 	if (args == NULL)
    385  1.1.2.1  chap 		goto usage;
    386  1.1.2.1  chap 
    387  1.1.2.1  chap 	len = strcspn(args, " \t\r\n");
    388  1.1.2.1  chap 
    389  1.1.2.1  chap 	if (args[len + strspn(args + len, " \t\r\n")])
    390  1.1.2.1  chap 		goto usage;
    391  1.1.2.1  chap 
    392  1.1.2.1  chap 	if (memcmp(args, "counts", len) == 0)
    393  1.1.2.1  chap 		show = SHOW_COUNTS;
    394  1.1.2.1  chap 	else if (memcmp(args, "times", len) == 0)
    395  1.1.2.1  chap 		show = SHOW_TIMES;
    396  1.1.2.1  chap 	else if (memcmp(args, "ratio", len) == 0)
    397  1.1.2.1  chap 		show = SHOW_COUNTS | SHOW_TIMES;
    398  1.1.2.1  chap 	else
    399  1.1.2.1  chap 		goto usage;
    400  1.1.2.1  chap 
    401  1.1.2.1  chap 	return;
    402  1.1.2.1  chap 
    403  1.1.2.1  chap     usage:
    404  1.1.2.1  chap 	error("Usage: show [counts|times|ratio]");
    405  1.1.2.1  chap }
    406  1.1.2.1  chap 
    407      1.1   dsl static void
    408  1.1.2.1  chap getinfo(struct Info *stats, int get_what)
    409      1.1   dsl {
    410      1.1   dsl 	int mib[2];
    411      1.1   dsl 	size_t size;
    412      1.1   dsl 
    413      1.1   dsl 	cpureadstats();
    414      1.1   dsl 
    415  1.1.2.1  chap 	if (get_what & SHOW_COUNTS) {
    416  1.1.2.1  chap 		size = sizeof stats->counts;
    417  1.1.2.1  chap 		if (!counts_mib_len ||
    418  1.1.2.1  chap 		    sysctl(counts_mib, counts_mib_len, &stats->counts, &size,
    419  1.1.2.1  chap 			    NULL, 0)) {
    420  1.1.2.1  chap 			error("can't get syscall counts: %s\n", strerror(errno));
    421  1.1.2.1  chap 			memset(&stats->counts, 0, sizeof stats->counts);
    422  1.1.2.1  chap 		}
    423  1.1.2.1  chap 	}
    424  1.1.2.1  chap 
    425  1.1.2.1  chap 	if (get_what & SHOW_TIMES) {
    426  1.1.2.1  chap 		size = sizeof stats->times;
    427  1.1.2.1  chap 		if (!times_mib_len ||
    428  1.1.2.1  chap 		    sysctl(times_mib, times_mib_len, &stats->times, &size,
    429  1.1.2.1  chap 			    NULL, 0)) {
    430  1.1.2.1  chap 			error("can't get syscall times: %s\n", strerror(errno));
    431  1.1.2.1  chap 			memset(&stats->times, 0, sizeof stats->times);
    432  1.1.2.1  chap 		}
    433      1.1   dsl 	}
    434      1.1   dsl 
    435      1.1   dsl 	size = sizeof(stats->uvmexp);
    436      1.1   dsl 	mib[0] = CTL_VM;
    437      1.1   dsl 	mib[1] = VM_UVMEXP2;
    438      1.1   dsl 	if (sysctl(mib, 2, &stats->uvmexp, &size, NULL, 0) < 0) {
    439      1.1   dsl 		error("can't get uvmexp: %s\n", strerror(errno));
    440      1.1   dsl 		memset(&stats->uvmexp, 0, sizeof(stats->uvmexp));
    441      1.1   dsl 	}
    442      1.1   dsl 	size = sizeof(stats->Total);
    443      1.1   dsl 	mib[0] = CTL_VM;
    444      1.1   dsl 	mib[1] = VM_METER;
    445      1.1   dsl 	if (sysctl(mib, 2, &stats->Total, &size, NULL, 0) < 0) {
    446      1.1   dsl 		error("Can't get kernel info: %s\n", strerror(errno));
    447      1.1   dsl 		memset(&stats->Total, 0, sizeof(stats->Total));
    448      1.1   dsl 	}
    449      1.1   dsl }
    450