Re: CPU Utilization

H. Peter Anvin (hpa@freya.yggdrasil.com)
30 Jun 1996 22:40:51 GMT


Followup to: <199606281942.VAA19665@informatik.uni-koblenz.de>
By author: Systemkennung Linux <linux@mailhost.uni-koblenz.de>
In newsgroup: linux.dev.kernel
>
> Hi,
>=20
> > What's the best way to get the instantaneous CPU utilization? I am=
=20
> > trying to build-a-better-CPUMeter and I want a routine I can call a=
bout 4=20
> > times per second with little CPU overhead...
>=20
> Under Linux you can use the values in /proc/uptime. The first of the
> numbers is the number of seconds since the system was rebooted, the s=
econd
> the number of seconds idle time that were burned in the swapper proce=
ss.
> It should be obvious how to compute the CPU usage % from these number=
s.
>=20
> Or use the numbers from /proc/loadavg if they should fit your purpose
> better.
>=20
> It isn't really required to measure the CPU usage yourself unless you=
want
> to port this program to non-Linux operating systems which apparently =
still
> exist :-)
>=20

The *instantaneous* CPU usage, when measured, is always 100% since
your measuring process is obviously running at that time, the CPU is
being utilized... hence, it is a useless metric, and the reason a
decaying average is used instead.

-hpa

--=20
PGP public key available - finger hpa@zytor.com
I don't work for Yggdrasil, but they sponsor the linux.* hierarchy.
"The earth is but one country, and mankind its citizens." -- Bah=E1'u=
'll=E1h
Just Say No to Morden * Save Babylon 5: http://www.babylon5.com/cmp/sup=
port/