tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: top on machines with more than 9 CPUs
In article <20100624145307.GM12982%beverly.kleinbus.org@localhost>,
Ignatios Souvatzis <is%netbsd.org@localhost> wrote:
>Hi,
>
>one of my users at work, monitoring his computation on our 12-CPU amd64,
>noticed that the output of top is slightly distorted.
>
>I investigated, and found that this is caused by a formatting that only
>checks for 1 or more than 1 CPU, but assumes fixed column positions.
>
>Also, the width computation is off by one per column, leading to
>unnecessary early switch to the abbreviated format.
>
>I found that changing top/dist/display.c to thus:
>
>diff -u -r1.7 display.c
>--- display.c 5 May 2009 18:52:13 -0000 1.7
>+++ display.c 24 Jun 2010 14:35:11 -0000
>@@ -854,7 +854,8 @@
> *ip++ = cpustate_total_length;
> if ((i = strlen(*pp++)) > 0)
> {
>- cpustate_total_length += i + 8;
>+ cpustate_total_length += i + 7;
>+ /* strlen(" 100% ") is 6, strlen(" 99.9% ") is 7. Never 8. */
> }
> }
> }
>
>and to change cpustates_tag() to read (sorry, the diff is longer and
>unreadable).
>
>static char *
>cpustates_tag(int c)
>
>{
> unsigned width, u;
> static char fmttag[100];
>
> const char *short_tag = !multi || ncpu <= 1 ? "CPU: " : "CPU%0*d";
>
> const char *long_tag = !multi || ncpu <= 1 ?
> "CPU states: " : "CPU%0*d states: ";
>
> for (width=0, u=ncpu; u>0; u /= 10) {
> ++width;
> }
> /* if length + strlen(long_tag) > screen_width, then we have to
> use the shorter tag */
>
> snprintf(fmttag, sizeof(fmttag), long_tag, width, c);
>
> if (cpustate_total_length + (signed)strlen(fmttag) > screen_width) {
> snprintf(fmttag, sizeof(fmttag), short_tag, width, c);
> }
>
> /* set x_cpustates accordingly then return result */
> x_cpustates = strlen(fmttag);
> return(fmttag);
>}
>
>fixes both problems. I'll commit next week unless serious objections
>arise. Of course I'll feed the change upstreams.
I thought it could be more than 100% like 204.3%
christos
Home |
Main Index |
Thread Index |
Old Index