NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/43562: top: CPU percentages overlap labels



>Number:         43562
>Category:       bin
>Synopsis:       top: CPU percentages overlap labels
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 03 09:40:00 +0000 2010
>Originator:     Witold Jan Wnuk
>Release:        NetBSD-current
>Organization:
>Environment:
NetBSD foster 5.99.33 NetBSD 5.99.33 (FOSTER) #23: Sat Jul  3 09:07:28 CEST 
2010  w@foster:/home/w/NetBSD/src/sys/arch/i386/compile/FOSTER i386

>Description:
CPU0 states: 99.0% user, 0.0 % nice 0.0  % syste 0.0   % interru 1.0    % idle


>How-To-Repeat:

>Fix:
1. Revert column position calculation change from rev. 1.8
2. Fix cpustate_total_length calculation
3. Add missing ": " in short_tag
4. Fix CPU number maximum width calculation

Index: external/bsd/top/dist/display.c
===================================================================
RCS file: /cvsroot/src/external/bsd/top/dist/display.c,v
retrieving revision 1.8
diff -u -r1.8 display.c
--- external/bsd/top/dist/display.c     30 Jun 2010 11:08:12 -0000      1.8
+++ external/bsd/top/dist/display.c     3 Jul 2010 08:28:34 -0000
@@ -854,10 +854,10 @@
            *ip++ = cpustate_total_length;
            if ((i = strlen(*pp++)) > 0)
            {
-               cpustate_total_length += i + 7;
-               /* strlen(" 100% ") is 6, strlen(" 99.9% ") is 7. Never 8. */
+               cpustate_total_length += i + 8;
            }
        }
+       cpustate_total_length -= 2;
     }

 #ifdef ENABLE_COLOR
@@ -1151,24 +1151,24 @@
 cpustates_tag(int c)

 {
-    unsigned width, u;
+    unsigned maxcpuno_width, u;

     static char fmttag[100];

-    const char *short_tag = !multi || ncpu <= 1 ? "CPU: " : "CPU%0*d";
+    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;
+    for (maxcpuno_width = 0, u = ncpu - 1; u > 0; u /= 10) {
+       ++maxcpuno_width;
     }
+
     /* if length + strlen(long_tag) > screen_width, then we have to
        use the shorter tag */
-
-    snprintf(fmttag, sizeof(fmttag), long_tag, width, c);
+    snprintf(fmttag, sizeof(fmttag), long_tag, maxcpuno_width, c);

     if (cpustate_total_length + (signed)strlen(fmttag)  > screen_width) {
-       snprintf(fmttag, sizeof(fmttag), short_tag, width, c);
+       snprintf(fmttag, sizeof(fmttag), short_tag, maxcpuno_width, c);
     }

     /* set x_cpustates accordingly then return result */



Home | Main Index | Thread Index | Old Index