Re: a way of calculating cpu usage information in proc fs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 07, 2005 at 02:20:07PM -0000, sounak  chakraborty wrote:
>             After reading the proc.txt file,i come to the following  
>             conclusion:
> 
>           1. I get the total clock speed of the cpu   
>              from /proc/cpuinfo from cpu MHz entry. 
>           2. Now i add the values of all the colomns 
>              in the first row of /proc/stat(the row which 
>              starts with cpu).this gives the total cpu usage.
> 
> Then i am dividing the above value with 1000 and the resulting answer
> is again divided with the total clock speed to get the percentage of
> cpu usage.
> 
> Is my approach  correct.

No, the CPU MHz is not involved at all. Heck, your method will fail
when the MHz changes (yes, this happens with cpufreq).

total = user + nice + system + idle + iowait + irq + softirq

user percentage = user / total * 100
nice percentage = nice / total * 100
etc.

(Note that /proc/stat contains the total numbers. To calculate the
difference, you need to look two times).

> I am checking my results with system monitor but there is a variation.

True, because you can't guarantee that your program and the system
monitor sample at the same time.

> (This is my best effort to write a mail)

Thanks for your efforts. Now switch off posting in HTML and it's
perfect. Only spammers have a reason to use HTML.


Erik

-- 
Erik Mouw
J.A.K.Mouw@xxxxxxxxxxxxxx  mouw@xxxxxxxxxxxx

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux