示例#1
0
WINDOW *
openvmm(void)
{
	if (symbols_read == 0) {
		symbols_read = 1;
		read_symbols(NULL);
	}

	if (kinfo_get_cpus(&vmm_ncpus))
		err(1, "kinfo_get_cpus");

	vmm_cur = calloc(vmm_ncpus, sizeof(*vmm_cur));
	if (vmm_cur == NULL)
		err(1, "calloc vmm_cur");

	vmm_prev = calloc(vmm_ncpus, sizeof(*vmm_prev));
	if (vmm_prev == NULL)
		err(1, "calloc vmm_prev");

	vmm_cptime_cur = calloc(vmm_ncpus, sizeof(*vmm_cptime_cur));
	if (vmm_cptime_cur == NULL)
		err(1, "calloc vmm_cptime_cur");

	vmm_cptime_prev = calloc(vmm_ncpus, sizeof(*vmm_cptime_prev));
	if (vmm_cptime_prev == NULL)
		err(1, "calloc vmm_cptime_prev");

	getvmm();

	return (stdscr);
}
示例#2
0
g_val_t
cpu_num_func ( void )
{
   g_val_t val;
   int ncpu;

   if (kinfo_get_cpus(&ncpu))
        ncpu = 1;

   val.uint16 = ncpu;
   return val;
}
示例#3
0
    /*
     * Initialise the list of CPUs on the system
     *   (including descriptions)
     */
void init_cpu_kinfo( void ) {
    netsnmp_cpu_info *cpu;
    int i;
    size_t len;
    char           descr[ SNMP_MAXBUF ];

    cpu = netsnmp_cpu_get_byIdx( -1, 1 );
    strcpy(cpu->name, "Overall CPU statistics");

    kinfo_get_cpus(&cpu_num);
    len = sizeof(descr);
    sysctlbyname("hw.model", descr, &len, NULL, 0);
    for ( i = 0; i < cpu_num; i++ ) {
        cpu = netsnmp_cpu_get_byIdx( i, 1 );
        cpu->status = 2;  /* running */
        sprintf(cpu->name, "cpu%d", i);
        sprintf(cpu->descr, "%s", descr);
    }
}
示例#4
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;
	}
}