On Wed, Jan 13, 2010 at 2:07 AM, Sebastian Spies <sebastian.sp...@de-cix.net> wrote: > I need a method to get the load of a process in percent of cpu time on a > per second basis, just like top on Linux does.
So grab the code in 'top' or 'ps' that calculates the process cumulative cpu time and run that twice, one second apart, then do the subtraction and express as a percentage. Depending on your philosophy of MP, divide by the # of CPUs. WTP? > As I couldn't find something that does the calculation on a per second > basis, I started to write something on my own. For that reason I plan to > look at struct kinfo_proc2 field p_cpticks of libkvm, but this field > gives me some odd values, which I'm unable to interpret. Could you > please comment on the following code? No, you don't want p_cpticks, as that's zeroed every time schedcpu() runs. Philip Guenther