Pointers about CPU load measuring

Jose Marcio Martins da Cruz martins at saci.ensmp.fr
Fri Apr 2 13:52:02 PST 2004


> 
> In the last episode (Apr 02), Mark said:
> > Dan Nelson wrote:
> > >>> Someone can send some pointers on how to measure global CPU load
> > >>> under FreeBSD from a C program ? I'm looking for values for
> > >>> idle/kernel/user, in a similar way as does top. Is there any
> > >>> pointer or doc ?. I'd like to avoir browsing top code.
> > >>
> > >> Use sysctlbyname(3) to retrieve vm.loadavg, which is a struct
> > >> loadavg (defined in <sys/resource.h>)
> > >
> > > Actually the kern.cp_time variable might be better if you want
> > > idle/kernel/user values.
> > 
> > I current let snmpd do the job. Is that as accurate as manually
> > reading the kern.cp_time variable?
> 
> If you're talking about enterprises.ucdavis.systemStats, then yes.
> Snmpd digs directly into /dev/kmem instead of using sysctl (so it can
> run on older kernels that didn't provide the sysctl variable), but the
> values are the same.  enterprises.ucdavis.laTable is populated from the
> vm.loadavg sysctl variable.

If I'm not wrong, loadavg gives the mean number of processes in the
run queue averaged on 1, 5 and 15 minutes. This gives an idea of
system load but lacks precision. It seems to me that kern.cp_time
counters is a better metrics of CPU load.

> 
> -- 
> 	Dan Nelson
> 	dnelson at allantgroup.com
> 



More information about the freebsd-hackers mailing list