Commit Graph

104 Commits

Author SHA1 Message Date
Jim Warner
e77c8e8cf0 top: for performance, employ additional inlining
The 'refactor and enhance column width management'
recent redesign produced many subsequent benefits,
the latest of which is automatically sized fixed-width
non-scalable columns.

As expected, there was a cost associated with these
many enhancements.  That cost has now been identified
as a 1-4% performance degradation, depending on which
fields are being displayed.

This increased cost arises principally from current
drawing related function calls, whereas top-3.3.3 did
most of its drawing via macros effectively inlining
those duties.

This commit inlines the equivalent drawing functions,
thus eliminating the function call penalty, and places
this top on a par with top-3.3.3.  The trade off is a
modest additional 4k in executable size.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-11 21:13:14 +11:00
Jim Warner
f005411974 top: 'X' command offers auto option, man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-11 21:13:14 +11:00
Jim Warner
35cd340002 top: 'X' command offers auto option
The recent introduction of a column widths override
(the 'X' command) provided for a user input amount
to be added to default field size which ranged from
5 to 10 bytes.

While that approach could prevent truncated data, the
different default sizes would almost certainly mean
some precious screen real estate was waisted.

This commit introduces the concept of dynamic widths
where top will add only enough to a field default to
prevent truncation for that specific field.

Now users have a choice between their explicit width
override or a width chosen by top to exactly match
display needs.  The former is immediate but likely
wastes some horizontal space while the latter is
iterative but will be sized precisely.

Original 'X' Command:
commit 384afa494a
commit 47e1d063ac

Extensions to 'X' Command:
commit bbf8e44fb4
commit 7557f3f754

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-11 21:13:13 +11:00
Jim Warner
21237356ab top: map additional navigation keys, man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-11 21:10:44 +11:00
Jim Warner
bff927711b top: map additional navigation keys
There were some gaps in the alternate navigation keys
top provided.  Additionally, some inconsistencies
existed in the supporting key table.

This commit adds the following new key equivalents,
mirroring the standard vim navigation keys:
. ctrl+alt+ k = pgup, ctrl+alt+ j = pgdown
. ctrl+alt+ h = home, ctrl+alt+ l = end

Also, the supporting table entries now consistently
follow these "directions":
. up/pgup, down/pgdown, left/home, right/end

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-11 21:10:44 +11:00
Jim Warner
edd8aae5ba top: avoid potential xterm state corruption
To support the cursor navigation keys, after saving
the termios structure top issues 'smkx/keypad_xmit'
during startup.  However, some terminals appear to
treat that directive as persistent which leaves a
corrupted tty state after top exit.

This commit reverses the above terminal directive
via 'rmkx/keypad_local' just prior to restoring the
saved termios structure at program end.

For discovering this bug, and providing the 'rmkx'
clue to its solution, thanks to:
  Kirill A. Shutemov <kirill@shutemov.name>

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-11 21:10:44 +11:00
Jim Warner
bb6cc9c159 top: for user justify feature, remember old-top needs
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-11 21:10:44 +11:00
Jim Warner
d58dc6b1e7 top: swat a bug introduced with recent width refactor
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:40 +10:00
Jim Warner
7557f3f754 top: with new 'X' command, WCHAN becomes fixed-width
This 'Sleeping in function' field was made variable
width because the length of current kernel symbols
usually exceeded the former top's 9 character limit.

As a variable width field it would steal valuable
horizontal display positions from other, more likely,
displayed fields such as COMMAND or CGROUPS.

With the advent of the new 'X' toggle, no fixed-width
non-scalable field need suffer permanent truncation.
Thus, WCHAN is being made fixed width with a default
size of 10 characters.

Signed-off-by: Jim Warner <james.warner@comcast.net>

 top/top.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
2012-10-02 20:56:40 +10:00
Jim Warner
bbf8e44fb4 top: extend new 'X' command to include the TTY field
I have no idea what the maximum length of a terminal
name might be.  However, the library provides for up
to 128 characters (ouch).

So just to be safe, this commit extends the ability
to widen columns to embrace this field.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:40 +10:00
Jim Warner
47e1d063ac top: optional wider non-scalable cols, man document 2012-10-02 20:56:40 +10:00
Jim Warner
384afa494a top: optional wider non-scalable cols
This commit accommodates those fields which may have
suffered truncation due to these default limits:
  . 5 digits for uid/gid type fields
  . 8 characters for user/group type fields

With a new interactive command, users can increase the
width of all such fields, or return to the defaults.

Note:
   There are no restrictions on the amount added to
   the defaults.  The user is free to vastly exceed
   screen limits which simply means such fields can
   never be displayed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:40 +10:00
