From owner-freebsd-hackers@FreeBSD.ORG Sat Feb 12 20:51:26 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1E9A416A4CE for ; Sat, 12 Feb 2005 20:51:26 +0000 (GMT) Received: from gnu.univ.gda.pl (gnu.univ.gda.pl [153.19.120.250]) by mx1.FreeBSD.org (Postfix) with ESMTP id BEDB843D2D for ; Sat, 12 Feb 2005 20:51:25 +0000 (GMT) (envelope-from nimnod@gnu.univ.gda.pl) Received: from host76-193-24-244.limes.com.pl ([193.24.244.76] helo=localhost.kolonianet.pl) by gnu.univ.gda.pl with esmtp (Exim 3.36 #2 (Debian)) id 1D04EZ-0001Cv-00 for ; Sat, 12 Feb 2005 21:51:19 +0100 To: "freebsd-hackers@freebsd.org" References: <20050212201651.GE49626@dan.emsphone.com> Message-ID: Date: Sat, 12 Feb 2005 21:51:43 +0100 From: Nimnod Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In-Reply-To: <20050212201651.GE49626@dan.emsphone.com> User-Agent: Opera M2/7.54 (FreeBSD, build 955) Subject: Re: how to calculate CPU utilization? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Feb 2005 20:51:26 -0000 On Sat, 12 Feb 2005 14:16:51 -0600, Dan Nelson 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.