[ but stay tuned! there is a commit coming soon that ]
[ represents a rather major internal redesign, which ]
[ was prompted by the ps and top adaptation testing. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
It is documented behavior that when certain other keys
are active, sorts column highlighting will temporarily
be disabled. Among those keys is the 'L' (locate/find)
provision. The equals ('=') key can be used to restore
column highlighting by resetting other keys, except 1.
When a locate/find is active, the '=' key will have no
effect on 'x' column highlighting, which still remains
disabled. Further, when 'L' is active an 'x' keystroke
is processed changing the state of column highlighting
but without any visual clue (since it's yet disabled).
So this commit just extends the '=' key to embrace 'L'
processing resets, just like other highlight disabling
keys while avoiding 'x' state changes if approproiate.
Signed-off-by: Jim Warner <james.warner@comcast.net>
Ever since top was adapted to the new <pids> interface
there has been a bug that would cause an abnormal exit
when the '-p' argument contained *no* valid pids. This
was never revealed until now since the QA folks tested
only with valid, existing pids. (bunch of morons, eh?)
And even though the program author is blameless he has
taken it upon himself to clean up after the QA jokers.
Signed-off-by: Jim Warner <james.warner@comcast.net>
Two separate entries under the Fieldstab were employed
to manage 'relative' enumerators under that new <pids>
interface. However, just a single entry could actually
serve both needs with a negative 'not selected' value.
So this commit just borrows the approach used with the
ps conversion where -1 is now representing unselected.
Signed-off-by: Jim Warner <james.warner@comcast.net>
With the advent of the 'fatal_proc_unmounted' function
in the <pids.h> API to ensure the /proc filesystem was
mounted, we will finally get rid of the last remaining
vestiges of the former libprocps <readproc> interface.
[ also play a little catch up and whack some headers ]
[ that are not necessary now, beyond that readproc.h ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
Whoa, guess what field got overlooked in that march to
the newlib conversion? It was the TTY guy. However, it
wasn't completely top's fault - that newlib must share
at least some responsibility, for only offering a num.
[ and while we're at it, let's touch up the man page ]
[ to agree with ol' newlib's current implementation. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
When top was originally adapted to use that <pids> API,
the forest view support was redesigned since the proc_t
pad_3 byte could no longer be employed to hold a task's
nesting level. The redesign required additional arrays.
Now that the dust is settling on those initial efforts,
that PROCPS_PIDS_noop item was used as a substitute for
the old pad_3 along with a return to the former design.
But, while it proved adequate, the invariant nature for
that item required of top an extra initialization step.
So the library was coaxed into adding one more pid_item
(PROCPS_PIDS_extra) which will, unlike that 'noop' guy,
be reset with each reap. Everybody should be happy now.
Signed-off-by: Jim Warner <james.warner@comcast.net>
Craig's recent commit under that newlib branch dealing
with namespace support has prompted me to review top's
handling of those fields. Currently, when such a field
is zero, top displays a dash ('-'). This will mean the
justification toggles ('j/J') will behave incorrectly.
This patch simply allows the potential zero to display
or be suppressed with the already existing '0' toggle.
Signed-off-by: Jim Warner <james.warner@comcast.net>
A patch containing the following miscellaneous tweaks:
. remove a function that handled former library errors
[ that function should have gone bye-bye with 3.3.11 ]
[ when those 'wchan' provisions were much simplified ]
. make clearer a distinction between 'new' and 'reset'
[ use PROCPS_PIDS_noop when procps_pids_new() called ]
[ since at that point we are only establishing depth ]
Reference(s):
http://www.freelists.org/post/procps/newlib-for-pgrep,1
Signed-off-by: Jim Warner <james.warner@comcast.net>
A patch containing the following miscellaneous tweaks:
. exploit (actually adapt) a pids.h provided VAL macro
. remove some obsolete, now unused, sort related items
. clarify the comment for specialized extractor macros
Signed-off-by: Jim Warner <james.warner@comcast.net>
Just in case, make the old proc_t used in the before()
function static so valgrind doesn't get his panties in
a bunch over the fact the 'cmd' is now dynamic memory.
[ Shouldn't that function, or an equivalent, also be ]
[ part of our new library's implementation? However, ]
[ is it proper for a brand new library to abnormally ]
[ terminate a calling process with a stderr message? ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
It was probably always wrong to have a variable length
proc_t structure. This patch takes all remaining oomem
former suse only options and makes them unconditional.
Signed-off-by: Jim Warner <james.warner@comcast.net>
. didn't need a separate table for enum pids_reap_type
since top's 'Thread_mode' itself can be used directly.
. with pids support & the loss of forest_based(), that
forest_adds() function had to be renamed so the prolog
comment regarding naming convention was still honored.
. adapted to a library change to the pids_reap struct.
Signed-off-by: Jim Warner <james.warner@comcast.net>
TOP, respond to library change to the pids_reap struct ...
Signed-off-by: Jim Warner <james.warner@comcast.net>
The newlib informal cutoff for kernel support seems to
be around release 2.6. This commit eliminates any such
support for really old 2.4 and 2.5 kernels within top.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch adapts top to exploit the new <proc/pids.h>
interface. And it appears to have reduced top's weight
by a considerable margin. Gone were the sort callbacks
and manipulation of those library flags. Gosh, all top
needs to do now is track some enumerators of interest.
[ whoa, wait just a damn minute. it now appears some ]
[ that weight loss was solely the result of a theft. ]
[ jeeze, we turn our back for just a minute & newlib ]
[ up & steals our pids hashing logic for his history ]
[ needs. oh well, i guess life's just not that fair. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
While testing a newlib interface for pids acquisitions
I encountered some unexpected results if an idiot user
(me) turns off all displayable fields. So, this commit
ensures that the PID field will be shown as a minimum.
Signed-off-by: Jim Warner <james.warner@comcast.net>
When the USED column was introduced the proc_t.vm_swap
& proc_t.resident values were added together. However,
using 'resident' required an additional PROC_FILL flag
not to mention extra conversion of pages to kibibytes.
So now we'll use an already present vm_rss value which
removes any special handling for top's derived column.
And while we're at it we'll trade some more 'resident'
field uses with that more immediately usable 'vm_rss'.
[ this commit has been adapted for the newlib branch ]
Reference(s):
commit 709785e20b
Signed-off-by: Jim Warner <james.warner@comcast.net>
Jeeze, to correct spelling on one single word (incure)
you had to go and align the entire comments paragraph?
[ well, at least there's one other minor code change ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
Since it's possible that euser name is not being shown
or the horizontal position had been scrolled past that
USER column, then part of those headers will be blank.
So it doesn't make sense to try and show the USER that
is associated with a process at all. Thus, this commit
simply removes the 'user' provision from both headers.
Signed-off-by: Jim Warner <james.warner@comcast.net>
When a user is taking advantage of the scroll features
it is likely a scrolled vertical position is well past
the first displayable task. That is especially true of
top's forest view ('V') mode where those early systemd
attached processes are generally not very interesting.
As such, should the idle mode toggle ('i') be employed
a distorted display is almost guaranteed because tasks
that have used some cpu, and thus should be displayed,
have already been skipped by virtue of their position.
So this patch temporarily nullifies vertical scrolling
during the period when idle tasks are not being shown.
Signed-off-by: Jim Warner <james.warner@comcast.net>
In addition to that text shown below the line which is
common to several commit messages, this patch contains
several minor changes with lessor impact upon the API:
. A call to procps_stat_read_jiffs() has been added to
those jiffs functions carrying the 'fill' nomenclature
to parallel like functions in some of our other files.
. The #include header files are ordered alphabetically
now, with all those <sys/??> types separately grouped.
. Standard copyright boilerplate was added in .c file.
. The header file follows the conventions of indenting
(by 4 spaces) those parameters too lengthy for 1 line.
------------------------------------------------------
. The former 'chains' have now become 'stacks' without
the 'next' pointer in each result struct. The pointers
initially seemed to offer some flexibility with memory
allocations and benefits for the library access logic.
However, user access was always via displacement and a
a statically allocated chain was cumbersome to define.
. An enumerator ending in '_noop' will no longer serve
as a fencepost delimiter. Rather, it has become a much
more important and flexible user oriented tool. Adding
one or more such 'items' in any items list passed into
the library becomes the means of extending the 'stack'
to also include user (not just library) data. Any such
data is guaranteed to never be altered by the library.
. Anticipating PID support, where many different types
must be represented in a result structure, we'll adopt
a common naming standard. And, while not every results
structure currently needs to reflect disparate types a
union will be employed so the same dot qualifier ('.')
can be used consistently when accessing all such data.
Signed-off-by: Jim Warner <james.warner@comcast.net>
In addition to that text shown below the line which is
common to several commit messages, this patch contains
the following additional change without an API impact:
. The #include header files are ordered alphabetically
now, with all those <sys/??> types separately grouped.
------------------------------------------------------
. The former 'chains' have now become 'stacks' without
the 'next' pointer in each result struct. The pointers
initially seemed to offer some flexibility with memory
allocations and benefits for the library access logic.
However, user access was always via displacement and a
a statically allocated chain was cumbersome to define.
. An enumerator ending in '_noop' will no longer serve
as a fencepost delimiter. Rather, it has become a much
more important and flexible user oriented tool. Adding
one or more such 'items' in any items list passed into
the library becomes the means of extending the 'stack'
to also include user (not just library) data. Any such
data is guaranteed to never be altered by the library.
. Anticipating PID support, where many different types
must be represented in a result structure, we'll adopt
a common naming standard. And, while not every results
structure currently needs to reflect disparate types a
union will be employed so the same dot qualifier ('.')
can be used consistently when accessing all such data.
Signed-off-by: Jim Warner <james.warner@comcast.net>
The commit msg summary says it all (well, not really).
The previous statically allocated results chain served
the top program perfectly in all its lib memory needs.
But, someone needs to try out the brand new interface.
Besides, there were a few other changes which I wanted
to make. And among them were the following miscellany:
. some names were changed, like 'context' became 'ctx'
. an unnecessary redundant library call was eliminated
. the placement of a few globals was made more logical
( thanks Craig for following the capitalization rule )
Signed-off-by: Jim Warner <james.warner@comcast.net>
This is actually a systemcall getpagesize(2) or it is defined
in configure using a variety of methods, including a default
hard coded value as a last resort.
There is no need to have this in libprocps
Now that the dust is settling following an initial API
library effort, it is apparent my naming standards may
not have always been observed. This was a minor crime,
since those standards are unwritten (& not apparent?).
Basically, top has always capitalized the first letter
of global variables in an effort to distinguish global
definitions from local variables later in the program.
So this patch alters the new API variables to conform,
while also explicitly using 'context' for key structs.
Lastly, top now employs the new '#include <proc/name>'
conventions for the new/converted module header files.
Signed-off-by: Jim Warner <james.warner@comcast.net>
The new library meminfo & vmstat modules use structure
names for their context which exactly mirror the names
of the very /proc/ files whose particulars they yield.
The one exception to this rule was the readstat module
whose struct was named statinfo yet the file was stat.
This commit simply renames that structure (only) so as
to hopefully establish such a naming convention as our
standard going forward. And, it's makes good symmetry.
[ this module's name itself is just perfect as it is ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
The earlier attempt at protecting these functions from
already freed memory worked just fine until the memory
was, in fact, reused by the OS. At that point, the ref
count would most likely fail an existing a test for 0.
So this commit will take control of the 'info' pointer
and force it to NULL when a reference count reaches 0.
Plus, since it makes little sense returning an address
that a caller already has, henceforth we will return a
reference count out of the 'ref' and 'unref functions.
Reference(s):
commit 74beff80ff
Signed-off-by: Jim Warner <james.warner@comcast.net>
Procps library previously held functions that were about either
listing or finding signal names. These are not really the right
location for a library about reading procfs.
This patch handles signal related functions in two ways:
For functions purely found in skill, these have been moved back
into this binary as they are used nowhere else.
For functions used across the binaries, these have been moved
into include/signals.h and lib/signals.c. Besides formatting,
these functions are largely the same.
To assist the skill functions, two functions to access the
signal map array have been added to lib/signals.c
This commit is mostly about eliminating code, now that
a library is responsible for the cpu tics maintenance.
The top program will continue to provide numa support,
without involving the library in any of those details.
[ not to mention all the 'dl' and 'stderr' numa crap ]
With this transfer of the cpu tics duty to our library
the provision associated with the CPU_ZEROTICS #define
could not initially be migrated. The commit referenced
below suggests it may have lost its importance. In any
case such logic may yet be incorporated in the future.
But for now, that #define has been completely removed.
Reference(s):
commit ee3ed4b45e
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit represents the pioneering attempt at using
the concept of 'chained' library requests in an effort
to reduce function call overhead. It required exposing
no more implementation details than were already shown
through the individual calls, yet is satisfied in one.
It is just such an approach that will prove invaluable
when it comes time to access individual /proc/##/data.
Programs could 'chain' only those 'results' structures
representing their current view independent of all the
fields any such programs might be prepared to display.
Thus the standard 'read', which wouldn't apply to task
level data very well (or efficiently), can now become
a 'read_chain' whereby the former PROC_FILL flags need
can be satisfied & yield the minimum open/close calls.
Signed-off-by: Jim Warner <james.warner@comcast.net>
Removed the printf_uptime, binaries can do printf easily enough.
sprint_uptime split into two as there wasn't a lot of common
code
sprint_uptime(): old style uptime line
sprint_uptime_short(): short new style "uptime -p"
Hertz_hack needed this, no sane system uses the code (I think)
so just assume 100 like we do in FreeBSD.
With the commit referenced below, the linux version is
no longer available via an external variable. So we'll
eliminate the extra superficial function call employed
at program end as part of a debugging (only) o/p spew.
[ the user will soon be returned to the command line ]
[ & he/she can run their own 'uname -r' if in doubt! ]
Reference(s):
commit 56d9d5e7e7
Signed-off-by: Jim Warner <james.warner@comcast.net>
Added function procps_linux_version() which used to be an
exported integer instead. Also changed the method of obtaining
the linux version (more correctly the os release) to use a specific
procfs entry. This works for both Linux and FreeBSD.
This patch was made necessary by those library changes
in support of recently revised/simplified wchan logic.
Reference(s):
http://www.freelists.org/post/procps/WCHAN,11
Signed-off-by: Jim Warner <james.warner@comcast.net>
It doesn't make any sense to have the binary version strings
embedded into the library. The version strings are defined
already either in the Makefile or in include/c.h
This commit just tweaks top in the following respects:
. for alphabetic integrity, change 'INSP_hdr...' names
. eliminate the -Wsometimes-uninitialized warning that
was found under OSX Yosemite (llvm 6.0/clang-600.0.56)
. update program 'comments' reflecting copyright dates
Signed-off-by: Jim Warner <james.warner@comcast.net>
A recent commit eliminated the potential for a storage
violation with forest view mode. It occurred when some
program (erroneously?) created a lengthy forking loop.
However, the associated commit message was misleading.
The message implied that an unexpected order following
a sort on start_time was the cause of storage overruns
and a 'char' used to track nesting level only distorts
the display when it goes negative. Actually, the truth
is really just the opposite. Any start_time sort quirk
causes no harm while that 'char' can yield corruption.
Should some child end up sorted ahead of its parent by
way of an extremely unlikely shared start_time the end
result is such a child will be displayed unnested just
like init or kthreadd along with all its own children.
However, if nesting levels exceeded 255 (and became 0)
a massive array overrun could be triggered when such a
task and *all* its children were added to an array for
the second time. Exactly how much storage was violated
depended on the number of children that zeroed process
had spawned (hinted at via either SIGSEGV or SIGABRT).
The earlier commit limited nested levels to 100 so the
root cause of the storage violation was already fixed.
The potential for distorted nesting levels due to sort
on start_time would seem to remain. But it's extremely
unlikely that 2 tasks would share the same start_time.
Even so, a new #define has been introduced which makes
top impervious to the order of tasks such that a qsort
is no longer necessary (providing an init/systemd task
exists & was harvested as the first task by readproc).
It can be utilized if distorted nesting ever becomes a
real issue. But since there is a 5-10% performance hit
with that, we'll continue using start_time as default.
References(s):
commit ce70017eb1
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit will eliminate a very nasty bug associated
with top's forest view mode. It addresses a potential
SIGSEGV/SIGABRT that was only encountered when another
program (erroneously?) creates a lengthy forking loop.
If the growing list of nested children is sufficiently
fast such that proc_t start_time is duplicated between
children then the sort upon which top relies might not
produce the expected order. That, in turn, could cause
the forest_adds function to initially miss some child.
But that missed child would be caught by forest_create
and eventually would cause our array boundary overrun.
Such overrun occurs when some child of that originally
*missed* child is found and a duplicate add attempted.
In correcting this bug we'll also use this opportunity
to prohibit a borrowed proc_t padding byte (char) from
going negative. If the nesting level exceeded 127, the
effect was an "unnesting" with the snprintf width then
viewed as flag+width also yielding left justification.
Henceforth, we'll limit nesting to 100 with subsequent
children shown as " + ", not the usual " `- " prefix.
References(s):
https://bugzilla.redhat.com/show_bug.cgi?id=1153642http://www.freelists.org/post/procps/Bug-in-the-forrest-view,6
Signed-off-by: Jim Warner <james.warner@comcast.net>
When startup defaults were changed users with existing
rcfiles would likely find their previous configuration
was not being honored in all respects. The disparities
involved Graphs modes and Summary/Task memory scaling.
This patch simply restores what was always intended as
the proper behavior for previously saved config files.
References(s):
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=762928https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=762947
. new startup defaults
commit 8ef6cd91fc
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch will cure a potential aberration associated
with a terminal's size (SIGWINCH) and top's new graphs
modes. The symptoms were a dangling tilde (~) plus the
potential loss of a graph's right-most visual content.
The condition was only apparent when a %Cpu approached
100% usage. Also the apparent loss of content affected
the 'block' graph only. With 'bar' graphs, that affect
became the loss of proper right-most bar graph colors.
The cause was determined to be a combination of: 1) an
unnecessary snprintf precision specification; and 2) a
rounding quirk for any graphs which displayed distinct
types of information (as for user/syst, used/unavail).
These could then combine to produce an extra bar/block
which, in turn, resulted in the truncation of a pseudo
termcap attribute used by the show_special() function.
What was originally interpreted as an intractable race
condition turns out to be just a self inflicted wound.
Reference(s):
http://www.freelists.org/post/procps/top-Possible-bug-in-the-graphs,1
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch will trade a former pessimistic calculation
of free physical memory for a more optimistic one that
uses the newly added kb_main_available library export.
But in case one might wish to return to the old former
method, there's a new #define that was made available.
[ the new calculation will affect graphing mode only ]
Reference(s):
http://www.freelists.org/post/procps/systemd-support-to-library,9
Signed-off-by: Jim Warner <james.warner@comcast.net>
Might as well use the newly exposed sysinfo.h variable
'page_bytes' rather than our own. Plus, in the process
we can avoid incurring yet one more function call hit.
Signed-off-by: Jim Warner <james.warner@comcast.net>
Gosh, just because most of us might run with some swap
file allocated, not every system might. I only wish my
testing methodology was as sophisticated as Jaromir's.
Reference(s):
http://www.freelists.org/post/procps/latest-top-enhancements,7
Signed-off-by: Jim Warner <james.warner@comcast.net>
When startup argument parsing was recently enhanced to
account for LC_NUMERIC settings, some user input logic
dealing with numbers fails to exploit that capability.
This patch extends such enhancements to a running top.
Reference(s):
commit f7b84f45c7http://www.freelists.org/post/procps/topwatch-floating-point-input,2
Signed-off-by: Jim Warner <james.warner@comcast.net>
When those new cpu/memory graphs modes were introduced
they had global impact. In other words, the modes that
were chosen for a 'current' window affect Summary Area
appearance for every other window as well, even though
each window sets unique View_STATES/View_MEMORY flags.
I do not know how widespread the use of top's separate
window provisions is, but I do know that documentation
promises every window (field group) provides "a unique
separately configurable summary area". And even though
that promise does not include memory scaling (separate
'E' command) the graph modes are integral to 't' & 'm'
and those were already observed on a per window basis.
So this patch just takes the cpu and memory graph mode
values out of global scope in the configuration file &
gives each window its own unique pair of graph values.
Reference(s):
commit 1d171ec741
Signed-off-by: Jim Warner <james.warner@comcast.net>
Boy I hate locale stuff. For code I thought was pretty
robust, Jaromir sure proved that it wasn't. Anyway, me
thinks this commit closes some gaps and will cause top
to behave appropriately under various locale settings.
It does *not* permit top to respond to the ',' and '.'
floating point separator without regard to the locale.
It does, however, enforce proper LC_NUMERIC responses.
Let's look on this commit as an interim solution until
Jaromir can create that proposed 'fp_decode' function.
Who knows, he might even borrow some of our mkfloat().
[ An aside: the coreutils sleep and timeout programs ]
[ claim to permit floating point arguments. However, ]
[ neither one will accept the comma separator should ]
[ the locale be a country that in fact uses a comma. ]
[ In other words, with this commit we are way ahead! ]
Reference(s):
http://www.freelists.org/post/procps/topwatch-floating-point-inputhttp://www.freelists.org/post/procps/topwatch-floating-point-input,1
Signed-off-by: Jim Warner <james.warner@comcast.net>
While there was no harm done setting a handler for the
above two signals, they are in fact uncatchable. Thus,
whenever we ran with valgrind we're politely reminded.
Signed-off-by: Jim Warner <james.warner@comcast.net>
When the beginning of the Mem/Swap graphs was variable
scaling them to the current terminal's width was a bit
of a costly nightmare. So the graph size was fixed and
subject to truncation. However now that the start of a
graph can be easily predicted, I've revisited scaling.
As it turns out, any cost is minimal & mostly incurred
at an opportune time, at SIGWINCH or user interaction.
Plus, most of the apparent arithmetic is actually just
a means of documenting and will disappear thru compile
time constants in the ultimate generated machine code.
Note: those graphs will now behave just like any other
Summary Area element - they will scale from full sized
down to a terminal width of 80 columns, at which point
those displayed graphs are then subject to truncation.
Signed-off-by: Jim Warner <james.warner@comcast.net>
While the 'b' toggle remains window based (vs. global)
it should no longer require that the window be visible
and either the 'x' or 'y' toggles to be on. Previously
those requirements were intended to remind a user that
there must be something for this command to highlight.
With the introduction of graph modes (specifically the
the bar graph) the 'bold/reverse' toggle has important
implications beyond highlighting some columns or rows.
The %Cpu(s) graph and Mem portion of the memory graphs
are designed to offer a visual clue as to the separate
elements comprising them. But that separation could be
lost under some X color schemes or when top is running
without color (in monochrome mode) and the block graph
is selected. But, if the graph is then changed to bars
any separation always becomes visible whenever the 'b'
toggle is turned off. Portions then show in 'reverse'.
So from now on we'll check nothing, we'll just toggle.
[ Besides, with all the code thrown at restricting a ]
[ 'b' toggle use, it might have all been for naught. ]
[ That toggle could still be set/unset using the 'Z' ]
[ command and the color mapping screen. Geez Louise! ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
My original graph modes implementation made no attempt
to align the Cpu & Mem/Swap graphs. I thought, rather,
that such alignment could be best achieved by the user
using top's 'E' memory scaling command toggle. In that
way Mem/Swap prefixes could be reduced by 3 positions,
bringing the beginning '[' into line with the %Cpu(s).
If that proved to be too cumbersome a #define could be
enabled making the Mem/Swap prefix static while adding
a few padding bytes to the %Cpu line(s) for alignment.
It was those waisted bytes that were the most concern.
What I had not counted on was the fact that the memory
lines themselves might become misaligned & that became
likely with more physical memory present. That too can
be cured with the 'E' command but as scaling is raised
we soon reach a meaningless total such as '0.003' even
though the displayed % remains valid (and unchanging).
So this commit implements unconditionally what used to
be conditional. But, instead of waisting padding bytes
we'll put that space to good use with a new 'total %'.
Reference(s):
http://www.freelists.org/post/procps/latest-top-enhancements,1
commit 1d171ec741
Signed-off-by: Jim Warner <james.warner@comcast.net>
My first blush graphs modes implementation went just a
tad overboard on identifier lengths. As a result, some
program lines were getting quite long. So, this commit
will simply shorten some excessively long identifiers.
Reference(s):
http://www.freelists.org/post/procps/latest-top-enhancements
commit 1d171ec741
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch makes 't' (View_STATES) & 'm' (View_MEMORY)
commands into 4-way toggles. The two new modes provide
for two different graphs of the cpu and/or memory use.
These new capabilities are similar to those offered by
the 'htop' program. However they're aesthetically more
pleasing (to me) plus the scalings are more authentic.
Poor ol' top has long been troubled by the comparisons
offered up by the 'htop' program. Many of those things
were only true of the original redhat top while others
are no longer true of this current top program. So let
me use this commit msg to begin to correct the record.
Corrected comparisons between 'htop' & 'top' programs:
------------------------------------------------------
+ htop does not start faster, actually reverse is true
+ top offers scrolling vertically and horizontally too
. (and top offers better <Home> and <End> key support)
+ unassigned keystrokes don't subject top to any delay
. (but htop suffers that annoying ncurses <Esc> delay)
+ in top one need not type the PID to kill the process
+ in top one need not type the PID to renice a process
Some things the 'htop' program was not bragging about:
------------------------------------------------------
+ top can outperform the htop program by a wide margin
+ htop + SIGWINCH = corrupted display + restart likely
+ htop cannot preserve its screen data at suspend/exit
+ the htop column management scheme is very cumbersome
+ htop allows columns to be duplicated again and again
+ htop displays only full command lines, not pgm names
. (and that 'Command' column must always be displayed)
. (and it must always remain as the last column shown)
+ htop does not provide for any sort of command recall
+ htop's search feature does not highlight any matches
+ there is no 'find next' outside of htop search modes
+ htop does not allow Header or Process memory scaling
+ htop provides no flexibility on column justification
+ htop does not provide the means to change col widths
+ htop provides less control over colors configuration
+ htop always overwrites the rcfile with any UI change
Someday, maybe we'll provide a better comparison as an
addendum for (or replacement of) that README.top file.
Signed-off-by: Jim Warner <james.warner@comcast.net>
In anticipation of upcoming memory graphing provisions
the abbreviations 'Mem' and 'Swap' are being made into
individual translatable strings in order to be reused.
Additionally, the Mem 'used' amount will now no longer
included the 'buffers' and 'cached' values. Thus, each
Mem category becomes unique. This is the approach used
by tools such as 'htop' or the gnome 'System Monitor'.
Lastly, with that change to the 'used' category it has
been repositioned after 'free' on the Mem & Swap lines
making a comparison between 'total' and 'free' easier.
Signed-off-by: Jim Warner <james.warner@comcast.net>
For some time now, top has refrained from updating the
current number of cpus and memory totals with each and
every refresh cycle. Rather, to lessen overhead costs,
such values are updated periodically (5 min & 3 secs).
The delay in updating the cpu count was only important
with the addition of a cpu, since any loss is detected
immediately. And the large interval was chosen because
of the costs once associated with a glibc sysconf call
and an unlikely scenario of physically adding the cpu.
But the ease with which cpus can be taken offline then
placed back online under linux suggests that 5 minutes
may be too high. So, without addressing the likelihood
of that act, top is now more responsive in these ways:
1) that 5 minute interval has been reduced to 1 minute
2) any key, not just Enter/Space, refreshes cpus & mem
Note: we leave the man document as is, suggesting that
only the Enter/Space keys force an update for hotplug.
Signed-off-by: Jim Warner <james.warner@comcast.net>
. prevent any input recall overrun if window downsized
. adjust translation notes for true column hdr maximum
Signed-off-by: Jim Warner <james.warner@comcast.net>
In release 3.3.6, some commands were equipped with the
concept of a 'default pid'. The initial implementation
meant that the intuitive <Esc> key would not always be
treated as one would expect under any well behaved UI.
This patch ensures the expected <Esc> key behavior of:
terminating user input while still making possible the
necessary distinction between 'no input' & 'defaults'.
Reference(s):
http://www.freelists.org/post/procps/top-Escape-doesnt-abort-kill-command
Signed-off-by: Jim Warner <james.warner@comcast.net>
The granularity of /proc/uptime is fixed at hundredths
of a second. And, since we can cycle faster than that,
we are exposed to 'nan' when calculating elapsed time.
This commit will protect us from that outcome when the
delay interval has been set to an extremely low value.
Signed-off-by: Jim Warner <james.warner@comcast.net>
If a system's time is adjusted backwards, then elapsed
time could appear as negative. This yielded a negative
%CPU value. Alternately if zeros were suppressed ('0')
the result was a blank %CPU column. In both cases that
distortion would last for one display cycle or until a
user forced a display refresh via some keyboard input.
The original recommendation was trading gettimeofday()
for clock_gettime() using CLOCK_MONOTONIC. But on some
systems that might not be possible, forcing the use of
CLOCK_REALTIME instead. Not only would that complicate
the build system, but it may leave us with minus %CPU.
Another approach was to ensure that elapsed time could
never be negative. Of course, this produced distortion
of %CPU values but it would be proportionally correct.
This wasn't dissimilar to a distortion already present
should the time be adjusted forward or backward within
any 'remaining' top delay intervals. These aberrations
would be avoided with clock_gettime & CLOCK_MONOTONIC,
but that is a less than ideal solution as noted above.
This final solution, which originated down under, will
simply rely on the /proc/uptime seconds, which will be
immune to *any* tampering with the system clock. Thus,
we now have a fix for the distortion we didn't know we
suffered plus a negative %CPU that began this odyssey.
Thanks to:
sk.alvin.x@gmail.com, for the original effort
jcapik@redhat.com, for a heads up on CLOCK_MONOTONIC
csmall-procps@enc.com.au, for the best suggestion of all
Reference(s):
. original post/patch
http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday
. heads up on CLOCK_MONOTONIC
http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,2
. the final solution
http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,11
Signed-off-by: Jim Warner <james.warner@comcast.net>
Minor fixes that the translator (Yuri) has found in some of the
strings. You only know how many typos and thinkos you have when
someone is trying to translate it.
Signed-off-by: Craig Small <csmall@enc.com.au>
Since its inception top has always used enumerators to
identify displayable fields. They've taken the form of
P_PID, etc. As it turns out, something has changed for
libc6-dev versions beyond 2.17-93 wherein 'P_PID' will
now be exposed via stdlib.h. I have not pinpointed the
exact cause but it may depend on header include order.
This patch just trades top's long standing 'P_' prefix
convention for that of 'EU_' (short for enumerator). I
cannot find *any* header under /usr/include/ currently
utilizing this particular three character combination.
And as a further safeguard top will henceforth include
'system' specific headers after the standard includes.
Reference(s):
http://www.freelists.org/post/procps/top-wont-compile-anymore
Signed-off-by: Jim Warner <james.warner@comcast.net>
When top originally responded to the potential libnuma
stderr write, the library was consistently called with
each refresh cycle. That, in turn, guaranteed that any
warning message would be seen at program end by virtue
of: 1) having been issued before the 2nd refresh cycle
and; 2) benefiting from inherited /dev/null buffering.
A later efficiency refactor meant the numa library may
not always be called with every refresh cycle. Rather,
it was only called if top was in one of two numa views
(the '2' or '3' toggles). That, in turn, resulted in a
loss of any warning message at program end unless numa
mode had been preserved in the rcfile. In other words,
if top was started normally then a single cycle stderr
redirect would have long passed by the time the '2' or
'3' toggle was activated. The warning message actually
was spewed but quickly lost to the full screen refresh
which follows all keyboard interactions with the user.
This commit simply moves the restoration of our stderr
redirect to program end (instead of that first display
refresh). Now, any libnuma stderr warning message will
appear as the concluding output line upon quitting top
without regard to when any numa mode view was invoked.
And since this technique might be useful in some other
context (as an example of how to 'buffer' stderr) it's
been generalized with its own #define. But to maximize
its usefulness, the original redirect should be issued
much earlier in pgm startup than top has chosen to do.
Reference(s):
. original libnuma stderr response (msg seen)
commit 35dc6dcc49
. numa refractoring for efficiency (msg lost)
commit f12c0d5c6e
Signed-off-by: Jim Warner <james.warner@comcast.net>
Apparently there are occasions when NUMA nodes may not
always be contiguous. Under such conditions nodes that
were not used would still occupy precious Summary Area
space showing 100% idle, under the '2' command toggle.
With this commit top will no longer display numa nodes
that have no associated cpu when the '2' toggle is on.
But just in case we wish to return to former behavior,
a new #define called OFF_NUMASKIP has been introduced.
And as an aside, a recent refactor mentioned below set
the stage for this patch to be 'self-tuning'. In other
words, if an inactive/non-displayed node should become
active (if even possible), then top will begin showing
such a node automatically with the next screen update.
Unfortunately, all inactive nodes now 'suppressed' are
still accessible via the '3' command. Those nodes will
just be displayed as empty (no associated cpus shown).
This is not really a top problem but more of a libnuma
and/or user deficiency. The library lacks the means to
validate a node id and the user then input a node that
was not even shown under a '2' toggle Summary display.
( too bad libnuma does not offer an 'is_node_active' )
( type function so top could warn a user when such a )
( discontinuous node was requested using his '3' cmd )
( sure, top could achieve this objective himself but )
( that would require making yet another array global )
( which i'm just not in the mood to do - besides, we )
( have already made enough concessions to libnuma.so )
Lastly, an existing #define (PRETEND_NUMA) was changed
to 'disable' node #1 so as to simulate a discontinuous
node. This allows testing of the '2' and '3' commands.
Reference(s):
http://www.spinics.net/lists/util-linux-ng/msg08671.html
. set stage for self tuning
commit f12c0d5c6e
Signed-off-by: Jim Warner <james.warner@comcast.net>
A recent change involving a one cycle stderr redirect,
to handle a libnuma potential transgression, failed to
follow normal global variable naming conventions. This
patch will capitalize the 1st letter of 'Stderr_save'.
Reference(s):
commit 35dc6dcc49
Signed-off-by: Jim Warner <james.warner@comcast.net>
Excluding those special X_XON/X_XOF enums, which might
not even be present, restore strict collating order of
all the case labels in the task_show switch statement.
Also, adjust a few sort callbacks for the same reason.
Signed-off-by: Jim Warner <james.warner@comcast.net>
The recent addition of namespaces, combined with those
potential suse out-of-memory fields, means that we are
close to the maximum number of fields poor ol' top can
display. Imagine, the really old top was limited to 26
fields (28 with the suse hack) and this top had neared
the version 'g' rcfile limits which were a healthy 55.
This patch adds another 15 fields to the maximum while
making it even easier to increase in the future. Also,
top still silently accommodates older config files all
the way back to the original pre-ng version top-3.2.8!
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch is inspired by the 'minimize numa overhead'
patch. It trades the use of subscripts for pointers to
avoid gcc repeated subscript offset calculation bloat.
Now, throughout the cpus_refresh function, a subscript
will be resolved just once & this will (dramatically?)
reduce the path-length taken for each and every frame!
For example, a non-optimized compilation could produce
400+ fewer machine instructions through pointer usage.
[ ok, optimized compiles only save 18+ instructions! ]
Lastly, any residual 'symmetry only' crap is now gone!
Signed-off-by: Jim Warner <james.warner@comcast.net>
A recent libnuma potential corruption problem solution
has caused me to reevaluate some associated numa logic
for efficiency. Here is a summary of the problems that
exist with current libnuma/user possible interactions:
. Whenever the numa library was present extra overhead
would always be incurred in maintaining the node stats
even when the '2' or '3' commands were not being used.
. As part of such overhead a separate loop was used to
reinitialize each cpu/node structure with each display
cycle so that prior accumulated totals were preserved.
Again, it didn't matter if numa data was really shown.
This commit attempts to refocus on the 'critical path'
costs in a running top by optimizing for the occasions
when numa node data is not being displayed. Under such
conditions, no extra overhead will be incurred whether
or not a distribution has the libnuma library present.
To achieve this goal, some additional overhead will be
incurred, but only when actually displaying numa data.
And all such new costs have been minimized in spite of
the gcc inclination to duplicate subscript resolution.
Reference(s):
commit 24bd950cb2e1722d459461f0f9c0c30a4b9ffdaa
Signed-off-by: Jim Warner <james.warner@comcast.net>
A recent libnuma potential corruption problem solution
suggests that libnuma could change in the future so as
to not spew to stderr. This then raises a question how
top could exploit any such library change since we are
currently locked into version #1 of the library by way
of our dlopen("libnuma.so.1", RTLD_LAZY) runtime call.
While not an ultimate solution, this commit will first
try for the most recent version of that library during
top's startup before trying the original libnuma.so.1.
We do this via the unqualified library soname symlink.
For this new dlopen() call to succeed, technically the
numa 'devel' package would usually have been required,
but that's not always true with every distro. And when
the libnuma.so symlink isn't present, it can always be
manually added should a newer & better behaved library
arrive & users tire of the stderr warning at top exit.
Reference(s):
commit 24bd950cb2e1722d459461f0f9c0c30a4b9ffdaa
Signed-off-by: Jim Warner <james.warner@comcast.net>
There is a chance that the libnuma library may corrupt
top's display with some stderr warning messages in the
event something under /sys/devices/system/node/ cannot
be accessed. And, while 2 overridable 'weak' functions
are provided to alter such behavior, we can't use them
since top dynamically links to the library via dlopen.
This commit will redirect stderr to '/dev/null' during
just the first screen display cycle. Thus we can avoid
the corruption which would have remained visible until
the underlining screen row's data had finally changed.
Lastly, this patch should allow such a library warning
to actually appear when one finally exits our program.
[ i think the libnuma folks should consider changing ]
[ the error/warning interfaces to accommodate dlopen ]
[ rather than forcing something like the ugly kludge ]
[ we have employed or libnuma dependency on everyone ]
Reference(s):
https://bugzilla.redhat.com/show_bug.cgi?id=998678
Signed-off-by: Jim Warner <james.warner@comcast.net>
When Other filtering was introduced the nature of what
constituted a displayed row changed. No longer would a
task_show() call guarantee that another line is shown.
Rather, a non-empty string must have also been tested.
Unfortunately, when any task window was being filtered
for 'idle' mode or a particular 'user', the proc index
was incremented twice due to the perils of copy/paste.
Combining such an index increment with the new test of
task_show results works fine if filtering is inactive.
This was a particularly insidious bug which meant that
an adjacent task would be skipped whenever the current
task met 'idle' and/or 'user' filter criteria, and was
not otherwise excluded due to 'Other' filter criteria.
And, since it was the very next task that was ignored,
the bug was very susceptible to a window's sort order.
This could be illustrated when filtering on some user,
while sorting on PID. Then, toggling Forest View could
make otherwise unseen tasks appear and then disappear.
User workarounds are possible via interactive commands
trading the 'i' and 'u'/'U' provisions for the 'o'/'O'
other filtering capability thus avoiding an extra i++.
But that is certainly less than ideal and doesn't help
the 3.3.7 and 3.3.8 distorted command line provisions.
( this little buggie may end up costing me my pocket )
( protector, my coding badge & maybe even my cubicle )
Reference(s):
http://www.freelists.org/post/procps/Idle-elides-nonidle-processes
. bug originated with 'Other' filtering
commit 5edc6fb317
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch adds the final newline when exiting 'Batch'
mode. Interestingly, it has been missing since release
3.3.5 but undetected until the Redhat bugzilla report.
Reference(s):
https://bugzilla.redhat.com/show_bug.cgi?id=1008674
Signed-off-by: Jim Warner <james.warner@comcast.net>
Normally, the internally tracked 'Screen_cols' can not
exceed the lessor of 512 or actual screen width. There
was one case, however, where that 512 byte upper limit
was no longer properly imposed as it should have been.
When operating in 'Batch' mode the actual screen width
was allowed to be exceeded when the optional -w switch
was also used. But, it should never have exceeded 512.
This patch ensures the upper limit is always observed.
Reference(s):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=721204
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch addresses the four '-Wunused-result' errors
generated whenever an optimized compile is invoked. It
also made the configs_read() guy a little more robust.
In the process, some logic was rearranged slightly and
some comments were re-indented simply for consistency.
Reference(s):
warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result]
warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]
Signed-off-by: Jim Warner <james.warner@comcast.net>
When the final solution for cursor positioning for all
^Z or ^C cases was introduced the revised placement of
message line management introduced with the window mgr
'screen' refactor was retained. Those two commits mean
that a former tgoto was no longer needed when clearing
that msg line or displaying the scroll coordinate msg.
This patch eliminates the tgoto employed by frame_make
while assimilating a now defunct show_scroll function.
Reference(s):
. final cursor positioning for ^Z or ^C
commit 46a1356219
. 'screen' window manager refactor
commit 0fe393ff27
Signed-off-by: Jim Warner <james.warner@comcast.net>
Some more (very obscure) conditions where a suspension
or program end might embed the shell prompt within top
output have been uncovered beyond the 2 already known.
We had already covered some suspend/end contingencies:
1. the users were using the 'fields management' screen
2. the users were prompted for any line oriented input
However, there remained some situations where ^Z or ^C
could still produce a misplaced cursor + shell prompt:
3. the 'g' command while waiting for the window choice
4. the 'W' command if about to overwrite an old rcfile
5. the '=' command when exploiting the Inspect feature
6. the period during which any error message was shown
But, even when all those bases are covered there still
remains a remote possibility that such interrupts will
occur during a top repaint cycle. So rather than throw
yet more code at these self-inflicted problems perhaps
it is better if we just throw in the proverbial towel.
Thus, I'll take the only sane approach and restore the
results expected ever since top's inception and before
scrollback buffers entered the picture. Namely, with a
^Z or ^C the cursor will be placed on the final screen
row. That usually means it will immediately follow the
last output line but it may follow many blank lines if
the user interrupts top when *not* on the main screen.
Reference(s):
. expanded repositioning (for line oriented input)
commit 33104a2bcc
. introduced repositioning (for fields management)
commit 5c974ff44d
. scrollback buffers (the cursor handling changes)
commit dedaf6e1a8
Signed-off-by: Jim Warner <james.warner@comcast.net>
An obscure bug has been discovered where a 'W' with an
old rcfile, warning against overwrite, would display a
cursor that should normally be hidden. This followed a
user's reply. So some logic was rearranged just a bit.
Signed-off-by: Jim Warner <james.warner@comcast.net>
A recent patch introduced the ability to recognize the
need to reposition the cursor at suspension or program
end. There remained unmet 1 additional potential need.
This commit extends that ability to embrace line input
so that if a user issues ^Z or ^C while being prompted
the resulting shell output will no longer be embedded.
Reference(s):
http://www.freelists.org/post/procps/top-library-miscellaneous-tweaks,7
commit 5c974ff44d
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit mostly justs renames a few identifiers but
it also will now suppress any end-of-job report if top
wasn't ended via the 'q' key convention (i.e. signal).
Signed-off-by: Jim Warner <james.warner@comcast.net>
The title of this commit is actually quite misleading.
Were it more accurate, it would at least mention a tty
emulator's scrollback buffer, which was the cumulation
of a long pursuit to reduce the SIGWINCH overhead when
a window manager carelessly floods an application with
that signal *while* a user is still resizing a window!
Disabling and enabling that scrollback buffer resulted
in the final top display replaced with original screen
contents, a phenomenon acknowledged at the time but it
also represented a user interface change which has now
produced the first request for return to old behavior.
After the SIGWINCH dust settled, another problem arose
regarding behaviors under the 'screen' window manager.
In response, top was refactored a bit to avoid display
corruption. That was before discovering 'screen' could
duplicate the scrollback buffer behavior top expected.
As it turns out, the 'screen' refactoring had probably
made scrollback buffer manipulation unnecessary. Still
one could argue that a window should not be allowed to
scroll while a constantly updating program was active.
The solution represented in this commit returns former
behavior at program end (retaining top's last screen).
And if we ever wish to disable scrollback buffers, the
associated logic was retained but made conditional. It
is not reflected in configure.ac but might be someday.
Lastly, this commit corrects cursor positioning when a
^C is issued under 'Fields Management' at any terminal
that didn't have a scrollback buffer (i.e. a console).
Reference(s):
https://bugzilla.redhat.com/show_bug.cgi?id=977561http://www.freelists.org/post/procps/top-library-miscellaneous-tweaks,1
. screen program refactor
commit 0fe393ff27
. scrollback buffer disabled
commit dedaf6e1a8
. sigwinch management defines
commit adca737758
commit 4f33b6b8c5
Signed-off-by: Jim Warner <james.warner@comcast.net>
When the plug-in approach to NUMA support was added, I
carelessly employed the compile-time linker convention
for naming the library. Technically this then required
the 'devel' package for NUMA support to be present for
the unqualified soname symlink to be available. Either
that or one must have manually created such a symlink.
This commit adds the missing major version to dlopen()
of libnuma.so.1 so simply having a more likely package
such as 'numactl' will enable both '2' & '3' commands.
References(s):
http://www.freelists.org/post/procps/top-NUMA-node-CPU-utilization-support,25
. initial dlopen support
commit edba932a7e
Signed-off-by: Jim Warner <james.warner@comcast.net>
If top were invoked under the 'screen' window manager,
writing the terminfo string 'exit_ca_mode' at top exit
would not restore the display to the state existing at
the time top was started. That's what occurs normally.
The net result of that failure was a corrupted screen.
However, there is a 'screen' configuration option that
will produce proper 'rmcup' behavior, but it is off by
default. That screencr option is known as 'altscreen'.
I stumbled across this provision by cloning the screen
git repository then searching for references to 'cup'.
If 'altscreen on' had been in either the /etc/screenrc
or the $HOME/.screenrc configuration file, my poor old
top would never have been accused of such corruptions.
Of course, the Programming Gods decree that any simple
solution for our problem must always be revealed last.
So before discovering that rc option, another approach
was taken involving top only. With just a little extra
refactoring of top display logic he was made immune to
any such quirk in the implementation of 'smcup/rmcup'.
I always feel good about any enhancement that actually
reduces the total number of lines of code. Even though
this change involved mostly rearranging some logic, it
yielded one less line (can't judge by diffstat because
of braces & notes). Anyway, rather than requiring some
change to a screenrc file, now we are self-sufficient.
Reference(s):
procps ---------------------------------------------
https://bugzilla.redhat.com/show_bug.cgi?id=962022http://www.freelists.org/post/procps/top-procpsng337-no-screen-cleaning-at-exit,3
. top : disable tty scrollback buffer to improve SIGWINCH
commit dedaf6e1a8
screen ---------------------------------------------
git://git.sv.gnu.org/screen.git
. Improve cursor store/restore on smcup/rmcup.
commit f95352946080be803b794c9f2733d8c809c1a39a
. Fix using alternate screen buffers in some cases.
commit ad56f746c6243d45124485d198d577bdbb78071c
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=558724
Signed-off-by: Jim Warner <james.warner@comcast.net>
When summary & task area memory scaling was introduced
in release 3.3.6, the percentage columns were expanded
to provide 3 decimal places of precision. In hindsight
that may have been overkill, making those columns more
of a distraction than useful, with just too much info.
This patch will revert those columns to the former one
decimal place. And as was true, that decimal point may
be sacrificed depending on the number of cpus present.
And, in case anyone might prefer additional precision,
a build option can provide it (--enable-wide-percent).
Reference(s):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=707648http://www.freelists.org/post/procps/What-happened-to-my-top,1
commit 21e550bc08
Signed-off-by: Jim Warner <james.warner@comcast.net>