From owner-freebsd-hackers@FreeBSD.ORG Mon Apr 5 05:08:41 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 3C8D116A4CF for ; Mon, 5 Apr 2004 05:08:41 -0700 (PDT) Received: from saci.ensmp.fr (saci.ensmp.fr [194.214.158.176]) by mx1.FreeBSD.org (Postfix) with ESMTP id D221443D1D for ; Mon, 5 Apr 2004 05:08:40 -0700 (PDT) (envelope-from Jose-Marcio.Martins@ensmp.fr) Received: from ensmp.fr ([194.214.158.176]) by saci.ensmp.fr (sendmail 9.0.0.PreAlpha11) with ESMTP id S00000000406943D401; Mon, 5 Apr 2004 14:08:39 +0200 Message-ID: <40714C47.20802@ensmp.fr> Date: Mon, 05 Apr 2004 14:08:39 +0200 From: Jose Marcio Martins da Cruz Organization: Ecole des Mines de Paris User-Agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.0.1) Gecko/20020920 Netscape/7.0 X-Accept-Language: fr, en MIME-Version: 1.0 To: Dan Nelson References: <406D6CEF.9030501@ensmp.fr> <20040402205301.GD6724@dan.emsphone.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-hackers@freebsd.org 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: Mon, 05 Apr 2004 12:08:41 -0000 Hello, Thanks Dan. This is the best. I also tried using kvm, but code is longer and the program shall run as root. I'm working on a daemon which shall evaluate CPU load and SHALL not run as root. Best regards, Jose-Marcio Dan Nelson wrote: > 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. > -- --------------------------------------------------------------- Jose Marcio MARTINS DA CRUZ Tel. :(33) 01.40.51.93.41 Ecole des Mines de Paris http://j-chkmail.ensmp.fr 60, bd Saint Michel http://www.ensmp.fr/~martins 75272 - PARIS CEDEX 06 mailto:Jose-Marcio.Martins@ensmp.fr