Esempio n. 1
0
static void
getinfo(struct Info *ls)
{
	struct devinfo *tmp_dinfo;
	struct nchstats *nch_tmp;
	size_t size;
	size_t vms_size = sizeof(ls->Vms);
	size_t vmm_size = sizeof(ls->Vmm);
	size_t nch_size = sizeof(ls->nchstats) * SMP_MAXCPU;

        if (sysctlbyname("vm.vmstats", &ls->Vms, &vms_size, NULL, 0)) {
                perror("sysctlbyname: vm.vmstats");
                exit(1);
        }
        if (sysctlbyname("vm.vmmeter", &ls->Vmm, &vmm_size, NULL, 0)) {
                perror("sysctlbyname: vm.vmstats");
                exit(1);
        }

	if (kinfo_get_sched_cputime(&ls->cp_time))
		err(1, "kinfo_get_sched_cputime");
	if (kinfo_get_sched_cputime(&cp_time))
		err(1, "kinfo_get_sched_cputime");
	NREAD(X_BUFFERSPACE, &ls->bufspace, sizeof(ls->bufspace));
	NREAD(X_DESIREDVNODES, &ls->desiredvnodes, sizeof(ls->desiredvnodes));
	NREAD(X_NUMVNODES, &ls->numvnodes, sizeof(ls->numvnodes));
	NREAD(X_FREEVNODES, &ls->freevnodes, sizeof(ls->freevnodes));
	NREAD(X_NUMDIRTYBUFFERS, &ls->dirtybufspace, sizeof(ls->dirtybufspace));

	if (nintr) {
		size = nintr * sizeof(ls->intrcnt[0]);
		sysctlbyname("hw.intrcnt_all", ls->intrcnt, &size, NULL, 0);
	}
	size = sizeof(ls->Total);
	if (sysctlbyname("vm.vmtotal", &ls->Total, &size, NULL, 0) < 0) {
		error("Can't get kernel info: %s\n", strerror(errno));
		bzero(&ls->Total, sizeof(ls->Total));
	}

	if ((nch_tmp = malloc(nch_size)) == NULL) {
		perror("malloc");
		exit(1);
	} else {
		if (sysctlbyname("vfs.cache.nchstats", nch_tmp, &nch_size, NULL, 0)) {
			perror("sysctlbyname vfs.cache.nchstats");
			free(nch_tmp);
			exit(1);
		} else {
			if ((nch_tmp = realloc(nch_tmp, nch_size)) == NULL) {
				perror("realloc");
				exit(1);
			}
		}
	}

	if (kinfo_get_cpus(&ncpu))
		err(1, "kinfo_get_cpus");
	kvm_nch_cpuagg(nch_tmp, &ls->nchstats, ncpu);
	free(nch_tmp);

	tmp_dinfo = last.dinfo;
	last.dinfo = cur.dinfo;
	cur.dinfo = tmp_dinfo;

	last.busy_time = cur.busy_time;
	switch (getdevs(&cur)) {
	case -1:
		errx(1, "%s", devstat_errbuf);
		break;
	case 1:
		num_devices = cur.dinfo->numdevs;
		generation = cur.dinfo->generation;
		cmdkre("refresh", NULL);
		break;
	default:
		break;
	}
}
Esempio n. 2
0
static void
dosum(void)
{
	struct nchstats *nch_tmp, nchstats;
	size_t vms_size = sizeof(vms);
	size_t vmm_size = sizeof(vmm);
	int cpucnt;
	u_long nchtotal;
	u_long nchpathtotal;
	size_t nch_size = sizeof(struct nchstats) * SMP_MAXCPU;

	if (sysctlbyname("vm.vmstats", &vms, &vms_size, NULL, 0)) {
		perror("sysctlbyname: vm.vmstats");
		exit(1);
	}
	if (sysctlbyname("vm.vmmeter", &vmm, &vmm_size, NULL, 0)) {
		perror("sysctlbyname: vm.vmstats");
		exit(1);
	}
	printf("%9u cpu context switches\n", vmm.v_swtch);
	printf("%9u device interrupts\n", vmm.v_intr);
	printf("%9u software interrupts\n", vmm.v_soft);
	printf("%9u traps\n", vmm.v_trap);
	printf("%9u system calls\n", vmm.v_syscall);
	printf("%9u kernel threads created\n", vmm.v_kthreads);
	printf("%9u  fork() calls\n", vmm.v_forks);
	printf("%9u vfork() calls\n", vmm.v_vforks);
	printf("%9u rfork() calls\n", vmm.v_rforks);
	printf("%9u exec() calls\n", vmm.v_exec);
	printf("%9u swap pager pageins\n", vmm.v_swapin);
	printf("%9u swap pager pages paged in\n", vmm.v_swappgsin);
	printf("%9u swap pager pageouts\n", vmm.v_swapout);
	printf("%9u swap pager pages paged out\n", vmm.v_swappgsout);
	printf("%9u vnode pager pageins\n", vmm.v_vnodein);
	printf("%9u vnode pager pages paged in\n", vmm.v_vnodepgsin);
	printf("%9u vnode pager pageouts\n", vmm.v_vnodeout);
	printf("%9u vnode pager pages paged out\n", vmm.v_vnodepgsout);
	printf("%9u page daemon wakeups\n", vmm.v_pdwakeups);
	printf("%9u pages examined by the page daemon\n", vmm.v_pdpages);
	printf("%9u pages reactivated\n", vmm.v_reactivated);
	printf("%9u copy-on-write faults\n", vmm.v_cow_faults);
	printf("%9u copy-on-write optimized faults\n", vmm.v_cow_optim);
	printf("%9u zero fill pages zeroed\n", vmm.v_zfod);
	printf("%9u zero fill pages prezeroed\n", vmm.v_ozfod);
	printf("%9u intransit blocking page faults\n", vmm.v_intrans);
	printf("%9u total VM faults taken\n", vmm.v_vm_faults);
	printf("%9u pages affected by kernel thread creation\n", vmm.v_kthreadpages);
	printf("%9u pages affected by  fork()\n", vmm.v_forkpages);
	printf("%9u pages affected by vfork()\n", vmm.v_vforkpages);
	printf("%9u pages affected by rfork()\n", vmm.v_rforkpages);
	printf("%9u pages freed\n", vmm.v_tfree);
	printf("%9u pages freed by daemon\n", vmm.v_dfree);
	printf("%9u pages freed by exiting processes\n", vmm.v_pfree);
	printf("%9u pages active\n", vms.v_active_count);
	printf("%9u pages inactive\n", vms.v_inactive_count);
	printf("%9u pages in VM cache\n", vms.v_cache_count);
	printf("%9u pages wired down\n", vms.v_wire_count);
	printf("%9u pages free\n", vms.v_free_count);
	printf("%9u bytes per page\n", vms.v_page_size);
	printf("%9u global smp invltlbs\n", vmm.v_smpinvltlb);
	
	if ((nch_tmp = malloc(nch_size)) == NULL) {
		perror("malloc");
		exit(1);
	} else {
		if (sysctlbyname("vfs.cache.nchstats", nch_tmp, &nch_size, NULL, 0)) {
			perror("sysctlbyname vfs.cache.nchstats");
			free(nch_tmp);
			exit(1);
		} else {
			if ((nch_tmp = realloc(nch_tmp, nch_size)) == NULL) {
				perror("realloc");
				exit(1);
			}
		}
	}
	
	cpucnt = nch_size / sizeof(struct nchstats);
	kvm_nch_cpuagg(nch_tmp, &nchstats, cpucnt);

	nchtotal = nchstats.ncs_goodhits + nchstats.ncs_neghits +
	    nchstats.ncs_badhits + nchstats.ncs_falsehits +
	    nchstats.ncs_miss;
	nchpathtotal = nchstats.ncs_longhits + nchstats.ncs_longmiss;
	printf("%9ld total path lookups\n", nchpathtotal);
	printf("%9ld total component lookups\n", nchtotal);
	printf(
	    "%9s cache hits (%ld%% pos + %ld%% neg)\n",
	    "", PCT(nchstats.ncs_goodhits, nchtotal),
	    PCT(nchstats.ncs_neghits, nchtotal));
	printf("%9s deletions %ld%%, falsehits %ld%%\n", "",
	    PCT(nchstats.ncs_badhits, nchtotal),
	    PCT(nchstats.ncs_falsehits, nchtotal));
	free(nch_tmp);
}