Bug 218889

Summary: top(1) show CPU states header in batch mode
Product: Base System Reporter: reed
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Some People CC: eadler
Priority: --- Keywords: patch
Version: 11.0-RELEASE   
Hardware: Any   
OS: Any   

Description reed 2017-04-26 13:35:36 UTC
(The component field here in bugzilla doesn't have "contrib" so I chose "bin".)

I don't know history of why the dostates toggle is there to not show the CPU: states "the first time".  But this makes it so the batch view (like piped top to a file) excludes the CPU states and just has a blank line there.

Here is a simple fix (but maybe fix comment). Or maybe just get rid of "dostates".

Index: contrib/top/top.c
===================================================================
--- contrib/top/top.c   (revision 317435)
+++ contrib/top/top.c   (working copy)
@@ -637,7 +637,7 @@
                        system_info.procstates);
 
        /* display the cpu state percentage breakdown */
-       if (dostates)   /* but not the first time */
+       if ((!interactive) || (dostates))       /* but not the first time */
        {
            (*d_cpustates)(system_info.cpustates);
        }

(I originally saw this problem with pfSense's System Activity page while authoring a book about it.)
Comment 1 commit-hook freebsd_committer freebsd_triage 2018-06-23 03:17:59 UTC
A commit references this bug:

Author: eadler
Date: Sat Jun 23 03:17:11 UTC 2018
New revision: 335576
URL: https://svnweb.freebsd.org/changeset/base/335576

Log:
  top(1): show CPU state breakdown on first run

  There is no documented reason for this not to be shown on the first run.
  I can't find any good reason, and it breaks batch mode.

  PR:		218889
  Submitted by:	"Jeremy C. Reed" <reed@reedmedia.net>

Changes:
  head/usr.bin/top/top.c