From: "Theo de Raadt" Subject: Re: iostat cpu stats To: "Ted Unangst" Cc: tech@openbsd.org Date: Wed, 07 May 2025 08:00:07 -0600 Please put a comment there "limited to 99 because there is no more printing room" or something. Ted Unangst wrote: > Today's featured column width is iostat. > > Running iostat -w 1 I see a lot of messy output in the idle column. > > 0 68 0.00 0 0.00 0.00 0 0.00 0 0 1 0 0 99 > 0 70 0.00 0 0.00 0.00 0 0.00 0 0 0 0 0100 > 0 69 2.00 2 0.00 2.00 2 0.00 0 0 0 0 0100 > 0 69 0.00 0 0.00 0.00 0 0.00 0 0 0 0 1 99 > > Looking at the code, there's even a comment that 100% is too rare to > worry about. But my laptop is faster than the vaxen of yore, and I see > 100 all the time. I think a passable fix is to simply truncate to 99. > The columns are never guaranteed to sum up, and 100 in one column is > always a rounding error, so I think this is sufficiently accurate. > > 0 69 0.00 0 0.00 0.00 0 0.00 0 0 0 0 0 99 > 0 69 16.00 2 0.03 16.00 2 0.03 0 0 0 0 0 99 > 0 69 14.25 16 0.22 14.25 16 0.22 0 0 0 0 0 99 > 0 68 0.00 0 0.00 0.00 0 0.00 0 0 0 0 1 99 > > Index: iostat.c > =================================================================== > RCS file: /home/cvs/src/usr.sbin/iostat/iostat.c,v > diff -u -p -r1.47 iostat.c > --- iostat.c 8 Mar 2023 04:43:13 -0000 1.47 > +++ iostat.c 6 May 2025 21:30:33 -0000 > @@ -354,8 +354,12 @@ cpustats(void) > if (!t) > t = 1.0; > /* States are generally never 100% and can use %3.0f. */ > - for (state = 0; state < CPUSTATES; ++state) > - printf("%3.0f", 100. * cur.cp_time[state] / t); > + for (state = 0; state < CPUSTATES; ++state) { > + double v = 100. * cur.cp_time[state] / t; > + if (v > 99) > + v = 99; > + printf("%3.0f", v); > + } > } > > static void >