Jim Warner
46bd0085b0 top: column alignment under user control, man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:40 +10:00
Jim Warner
c07be1d492 top: column alignment under user control
This commit affords user control over justification
for both column headings and the subordinate data.

Separate toggles are provided for control of numeric
data and string data.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:40 +10:00
Jim Warner
0f61354bf7 top: refactoring now allows column header nls support
Now that column headings are independent of column
data format and require no carefully managed padding
bytes they are candidates for nls translation.

This commit migrates all column headings to the .pot
file with additional translator guidance in the form
of maximum sizes to avoid truncation.

It also places these new additions adjacent to their
associated descriptions, which were already present.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:40 +10:00
Jim Warner
64cfdda756 top: refactor and enhance column width management
This commit accomplishes the following objectives:
 * remove extra task_show parm added with 'Locate'
 * avoid column overflow with subsequent misalignment
 * eliminate spaces for column heading padding
 * decouple column headings from column data formats
 * eliminate all hardcoded column format specifiers
 * generalize the inter-column spacing management
 * remove Fieldstab.desc in favor of direct nls access
 * set the stage for nls support of column headings
 * set the stage for dynamic changes to justification

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:39 +10:00
Jim Warner
767a13b96c top: tidy up some miscellaneous user input logic
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:39 +10:00
Jim Warner
718cececc7 top: correct an old man document flaw
This flaw was revealed under 'man2htm' and dates back
to the first Gitorious revised top submission.

Reference:
commit fd62123562
Date:   Thu Mar 31 22:15:12 2011 +1100

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:39 +10:00
Jim Warner
beb0982b28 top: implement a new approach to forest view mode
The TREE_RESCANS #define (formerly TREE_ONEPASS) has
been eliminated and the approach to forest view mode
redesigned.  The chance of dangling children has been
eliminated and overhead reduced.

We now order processes on start_time (non-display)
and are therefore immune to any pid, ppid or tgid
anomalies when pid values wrap.

The new algorithm also accommodates any distortions
caused by the 3.3 kernel 'hidepid' provisions --
something guaranteed to produce dangling children
under the former approach.

Related References:
commit a2086dfdf6
commit cd608f462e
commit 41ed28aa5d

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-31 07:22:31 +10:00
Jim Warner
d9890fb5ac top: add major/minor page fault deltas, man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:37:37 +10:00
Jim Warner
d9cf59a9b2 top: add major/minor page fault deltas
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:37:29 +10:00
Jim Warner
6cc7416441 top: add new scrollable column ENVIRON, man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:35:33 +10:00
Jim Warner
17e0eaf0f3 top: add new scrollable column ENVIRON
The recent introduction of scrollable variable width
columns makes a process 'environment' a potentially
useful addition to top's displayable fields.

This commit exploits the following new library flag:
   PROC_EDITENVRCVT

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:35:24 +10:00
Jim Warner
a2086dfdf6 top: revise default for forest view child scans
In an effort to avoid dangling children when in forest
view mode, top defaulted to a complete rescan of every
proc_t for each child encountered.

That expense was never really cost justified and now
with the 3.3 kernel 'hidepid' provisions it no longer
can offer such protection.

With this commit, the TREE_ONEPASS define is changed
to TREE_RESCANS so as to reverse the default scan
behavior.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:30:26 +10:00
Jim Warner
06e92e93b8 top: miscellaneous minor tweaks (mostly spelling)
This commit represents mostly spelling corrections
in comments.  It also includes a few very minor logic
changes/relocations.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:29:46 +10:00
Jim Warner
6940430c55 top: correct field order within Section 3a, man document
This section purported to list fields in alphabetical
order, but this was not always true.

With this commit, strict ascii collating sequence is
now observed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:29:34 +10:00
Jim Warner
22515ce62e top: improve unsolicited user input validation
The logic associated with invalid keystrokes was
simplified through some minor reordering.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:29:17 +10:00
Jim Warner
fbfaa868ba top: improve scroll coordinates message handling
With the introduction of intra-column scrolling, the
scroll coordinates message was enhanced to give some
hint of positioning within a scrolled column.

Rather than rebuild this somewhat costly string from
scratch with each frame, we'll now do the bulk of the
work only when column headers are constructed.

The only remaining per frame costs will then be the
addition of a few terminfo escapes and the current
Frame_maxtask count.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:28:53 +10:00
Jim Warner
896f3deeb9 top: add intra-column horizontal scrolling, man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:28:34 +10:00
Jim Warner
a652ba8c9d top: add intra-column horizontal scrolling
This commit introduces horizontal scrolling within any
variable width column.  Thus, an entire command line,
complete list of control groups, etc. can now be
viewed -- not just a screen width's portion.

