When that 'F' focus command has been applied to a task
in forest view it should remain as the topmost process
in a particular window. But without this patch that is
not guaranteed. Newly forked/cloned tasks 'above' such
a process result in task(s) appearing which shouldn't.
The effect was as if that up arrow key scrolled beyond
the topmost parent task, which would never be allowed.
[ since scrolling is permitted within a focus range, ]
[ when any task 'above' our focus/topmost task ends, ]
[ we respond as if scrolled with the down arrow key. ]
[ that result is completely appropriate. if the user ]
[ wishes to return to a focused parent, the up arrow ]
[ or home key can be used to accomplish such a goal. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
In an effort to improve the performance & decrease the
cost of our separate background update threads we will
relocate some overhead so that it might be overlapped.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit just ensures that at program end all those
semaphores are removed in the same order for symmetry.
From thread's view of importance, we do least to most.
Signed-off-by: Jim Warner <james.warner@comcast.net>
Rather than having those 3 separate background threads
enabled by default, we'll turn them off until somebody
chooses to activate them. That seems more appropriate.
Signed-off-by: Jim Warner <james.warner@comcast.net>
After the stage had been set in the previous patch, in
this patch we will actually implement those background
updates via 3 separate threads. The design was simple:
. the do-while loops have now been made truly infinite
. 2 semaphores per thread allow needed synchronization
. 1 semaphore will provide for each thread to sem_wait
. 1 semaphore will provide for display o/p to sem_wait
. and all 3 thread's program name was made descriptive
A complication was the potential for a signal directed
to one of our new threads. Rather than having a thread
try to deal with such signals, we pass a mask with all
signals blocked at pthread_create time. Thereafter any
subsequent signals are forwarded to the parent thread.
[ also sigprocmask was exchanged for pthread_sigmask ]
[ since warned about use "in multithreaded process". ]
[ plus we also modified each of those POSIX comments ]
[ about 2004 to agree with current signal-safety(7). ]
Sadly, after all this effort there were no performance
benefits to having separate threads. In fact there was
a measurable performance degradation when running with
ever smaller delay intervals. But even with a delay of
1/10 second the 'real' cost increase is only about 1%.
There is one way whereby any additional costs might be
eliminated (at least seemingly). One could introduce 2
separate sets of contexts for each of those 3 threads.
Then retrieval & display could be overlapped. However,
the resulting display wouldn't represent the real-time
results. Rather it would be stale by 1 delay interval.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit sets the stage for turning three functions
into code that can support a separate thread to update
their respective data while working in the background.
It involved relocating 1 function, renaming 2 routines
and adding parameters plus return addresses to each of
three functions. Those latter changes will be required
when issuing 'pthread_create' calls in the next patch.
The final step was organizing this code into what will
become the infinite do-while loop supporting a thread.
Signed-off-by: Jim Warner <james.warner@comcast.net>
The master branch top is pretty well insulated against
signal-unsafe function calls during end-of-job action.
However, this newlib branch top had exposed himself to
a bunch of such unsafe activity in the form of 'unref'
function calls to the new library. In those guys there
will be several 'free' invocations which are not safe.
So, this commit will simply correct such an oversight.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is an example of what can happen when this
author is waiting around for the release of our newlib
& otherwise runs out of legitimate changes to be made.
[ on the other hand, such changes surely make us run ]
[ quite a bit more efficiently, if i am not mistaken ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
This darn patch began as 1 correction to an extraneous
comma in the man document. Then, it grew to include an
adjustment for a couple of additional man page things.
After that, I figured I might as well tighten up logic
dealing with those awful gaps in the getopt_long code.
[ the error_exit mentioned in the associated comment ]
[ will only be taken when '=' ends the argv vectors! ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
For quite some time now, top has stood out like a sore
thumb regarding the approach to cmdline options & help
text. Only short options were used and that same help
text was displayed for '-h' (help) plus 'v' (version).
[ also, top 'rolled his own' when it came to parsing ]
[ options while avoiding that getopt implementation. ]
Well, with this commit all of that has changed and top
now has added a long form of his options. Additionally
he employs getopt_long() for the bulk of that parsing.
[ however, top will still avoid separate fputs calls ]
[ characteristic of other procps-ng programs when it ]
[ comes to help. rather all such text is one string. ]
Along the way, the following major getopt deficiencies
were addressed, assuming the absence of a new #define:
* an equals sign ('=') is allowed on both option forms
* whitespace is allowed before & after the equals sign
* optional arguments needn't abut their related option
for short form nor is an '=' required with either form
Signed-off-by: Jim Warner <james.warner@comcast.net>
The commit referenced below forced a return to row one
whenever there was a thread mode transition. Now, with
our new focus ('F') feature, we should adopt a similar
philosophy so as to avoid potential display anomalies.
Reference(s)
. Jun 2018, force row 1 w/ thread mode transition
commit 19ec80bd41
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch makes it possible to honor our '-H' threads
switch even when operating under that '-p' switch used
to select/filter only certain pids. Of course, what we
have done is just exploit the new library enhancement.
[ and we're pretending we don't know the enumerators ]
[ PIDS_FETCH_THREADS_TOO + PIDS_SELECT_PID are equal ]
[ to that PIDS_SELECT_PID_THREADS enumerator itself. ]
[ thankfully, those dependencies can be assured with ]
[ a 'make check-lib' which exploits ITEMTABLE_DEBUG! ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
[ we'll also eliminate a couple of references to the ]
[ repurposed 'F' command which should have gone away ]
[ with the introduction of that new 'focus' feature! ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
Ordinarily, whenever a new field is added to top, that
RCF_VERSION_ID should be bumped which then prevents an
older version of top from reading the expanded rcfile.
With this change, however, we'll keep the existing 'k'
version since we've yet to release the newlib version.
Signed-off-by: Jim Warner <james.warner@comcast.net>
As far back as release 3.2.8 (maybe even farther) this
man page used a number with each field's descriptions.
That practice caused no real harm when top was limited
to a grand total of 26 fields (thru lower case letters
of the alphabet). However, now we've reached 70 fields
and, depending on the name that's chosen, adding a new
field could result in a massive renumbering of fields.
Thus, this patch eliminates such potential by removing
all numbers from section '3a. DESCRIPTIONS of Fields'.
Signed-off-by: Jim Warner <james.warner@comcast.net>
The commit shown below introduced two abreast printing
for %Cpu statistics. But, the Memory & Swap lines have
always been printed on separate lines when '4' was on.
With this commit, those lines will now be treated just
like %Cpu stats, either separate lines or two abreast.
Reference(s):
. May 2020, added '4' toggle for 2 abreast
commit 59f5a37a24
Signed-off-by: Jim Warner <james.warner@comcast.net>
When the '4' toggle is on, and Summary Area %Cpu lines
are shown two abreast, it's not always clear where the
separation is between the two processors. So with this
patch we'll now print a vertical bar separator between
them (looking similar to the existing field headings).
We will also reduce that 'GRAPH_suffix' constant to 1,
reflecting the the trailing ']' bracket only, so as to
maximize top's exploitation of available screen width.
[ plus a superfluous double '+ +' has now been fixed ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
As promised, this commit will ensure that TREE_FOCUS_X
impacts only the window under which an 'F' was issued.
Previously, when 'F' was invoked it would impact every
window that was displaying forest view. Now, only that
window where 'F' was applied will show the indentation
losses whenever multiple windows were being displayed.
[ each of the 4 windows can now have different focus ]
[ pids active and not impact any other forest views! ]
Reference(s):
. 'TREE_FOCUS_X' introduction
commit c23d2708d4
Signed-off-by: Jim Warner <james.warner@comcast.net>
For every function whose parameters consist of a WIN_t
pointer and a pointer to a pids_stack, we will instead
pass the WIN_t pointer and index to that window's ppt.
This change will save six instructions per invocation,
and converts the index once in those called functions.
[ you can consider this an efficiency change, but it ]
[ is really being implemented so that 'TREE_FOCUS_X' ]
[ #define can be made to behave as one should expect ]
[ when running under top's 'alternate display' mode! ]
[ stay tuned for the very next commit to be pushed!! ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
For some reason, when top was modified to exploit that
<pids> api, one function prologue was removed. So this
commit just restores it to the 'window_show' function.
Reference(s):
. Aug, 2015 - adapted to new <pids> api
commit 77dc22b910
Signed-off-by: Jim Warner <james.warner@comcast.net>
Just to see if I could, the new #define will force the
indentation of a parent task to be reset to zero while
maintaining the proper child indentation relationship.
Signed-off-by: Jim Warner <james.warner@comcast.net>
Sometimes, it might be useful to isolate a parent task
and its forked children from other system activity. As
an example, a user might want to examine workload in a
specific lxc container. Or maybe there is some need to
question what's happening under the same tmux session.
Since forest view mode tends to be a relatively stable
display, it will sometimes satisfy the above need. But
that mode can't currently guarantee the target process
always remains as the topmost task or even is visible.
So, this patch will enable focusing on any parent task
and keeping it as the topmost process while displaying
it and its forked children only. It then appears as if
there is no other activity in that system by virtue of
the blank lines which follow that final child process.
To implement this new feature, top's redundant 'F' key
has been repurposed. It made little sense devoting two
keys to the Fields Management screen (especially since
the key we've taken required two separate keystrokes).
[ and while we're at it, i also added punctuation to ]
[ the prologue for that renamed 'forest_display' guy ]
[ since all other forest functions used punctuation. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
Since the internally kept nesting 'level' under forest
view is limited to a maximum of 101, we will now treat
it as signed to avoid any potential conversion issues.
Signed-off-by: Jim Warner <james.warner@comcast.net>
If there are zero numa nodes then the View_CPUNOD flag
cannot possibly be set. So it was unnecessary to check
both the numa total and View_CPUNOD in 'summary_show'.
Signed-off-by: Jim Warner <james.warner@comcast.net>
This new #define will produce top results identical to
the results achieved for './configure --disable-numa'.
However it keeps the change entirely local to our top.
[ it has been introduced to test the following patch ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
In the merge request shown below, 1 too many bytes are
written to stdout thus including the terminating null.
As the cure, this commit just reduces the length by 1.
[ along the way, we will remove some unneeded braces ]
[ plus add some additional comments with attribution ]
Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/127
. original ported cchange
commit 6b8980a3b6
Signed-off-by: Jim Warner <james.warner@comcast.net>
Some time ago, IO accounting was added for the library
and exploited by the ps program. This patch just plays
a little catch-up & adds similar functionality to top.
[ and we also finally get around to incrementing the ]
[ rcfile id which should have already been done when ]
[ the smaps fields were added or, at least, with USS ]
Reference(s):
. added IO accounting to ps program
commit 8baf8eeab4
. added IO accounting to library
commit a7afe06e6f
Signed-off-by: Jim Warner <james.warner@comcast.net>
We're just following the ps program's lead introducing
a new 'USS' field to represent the non-swapped portion
of physical memory ('RSS') not shared by another task.
Signed-off-by: Jim Warner <james.warner@comcast.net>
In the patch referenced below, 2 potential abends were
fixed both of which involved 'alternate display mode'.
The root cause of those abends was a negative value in
the 'begnext' field for other than the current window.
And while that potential is fixed for now the existing
code almost invites such problems again in the future.
So, this patch will remove any temptation to name some
other window in the 'mkVIZrow1' macro. And, since that
macro is not the only source of 'begnext' changes, the
'mkVizrowX' is being added to identify such occasions.
[ and for symmetry i've added a 'mkVIZyes' macro and ]
[ ameliorated an otherwise surreptitious assignment! ]
Reference(s):
commit 8281ac4f98
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit will address potential abends upon leaving
the windows help or color mapping screens and invoking
alternate display mode ('A'). It only happens if that
current window was changed with multiple 'a'/'w' keys.
So now, rather than leaving a trail of negative values
in the 'begtask' field, compliments of that win_select
function, we'll remove the mkVIZrow1 macro. Henceforth
it will be issued just once per user interaction. Thus
a promise of 'Curwin' only being impacted is restored.
[ my thanks to Vladimir Chren for reporting this bug ]
Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/210https://gitlab.com/procps-ng/procps/-/merge_requests/135
Discovered by:Vladimir Chren <vladimir.chren@gmail.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
[ of course, we had to renumber most existing fields ]
[ with these additions. plus, some typos were fixed. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
My, how time flies. Here we are finally attending to a
2 year old issue at long last (well, at least top is).
In truth, this change was prompted by that more recent
issue #201 and simply represents my initial picks from
among those available with the new library provisions.
Note: we have to bump that rcfile version whenever new
fields are added. That will mean older top programs no
longer can read this top's rcfile. But that's Ok since
top offers a warning before replacing an older rcfile.
Doubtless, more smaps_rollup fields will be introduced
under top as we get more experience with this feature.
However, any such usage comes with tremendoud costs as
was reported for the previous patch and repeated here:
Here is a small preview of just what you will discover
when using this command line: time top/top -d0 -n1000.
------------------------------------ as a regular user
with only PID + RES (statm)
real 0m2.605s
user 0m1.060s
sys 0m1.377s
with only PID + RSS (smaps)
real 0m26.397s 10x more costly
user 0m1.253s
sys 0m24.915s
----------------- as a root (thus smaps for all tasks)
with only PID + RES (statm)
real 0m2.651s
user 0m1.177s
sys 0m1.286s
with only PID + RSS (smaps)
real 0m33.040s 12x more costly
user 0m1.256s
sys 0m31.533s
Reference(s):
. top/ps: add support for PSS reporting
https://gitlab.com/procps-ng/procps/-/issues/112
. ps: expose shared/private memory separately
https://gitlab.com/procps-ng/procps/-/issues/201
Signed-off-by: Jim Warner <james.warner@comcast.net>
In anticipation of adding some smaps_rollup stuff, our
end-of-job report will now offer some insight into the
current unused entries for a window's fieldscur array.
Signed-off-by: Jim Warner <james.warner@comcast.net>
With that commit referenced below, which preserved the
'4' and + '!' toggles in the rcfile, this VER_J_RCFILE
macro was made superfluous. But, it was never removed.
Reference(s):
commit b46af6d213
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch is ported from a merge request shown below,
and the following represents the original commit text.
------------------------------------------------------
top: In the bye_bye function, replace fputs with the write interface.
When top calls malloc, if a signal is received, it will
call sig_endpgm to process the signal. In the bye_bye function, if the
-b option is enable, the Batch variable is set, the fputs function
will calls malloc at the same time. The malloc function is not reentrant, so
it will cause the program to crash.
Signed-off-by: Shaohua Zhan <shaohua.zhan@windriver.com>
------------------------------------------------------
Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/127
Signed-off-by: Jim Warner <james.warner@comcast.net>
While experimenting with a new feature, wherein select
fields display the total upon request, the capacity of
the 'num' passed to some 'scale' guys became an issue.
So this commit will, with the compiler's help, put the
responsibility for converting the integer into a float
within the calling code (instead of the called logic).
Signed-off-by: Jim Warner <james.warner@comcast.net>
With the 4 header files removed in the previous patch,
this commit just changes all those obsolete references
to that new consolidated 'misc.h' header file instead.
Signed-off-by: Jim Warner <james.warner@comcast.net>