Date: Tue, 1 Feb 2011 15:17:20 +0000 From: Alexander Best <arundel@freebsd.org> To: John Baldwin <jhb@freebsd.org> Cc: freebsd-hackers@freebsd.org, Sergey Kandaurov <pluknet@gmail.com> Subject: Re: weird characters in top(1) output Message-ID: <20110201151720.GA34590@freebsd.org> In-Reply-To: <201102010939.38474.jhb@freebsd.org> References: <20110201122432.GA6786@freebsd.org> <AANLkTinxVd5wieR87vpQHU6Dg4RO_CvFyoB=pN4dLc5J@mail.gmail.com> <20110201131154.GA14569@freebsd.org> <201102010939.38474.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue Feb 1 11, John Baldwin wrote:
> On Tuesday, February 01, 2011 8:11:54 am Alexander Best wrote:
> > On Tue Feb 1 11, Sergey Kandaurov wrote:
> > > On 1 February 2011 15:24, Alexander Best <arundel@freebsd.org> wrote:
> > > > hi there,
> > > >
> > > > i was doing the following:
> > > >
> > > > top inf > ~/output
> > > >
> > > > when i noticed that this was missing the overall statistics line. so i went
> > > > ahead and did:
> > > >
> > > > top -d2 inf > ~/output
> > > >
> > > > funny thing is that for the second output some weird characters seem to get
> > > > spammed into the overall statistics line:
> > > >
> > > > last pid: 14320; load averages: 0.42, 0.44, 0.37 up 1+14:02:02 13:21:05
> > > > 249 processes: 1 running, 248 sleeping
> > > > CPU: ^[[3;6H 7.8% user, 0.0% nice, 10.6% system, 0.6% interrupt, 81.0% idle
> > > > Mem: 1271M Active, 205M Inact, 402M Wired, 67M Cache, 212M Buf, 18M Free
> > > > Swap: 18G Total, 782M Used, 17G Free, 4% Inuse
> > > >
> > > > this only seems to happen when i redirect the top(1) output to a file. if i do:
> > > >
> > > > top -d2 inf
> > > >
> > > > ...everything works fine. i verified the issue under zsh(1) and sh(1).
> > >
> > > My quick check shows that this is a regression between 7.2 and 7.3.
> > > Reverting r196382 fixes this bug for me.
> >
> > thanks for the help. indeed reverting r196382 fixes the issue.
>
> Hmm, you need more than 10 CPUs to understand the reason for that fix.
> Without it all of the updated per-CPU states are off by one column so you
> get weird screen effects. The "garbage" characters are actually just a
> terminal sequence to move the cursor. top uses these things a _lot_ to
> move the cursor around.
>
> You can try this instead though, it figures out the appropriate number of
> spaces rather than using Move_to() for these two routines:
the patch works for me:
last pid: 15311; load averages: 0.13, 0.54, 0.73 up 1+16:56:18 16:15:21
276 processes: 2 running, 273 sleeping, 1 zombie
CPU: 9.8% user, 0.0% nice, 16.5% system, 2.2% interrupt, 71.6% idle
Mem: 1329M Active, 135M Inact, 417M Wired, 79M Cache, 212M Buf, 1608K Free
Swap: 18G Total, 1414M Used, 17G Free, 7% Inuse, 4K In
#CPU cores == 2 on my system btw.
cheers.
alex
>
> Index: display.c
> ===================================================================
> --- display.c (revision 218032)
> +++ display.c (working copy)
> @@ -447,12 +447,14 @@
> /* print tag and bump lastline */
> if (num_cpus == 1)
> printf("\nCPU: ");
> - else
> - printf("\nCPU %d: ", cpu);
> + else {
> + value = printf("\nCPU %d: ", cpu);
> + while (value++ <= cpustates_column)
> + printf(" ");
> + }
> lastline++;
>
> /* now walk thru the names and print the line */
> - Move_to(cpustates_column, y_cpustates + cpu);
> while ((thisname = *names++) != NULL)
> {
> if (*thisname != '\0')
> @@ -532,7 +534,7 @@
> register char **names;
> register char *thisname;
> register int *lp;
> - int cpu;
> + int cpu, value;
>
> for (cpu = 0; cpu < num_cpus; cpu++) {
> names = cpustate_names;
> @@ -540,11 +542,13 @@
> /* show tag and bump lastline */
> if (num_cpus == 1)
> printf("\nCPU: ");
> - else
> - printf("\nCPU %d: ", cpu);
> + else {
> + value = printf("\nCPU %d: ", cpu);
> + while (value++ <= cpustates_column)
> + printf(" ");
> + }
> lastline++;
>
> - Move_to(cpustates_column, y_cpustates + cpu);
> while ((thisname = *names++) != NULL)
> {
> if (*thisname != '\0')
>
> --
> John Baldwin
--
a13x
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110201151720.GA34590>
