how to calculate CPU utilization?

Nimnod nimnod at
Sat Feb 12 04:30:13 PST 2005


i am looking for how to accurately calculate the CPU utilization per  
i have looked through the top sources, and found out it's using the kvm  
lib, which isn't suitable for my purpose.
is there a way to accurately calculate %CPU based on information from the  
struct proc ? it does carry info on proc time (p_runtime), system, user  
and interrupt ticks, and previous system, user and int times in usec, but  
i just can't make the right equation to get the appropriate values.
first, i attempted to divide the process runtime by system uptime, which  
seemed ok, but obviously this is not the way.
could anyone please help?


More information about the freebsd-hackers mailing list