Date: Sun, 23 Nov 2014 09:45:55 -0800 From: David Wolfskill <david@catwhisker.org> To: Fernando =?iso-8859-1?Q?Apestegu=EDa?= <fernando.apesteguia@gmail.com> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: top -d1 behavior Message-ID: <20141123174555.GB1228@albert.catwhisker.org> In-Reply-To: <CAGwOe2Zp2cHhCb%2Br_m5HZYJFyc=3DDsPEi7v_7ZVxJ0fkO1jEA@mail.gmail.com> References: <CAGwOe2Zp2cHhCb%2Br_m5HZYJFyc=3DDsPEi7v_7ZVxJ0fkO1jEA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--JYK4vJDZwFMowpUq Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Nov 23, 2014 at 06:11:02PM +0100, Fernando Apestegu=EDa wrote: > Hi hackers, >=20 > While writing a small script for a friend, I run into a peculiar top beha= vior: >=20 > top -d1 shows only one 'iteration' of the information screen, but in > it, the CPU percentages line is not well formed: there are 5 columns > with the '%' symbol, but no values are shown. This only happens for > -d1 and this behavior is deliberately done in the sources (see > 'dostates' variable). > ... > My point is: why are we doing this? If we remove that constraint, top > would show the values for -d1. I don't know if they would be really > accurate, but not printing anything doesn't seem a nice behavior > either (especially when this is not documented in the man page) > .... At the time of the inital display, the program only has access to the counters (from kern.cp_time) from one instant. In order to calculate the relative proportion of CPU time spent in each of the 5 states, it is necessary to determine the extent to which those counters changed over an interval. If we call the time when the first sample is taken "T0" and the time when the second sample is takne "T1", we get something like: Time user nice sys intr idle T0 user_0 nice_0 sys_0 intr_0 idle_0 T1 user_1 nice_1 sys_1 intr_1 idle_1 To determine the relative proportions for the interval from T0:T1, we first determnine the differences (or deltas): user_delta <=3D=3D user_1 - user_0 nice_delta <=3D=3D nice_1 - nice_0 sys_delta <=3D=3D sys_1 - sys_0 intr_delta <=3D=3D intr_1 - intr_0 idle_delta <=3D=3D idle_1 - idle_0 Then sum the deltas: Interval_total =3D user_delta + nice_delta + sys_delta + intr_delta + idle_= delta Then, for each of user, nice, sys, intr, and idle, the percentage for the interval is 100 * _delta / Interval_total. Here's a sample (produced by a little shell script): albert(10.1-S)[6] get_sys_info -N 0 -c 2 -w 10 kern.cp_time time:1416763949 kern.cp_time:20934 0 28872 5664 1027225=20 time:1416763959 kern.cp_time:20980 0 28933 5674 1029686=20 Given those numbers, we have: Time user nice sys intr idle 1416763949 20934 0 28872 5664 1027225 1416763959 20980 0 28933 5674 1029686 The differences: user nice sys intr idle 46 0 61 10 2461 The total of the deltas is 46+0+61+10+2461 =3D=3D> 2578. The percentages: user nice sys intr idle 1.78 0.00 2.37 0.39 95.46 (System's uptime, in this case, was a little over an hour -- I had just updated in to stable/10 @r274909.) Peace, david --=20 David H. Wolfskill david@catwhisker.org Taliban: Evil cowards with guns afraid of truth from a 14-year old girl. See http://www.catwhisker.org/~david/publickey.gpg for my public key. --JYK4vJDZwFMowpUq Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQJ8BAEBCgBmBQJUch1SXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQ4RThEMDY4QTIxMjc1MDZFRDIzODYzRTc4 QTY3RjlDOERFRjQxOTNCAAoJEIpn+cje9Bk7MPsP/ivKBYwNjc5qPhW/55eJz/w9 LHa03wTPo7AXIS2eS+RxLSyUdQADa8Vv6Z/DfOjfUQnSG3V+92YyjLSQNS9KPPbu DCWikSWirMbe2V+Vj9dUusxX2HFaQushViK8lD52ZMwNXehsIqkTg8WgyyFH6MUh 8Ss2sSn1choU25ZSlhs/vcLz8rBKLc8UQ+uiXTkC0ARD80xhRizF9NbzKZcBAd2W 4Eq5rjobDrPLGrlLqcvyAjzfRu94Pv0MVpSFnwiobLfcig5pBEVx9G+EsLLL/FQu 63T4M4t9NRwsyuRDtVuDj60PtXkGumGi+YpznldLjL1nqL9m3wNrKcyoDp+91+FC hjZ4Y2BFYi+1oEGAvUyUJExj6WESCbESfPMRdHWnIPgl/NoRHosPomPdQDAZueZm NwrjHr4M/1iW7iiO4wtwikwbG3KVZaRTmBHgu8C78hwrvhogQshJua9bGdaMFKZS E464Fpyn6iZQVH1ucWo6kQP5qp9G/Dc10IJxpmRNsiMJvTcMGplSe8+GMncW2Rl5 K80Kjs0W2/61kATsgiOzgE4Wrixpu90ewIx8bdLwTNxpthV7PhKVDj5OmFAWy1jo T8tGA9fWaly72AMoEJhSoOn6wSq6eYpIBKG15PBH2eXR+im4cs67syfmFMO502/I ehcZZUOG8FO8osPUceKa =tRby -----END PGP SIGNATURE----- --JYK4vJDZwFMowpUq--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141123174555.GB1228>