From owner-freebsd-hackers@freebsd.org Fri Oct 23 11:20:39 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 24BEC443A51 for ; Fri, 23 Oct 2020 11:20:39 +0000 (UTC) (envelope-from david@catwhisker.org) Received: from mx.catwhisker.org (mx.catwhisker.org [107.204.234.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4CHhc56W71z40f4 for ; Fri, 23 Oct 2020 11:20:37 +0000 (UTC) (envelope-from david@catwhisker.org) Received: from albert.catwhisker.org (localhost [127.0.0.1]) by albert.catwhisker.org (8.16.1/8.15.2) with ESMTP id 09NBKUB5050780; Fri, 23 Oct 2020 11:20:30 GMT (envelope-from david@albert.catwhisker.org) Received: (from david@localhost) by albert.catwhisker.org (8.16.1/8.16.1/Submit) id 09NBKUEH050779; Fri, 23 Oct 2020 04:20:30 -0700 (PDT) (envelope-from david) Date: Fri, 23 Oct 2020 04:20:30 -0700 From: David Wolfskill To: Wojciech Puchar Cc: freebsd-hackers@freebsd.org Subject: Re: displaying total CPU usage Message-ID: <20201023112030.GF1427@albert.catwhisker.org> Mail-Followup-To: David Wolfskill , Wojciech Puchar , freebsd-hackers@freebsd.org References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Lfdj09rG01n7l08B" Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4CHhc56W71z40f4 X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of david@catwhisker.org designates 107.204.234.170 as permitted sender) smtp.mailfrom=david@catwhisker.org X-Spamd-Result: default: False [-5.44 / 15.00]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; FREEFALL_USER(0.00)[david]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:107.204.234.170]; NEURAL_HAM_LONG(-1.01)[-1.006]; MIME_GOOD(-0.20)[multipart/signed,text/plain]; DMARC_NA(0.00)[catwhisker.org]; NEURAL_HAM_MEDIUM(-0.97)[-0.975]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-1.06)[-1.058]; RCPT_COUNT_TWO(0.00)[2]; SIGNED_PGP(-2.00)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ASN(0.00)[asn:7018, ipnet:107.192.0.0/12, country:US]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-hackers] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Oct 2020 11:20:39 -0000 --Lfdj09rG01n7l08B Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Oct 23, 2020 at 01:03:30PM +0200, Wojciech Puchar wrote: > how to do it in batch - something like this line >=20 > CPU: 0.8% user, 0.0% nice, 1.3% system, 0.0% interrupt, 97.9% idle >=20 > from top but produced in non terminal/batch mode >=20 > 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. Peace, david --=20 David H. Wolfskill david@catwhisker.org My ballot status: "Your ballot has been accepted! Your ballot was received by your county elections office and will be counted." See http://www.catwhisker.org/~david/publickey.gpg for my public key. --Lfdj09rG01n7l08B Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGTBAEBCgB9FiEE4owz2QxMJyaxAefyQLJg+bY2PckFAl+SvH1fFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEUy OEMzM0Q5MEM0QzI3MjZCMTAxRTdGMjQwQjI2MEY5QjYzNjNEQzkACgkQQLJg+bY2 PclYYAf/WWMkW8QNyye8u98qgrsazO6bcc8TGYZoaceGU3sD9ap2eDWejBunNdP/ +zY+ppo1V1iEoyLvy7IaENgk7KeoVTyAvOzRnQ2EoTCDHNN3yYJg8YPnD/0SVI+N JgVmUEEbVQwmf9jreNy2gYlqK6p8NzOiHqds1A+NoLapdLWr1tJizUif7S45Co6p QrCJOAGMVySXnyx0Mqw7jvv+Q0XLa2XBSISQwDP2g5b3+lxwUiZ64EaxeiseUKin SI40PKiPoJPopyA5/rcdnL7GyTgLLTDA7/e+rdZVzRKcLuUCPKW4/XIuJds5pjvy B6GRKOyjq8fpjBqoGtrOuTL0L7bFSg== =eSJb -----END PGP SIGNATURE----- --Lfdj09rG01n7l08B--