It is activated when any variable width column:
 . is (via field selection) or
 . has become (via the right arrow key)
the only displayed field.

Then, the right and left arrow keys can be used in the
normal way to continue scrolling within that column.

The amount scrolled with each key press is currently
set as the normal tab stop increment of 8 characters.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:28:18 +10:00
Jim Warner
f114476a94 top: exploit library changes to cgroup & supgid
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:26:54 +10:00
Jim Warner
04ca0b1cbf top: ensure /proc is mounted before term is diddled
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-04-25 15:23:22 +10:00
Jim Warner
39243fe306 top: address a defect with the library PROC_PID flag
The library does not weed out potential duplicate PID
values when sampling with the PROC_PID flag.  This was
treated as merely an inefficiency by top and safely
ignored prior to the advent of forest view mode.

Now, however, if the -p switch duplicates certain PIDs,
*and* those processes have no PPID, *and* top's forest
view mode is active or activated, then a SEGV will be
generated (and caught).

This rather obscure buglet is thus limited to pid #1
(/sbin/init) and pid #2 (kthreadd).  With any other
duplicate PIDs the worse case scenario was a '?' in
place of the usual forest view artwork.

This commit silently ignores any duplicate process ids
and thereby avoids the potential segmemtation fault.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-04-25 13:46:17 +10:00
Jim Warner
421b08a4df all: fix misspellings in docs and program comments
We might as well join the coreutils and util-linux
projects in correcting our own typos.

The following was left unchanged:
   top/top.c[1797]: thru -> "through"

references:
http://lists.gnu.org/archive/html/coreutils/2012-04/msg00057.html
http://marc.info/?l=util-linux-ng&m=133518057419736&w=2

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-04-25 13:46:02 +10:00
Sami Kerola
47100a8125 docs: fix manual page warnings
All warnings where about unnecessary quoting.  The scriptlet
below will tell what was wrong.

