Date: Sat, 12 Feb 2005 21:51:43 +0100 From: Nimnod <nimnod@gnu.univ.gda.pl> To: "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org> Subject: Re: how to calculate CPU utilization? Message-ID: <opsl3qwhta5x937e@localhost.kolonianet.pl> In-Reply-To: <20050212201651.GE49626@dan.emsphone.com> References: <opsl23o6hf5x937e@localhost.kolonianet.pl> <20050212201651.GE49626@dan.emsphone.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 12 Feb 2005 14:16:51 -0600, Dan Nelson <dnelson@allantgroup.com> wrote: > In the last episode (Feb 12), Nimnod said: >> i am looking for how to accurately calculate the CPU utilization per >> process. i have looked through the top sources, and found out it's >> using the kvm lib, which isn't suitable for my purpose. > > Why not? You don't need to be setuid root to call kvm functions; when > possible they fetch their info via sysctl. Neither top nor ps are > setuid. > Well, unfortunately you DO need to be setuid if you want to list all processes and the sysctl showallprocs is set to 0. That's the first thing. The reason why i don't want or even can't use kvm is because this to be used by non-suid app which interacts with a custom kern module, calling custom syscall. At the beginning of the project I considered two approaches - a suid app without modules, and a non-suid one getting proc info and doing other stuff through the kernel space. You cannot call kvm functions from within the module, and setuiding my app right now just for the sake of KVM, would prove the whole idea useless, getting me a hybrid system, partially talking to a module, and partially making use of setuid feature. Whilst, then, the module part would make more sense when moved to the app sources, thus, in turn, leaving the module itself useless. :) > You need to take two samples separated by some delay (1 or 5 seconds > maybe), then take their difference and divide by the delay. That will > give you the cpu usage over that period. > Thx for this one. About to try out. rgds, Nimnod.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?opsl3qwhta5x937e>