/* * Load the latest CPU usage statistics */ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) { struct vmmeter vmm; size_t len; struct kinfo_cputime cp_time; netsnmp_cpu_info *cpu = netsnmp_cpu_get_byIdx( -1, 0 ); kinfo_get_sched_cputime(&cp_time); len = sizeof(vmm); sysctlbyname("vm.vmmeter", &vmm, &len, NULL, 0); cpu->user_ticks = cp_time.cp_user; cpu->nice_ticks = cp_time.cp_nice; cpu->sys2_ticks = cp_time.cp_sys + cp_time.cp_intr; cpu->idle_ticks = cp_time.cp_idle; cpu->kern_ticks = cp_time.cp_sys; cpu->intrpt_ticks = cp_time.cp_intr; cpu->swapIn = vmm.v_swappgsin + vmm.v_vnodepgsin; cpu->swapOut = vmm.v_swappgsout + vmm.v_vnodepgsout; cpu->nInterrupts = vmm.v_intr; cpu->nCtxSwitches = vmm.v_swtch; /* Copy "overall" figures to cpu0 entry */ _cpu_copy_stats( cpu ); return 0; }
/* * Load the latest CPU usage statistics */ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) { long cpu_stats[CPUSTATES]; struct vmmeter mem_stats; netsnmp_cpu_info *cpu = netsnmp_cpu_get_byIdx( -1, 0 ); auto_nlist( CPU_SYMBOL, (char *) cpu_stats, sizeof(cpu_stats)); auto_nlist( MEM_SYMBOL, (char *)&mem_stats, sizeof(mem_stats)); cpu->user_ticks = (unsigned long long)cpu_stats[CP_USER]; cpu->nice_ticks = (unsigned long long)cpu_stats[CP_NICE]; cpu->sys2_ticks = (unsigned long long)cpu_stats[CP_SYS]+cpu_stats[CP_INTR]; cpu->idle_ticks = (unsigned long long)cpu_stats[CP_IDLE]; cpu->kern_ticks = (unsigned long long)cpu_stats[CP_SYS]; cpu->intrpt_ticks = (unsigned long long)cpu_stats[CP_INTR]; /* wait_ticks, sirq_ticks unused */ /* * Interrupt/Context Switch statistics * XXX - Do these really belong here ? */ #if defined(openbsd2) || defined(darwin) cpu->swapIn = (unsigned long long)mem_stats.v_swpin; cpu->swapOut = (unsigned long long)mem_stats.v_swpout; #else cpu->swapIn = (unsigned long long)mem_stats.v_swappgsin+mem_stats.v_vnodepgsin; cpu->swapOut = (unsigned long long)mem_stats.v_swappgsout+mem_stats.v_vnodepgsout; #endif cpu->nInterrupts = (unsigned long long)mem_stats.v_intr; cpu->nCtxSwitches = (unsigned long long)mem_stats.v_swtch; #ifdef PER_CPU_INFO for ( i = 0; i < n; i++ ) { cpu = netsnmp_cpu_get_byIdx( i, 0 ); /* XXX - per-CPU statistics */ } #else /* Copy "overall" figures to cpu0 entry */ _cpu_copy_stats( cpu ); #endif return 0; }
/* * Load the latest CPU usage statistics */ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) { int i,n; perfstat_id_t name; perfstat_cpu_total_t cs; perfstat_cpu_t *cs2; perfstat_memory_total_t ms; netsnmp_cpu_info *cpu = netsnmp_cpu_get_byIdx( -1, 0 ); if (perfstat_cpu_total((perfstat_id_t *)NULL, &cs, sizeof(perfstat_cpu_total_t), 1) > 0) { /* Returns 'u_longlong_t' statistics */ cpu->user_ticks = (unsigned long long)cs.user / cs.ncpus; cpu->sys_ticks = ((unsigned long long)cs.sys + (unsigned long long)cs.wait) / cs.ncpus; cpu->kern_ticks = (unsigned long long)cs.sys / cs.ncpus; cpu->wait_ticks = (unsigned long long)cs.wait / cs.ncpus; cpu->idle_ticks = (unsigned long long)cs.idle / cs.ncpus; /* intrpt_ticks, sirq_ticks, nice_ticks unused */ /* * Interrupt/Context Switch statistics * XXX - Do these really belong here ? */ cpu->pageIn = (unsigned long long)cs.sysread; cpu->pageOut = (unsigned long long)cs.syswrite; cpu->nInterrupts = (unsigned long long)cs.devintrs + cs.softintrs; cpu->nCtxSwitches = (unsigned long long)cs.pswitch; } if (perfstat_memory_total((perfstat_id_t *)NULL, &ms, sizeof(perfstat_memory_total_t), 1) > 0) { cpu->swapIn = (unsigned long long)ms.pgspins; cpu->swapOut = (unsigned long long)ms.pgspouts; } /* * Per-CPU statistics */ n = cs.ncpus; /* XXX - Compare against cpu_num */ cs2 = (perfstat_cpu_t*)malloc( n*sizeof(perfstat_cpu_t)); strcpy( name.name, ""); if (perfstat_cpu(&name, cs2, sizeof(perfstat_cpu_t), n) > 0) { for ( i = 0; i < n; i++ ) { cpu = netsnmp_cpu_get_byIdx( i, 1 ); cpu->user_ticks = (unsigned long long)cs2[i].user; cpu->sys_ticks = (unsigned long long)cs2[i].sys + (unsigned long long)cs2[i].wait; cpu->kern_ticks = (unsigned long long)cs2[i].sys; cpu->wait_ticks = (unsigned long long)cs2[i].wait; cpu->idle_ticks = (unsigned long long)cs2[i].idle; cpu->pageIn = (unsigned long long)cs2[i].sysread; cpu->pageOut = (unsigned long long)cs2[i].syswrite; cpu->nCtxSwitches = (unsigned long long)cs2[i].pswitch; /* Interrupt stats only apply overall, not per-CPU */ } } else { _cpu_copy_stats( cpu ); } free(cs2); return 0; }
/* * Load the latest CPU usage statistics */ int netsnmp_cpu_arch_load( netsnmp_cache *cache, void *magic ) { #ifdef NETSNMP_KERN_MCPU int i; #endif /* * Strictly speaking, BSDi ought to use * "struct cpustats cpu_stats" * but this array was used in the previous code, and * is correct for the {Open,Net}BSD versions too. * Don't fight it, Dave - go with the flow.... */ NETSNMP_CPU_STATS cpu_stats[CPUSTATES]; #if !defined(__FreeBSD__) || defined(__FreeBSD_kernel__) && !defined(__NetBSD__) int cpu_mib[] = { CTL_KERN, NETSNMP_KERN_CPU }; #endif size_t cpu_size = sizeof(cpu_stats); #ifdef NETSNMP_KERN_MCPU NETSNMP_KERN_MCPU_TYPE *mcpu_stats; int mcpu_mib[] = { CTL_KERN, NETSNMP_KERN_MCPU }; size_t mcpu_size; #endif NETSNMP_VM_STATS_TYPE mem_stats; int mem_mib[] = { CTL_VM, NETSNMP_VM_STATS }; size_t mem_size = sizeof(NETSNMP_VM_STATS_TYPE); netsnmp_cpu_info *cpu = netsnmp_cpu_get_byIdx( -1, 0 ); #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)) sysctlbyname("kern.cp_time", cpu_stats, &cpu_size, NULL, 0); #else sysctl(cpu_mib, 2, cpu_stats, &cpu_size, NULL, 0); #endif cpu->user_ticks = (unsigned long long)cpu_stats[CP_USER]; cpu->nice_ticks = (unsigned long long)cpu_stats[CP_NICE]; cpu->sys2_ticks = (unsigned long long)cpu_stats[CP_SYS]+cpu_stats[CP_INTR]; cpu->kern_ticks = (unsigned long long)cpu_stats[CP_SYS]; cpu->idle_ticks = (unsigned long long)cpu_stats[CP_IDLE]; cpu->intrpt_ticks = (unsigned long long)cpu_stats[CP_INTR]; /* wait_ticks, sirq_ticks unused */ /* * Interrupt/Context Switch statistics * XXX - Do these really belong here ? */ sysctl(mem_mib, 2, &mem_stats, &mem_size, NULL, 0); cpu->nInterrupts = (unsigned long long)mem_stats.NS_VM_INTR; cpu->nCtxSwitches = (unsigned long long)mem_stats.NS_VM_SWTCH; cpu->swapIn = (unsigned long long)mem_stats.NS_VM_SWAPIN; cpu->swapOut = (unsigned long long)mem_stats.NS_VM_SWAPOUT; #ifdef NS_VM_PAGEIN cpu->pageIn = (unsigned long long)mem_stats.NS_VM_PAGEIN; #endif #ifdef NS_VM_PAGEOUT cpu->pageOut = (unsigned long long)mem_stats.NS_VM_PAGEOUT; #endif #ifdef NETSNMP_KERN_MCPU mcpu_size = cpu_num*sizeof(NETSNMP_KERN_MCPU_TYPE); mcpu_stats = malloc(mcpu_size); sysctl(mcpu_mib, 2, mcpu_stats, &mcpu_size, NULL, 0); for ( i = 0; i < cpu_num; i++ ) { cpu = netsnmp_cpu_get_byIdx( i, 0 ); /* XXX - per-CPU statistics - mcpu_mib[i].??? */ } free(mcpu_stats); #else /* Copy "overall" figures to cpu0 entry */ _cpu_copy_stats( cpu ); #endif return 0; }