예제 #1
0
파일: iostat.c 프로젝트: darksoul42/bitrig
int
initiostat(void)
{
	field_view *v;

	dkinit(1);
	dkreadstats();

	bzero(&bccur, sizeof(bccur));

	for (v = views_io; v->name != NULL; v++)
		add_view(v);

	return(1);
}
예제 #2
0
파일: vmstat.c 프로젝트: SylvestreG/bitrig
static void
getinfo(struct Info *si)
{
	static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME };
	static int nchstats_mib[2] = { CTL_KERN, KERN_NCHSTATS };
	static int uvmexp_mib[2] = { CTL_VM, VM_UVMEXP };
	static int vmtotal_mib[2] = { CTL_VM, VM_METER };
	int mib[4], i;
	size_t size;

	dkreadstats();

	for (i = 0; i < nintr; i++) {
		mib[0] = CTL_KERN;
		mib[1] = KERN_INTRCNT;
		mib[2] = KERN_INTRCNT_CNT;
		mib[3] = i;
		size = sizeof(si->intrcnt[i]);
		if (sysctl(mib, 4, &si->intrcnt[i], &size, NULL, 0) < 0) {
			si->intrcnt[i] = 0;
		}
	}

	size = sizeof(si->time);
	if (sysctl(cp_time_mib, 2, &si->time, &size, NULL, 0) < 0) {
		error("Can't get KERN_CPTIME: %s\n", strerror(errno));
		bzero(&si->time, sizeof(si->time));
	}

	size = sizeof(si->nchstats);
	if (sysctl(nchstats_mib, 2, &si->nchstats, &size, NULL, 0) < 0) {
		error("Can't get KERN_NCHSTATS: %s\n", strerror(errno));
		bzero(&si->nchstats, sizeof(si->nchstats));
	}

	size = sizeof(si->uvmexp);
	if (sysctl(uvmexp_mib, 2, &si->uvmexp, &size, NULL, 0) < 0) {
		error("Can't get VM_UVMEXP: %s\n", strerror(errno));
		bzero(&si->uvmexp, sizeof(si->uvmexp));
	}

	size = sizeof(si->Total);
	if (sysctl(vmtotal_mib, 2, &si->Total, &size, NULL, 0) < 0) {
		error("Can't get VM_METER: %s\n", strerror(errno));
		bzero(&si->Total, sizeof(si->Total));
	}
}
예제 #3
0
파일: iostat.c 프로젝트: darksoul42/bitrig
int
read_io(void)
{
	int mib[3];
	size_t size;

	dkreadstats();
	dkswap();
	num_disp = cur.dk_ndrive + 1;

	bclast = bccur;
	mib[0] = CTL_VFS;
	mib[1] = VFS_GENERIC;
	mib[2] = VFS_BCACHESTAT;
	size = sizeof(bccur);

	if (sysctl(mib, 3, &bccur, &size, NULL, 0) < 0)
		error("cannot get vfs.bcachestat");

	if (bclast.numbufs == 0)
		bclast = bccur;

	return 0;
}
예제 #4
0
void
updatestat(void)
{
    int i, mib[2], save_errno = errno;
    struct uvmexp uvmexp;
    size_t len;
    struct if_data *ifdp;
    struct ifaddrs *ifaddrs, *ifa;
    double avrun[3];
    struct timeval tm, btm;
    long *cp_time = cur.cp_time;

#ifdef DEBUG
    syslog(LOG_DEBUG, "entering updatestat");
#endif
    if (sincelastreq >= closedown) {
#ifdef DEBUG
        syslog(LOG_DEBUG, "about to closedown");
#endif
        if (from_inetd)
            _exit(0);
        else {
            stat_is_init = 0;
            errno = save_errno;
            return;
        }
    }
    sincelastreq++;

    /*
     * dkreadstats reads in the "disk_count" as well as the "disklist"
     * statistics.  It also retrieves "hz" and the "cp_time" array.
     */
    dkreadstats();
    memset(stats_all.s1.dk_xfer, '\0', sizeof(stats_all.s1.dk_xfer));
    for (i = 0; i < dk_ndrive && i < DK_NDRIVE; i++)
        stats_all.s1.dk_xfer[i] = cur.dk_rxfer[i] + cur.dk_wxfer[i];

    for (i = 0; i < CPUSTATES; i++)
        stats_all.s1.cp_time[i] = cp_time[cp_xlat[i]];
    (void)getloadavg(avrun, sizeof(avrun) / sizeof(avrun[0]));
    stats_all.s2.avenrun[0] = avrun[0] * FSCALE;
    stats_all.s2.avenrun[1] = avrun[1] * FSCALE;
    stats_all.s2.avenrun[2] = avrun[2] * FSCALE;
    mib[0] = CTL_KERN;
    mib[1] = KERN_BOOTTIME;
    len = sizeof(btm);
    if (sysctl(mib, 2, &btm, &len, NULL, 0) < 0) {
        syslog(LOG_ERR, "can't sysctl kern.boottime: %m");
        _exit(1);
    }
    stats_all.s2.boottime.tv_sec = btm.tv_sec;
    stats_all.s2.boottime.tv_usec = btm.tv_usec;


#ifdef DEBUG
    syslog(LOG_DEBUG, "%d %d %d %d", stats_all.s1.cp_time[0],
           stats_all.s1.cp_time[1], stats_all.s1.cp_time[2],
           stats_all.s1.cp_time[3]);
#endif

    mib[0] = CTL_VM;
    mib[1] = VM_UVMEXP;
    len = sizeof(uvmexp);
    if (sysctl(mib, 2, &uvmexp, &len, NULL, 0) < 0) {
        syslog(LOG_ERR, "can't sysctl vm.uvmexp: %m");
        _exit(1);
    }
    stats_all.s1.v_pgpgin = uvmexp.fltanget;
    stats_all.s1.v_pgpgout = uvmexp.pdpageouts;
    stats_all.s1.v_pswpin = uvmexp.swapins;
    stats_all.s1.v_pswpout = uvmexp.swapouts;
    stats_all.s1.v_intr = uvmexp.intrs;
    stats_all.s2.v_swtch = uvmexp.swtch;
    gettimeofday(&tm, (struct timezone *) 0);
    stats_all.s1.v_intr -= hz*(tm.tv_sec - btm.tv_sec) +
                           hz*(tm.tv_usec - btm.tv_usec)/1000000;
    stats_all.s1.if_ipackets = 0;
    stats_all.s1.if_opackets = 0;
    stats_all.s1.if_ierrors = 0;
    stats_all.s1.if_oerrors = 0;
    stats_all.s1.if_collisions = 0;
    if (getifaddrs(&ifaddrs) == -1) {
        syslog(LOG_ERR, "can't getifaddrs: %m");
        _exit(1);
    }
    for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
        if (ifa->ifa_addr->sa_family != AF_LINK)
            continue;
        ifdp = (struct if_data *)ifa->ifa_data;
        stats_all.s1.if_ipackets += ifdp->ifi_ipackets;
        stats_all.s1.if_opackets += ifdp->ifi_opackets;
        stats_all.s1.if_ierrors += ifdp->ifi_ierrors;
        stats_all.s1.if_oerrors += ifdp->ifi_oerrors;
        stats_all.s1.if_collisions += ifdp->ifi_collisions;
    }
    freeifaddrs(ifaddrs);
    stats_all.s3.curtime.tv_sec = tm.tv_sec;
    stats_all.s3.curtime.tv_usec = tm.tv_usec;

    alarm(1);
    errno = save_errno;
}
예제 #5
0
void
dovmstat(u_int interval, int reps)
{
	time_t uptime, halfuptime;
	struct clockinfo clkinfo;
	struct vmtotal total;
	size_t size;
	int mib[2];

	uptime = getuptime();
	halfuptime = uptime / 2;
	(void)signal(SIGCONT, needhdr);

	mib[0] = CTL_KERN;
	mib[1] = KERN_CLOCKRATE;
	size = sizeof(clkinfo);
	if (sysctl(mib, 2, &clkinfo, &size, NULL, 0) < 0) {
		warn("could not read kern.clockrate");
		return;
	}
	hz = clkinfo.stathz;

	for (hdrcnt = 1;;) {
		/* Read new disk statistics */
		dkreadstats();
		if (!--hdrcnt || last.dk_ndrive != cur.dk_ndrive)
			printhdr();
		if (nlistf == NULL && memf == NULL) {
			size = sizeof(struct uvmexp);
			mib[0] = CTL_VM;
			mib[1] = VM_UVMEXP;
			if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
				warn("could not get vm.uvmexp");
				bzero(&uvmexp, sizeof(struct uvmexp));
			}
		} else {
			kread(X_UVMEXP, &uvmexp, sizeof(struct uvmexp));
		}
		size = sizeof(total);
		mib[0] = CTL_VM;
		mib[1] = VM_METER;
		if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) {
			warn("could not read vm.vmmeter");
			bzero(&total, sizeof(total));
		}
		(void)printf(" %u %u %u ",
		    total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
#define	rate(x)	((unsigned)((((unsigned)x) + halfuptime) / uptime)) /* round */
#define pgtok(a) ((a) * ((unsigned int)uvmexp.pagesize >> 10))
		(void)printf("%6u %7u ",
		    pgtok(uvmexp.active + uvmexp.swpginuse),
		    pgtok(uvmexp.free));
		(void)printf("%4u ", rate(uvmexp.faults - ouvmexp.faults));
		(void)printf("%3u ", rate(uvmexp.pdreact - ouvmexp.pdreact));
		(void)printf("%3u ", rate(uvmexp.pageins - ouvmexp.pageins));
		(void)printf("%3u %3u ",
		    rate(uvmexp.pdpageouts - ouvmexp.pdpageouts), 0);
		(void)printf("%3u ", rate(uvmexp.pdscans - ouvmexp.pdscans));
		dkstats();
		(void)printf("%4u %5u %4u ",
		    rate(uvmexp.intrs - ouvmexp.intrs),
		    rate(uvmexp.syscalls - ouvmexp.syscalls),
		    rate(uvmexp.swtch - ouvmexp.swtch));
		cpustats();
		(void)printf("\n");
		(void)fflush(stdout);
		if (reps >= 0 && --reps <= 0)
			break;
		ouvmexp = uvmexp;
		uptime = interval;
		/*
		 * We round upward to avoid losing low-frequency events
		 * (i.e., >= 1 per interval but < 1 per second).
		 */
		halfuptime = uptime == 1 ? 0 : (uptime + 1) / 2;
		(void)sleep(interval);
	}
}