pcp
[Top] [All Lists]

Re: cpu times

To: Madhu Sudhan R Tera <mst9696@xxxxxxxxxxx>
Subject: Re: cpu times
From: Ken McDonell <kenmcd@xxxxxxxxxxxxxxxxx>
Date: Wed, 1 May 2002 06:10:11 +1000
Cc: pcp@xxxxxxxxxxx
In-reply-to: <Pine.GSO.4.44.0204300332130.15445-100000@xxxxxxxxxxxxxxxxxx>
Sender: owner-pcp@xxxxxxxxxxx
On Tue, 30 Apr 2002, Madhu Sudhan R Tera wrote:

> Hello All!
> we are working on project which requires calculation
> of %cpu usages for each process running on a particular
> machine.
> So I want to know if the following is correct or not:
> kernel.all.cpu.user + kernel.all.cpu.sys + kernel.all.cpu.idle = sum of
> (proc.psinfo.stime + proc.psinfo.utime)  all processes considered.
>
> If its not appropriate, then please tell me the best way to calculate the
> percentage usage of CPU for each process using PCP metrics.

As Mark already noted, do not include kernel.all.cpu.idle.

But these are counters, so you need to make 2 observations separated
by some time, say t1 and t2, and thus

        kernel.all.cpu.user@t2 - kernel.all.cpu.user@t1
      + kernel.all.cpu.sys@t2 - kernel.all.cpu.sys@t1

will be close to

    sum over all pids existing at t1 and t2 of
        proc.psinfo.utime[pid]@t2 - proc.psinfo.stime[pid]@t1
      + proc.psinfo.stime[pid]@t2 - proc.psinfo.stime[pid]@t1
  + sum over all pids existing at t2 and not existing at t1
        proc.psinfo.utime[pid]@t2
      + proc.psinfo.stime[pid]@t2

In addition to some sampling errors, remember that some processes will
exit during the sample interval and the contribution of these will be
in the kernel numbers and not in the proc numbers.  If the fork() rate
is low over the sample interval, this error will be small.

Another small error may comes from the way the kernel and proc times
are accounted (the kernel ones typically use statistical sampling, the
proc ones may use a high resolution timer).

And finally, some kernels consume (usually small amounts) of cpu time
outside the context of a user process (e.g. in interrupt handling), and
this usually is added to the kernel times but obviously not to any proc
times.


<Prev in Thread] Current Thread [Next in Thread>