From nobody@FreeBSD.org  Sat Jun 23 08:57:50 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 5087D37B407
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 23 Jun 2001 08:57:50 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.3/8.11.3) id f5NFvoK20343;
	Sat, 23 Jun 2001 08:57:50 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200106231557.f5NFvoK20343@freefall.freebsd.org>
Date: Sat, 23 Jun 2001 08:57:50 -0700 (PDT)
From: Tyler Spivey <tspivey8@home.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: top -d 1 will not show proper information concerning cpu states, nor will -d1
X-Send-Pr-Version: www-1.0

>Number:         28367
>Category:       bin
>Synopsis:       top -d 1 will not show proper information concerning cpu states, nor will -d1
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jun 23 09:00:12 PDT 2001
>Closed-Date:    Thu Aug 2 11:53:04 PDT 2001
>Last-Modified:  Thu Aug 02 11:54:50 PDT 2001
>Originator:     Tyler Spivey
>Release:        4.3-r
>Organization:
>Environment:
FreeBSD home.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Thu Jun 21 19:22:35 EDT 2001     root@home.com:/usr/src/sys/compile/FAST  i386
>Description:
here is the script command showing top (-d1 and -d 1).
Script started on Sat Jun 23 07:52:20 2001
bash-2.05$ top -d1
[H[Jlast pid: 10966;  load averages:  0.21,  0.76,  0.50[1;56H up 0+12:57:55[1;72H07:52:29
44 processes:  1 running, 43 sleeping
CPU states:     % user,     % nice,     % system,     % interrupt,     % idle
Mem: 24M Active, 16M Inact, 13M Wired, 3816K Cache, 14M Buf, 2884K Free
Swap: 204M Total, 128K Used, 204M Free

  PID USERNAME PRI NICE  SIZE    RES STATE    TIME   WCPU    CPU COMMAND
  364 tspivey8  10   0  9592K  8944K wait     1:43  0.00%  0.00% perl
  291 tspivey8   2   0  1720K  1216K select   0:09  0.00%  0.00% screen
  208 root       2   0   352K   124K nfsd     0:02  0.00%  0.00% nfsd
  298 root       3   0  1388K   956K ttyin    0:01  0.00%  0.00% csh
  295 tspivey8   3   0  1068K   740K ttyin    0:01  0.00%  0.00% bash
  244 root       2   0  2484K  1448K select   0:01  0.00%  0.00% sendmail
  241 root      10   0   968K   620K nanslp   0:00  0.00%  0.00% cron
  195 root       2   0   924K   560K select   0:00  0.00%  0.00% syslogd
  248 root       2   0  2488K  1192K select   0:00  0.00%  0.00% sshd
  290 tspivey8  18   0  1508K   840K pause    0:00  0.00%  0.00% screen
  250 root       2   0   896K   504K select   0:00  0.00%  0.00% usbd
10966 tspivey8  30   0  1896K   916K RUN      0:00  0.00%  0.00% top
  288 tspivey8  10   0  1052K   680K wait     0:00  0.00%  0.00% bash
 1199 tspivey8   2   0  2380K  1412K select   0:00  0.00%  0.00% ssh
  239 root       2   0  1048K   620K select   0:00  0.00%  0.00% inetd
  209 root       2   0   352K   124K nfsd     0:00  0.00%  0.00% nfsd
  210 root       2   0   352K   124K nfsd     0:00  0.00%  0.00% nfsd[6;1H[24;1H[Kbash-2.05$ top -d 1
[H[Jlast pid: 10967;  load averages:  0.15,  0.71,  0.49[1;56H up 0+12:58:15[1;72H07:52:49
44 processes:  1 running, 43 sleeping
CPU states:     % user,     % nice,     % system,     % interrupt,     % idle
Mem: 24M Active, 16M Inact, 13M Wired, 3816K Cache, 14M Buf, 2884K Free
Swap: 204M Total, 128K Used, 204M Free

  PID USERNAME PRI NICE  SIZE    RES STATE    TIME   WCPU    CPU COMMAND
  364 tspivey8  10   0  9592K  8944K wait     1:43  0.00%  0.00% perl
  291 tspivey8   2   0  1720K  1216K select   0:09  0.00%  0.00% screen
  208 root       2   0   352K   124K nfsd     0:02  0.00%  0.00% nfsd
  298 root       3   0  1388K   956K ttyin    0:01  0.00%  0.00% csh
  295 tspivey8   3   0  1068K   740K ttyin    0:01  0.00%  0.00% bash
  244 root       2   0  2484K  1448K select   0:01  0.00%  0.00% sendmail
  241 root      10   0   968K   620K nanslp   0:00  0.00%  0.00% cron
  195 root       2   0   924K   560K select   0:00  0.00%  0.00% syslogd
  248 root       2   0  2488K  1192K select   0:00  0.00%  0.00% sshd
  290 tspivey8  18   0  1508K   840K pause    0:00  0.00%  0.00% screen
  250 root       2   0   896K   504K select   0:00  0.00%  0.00% usbd
10967 tspivey8  30   0  1896K   916K RUN      0:00  0.00%  0.00% top
  288 tspivey8  10   0  1052K   680K wait     0:00  0.00%  0.00% bash
 1199 tspivey8   2   0  2380K  1412K select   0:00  0.00%  0.00% ssh
  239 root       2   0  1048K   620K select   0:00  0.00%  0.00% inetd
  209 root       2   0   352K   124K nfsd     0:00  0.00%  0.00% nfsd
  210 root       2   0   352K   124K nfsd     0:00  0.00%  0.00% nfsd[6;1H[24;1H[Kbash-2.05$ exit
exit

Script done on Sat Jun 23 07:53:09 2001
>How-To-Repeat:
top -d1 
top -d 1
both of those, it may sometimes not show cpu.
near the top of the display. don't use "top", it wil show correctly.
(-d1/-d 1 is good in scripts)
>Fix:
change top's -d1/-d 1, dunno which is proper,
to show proper cpu states like ncurses top .
"top" (updating display) works.
>Release-Note:
>Audit-Trail:

From: Jonathan Chen <jon@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org, tspivey8@home.com
Cc:  
Subject: Re: bin/28367: top -d 1 will not show proper information concerning cpu states, nor will -d1
Date: Thu, 2 Aug 2001 13:49:14 -0400

 Unfortunately, due to the way top obtains the cpu statistics, fixing 
 top -d1 properly is a nontrivial task.  These cpu statistics are obtained 
 by reading some numbers twice and taking the differences.  Of course, if 
 you wish top -d1 to return immediately, you cannot get the cpu statistics.  
 You may wish to run top -d2 and ignore the first output.  Alternatively, 
 the following patch is a quick workaround to the problem if you must use 
 -d1.  This will not be integrated into FreeBSD, but you may wish to apply 
 it to your local source tree to get a "fixed" top.
 
 Top is a "contributed" software in FreeBSD.  This means that top is 
 maintained by someone outside of the FreeBSD community.  You may have 
 better response by directing further inquiries about top to its author:
 William LeFebvre <wnl@groupsys.com>  Of course, any FreeBSD specific 
 problems should still be submitted to us.
 
 Thank you for your interest in FreeBSD.
 
 -Jon
 
 [Patch included below]
 
 diff -u -r1.6 top.c
 --- contrib/top/top.c	2000/11/03 22:00:10	1.6
 +++ contrib/top/top.c	2001/08/02 17:34:11
 @@ -529,6 +529,12 @@
       *		indicates infinity (by being -1)
       */
  
 +    if (displays == 1) {
 +	get_system_info(&system_info);
 +	usleep(100000);
 +	dostates = Yes
 +    }
 +
      while ((displays == -1) || (displays-- > 0))
      {
  	/* get the current stats */
State-Changed-From-To: open->closed 
State-Changed-By: jon 
State-Changed-When: Thu Aug 2 11:53:04 PDT 2001 
State-Changed-Why:  
Impossible to correct problem without major modification to top. 
Workaround provided and user refered to top maintainer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28367 
>Unformatted:
