Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Oct 2020 14:45:57 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        David Wolfskill <david@catwhisker.org>, Wojciech Puchar <wojtek@puchar.net>, freebsd-hackers@freebsd.org
Subject:   Re: displaying total CPU usage
Message-ID:  <20201023114557.GX2643@kib.kiev.ua>
In-Reply-To: <20201023112030.GF1427@albert.catwhisker.org>
References:  <alpine.BSF.2.20.2010231301550.3469@puchar.net> <20201023112030.GF1427@albert.catwhisker.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Oct 23, 2020 at 04:20:30AM -0700, David Wolfskill wrote:
> On Fri, Oct 23, 2020 at 01:03:30PM +0200, Wojciech Puchar wrote:
> > how to do it in batch - something like this line
> > 
> > CPU:  0.8% user,  0.0% nice,  1.3% system,  0.0% interrupt, 97.9% idle
> > 
> > from top but produced in non terminal/batch mode
> > 
> > all my attempts to do it with top failed - this line is missing
> > ....
> 
> Measuring CPU usage requires sampling the per-state counters at the
> beginning and at the end of an interval: it's thus done over a time
> period, not an "instant."
> 
> It's a bit of arthmetic, but you can get the counters via `sysctl
> kern.cp_time` (if you want per-core, use `sysctl kern.cp_times`).
> 
> The result is a (per-core array, in the latter case) array of counters:
> system, interrupt, user, nice, and idle.
> 
> Each difference will be the numerator; the sum of the differences will
> be the denominator for each state.  Multiply each fraction by 100 if you
> want percentages.

`vmstat 1' readily provides the measurements.



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