Commit Graph

529 Commits

Author SHA1 Message Date
Jim Warner
99c1f0578f top: correct one source comment plus one man page oops
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-01-17 20:26:17 +11:00
Jim Warner
44ca06f1a0 top: eliminate every warning for '-Wformat-truncation'
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-01-13 19:34:39 +11:00
Jim Warner
91ffe81734 misc: fixed several inconsistencies in email addresses
[ you wouldn't believe how many back-and-forths were ]
[ involved in Craig convincing me there were several ]
[ inconsistencies. i am so dense sometimes (often?). ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-01-08 07:15:59 +11:00
Craig Small
c83cd6e6c0 top: Fix my email address
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2022-01-07 19:29:23 +11:00
Jim Warner
cbff1dd106 top: bust up that overly large 'summary_show' function
Over the years the summary_show function has increased
from around 77 lines of code & comments to its current
size of 243 lines. This is well beyond an ideal length
of available screen rows. So this patch will split it.

We'll take the cpu and memory duties and make separate
functions out of them. Of course, this will incur some
additional call overhead but, given current cpu/memory
logic, any such increase really becomes insignificant.

Now summary_show's a svelte 57 lines of code/comments.

[ this is like what was done to that do_key function ]
[ a decade ago except overhead of new function calls ]
[ plus table lookup was even less of a concern since ]
[ a human was involved, not normal iterative output. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-01-07 19:19:15 +11:00
Jim Warner
0e744d3656 top: provide for avoiding task focus ('F') distortions
In the patch referenced below the focus task logic was
improved to ensure that newly cloned tasks 'above' the
focused task did not force an effect like the up arrow
key. That commit also acknowledged that when some task
'above' ended, it *would* act like the down arrow key.

Well, with this commit a task ending 'above' a focused
task no longer distorts the focus. That's assuming the
new '#define FOCUS_HARD_Y' is specified plus the total
focused tasks does not exceed the current screen rows.

Thus, the manual scrolling with up and down arrow keys
is allowed when the total focused exceeds screen rows.

[ but keep in mind that when a focused task has been ]
[ hardened some otherwise useful toggles will not be ]
[ available. keystrokes like 'v' and even 'F' itself ]
[ can not be applied to another task with no scroll. ]

Reference(s):
. Sep, 2021 - 'focus' logic improved
commit 69978e3650

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-01-07 19:19:15 +11:00
Jim Warner
afdd4690fc misc: amend the man page & source file copyright dates
This just updates the copyright dates in the documents
where I was already represented. Others are unchanged.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-01-07 19:19:15 +11:00
Jim Warner
d79157db51 top: make the __LINE__ usage and whitespace consistent
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-12-20 21:38:16 +11:00
Jim Warner
9b24a423b1 top: touch up that code for proc mounted as subset=pid
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-12-20 21:38:16 +11:00
Jim Warner
16145af663 top: adapt for running with proc mounted as subset=pid
As the issue cited below illustrates, a pids namespace
with proc mounted as subset=pid denies our library any
access to non-task data. In top's case, the result was
a fatal error message which involved "cpu statistics".

With this patch top will now assume an error involving
global cpu (stat) or memory (meminfo) data means we're
running under a restricted pids namespace. As such, an
attempt will be made to still display task level data.

[ if our assumption is incorrect, it's of no matter. ]
[ instead of a fatal error, we'll still try to offer ]
[ a user some minimally useful bit of functionality. ]

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/227
https://www.freelists.org/post/procps/three-for-newlib,1
. 1st cut at subset=pid
commit bcb837b8c7

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-12-17 07:21:51 +11:00
Jim Warner
957b74292f ps,top: convert 'PIDS_PROCESSOR' into a signed integer
Not only does that library tweak help to simplify some
top code, but now that ps snprintf fmtstr will finally
be accurate. That is two birdies with a single pebble!

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-12-16 20:50:07 +11:00
Jim Warner
ad51fef1aa top: tweak some end-of-job logic when separate threads
The separate threads for background updates were added
to top in the commit shown below. At that time cleanup
logic was added to end-of-job processing to cancel any
active threads and destroy any semaphores then in use.

That seemed like simple good stewardship with an added
benefit of avoiding potential valgrind 'possibly lost'
warnings for 320 byte blocks. Those blocks represented
an initial stack allocation for each of three threads.

All of that worked perfectly if such code was executed
under the main thread. In other words, if the keyboard
or a signal directed to any thread was used to trigger
program end. However, it might not always be the case.

Each of those 'refresh' routines supporting a separate
thread interacts with a newlib interface. As a result,
each is required to check the library's return result.
Should some error be detected, 'error_exit' is called.
Now we've got big problems with that eoj cleanup code.

One can't 'pthread_cancel' and 'pthread_join' a thread
from withing that same thread. Thus, when an error was
returned by the library with threads active, top would
hang with no possibility of removal short of a reboot.

So, this commit only executes that cancel/join cleanup
code when we are running under the main thread. Should
program end be triggered by a library error under some
sibling thread, all such cleanup will now be bypassed.
In the latter case, we will rely on documentation that
says any thread calling exit(3) will end every thread.

[ now, the only time we'll see any valgrind warnings ]
[ is with a library error, which is the least likely ]
[ scenario for running valgrind & top to begin with. ]

[ besides, if the valgrind warnings became a problem ]
[ one could easily add a 'warning-suppression' file. ]

Reference(s):
. Sep 2021, top introduced threads
commit 29f0a674a8

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-10-31 17:12:32 +11:00
Jim Warner
5d09875488 top: only use 'pthread_sigmask' under separate threads
When multi-threading was introduced in the patch shown
below, the former calls to sigprocmask were traded for
a pthread_sigmask call. This was done unconditionally.

As a result, even when those threads weren't enabled a
need to link with libpthread was created. In hindsight
the need should only arise when top is multi-threaded.

This commit will make pthread_sigmask use conditional.

Reference(s):
. 09/2021, separate threads introduced
commit 29f0a674a8

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-10-18 17:38:43 +11:00
Jim Warner
67c150ed7c top: restore ending ']' when summary graphs are scaled
When a visual separator was added to 2 abreast summary
items in a recent commit, this bug was introduced. So,
from that earlier patch we'll revert one line of code.

The bug surfaced under an 80/even column terminal only
when that '4' toggle was off. With an an 81/odd column
screen, it existed in both single and 2 abreast modes.

[ this commit also goes the extra distance to ensure ]
[ two abreast mode maximizes available screen width. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-10-08 18:30:44 +11:00
Jim Warner
a5b51bc417 top: revert part of a patch regarding separate threads
In the patch referenced below, some logic was moved in
that frame_make function in an effort to overlap those
background threads with additional main thread duties.

Unfortunately, the auto-size column feature was broken
in the process. So this patch will revert a portion of
the earlier patch so as to restore the broken feature.

Reference(s):
. Sep 2021, top overlap additional processing
commit f11f43b4f7

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-10-02 13:00:00 +10:00
Jim Warner
69978e3650 top: ensure those potential focused tasks stay focused
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>
2021-09-26 14:47:21 +10:00
Jim Warner
f11f43b4f7 top: overlap some more processing for separate threads
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>
2021-09-26 14:47:21 +10:00
Jim Warner
d89047659c top: modify semaphore destruction for separate threads
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>
2021-09-26 14:47:21 +10:00
Jim Warner
476327048c top: reverse the #define defaults for separate threads
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>
2021-09-20 20:05:44 +10:00
Jim Warner
29f0a674a8 top: introduce background updates via separate threads
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>
2021-09-20 20:05:44 +10:00
Jim Warner
b4b68f11d6 top: refactor 3 routines ahead of the separate threads
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>
2021-09-20 20:05:44 +10:00
Jim Warner
1d1c1b84df top: tweak end-of-job processing if invoked via signal
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>
2021-09-20 20:05:44 +10:00
Jim Warner
8c23dfdcd4 top: some minor tweaks supporting long cmdline options
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>
2021-09-08 21:35:20 +10:00
Jim Warner
c91b371485 top: utilize getopt and introduce long cmdline options
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>
2021-09-07 08:02:43 +10:00
Jim Warner
1c00486728 top: and just eliminate a couple of unnecessary braces
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-24 20:52:10 +10:00
Jim Warner
40cf72b7b9 top: reposition call to cpus_refresh() for consistency
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-24 20:52:10 +10:00
Jim Warner
243bca8ab0 top: thread mode transitions should remove focus ('F')
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>
2021-08-09 22:03:23 +10:00
Jim Warner
23776571a7 top: respond to that preceding fix in the 'select' i/f
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>
2021-08-09 22:03:23 +10:00
Jim Warner
b789b46f84 top: exploit new items for displaying autogroup values
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>
2021-08-09 22:00:23 +10:00
Jim Warner
178acafb8a top: allow the summary memory lines to print 2 abreast
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>
2021-08-06 20:17:51 +10:00
Jim Warner
6eb9d4b586 top: add a visual separator to lines printed 2 abreast
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>
2021-08-06 20:17:51 +10:00
Jim Warner
2e11351b6f top: TREE_FOCUS_X works properly with multiple windows
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>
2021-08-01 20:36:55 +10:00
Jim Warner
38eeba364a top: trade most pids_stack pointers for a WIN_t ppt ix
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>
2021-08-01 20:36:55 +10:00
Jim Warner
335ec18774 top: restored a function prologue lost a long time ago
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>
2021-08-01 20:36:55 +10:00
Jim Warner
c23d2708d4 top: new #define added for focus ('F') toggle tweaking
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>
2021-07-27 21:17:18 +10:00
Jim Warner
3e922e671d top: introduced new focus toggle ('F'), program source
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>
2021-07-27 21:17:18 +10:00
Jim Warner
8c2622aea8 top: make eu_TREE_LVL a signed int not an unsigned int
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>
2021-07-27 21:17:18 +10:00
Jim Warner
1c1dd02862 top: whack a label & branch in 'summary_show' function
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>
2021-07-27 21:17:18 +10:00
Jim Warner
6a8d8ff80b top: added a new #define to test absence of numa nodes
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>
2021-07-27 21:17:18 +10:00
Jim Warner
27e60e86e9 top: fix a fix for the 'bye_bye' function (merge #127)
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>
2021-06-23 18:23:49 +10:00
Jim Warner
ae8d63addb top: follow ps lead & add several IO accounting fields
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>
2021-06-23 18:23:49 +10:00
Jim Warner
a30d949acf top: exploit the newly added library smaps_rollup item
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>
2021-06-17 16:42:58 +10:00
Jim Warner
2ea082b4af top: refactor 'mkVIZ' support to avoid future problems
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>
2021-06-17 16:42:58 +10:00
Jim Warner
8281ac4f98 top: fix two potential 'alternate display mode' abends
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/210
https://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>
2021-06-02 20:16:32 +10:00
Jim Warner
b05770d94a top: exploit some of those new smaps_rollup provisions
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>
2021-04-29 21:42:45 +10:00
Jim Warner
4153e72921 top: extend end-of-job report to reflect unused fields
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>
2021-04-29 21:42:44 +10:00
Jim Warner
8e0e3aff64 top: respond to library type change for TICS_ALL_DELTA
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-04-24 11:11:03 +10:00
Shaohua Zhan
6b8980a3b6 top: replaced one use of fputs(3) with a write(2) call
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>
2021-03-23 21:43:13 +11:00
Jim Warner
62928cf461 top: enabled arbitrarily large numbers in 'scale' guys
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>
2021-03-11 21:21:23 +11:00
Jim Warner
0749704006 top: update the man page & source file copyright dates
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-02-09 16:40:52 +11:00
Jim Warner
423297c9db all: make buildable again for new 'misc.h' header file
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>
2021-01-21 17:30:25 +11:00
Jim Warner
a0aed7b3df top: relocate the 'fatal_proc_unmounted' function call
With the restoration of corrupt utf8 multibyte editing
to the library, it's important to establish the proper
locale before calling that 'fatal_proc_unmounted' guy.

He calls the original 'look_up_our_self' who, in turn,
will invoke 'stat2proc' which then calls 'escape_str'.
Once there, it's too late to effect changes to locale.

[ the result would be lots and lots of '?' displayed ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-01-02 15:42:10 +11:00
Jim Warner
9c212a7e77 top: added utf8 multibyte support to additional fields
When any process' command line contains multibyte utf8
characters, two separate display problems could arise.

1. If that COMMAND column is not displayed as the very
last field, then field(s) to the right are misaligned.

2. Even when last, should utf8 string length (not that
display length) exceed allowable screen width, it will
nonetheless suffer from improper premature truncation.

Number 1 is less of a concern since the cmdline column
is likely to always be the last field to be displayed,
if only to enable right and left scrolling provisions.

Number 2 is much more likely to occur, especially with
additional fields which might be shown before COMMAND.
Or, forest view child tasks can yield the same effect.

So, this commit will permit the correct utf8 multibyte
display regardless of field position or string length.

And, we'll bring top into line with the ps program for
additional fields potentially subject to utf8 display.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-12-29 08:48:23 +11:00
Jim Warner
d1f5004df5 top: add pids_item enumerator as comments to task_show
The Fieldstab uses the full pids_item enumerator names
but also shows top's cryptic relative enumerator names
as comments. So, this commit will mirror that approach
in task_show, adding full pids_item names as comments.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-12-29 08:48:23 +11:00
Jim Warner
07e4c08c62 misc: just a couple cosmetic changes for comments only
Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-12-29 08:48:23 +11:00
Jim Warner
da02101513 top: fix additional SEGVs if no tasks were displayable
This patch is an outgrowth of that commit shown below.

Many additional potential segmentation faults might be
encountered if interactive commands are opened up to a
user when a '-p' switch has a single non-existent pid.

[ always the 'k', 'L', 'r', 'Y' keys & maybe 'v' too ]

So, this patch will restrict such a loser (oops, user)
to a reduced subset of normal commands until he/she/it
quits then restarts top with something to be displayed
or issues the '=' command overriding that '-p' switch.

Reference(s):
commit d3203d99dd

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-09-16 14:26:59 +10:00
Jim Warner
d3203d99dd top: fix potential SEGV when no tasks were displayable
This patch fixes a nearly decade old bug discovered by
Frederik Deweerdt. His merge request shown below would
be an adequate solution except for iterative overhead.

This alternate patch will represent substantially less
overhead for an admittedly extremely rare possibility.

Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/114

And-thanks-to: Frederik Deweerdt <fdeweerdt@fastly.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-09-13 10:00:49 +10:00
Jim Warner
fa51c2524a top: even more useless cosemetic stuff (only comments)
[ this is what happens when i've run out of bugs and ]
[ issues and am now left with way too much free time ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-08-26 21:50:20 +10:00
Jim Warner
e80b352b74 top: more useless cosemetic changes (chiefly comments)
All of these changes are self-explanatory, so I'll not
provide any more comments thus avoiding further shame.

[ everything's perfectly justified and right margins ]
[ are filled entirely, but of course it must be luck ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-08-26 21:50:20 +10:00
Jim Warner
01848d2adb top: make that 'cpu_prt' function a tad more efficient
This commit only eliminates two 'nop' instructions and
one 'jmp' instruction. However, it makes that C source
code look a little bit prettier than it looked before.

[ and yes, some unnecessary parenthesis were used to ]
[ force an alignment of some related lines. it costs ]
[ us nothing in extra code yet helps in readability. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-07-20 16:15:14 +10:00
Jim Warner
3e2cd9f87b top: make the 'cpu_tics' function a tad more efficient
This patch eliminates one variable which resulted in a
corresponding elimination of three 'mov' instructions.

[ that was 6 bytes per 'mov' for a total of 18 bytes ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-07-20 16:15:14 +10:00
Jim Warner
65ec527e4c top: response to revised numa stuff in that <stat> api
[ actually, this patch goes a little beyond what was ]
[ strictly required. some messages were expanded for ]
[ clarity and should an inactive node be selected by ]
[ the '3' command, a second '2' no longer is needed. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-06-25 20:08:22 +10:00
Jim Warner
740e585b9d top: provide for zero length character in utf8 support
This commit is prompted by the preceding change to the
library's escape.c module which, in turn, was prompted
by that issue shown below (with thanks to Konstantin).

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/176

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-06-23 19:09:05 +10:00
Jim Warner
38537f79c7 top: some miscellaneous accumulated tweaks and cleanup
I've grown to hate that man document rendering when it
comes to hyphenation. So this patch will eliminate it.

And we'll also eliminate an unnecessary initialization
in that top program code concerned with combined cpus.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-06-23 19:09:05 +10:00
Jim Warner
a3f8fa3763 top: fix a minor startup flaw for the '2 abreast' mode
This ensures that a single '4' keystroke will reliably
toggle the new 2 abreast mode ON. Depending on whether
an older configuration file existed or whether top was
configured with '--disable-modern-top', keying the '4'
for a second time might otherwise have been necessary.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-06-04 20:19:03 +10:00
Jim Warner
ef5750765f top: help the '#define PRETEND48CPU' be more realistic
An old PRETEND8CPUS #define was reintroduced & changed
to PRETEND48CPU to better exercise the new '4' and '!'
toggles. But, the implementation simply duplicated the
/proc/stat summary line for each cpu. Therefore, every
cpu showed the same graph/detail (depending upon 't').

This patch shows the actual individual cpu information
(duplicated, of course, when total cpus are exceeded).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-06-04 20:19:03 +10:00
Jim Warner
b46af6d213 top: preserved those new '4' and '!' toggles in rcfile
This patch will address Craig's feedback regarding the
original implementation of top's two new toggles. It's
likely other users would have questioned why they were
not saved also, once they discover these new features.

And, since the minimum terminal width was just lowered
to 80 columns, the default for window #1 is also being
changed to show the individual cpu graphs two abreast.

[ assuming no '--disable-modern-top' for ./configure ]

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/172
https://www.freelists.org/post/procps/two-major-changes-to-top,1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-05-31 22:06:26 +10:00
Jim Warner
98ae31584b top: warn users if rcfile save prevents older top read
I'm about to break older top rcfile compatibility when
preserving those two new toggles. And, though this has
happened several times over the years, we never issued
any warnings that such thing was just about to happen.

So, this patch corrects the long standing shortcoming.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-05-31 22:06:26 +10:00
Jim Warner
be3dcaa842 top: reduce minimum terminal width with 2 abreast mode
For the original implementation of the '4' toggle, the
minimum width was set at 165 columns. This was done to
avoid truncations when detailed cpu statistics (versus
graphs) were being displayed. Those can not be scaled.

Upon reflection, it seems more appropriate to give the
user the choice of whether or not to truncate. And, by
reducing that minimum width requirement to 80 columns,
we'll vastly expand potential use of two abreast mode.

[ we'll keep that original as '#define TOG4_NOTRUNC' ]

The patch also updates the man document appropriately.
Along the way, we will trade the potentially confusing
word 'adjacent' for the more natural 'additional' when
detailing the '!' toggle in 4b. Summary-Area-Commands.

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/172
https://www.freelists.org/post/procps/two-major-changes-to-top

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-05-31 22:06:26 +10:00
Jim Warner
4c0b69f385 top: address each of the most recent coverity warnings
This patch attempts to supress the following warnings:

. MISSING_BREAK, TAINTED_SCALAR plus SIZEOF_MISMATCH .

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-05-31 22:06:26 +10:00
Jim Warner
2ca99a2ee4 top: adapt former PRETEND8CPUS #define as PRETEND48CPU
This patch simply allows for better testing of our two
new toggles: '4' (2 abreast) plus '!' (combined cpus).

It had previously been dropped under the newlib branch
since top no longer managed cpus. However, now that we
have those new toggles, it seemed worth the efforts to
once again re-imagine then implement such a provision.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-05-28 19:49:40 +10:00
Jim Warner
94d6db6b40 top: add '!' toggle for combined cpus display, program
When implementing that earlier '4' toggle, in response
to the issue referenced below, I got to thinking about
those environments with massively parallel processors.

Such environments may not benefit from the '4' toggle.

So, I decided to implement a feature that could enable
use of those '1' and/or '4' toggles no matter how many
active processors top may have ultimately encountered.

With the new '!' toggle, adjacent cpus can be combined
to any degree, represented as a single cpu group/line.

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/172

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-05-28 19:49:40 +10:00
Jim Warner
59f5a37a24 top: add '4' toggle for 2 abreast cpu display, program
In the back of my mind, I've always wanted to enable a
two abreast cpu display. Folks with massively parallel
machines must surely have been frustrated with the '1'
toggle when Off (individual cpus in the Summary Area).

So, I'll use that recently raised issue shown below as
a justification for finally implementing this feature.

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/172

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-05-28 19:49:40 +10:00
Jim Warner
992217d1c0 top: updated man page and copyright dates to year 2020
Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-04-20 22:07:43 +10:00
Jim Warner
3a3c1604ff top: for symmetry with 'E' add 'e' command line switch
Several years after the 'e' & 'E' interactive commands
were introduce to affect memory scaling, an 'E' switch
was added. This was after discovering a dropped Redhat
patch which provided a unique 'M' command line switch.

If only for symmetry it makes sense to offer a similar
command switch ('e') for the Task Area memory scaling.

As was true with 'E', top's help text will show 'e' as
if it were a switch without arguments in order to keep
help text displayed without wrap in an 80x24 terminal.
The man page, however, will show all of the arguments.

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/165
. 03/2017, added 'E' command line switch
commit b2bd65407a
. 12/2012, added 'e' interactive command
commit 21e550bc08
. 12/2012, added 'E' interactive command
commit bc46f67f9a

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-04-10 14:37:15 +10:00
Jim Warner
11af3b2020 top: eliminate inadvertent trailing double semi-colons
Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-04-10 14:37:15 +10:00
Jim Warner
d28f3f28aa top: restore configuration file backward compatibility
The Debian bug referenced below has nothing to do with
locales. In fact, top was made locale independent back
in release 3.3.13 (April, 2018). However, that bug did
reveal some misplaced logic which this patch corrects.

Prompted by the Qualys audit, all rcfile field strings
were checked for potential duplicates which could only
have resulted from some user's manual/malicious edits.

Unfortunately, that code was executed before top had a
chance to enforce the proper/maximum string length (in
the event an extremely old rcfile had just been read).
This created some potential string overrun references.

In top's original 3.3.15 implementation, the potential
overrun extended for 15 characters. That is the number
of field characters added with 3.3.9 (December, 2013).
But, since strchr() was used, no error exit was taken.

In the revised 3.3.16 implementation, the strchr() was
replaced with '&w->rc.fieldscur[n]'. This held overrun
to a single position while producing an error message.

So, this commit just moves that logic to a point where
fieldscur is guaranteed to be longer than EU_MAXPFLGS.

Reference(s):
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=951335
. revised 3.3.16 validation logic
commit 775223a817
. original 3.3.15 validation logic
commit 085351a0ee

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-02-18 11:36:04 +11:00
Jim Warner
be31d2470b top: restore one line of code to sig_endpgm() function
When that potential abend at program end was addressed
in the patch shown below, one line of code was removed
in error. That line served to suppress some end-of-job
reports should ATEOJ_RPTSTD or ATEOJ_RPTHSH be active.

So, this patch restores that previously deleted logic.

Reference(s):
. potential SEGV fix, newlib branch
commit 90c22e64ff

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-02-18 11:36:04 +11:00
Jim Warner
1d73eb567c top: at abnormal end allow core dumps (fix qualys bug)
A Qualys audit patch, represented in the commit below,
added the _exit() call to our abnormal signal handler.
Unfortunately, that disabled the associated core dump.

This patch restores expected behavior of those signals
whose default produces a core dump file + termination.

Reference(s):
commit e1f419737f

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-01-06 09:11:20 +11:00
Jim Warner
7ef9289ae9 top: update copyright notations & fix a man page error
Beyond the copyrights, the single oops in the man page
was introduced in the commit which is referenced below
dealing with some cleanup following that Qualys audit.

Reference(s):
. man page error introduced
commit 4550e60144

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-10-27 22:27:49 +11:00
Jim Warner
8174a5c8b7 top: whack insidious bug surrounding auto-sized fields
This patch will eliminate a bug which is unique to our
newlib branch. It's extremely rare and only happens if
a search ('L'/'&') is initiated during the period when
fields are currently being auto-sized (AUTOX_MODE on).

This bug surfaces as either all zero results for tasks
displayed or a segmentation fault, depending upon what
fields were activated. It is caused by the timing of a
call to the <pids> 'reset' function. When called after
a task refresh, but before do_key(), this bug appears.

So this patch just ensures that 'reset' will be called
after do_key() & before the tasks have been refreshed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-10-27 22:27:49 +11:00
Jim Warner
34a5ea71cd top: parallel the master branch pids monitoring change
This commit will just parallel a pending master branch
merge request referenced below. Note, however, that it
is not really needed in this newlib branch because the
procps_pids_select() function itself provides a 'zero'
delimiter with every caller's designated list of pids.

[ since it's required under the master branch, we're ]
[ repeating it here just for documentation purposes. ]

Reference(s):
https://gitlab.com/procps-ng/procps/merge_requests/86

Originally-by: Yoann Lecuyer <yoann.lecuyer@gmail.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-09-22 07:32:03 +10:00
Jim Warner
90c22e64ff top: avoid a potential SEGV during program termination
The backtrace shown in the bug report referenced below
illustrates a 'normal' program termination interrupted
with some signal, ultimately then causing a top crash.

So this commit just rearranges a little code such that
all signals will be blocked during that rather lengthy
end of program processing regardless of how initiated.

[ in that report, ignore the assertion regarding the ]
[ '-n' option. it obviously was not '1' since do_key ]
[ had been called, which otherwise wouldn't be true. ]

[ and when it is '1' the -d option would be ignored. ]

Reference(s):
https://bugzilla.redhat.com/show_bug.cgi?id=1737552

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-09-22 07:32:03 +10:00
Jim Warner
33cd2ccf87 top: tweak logic associated with keyboard translations
This commit most significant change is the elimination
of the kbd_ENTER entry from that tinfo_tab in iokey().

That entry was a useless artifact left from the commit
which is shown below. It makes no sense to 'translate'
a keystroke into something it already was (i.e. '\n').

The remaining changes just reorder those table entries
for a progression consistent with vim keys: h,j,k & l.

Reference(s):
. fix 'iokey()' flaw preventing proper translations
commit c3323bdb68

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-09-22 07:32:03 +10:00
Jim Warner
97e1264525 top: standardize PgUp/PgDn management within task area
This commit standardizes the behavior of the PgUp/PgDn
keys when on the main top display. With PgDn, the last
process will become the first process. With PgUp, that
first task will now appear as the last task displayed.

[ this also eliminates some quirks that were evident ]
[ when paging at or near the end of the process list ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-07-04 20:46:18 +10:00
Jim Warner
e6a2931c39 top: attempt to provide missing xterm vim keys support
A recent issue (and merge request) reminded me of gaps
in top's alternate 'vim' navigation keys support. Some
xterm emulators do not pass the customary strings when
keys were used with the <Ctrl> and/or <Alt> modifiers.

While it was a known problem, this issue/merge request
prompted research into the root cause. As it turns out
the problem is traceable to an X resource known by the
name 'eightBitInput'. When 'true' (the default), a key
pressed in combination with <Alt> will not be preceded
by the <Esc> character. Rather, a single character was
presented (modified via an 'eightBitMeta' X resource).

The following approaches would eliminate this problem:

. start xterm thus: xterm -xrm '*eightBitInput: false'

. use: ~/.Xresources with 'Xterm*eightBitInput: false'

. build xterm with 'configure --enable-meta-sends-esc'
( apparently used for CentOS, Fedora, openSUSE, etc. )

. enable xterm's menu via 'configure --enable-toolbar'
( so the user can set the 'Meta Sends Escape' option )

Of course, none of the above steps is desirable from a
user's perspective. So, this patch will add additional
entries to the iokey function's tinfo_tab to represent
strings passed when the <Alt> key does not send <Esc>.

[ hopefully they'll be the same across all platforms ]

Lastly, this patch will also eliminate those redundant
<Atl> + '\', '/', '<' & '>' provisions, which now seem
like overkill and suffer from that same 'eightBitMeta'
xterm problem. And we might as well say goodbye to the
4 '<Alt> + arrow key' table entries (which do not seem
to currently work with any emulator which I can find).

[ what in the world was I thinking way back in 2011? ]

Reference(s):
. issue
https://gitlab.com/procps-ng/procps/issues/135
. merge request
https://gitlab.com/procps-ng/procps/merge_requests/84

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-07-04 20:46:18 +10:00
Jim Warner
e85e3ee4d8 top: just correct a couple of misspellings in comments
Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-03-26 19:55:30 +11:00
Jim Warner
34ca0a17ec top: adapt for changes in item identifiers, <STAT> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-01-22 22:49:24 +11:00
Jim Warner
ca9142767c top: harden management of 'Hide_pid' array allocations
While setting the size of that Hide_pid array to equal
total pids high water mark was probably safe, in truth
there is no real relationship. At some point one could
exceed that HWM if the 'v' toggle was used extensively
and at least 1 of those entries remained non-negative.

This commit simply divorces Hide_tot from the pids HWM
and bases Hide_pid array size on actual run-time need.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-01-03 08:06:48 +11:00
Jim Warner
22ae537707 top: enable alternate '+' placement with collapsed pid
Currently, except for tasks that have no parents, when
a process' children are collapsed the '+' indicator is
shown in the first position within that COMMAND field.

This commit simply provides for indenting the '+' char
so it displays next to that program name/command line.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-01-03 08:06:48 +11:00
Jim Warner
59f02f19c7 top: plug a minor hole in the vertical scrolling logic
In that commit referenced below, a few edge cases were
addressed regarding vertical positioning involving any
'hidden' tasks. But, 2 additional edge cases remained.

In a running top, if the user employed 'other filters'
(o/O) or 'user filters' (u/U) proper vertical position
was not ensured. And, while this could be easily fixed
by striking the home/end or up/down arrow keys, it was
very poor etiquette to shift this burden to the users.

So, this patch plugs that gap, automating the process.

Reference(s):
commit 9d59ddc466

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-01-03 08:06:48 +11:00
Jim Warner
a6dfc2382e top: eliminated the use of that 'procps.h' header file
That prior patch set the stage for eliminating the use
of that 'procps.h' header, while retaining support for
a ./configure -DXTRA_PROCPS_DEBUG' during development.

This commit just eliminates top's use of 'procps.h' in
favor of a separate include for needed newlib headers.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-09-12 21:12:06 +10:00
Jim Warner
19dd4f7120 top: a tweak to the forest view collapsed code (again)
From the outset, top has tried to provide some minimal
garbage collection in support of forest view collapse.
For example, with every 'v' keystroke, a check is made
of the currently targeted pids.  If all were negative,
which means expanded, that Hide_pid array was emptied.

Recently, yet another efficiency was added wherein the
continuing scan for a targeted pid was terminated when
a match was found. But, one more inefficiency existed.

When a task which was subject to collapse under forest
view mode has disappeared (ended), repeatedly scanning
for such a pid with each iteration makes little sense.

So this commit will negate such targeted pids and thus
avoid scanning every current task looking for a match.
Then, if 'v' is ever stuck at some point in the future
there will be a chance to empty that Hide_pid[] array.

[ hopefully this will be a final tweak of the forest ]
[ view collapse stuff, but cross your fingers anyway ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-09-12 21:12:05 +10:00
Jim Warner
5c8d94ff2e top: the '#define SCROLLVAR_NO' is bent but not broken
This patch simply avoids an 'unused' variable warning.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-09-12 21:12:05 +10:00
Jim Warner
43caa7a144 top: speed up the collapsed children forest view logic
In forest view mode, once a collapsible parent process
and all of its children (if any) have been identified,
there is no longer a need to scan the remaining tasks.

So this patch will just force a new scan for any other
'Hide_pid' entries which might remain to be identified
after a targeted parent has been completely processed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-13 20:55:50 +10:00
Jim Warner
52376d16e2 top: miscellaneous accumulated tweaks to code/comments
This patch includes the following miscellaneous stuff:

. ensure 1 space before any '*' ptr sizeof() reference

. explain the rather cryptic 'ioa' guy a little better

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-13 20:55:50 +10:00
Jim Warner
65feb3c558 top: eliminate all of that 'relative enumerator' bloat
The top program has always specified the maximum stack
depth at 'new' time. Then, in those stacks the minimum
number of result structures were used for representing
only fields actually being displayed in the 4 windows.

That, however, complicated all subsequent access since
each field's enumerator then had to be translated into
a relative position when interacting with the library.
This was accomplished by that Fieldstab 'erel' member.

So this patch eliminates an extra level of indirection
by fully exploiting the existing maximum sized stacks.
Now, the enumerators that top uses to represent fields
also represent their relative positions in each stack.

[ for fields not actually displayed, the position in ]
[ a stack is represented by the 'PIDS_extra' struct. ]
[ thus, there isn't any real library costs for those ]
[ enumerators/fields which aren't currently visible. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-13 20:54:48 +10:00
Jim Warner
ede4a5f9b0 top: existing 'Inspect' pipe feature now more flexible
Currently, it isn't possible to establish an 'Inspect'
pipe that relies on SIGINT to end. That's because this
signal will also end the parent process (top) as well.

So this patch will temporarily ignore that signal when
processing any 'Inspect' pipe, allowing one like this:

. pipe ^I Trace Calls ^I /usr/bin/strace -r -p %d 2>&1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-01 21:38:44 +10:00
Jim Warner
40dbd50056 top: avoid unrecognized 'Inspect' entries memory leaks
Upon startup there exists the potential for some minor
memory leakage should some rcfile 'Inspect' entries be
invalid. By delaying any malloc/strdup until after the
entries are completely validated we will prevent that.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-01 21:38:44 +10:00
Jim Warner
11b87c73ed top: ensure collapsed children cpu reported accurately
Parent tasks with collapsed children should have their
cpu reflect any unseen tasks only under the following:

1) When built without TREE_VCPUOFF having been defined

2) Exclusively when 'Show_FOREST' display mode was set

3) And only under the current window when in alternate
display mode (except if TREE_VWINALL has been defined)

So, this commit just ensures these objectives are met.

Reference(s):
. issue that began odyssey
https://gitlab.com/procps-ng/procps/issues/99
. original cpu implementation
commit 7c7903e50d

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-01 21:38:44 +10:00