Dear list,
I had some questions regarding using /proc/stat (on the 2.6 kernel).
Can I assume that reading /proc/stat is 'atomic'? Can I assume that when I read
the file, that nothing will change the data while I am reading it?
IE:
cpu 15948315 4687107 3321012 122412279 659908 43304 144288
cpu0 15948315 4687107 3321012 122412279 659908 43304 144288
can I assume that while I am reading the third value (system), that the fourth value (idle)
will not be changed underneath me? Can I assume that all the lines? cpu, cpu0 will all be
generated at once?
My second question is regarding using these values to calculate usage...
Should I calculate usage by
(where T1, T2 are time)
A) read /proc/stat
Fill variables UserT1, NiceT1, SystemT1, IdleT1, IOWaitT1, irqT1, irq2T1
wait a time
Fill variables UserT2, NiceT2, SystemT2, IdleT2, IOWaitT2, irqT2, irq2T2
DeltaTotalTime=(UserT2-UserT1)+(NiceT2-NiceT1)+(SystemT2- SystemT1)+(.........)
Then calculate the values I want as the delta variableOfInterest / total delta
ie: (UserT2-UserT1)/DeltaTotalTime
Can I assume that all these values added together should add up to 100%?
or
B) read /proc/stat
read variable of interest, ie: UserT1 and btimeT1 and number of CPUs
wait a time
read variable of interest, ie: UserT2 and btimeT2 and number of CPUs
Then calculate the values I want as
((UserT2-UserT1)/NumCPU)/(btimeT2-btimeT1)*100 (Jiffies)