Commit Graph

77 Commits

Author SHA1 Message Date
Jim Warner
39f4067c66 top: kill/nice provide for a default pid
As an aid to the above 2 commands, and as a prelude to
an upcoming 'inspect other output' capability, the act
of selecting a process for either has been simplified.

Positioning a task as the first one displayed, via the
up/down arrow keys, will now establish it as a default
selection for the appropriate command.  Thus, that pid
will then be incorporated in a subsequent input prompt.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-11-27 22:08:01 +11:00
Jim Warner
44ceff845b top: include under nls support an overlooked error msg
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-11-27 22:08:00 +11:00
Jim Warner
99010db097 top: tweak scroll coordinates msg handling (again)
An earlier commit improved the scroll coordinates
message performance by offloading most of the work
to those occasions when column headers were rebuilt.

The only remaining per-frame costs were the addition
of some terminfo escapes and the Frame_maxtask count.

This commit further reduces those per-frame costs to
the absolute minimum.

Reference:
commit fbfaa868ba

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-26 18:58:42 +11:00
Jim Warner
0163abb48b top: allow exit from 2nd level help via <Esc> key
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-26 18:58:42 +11:00
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
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
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
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
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
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
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
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
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
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
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
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
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
Jim Warner
efb9fcb816 top: relocate a prototype to prevent compiler warning
Until the 'locate/search' provisions were added,
top avoided the need for any function prototypes
through careful source file organization.  But
the addition of the find_string function required
a prototpe for task_show, lest a massive file
reorganization be undertaken.

This commit moves the actual protype out of top.h
and places it adjacent to the caller in order to
avoid a warning when top_nls.c is compiled.

References:
commit 270e8e7eeb
commit d6e6a9aa38

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-28 08:45:44 +11:00
Jim Warner
045538e01b top: remove residual logic for obsolete functionality
At one time the 'open_psdb_message' library call was
supported with the concept of a postponed message
which would display after top startup completed.
In turn, that required logic to strip the '\n' which
was embedded (inappropriately) in any such message.

Nowdays top treats such a returned error as fatal so
there is no need for the 'strim' function which is
being removed with this commit.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-28 08:45:12 +11:00
Jim Warner
ee3ed4b45e top: update latest CPU % distortions understanding
We originally approached the potential problem of
% CPU distortions as unique to Nehalem type cpus.
The latest information suggests that it may have
been due to a kernel anomaly that has since been
corrected.

Yet even without such a cpu, wide disparities in
tics allocation among all available cpus have
sometimes been observed -- spikes as it were in
the normal pattern.  This has happened under both
version 2.26.38-13 and 3.0.0-15 kernels.

The small amount of additional code addressing the
original problem carries very little overhead.  It
is being retained to afford protection against any
future tic accounting aberrations.

In this commit, supporting programmer comments have
been divorced from any particular cpu type.  Also,
another variable and manifest constant will now be
eliminated when CPU_ZEROTICS is defined.

References:
commit 02508b3d76
http://www.freelists.org/post/procps/CStates-handling-new-switch,50
2012-02-28 08:45:07 +11:00
Jim Warner
ccb5144050 top: fix regression created when fields mgmt reorg'd
When the calibrate_fields function was broken up for
mainainability, an obscure regression was introduced.

For the resulting bug to affect the display, all of
the following conditions would have to be met:
 . USE_X_COLHDR was not defined
 . column highlighting had been turned on
 . many, perhaps all, fields were displayable
 . the user then typed the <End> key
 . and the current sort column just happened to
   be immediately to the left of the left-most
   visible field

This patch corrects for that remote possibility.

Reference:
commit d0e16acf15

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-28 08:44:59 +11:00
Jim Warner
a096fec8c0 top: extend the Copyright (c) dates to include 2012
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-12 21:52:23 +11:00
Jim Warner
d0e16acf15 top: reorganize some fields management logic
The calibrate_fields function had grown too large and
was adversly impacting maintainence.  So half of the
logic was split out into a new function.

Now, maintainence of column headers and the required
library flags is organized as follows:

 . adj_geometry   (calibrate_fields helper)
     provides low-level support for sigwinch, memory

 . build_headers  (calibrate_fields helper)
     constructs the headers and library flags

 . calibrate_fields
     establishes which fields will be displayed

( note the alpha order mentioned in a prior commit )

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-12 21:52:23 +11:00
Jim Warner
270e8e7eeb top: standardize names of all 'helper' functions
The top program is carefully organized into sections
and those sections are carefully placed so as to avoid
the need for prototypes. *

Additionally, names of functions are carefully chosen
to maintain alphabetical order within each section.

The names of most 'helper' functions, which are always
placed immediately above the calling functions, often
only met the spirit of the alphabetical law, not the
actual letter of that law.

This commit alters the names of such helper functions
so as to mainatin strict ascii alphabetical order
within each section.

* the single exception to prototypes is find_string,
  which calls the task_show function, and would have
  prompted a massive reorganization.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-12 21:52:23 +11:00
Jim Warner
02508b3d76 top: use CPU_ZEROTICS to embrace the Nehalem logic
The recently added logic dealing with "missing" tics
is mutually exclusive with logic associated with a
define called CPU_ZEROTICS.

This commit expands the use of that define to exclude
such Nehalem logic as appropriate.

It also extends programmer notes in top.h to include
an attribution for initiating the topic of potential
Nehalem type % CPU distortions, acknowledging:
  Jaromir Capik, <jcapik@redhat.com>

References
commit ce1410a51a
commit 9e7dd43ab7
commit a9041a5526
2012-02-12 21:52:23 +11:00
James Cloos
95f2201730 top: postpone the switch from Kb to Mb in summary display
The mem and swap lines have enough room to show eight significant
digits, so switch to showing MB when >=100MB, not >=10MB.

The extra detail is valuable; it should not be elided.

Signed-off-by: James Cloos <cloos@jhcloos.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-02-12 21:52:23 +11:00