From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 1 14:53:13 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D0D0A10656EC; Tue, 1 Feb 2011 14:53:13 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 909598FC15; Tue, 1 Feb 2011 14:53:13 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 3144046B03; Tue, 1 Feb 2011 09:53:13 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.10]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 47A468A02B; Tue, 1 Feb 2011 09:53:12 -0500 (EST) From: John Baldwin To: Alexander Best Date: Tue, 1 Feb 2011 09:39:38 -0500 User-Agent: KMail/1.13.5 (FreeBSD/7.4-CBSD-20110107; KDE/4.4.5; amd64; ; ) References: <20110201122432.GA6786@freebsd.org> <20110201131154.GA14569@freebsd.org> In-Reply-To: <20110201131154.GA14569@freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201102010939.38474.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Tue, 01 Feb 2011 09:53:12 -0500 (EST) X-Virus-Scanned: clamav-milter 0.96.3 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=0.5 required=4.2 tests=BAYES_00,MAY_BE_FORGED, RDNS_DYNAMIC autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on bigwig.baldwin.cx Cc: freebsd-hackers@freebsd.org, Sergey Kandaurov Subject: Re: weird characters in top(1) output X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2011 14:53:14 -0000 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 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: 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