Bug 28367

Summary: top -d 1 will not show proper information concerning cpu states, nor will -d1
Product: Base System Reporter: Tyler Spivey <tspivey8>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Tyler Spivey 2001-06-23 17:00:12 UTC
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

Fix: 

change top's -d1/-d 1, dunno which is proper,
to show proper cpu states like ncurses top .
"top" (updating display) works.
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)
Comment 1 Jonathan Chen freebsd_committer freebsd_triage 2001-08-02 18:49:14 UTC
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 */
Comment 2 Jonathan Chen freebsd_committer freebsd_triage 2001-08-02 19:53:04 UTC
State Changed
From-To: open->closed

Impossible to correct problem without major modification to top. 
Workaround provided and user refered to top maintainer.