Subject: Re: getting cpu utilization
To: None <netbsd-users@netbsd.org>
From: George Georgalis <george@galis.org>
List: netbsd-users
Date: 01/11/2007 20:08:46
On Thu, Jan 11, 2007 at 06:46:30PM -0600, Jeremy C. Reed wrote:
>> I'm using a /bin/sh function to generate a the cpu utilization 
>> 
>> util () { # CPU Utilization
>>  idle=$(echo "2 k $(top -b -d2 | grep '^CPU states' | awk '{print $11}' | sed 's/%//') 1 + p" | dc)
>>  echo "2 k 1 $idle / p"  | dc ;}
>> 
>> That returns the inverse of the cpu idle % found in top.  I add
>> 1 to the value before I invert it to prevent divide by zero, so
>> output is pretty much between 0 and 1.
>> 
>> Running two top reports seems a pretty inefficient way to get the
>> value.  I think I can tune top a bit, but is there a more direct
>> way to get the measurement?
>
>Maybe "sysctl kern.cp_time" ?

hey that looks pretty good, but I cannot find any doc on it
sysctl(8) mentions it; but no detail in (3) 

my best guess to the numbers is the number of 0.01 seconds elapsed
per cpu, so idle athlon below increments idle time silghtly over
100 per second, while the idle 8 core opteron increments at a
little more than 800 per second.

does that sound right?

// George


one athlon cpu
uptime ; while :; do sysctl kern.cp_time ; sleep 1 ; done
 7:54PM  up 24 days, 22:50, 4 users, load averages: 0.38, 0.31, 0.26
kern.cp_time: user = 4322591, nice = 0, sys = 1818184, intr = 80960, idle = 209356004
kern.cp_time: user = 4322591, nice = 0, sys = 1818184, intr = 80960, idle = 209356105
kern.cp_time: user = 4322591, nice = 0, sys = 1818184, intr = 80960, idle = 209356206
kern.cp_time: user = 4322591, nice = 0, sys = 1818184, intr = 80960, idle = 209356307
kern.cp_time: user = 4322591, nice = 0, sys = 1818184, intr = 80960, idle = 209356408
kern.cp_time: user = 4322591, nice = 0, sys = 1818184, intr = 80960, idle = 209356509
kern.cp_time: user = 4322591, nice = 0, sys = 1818184, intr = 80960, idle = 209356610
kern.cp_time: user = 4322591, nice = 0, sys = 1818184, intr = 80960, idle = 209356711
kern.cp_time: user = 4322591, nice = 0, sys = 1818187, intr = 80960, idle = 209356809
kern.cp_time: user = 4322591, nice = 0, sys = 1818187, intr = 80960, idle = 209356910
kern.cp_time: user = 4322591, nice = 0, sys = 1818187, intr = 80960, idle = 209357011
kern.cp_time: user = 4322591, nice = 0, sys = 1818187, intr = 80960, idle = 209357112
kern.cp_time: user = 4322591, nice = 0, sys = 1818187, intr = 80960, idle = 209357213

8 opteron cores
 $ uptime ; while :; do sysctl kern.cp_time ; sleep 1 ; done
 7:56PM  up 21:44, 1 user, load averages: 0.11, 0.10, 0.08
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62538479
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62539283
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62540091
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62540899
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62541707
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62542515
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62543323
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62544131
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62544939
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62545747
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62546555
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62547363
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62548171
kern.cp_time: user = 16500, nice = 0, sys = 26953, intr = 2971, idle = 62548979






-- 
George Georgalis, systems architect, administrator <IXOYE><