From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 2 12:53:11 2004 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 C037216A4CE for ; Fri, 2 Apr 2004 12:53:11 -0800 (PST) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 77D0743D46 for ; Fri, 2 Apr 2004 12:53:11 -0800 (PST) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.10/8.12.10) id i32Kr2bY049006; Fri, 2 Apr 2004 14:53:02 -0600 (CST) (envelope-from dan) Date: Fri, 2 Apr 2004 14:53:02 -0600 From: Dan Nelson To: Dag-Erling Smorgrav Message-ID: <20040402205301.GD6724@dan.emsphone.com> References: <406D6CEF.9030501@ensmp.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-OS: FreeBSD 5.2-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.6i cc: freebsd-hackers@freebsd.org cc: Jose Marcio Martins da Cruz Subject: Re: Pointers about CPU load measuring 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: Fri, 02 Apr 2004 20:53:11 -0000 In the last episode (Apr 02), Dag-Erling Smorgrav said: > Jose Marcio Martins da Cruz writes: > > Someone can send some pointers on how to measure global CPU load under > > FreeBSD from a C program ? I'm looking for values for > > idle/kernel/user, in a similar way as does top. Is there any pointer > > or doc ?. I'd like to avoir browsing top code. > > Use sysctlbyname(3) to retrieve vm.loadavg, which is a struct loadavg > (defined in ) Actually the kern.cp_time variable might be better if you want idle/kernel/user values. It returns a long cp_time[CPUSTATES]; the states are listed in . Top calculates percentages by keeping the previous interval values, calculating diffs, totaling up the diffs, and setting percentage[cpustate] = diff[cpustate]/totaldiff. -- Dan Nelson dnelson@allantgroup.com