for I in ./top/top.1 ./ps/ps.1 ./*.[0-9]; do
    echo "== $I warnings =="
    man --warnings=all $I > /dev/null
done

This should probably be turned to 'make check' script.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-16 12:55:53 +02:00
Jim Warner
e9a9bad264 top: document an existing provision of pid monitoring
Since its inception top has provided for monitoring
only specific process ids via the -p command line
switch.  This provision has also embraced the top
process itself, even though its pid wasn't yet known.

This commit simply documents the special zero value,
which would otherwise be an invalid process id.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-04-16 08:30:06 +10:00
Craig Small
09d67d5ab2 Merge remote-tracking branch 'sami/2012wk12'
Conflicts:
	watch.c
2012-04-15 10:44:37 +10:00
Jim Warner
cd253e0dc6 top: fix a segfault when -p switch specified invalid pid
In attempting to keep at least one task visible when
scrolling vertically, a negative task index would be
produced when pid monitoring was in effect and no
matching pid was found.

Since there were already other conditions where no
task might displayed, the faulty source line has been
removed.

Bug-Debian: http://bugs.debian.org/668335

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-04-15 10:25:05 +10:00
Jim Warner
b079d130d7 top: miscellaneous cosmetic non-logic changes
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-04-15 10:24:59 +10:00
Jim Warner
0c874637ee top: extend case-insensitive option to include 'Locate'
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-04-15 10:24:54 +10:00
Sami Kerola
52269d22f3 all: check stdout and stderr status at exit
If stream status is not checked at the end of execution below problem
would not report error, or non-zero exit code.  The uptime is just an
example same was true with all commands of the project.

$ uptime >&- ; echo $?
uptime: write error: Bad file descriptor
1
$ uptime >/dev/full ; echo $?
uptime: write error: No space left on device
1

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-23 15:57:53 +01:00
Jim Warner
2323f864f3 top: correct miscellaneous omission, typo and buglet
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-18 08:18:11 +11:00
Jim Warner
fa21a6ca81 top: correct loss of keystrokes paste capability
When top introduced true line input editing, the
ability to paste keystrokes was lost.  This remains
a necessary evil so that top has an opportunity to
translate cursor motion keystrokes into terminfo
escapes during line input.  Motion keys themselves,
of course, can never be pasted.

If pasting ever became more important than input
editing, then native termios support should have been
available via a define called TERMIOS_ONLY.  But a
recent commit, eliminating what was thought to be
obsolete logic, rendered the alternate linein()
function virtually useless.

Similar to top-3.2.8, when native termios input is
functional, these abberations can be experienced:
. cursor motion keys will appear as escapes
. excessive input can cause line wraps
. ^Z during i/p is not be honored until <Enter>
. SIGWINCH during i/p corrupts screen temporarily

In hindsight, it now seems that the ability to paste
keystrokes may indeed outweigh any shortcomings of
native termios support.  This is especially true if
one is preparing to search ('L') for some lengthy
process command line contined in the clipboard.

Thus, this patch fixes the alternate linein() function
and changes TERMIOS_ONLY to TERMIO_PROXY so that top
now defaults to using native termios input.  In turn,
that will restore the paste keystrokes capability.

Reference(s):
commit: 045538e01b

Reported by: sergio <mailbox@sergio.spb.ru>
Bug-Debian:  http://bugs.debian.org/663334

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-16 07:10:53 +11:00
Jim Warner
397810a67f top: some isolated typos and minor code changes
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-16 07:06:53 +11:00
Jim Warner
2fc3f15770 top: refer to memory using strict IEC standard names
Admittedly, top referred to memory quantities in
a variety of non-standard ways.  This commit brings
the program and supporting documentation into strict
compliance with IEC standard binary names.

According to wikipedia, as of 2012 this IEC standard
was still not in widespread use.  However, I'm making
this change now for the anal-retentive among us.

Reference:
http://en.wikipedia.org/wiki/Megabyte

Reported by: Roman Mamedov <rm@romanrm.ru>
Bug-Debian:  http://bugs.debian.org/662786

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-09 06:56:06 +11:00
Jim Warner
87bb21b557 top: fix selected miscellaneous compiler warnings
These per instance warnings have been eliminated:
warning: range expressions in switch statements are non-standard
warning: padding struct to align 'winflags'
warning: dereferencing type-punned pointer will break strict-aliasing rules

   These per instance warnings have not been addressed
   since they simply trade one warning for another:
      From:
warning: ISO C does not permit named variadic macros
warning: ISO C does not support the '%Lu' gnu_scanf format
      To:
warning: anonymous variadic macros were introduced in C99
warning: ISO C90 does not support the 'll' gnu_scanf length modifier

   Lastly, since all C compilers have supported use of
   C++ style comments for the past 20 years, the top
   program will never trade them for the often more
   cumbersome C style comments simply to avoid this
   once per source file warning:
warning: C++ style comments are not allowed in ISO C90

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-06 11:05:42 +11:00
Jaromir Capik
0f6b289212 license: update FSF addresses
The license files are synchronized with the versions from GNU web
site.

http://www.gnu.org/licenses/gpl-2.0.html
http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html

Signed-off-by: Jaromir Capik <jcapik@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-04 08:04:24 +11:00
Jim Warner
0053eefbb9 top: extend rcfile conversions for '--enable-oomem'
Under openSUSE, old top uses additional fields for
out-of-memory reporting.  As a result, under the
original approach to rcfile conversion, new top would
issue a fatal corrupt window entry message asking that
the rcfile be deleted.

This patch extends the conversion range to include
the extra openSUSE field characters.  It's effective
when ./configure specifies the --enable-oomem option
which in turn defines OOMEM_ENABLE.

This commit also makes the conversion logic slightly
more forgiving.  While enforcing an upper limit on the
expected number of old style field characters, amounts
less than that will be handled seemlessly.

Reference:
commit 4b98733132

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-03 14:01:35 +11:00
Jim Warner
4b98733132 top: honor the restrictive, crufty old top rcfile
At one time, new top silently defaulted when an rcfile
was found to be incompatible.  This is exactly what
the old top did.  However, after some discussion it
was decided top should alert the user and thereby
save the system administrator some headaches.

Now, some are upset over the fatal error, proving you
can't please everybody.  But in all fairness, given
the difficulty of customizing old top, any reluctance
to delete an old saved rcfile is understandable.

To ease transition to this new top, old style rcfiles
will now be honored and converted to the new format.
And if not disabled at ./configure time via CFLAGS,
a user will be warned when an old style rcfile is
about to be overwritten using the 'W' command.

Lastly, the config validation logic was enhanced to
help ensure both types of rcfile haven't been edited
manually and possibly made unuseable.

Reported-By: sergio <mailbox@sergio.spb.ru>
Bug-Debian:  http://bugs.debian.org/651213

Reported-By: martin f krafft <madduck@debian.org>
Bug-Debian:  http://bugs.debian.org/651863

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-02 21:29:43 +11:00
Jim Warner
488aa10d33 top: fix a regression associated with USE_X_COLHDR
When sort column header emphasis was extended to a
monochrome screen, the ability to emphasize selections
on the Fields Management screen was lost when colors
were not being displayed.

This patch corrects that bug by using the capclr_hdr
terminfo string instead of capclr_msg.

Reference:
commit 0c6aa6af41

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-02 21:29:26 +11:00