From owner-freebsd-hackers@FreeBSD.ORG Sat Feb 12 12:30:13 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 75B4F16A4CE for ; Sat, 12 Feb 2005 12:30:13 +0000 (GMT) Received: from gnu.univ.gda.pl (gnu.univ.gda.pl [153.19.120.250]) by mx1.FreeBSD.org (Postfix) with ESMTP id 075F843D45 for ; Sat, 12 Feb 2005 12:30:12 +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 1CzwPa-0005Ic-00 for ; Sat, 12 Feb 2005 13:30:10 +0100 To: freebsd-hackers@freebsd.org Date: Sat, 12 Feb 2005 13:30:32 +0100 From: Nimnod Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: User-Agent: Opera M2/7.54 (FreeBSD, build 955) Subject: 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 12:30:13 -0000 Hi, 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. 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? rgds, Nimnod.