Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 06 Nov 2017 04:16:16 -0600
From:      "Zane C. B-H." <v.velox@vvelox.net>
To:        freebsd-hackers@freebsd.org
Subject:   Re: using pctcpu
Message-ID:  <90c4bd3e914ee531a99a98291e12bf16@vvelox.net>
In-Reply-To: <f26ba6655ab2059362eacf251f0e0c5b@vvelox.net>
References:  <f26ba6655ab2059362eacf251f0e0c5b@vvelox.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?90c4bd3e914ee531a99a98291e12bf16>