From owner-freebsd-hackers@freebsd.org Mon Nov 6 10:16:18 2017 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 27C40E588FF for ; Mon, 6 Nov 2017 10:16:18 +0000 (UTC) (envelope-from v.velox@vvelox.net) Received: from vulpes.vvelox.net (vulpes.vvelox.net [96.95.67.25]) by mx1.freebsd.org (Postfix) with ESMTP id 0CB8268426 for ; Mon, 6 Nov 2017 10:16:17 +0000 (UTC) (envelope-from v.velox@vvelox.net) Received: from vvelox.net (vulpes.vvelox.net [192.168.14.42]) (Authenticated sender: kitsune) by vulpes.vvelox.net (Postfix) with ESMTPA id D000B224A9A3 for ; Mon, 6 Nov 2017 04:16:16 -0600 (CST) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 06 Nov 2017 04:16:16 -0600 From: "Zane C. B-H." To: freebsd-hackers@freebsd.org Subject: Re: using pctcpu In-Reply-To: References: Message-ID: <90c4bd3e914ee531a99a98291e12bf16@vvelox.net> X-Sender: v.velox@vvelox.net User-Agent: Roundcube Webmail/1.3-beta X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Nov 2017 10:16:18 -0000 On 2017-10-09 23:16, Zane C. B-H. wrote: > Using https://metacpan.org/pod/BSD::Process that to get pctcpu, but I > can't get it to line up nicely with ps. > > The closest I can get is dividing pctcpu by 20, but that still tends > to run high. For example dividing by 20 will give me 1635.8 while ps > will show 1595.3. > > I know the 1635.8 is definitely off as this machine only has 16 cores. The answer to this happens to be... my $bproc=BSD::Process::info( $proc->pid ); my $pctcpu=$bproc->{pctcpu}; if ( ! defined( $pctcpu ) ){ $values{pctcpu}=0 }else{ my $fscale=`/sbin/sysctl -a kern.fscale`; $fscale=~s/^.*\: //; chomp($fscale); $values{pctcpu}= 100 * ( $pctcpu / $fscale ); } Also Wooho! Initial release of Proc-ProcessTable-Colorizer published to CPAN. :3