Commit Graph

396 Commits

Author SHA1 Message Date
Jim Warner
fad0c62076 top: extend multi-byte support to 'Inspection' feature
The previous commit implemented multi-byte support for
the basic top user interaction and display provisions.
This commit completes multi-byte support by addressing
that 'Inspect Other Output' feature (the 'Y' command).

Few people probably exploit this very powerful feature
which allows the perusing of any file or piped output.
And even if nobody uses 'Y', someone will stumble over
it on the help screen and try it out. Assuming top was
not built with INSP_OFFDEMO defined, they'll end up on
the screen our translators have faithfully translated.

Without this patch, such a screen would display with a
bunch of 'unprintable' characters which will then show
in the standard (less-like) way as: '^A', '<C3>', etc.
In other words, those poor screens will be a big mess!

[ this program can even display an executable binary ]
[ while at that same time supporting Find/Find Next. ]
[ imagine, a file with no guarantee of real strings! ]
[ just try a Find using less with such binary files. ]

With this commit, the translated 'Y' demo screens will
now be properly shown, providing no invalid multi-byte
characters have been detected. Should that be the case
then they'll be displayed in that less-like way above.

And, if users go on to fully exploit this 'Y' command,
there is a good chance that a file or pipe might yield
output in a utf-8 multi-byte form. Should that be true
such output will thus be handled appropriately by top.

[ in many respects, this change was more challenging ]
[ than the basic support within the previous commit. ]
[ story of my life: least used = most effort needed. ]

Many thanks to our procps-ng translators which enabled
a proper test of these changed 'Y' command provisions:
. Vietnamese: Trần Ngọc Quân
. Polish: Jakub Bogusz
. German: Mario Blättermann
. French: Frédéric Marchal, Stéphane Aulery

[ and my sincerest apologies too, for my negligence! ]

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-01 22:19:58 +11:00
Jim Warner
7ef38420a4 top: refactored for correct multi-byte string handling
When this project first began implementing translation
support nearly 6 years ago, we overcame many 'gettext'
obstacles and limitations.  And, of course, there were
not any actual translations at the time so our testing
was quite limited plus, in many cases, only simulated.

None of that, however, can justify or excuse the total
lack of attention to top's approach to NLS, especially
since some actual translations have existed for years.

When the issue referenced below was raised, I suffered
immediate feelings of anxiety, doubt and pending doom.
This was mostly because top strives to avoid line wrap
at all costs and that did not bode well for multi-byte
translated strings, using several bytes per character.

I was also concerned over possible performance impact,
assuming it was even possible to properly handle utf8.

But, after wrestling with the problem for several days
those initial feelings have now been replaced by guilt
over any trouble I initially caused those translators.

One can only imagine how frustrating it must have been
after the translation effort to then see top display a
misaligned column header and fields management page or
truncated screens like those of help or color mapping.
------------------------------------------------------

Ok, with that off my chest let's review these changes,
now that top properly handles UTF8 multi-byte strings.

. Performance - virtually all of this newly added cost
for multi-byte support is incurred during interactions
with the user. So, performance is not really an issue.

The one occasion when performance is impacted is found
during 'summary_show()' processing, due to an addition
of one new call to 'utf8_delta()' in 'show_special()'.

. Extra Wide Characters - I have not yet and may never
figure out a way to support languages like zh_CN where
the characters can be wider than most other languages.

. Translated User Name - at some future point we could
implement translation of user names. But as the author
of the issue acknowledged such names are non-standard.
Thus task display still incurs no new multi-byte costs
beyond those already incurred in that escape.c module.

For raising the issue I extend my sincerest thanks to:
Göran Uddeborg

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-01 22:19:58 +11:00
Jim Warner
01fb8d5a78 top: correct a minor instance of wrong NLS macro usage
The 'N_fmt' and 'N_txt' macros are interchangeable and
just highlight the 2 str types found in Norm_nlstable.

The change in this patch (strictly cosmetic) was found
during the coding for what will be the next 2 commits.
It has not been squashed into either of those so as to
not muddy up the waters for what was a major refactor.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-01 22:19:58 +11:00
Jim Warner
a2ceb95e2a top: protect against the anomalous 'Mem' graph display
Until this patch, top falsely assumed that there would
always be some (small) amount of physical memory after
subtracting 'used' and 'available' from the total. But
as the issue referenced below attests, a sum of 'used'
and 'available' might exceed that total memory amount.

I'm not sure if this is a problem with our calculation
of the 'used' amount, a flaw in the kernel 'available'
algorithms or some other reason I cannot even imagine.

Anyway, this patch protects against such a contingency
through the following single line addition of new code
. if (pct_used + pct_misc > 100.0 || pct_misc < 0) ...

The check for less than zero is not actually necessary
as long as the source numbers remain unsigned. However
should they ever become signed, we'll have protection.

[ Most of the changes in this commit simply separate ]
[ a variable's definition from its associated logic. ]

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-08-19 20:55:46 +10:00
Jim Warner
e3c729adfa top: address a Debian wishlist NLS man page suggestion
Reference(s):
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=865689

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-08-19 20:55:46 +10:00
Jan Rybar
d9c4b6b011 top: refresh interval accepts non-locale decimal value
For the past 3 years top has fully honored that locale
LC_NUMERIC setting which impacts his refresh interval.
For the past nearly 5 years top has saved that refresh
value in a locale independent form in his config file.

With this commit we'll intentionally break top so that
a comma or period will be accepted for the radix point
regardless of what that LC_NUMERIC may have suggested.

The current locale LC_NUMERIC will, however, determine
how the delay interval is displayed in the 'd' prompt.

[ This position is better than the approach employed ]
[ by those coreutils 'sleep' and 'timeout' programs. ]
[ Both claim to permit floating point arguments. But ]
[ neither one will accept the comma separator should ]
[ the locale be a country that in fact uses a comma. ]

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

Prototyped by: Jan Rybar <jrybar@redhat.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-08-14 22:13:28 +10:00
Jim Warner
ac76e4db2c top: fixing command line parsing errors is now a habit
Ok, I admit it. I'm now tired of cleaning up after me.

This is the 3rd related tweak after that '-1' argument
was originally introduced. And with this patch we will
once again properly honor the '-o' and '-u|U' switches
without a need to be followed by an additional switch.

[ one can follow my unfortunate trail of alterations ]
[ beginning with my most recent fix referenced below ]

Reference(s):
commit 4b44aebd80

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-07-04 20:29:26 +10:00
Jim Warner
0998225651 top: ensure necessary proc_t support if '-U' filtering
While the effective user id would always be present in
each proc_t, thus supporting 'u' filtering, other user
ids would only be present if /proc/$$/status was read.

This commit just puts the 'master' branch top on a par
with the 'newlib' branch when user filtering with 'U'.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-07-04 20:29:25 +10:00
Jim Warner
4b44aebd80 top: correct functioning of the '-p' command line args
With the introduction of a new '1' command line toggle
I have gone and broken a provision of the '-p' command
line switch (pids monitoring). Multiple pids could not
be specified through the use of comma delimited lists.

Thus, this commit simply corrects that newly added bug
which was born in the 'adjustment' commit shown below.

Reference(s):
. adjustment to '-1' implementation
commit 909b37d755

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-06-04 21:28:39 +10:00
Jim Warner
c409f5a433 top: address the argument parsing quirk involving '-h'
There exists the possibility that a 'putp' call can be
issued before the 'setupterm' invocation has occurred,
as is reflected in a bugzilla report referenced below.

Strangely, such a SEGV isn't always triggered as logic
would suggest it ought to be. I experienced a fault in
these environments with the associated curses version:
. archlinux, procps-ng 3.3.12, ncurses 6.0.20170429
. fedora-25, procps-ng 3.3.10, ncurses 6.0.20160709
. opensuse-42.2, procps-ng 3.3.9, ncurses 5.9.20140201
. gentoo, procps-ng 3.3.12, ncurses 6.0.20150808
. slackw-14.2, procps-ng 3.3.12, ncurses 6.0.20160910

Whereas under these environments there was no problem:
. ubuntu-17.04, procps-ng 3.3.12, ncurses 6.0.20160625
. debian-test, procps-ng 3.3.12, ncurses 6.0.20161126
. mageia-5.1, procps-ng 3.3.9, ncurses 5.9.20140323

[ as an aside, the expected result in the bug report ]
[ is incorrect and should mention the '1' parameter. ]

[ however, until release 3.3.13 when the '1' becomes ]
[ a valid switch, numbers are not detected when used ]
[ with any switch which doesn't require an argument. ]

[ you're welcome to treat that as a separate bugglet ]

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-05-22 21:34:38 +10:00
Jim Warner
1422c219ac top: now includes that NUMA node field display support
[ this patch has been adapted from the newlib branch ]

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-05-22 21:34:32 +10:00
Jim Warner
f6f859c8f3 top: correct man page alphabetical order for -E switch
Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-05-22 21:34:32 +10:00
Jim Warner
56d79b9d13 top: provide more accurate cpu usage stats for startup
The top program already incorporated a modest delay at
startup so that some minimal process cpu history could
be established. However, Summary Area system level cpu
statistic history reflected usage since boot. As such,
unchanging % values would be shown with every restart.

This commit just adopts the same approach used in task
%CPU history for the Summary Area statistics. In other
words, it introduces a 'priming read' at startup as is
found in the newlib implementation for the <stat> API.

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-29 22:07:44 +11:00
Jim Warner
909b37d755 top: make command line switch parsing even more robust
This program has always tried to maintain an extermely
robust command line parsing procedure, far more robust
that what's available with the getopt stuff. But, with
the introduction of our first numeric switch it should
have been made even more robust than, in fact, it was.

This commit will now accomplish such a desirable goal.

Reference(s):
. added '1' command line switch
commit 89db82d143

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-29 22:07:44 +11:00
Jim Warner
90ac0dabf5 top: just update all of the copyright dates in sources
Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Jim Warner
fc5f5a93ba top: by default, show cmd line vs. cmd name at startup
All of top's display was designed to fit into an 80x24
terminal. This includes the help screens plus both the
Summary and Task Areas, assuming no saved config file.

With release 3.3.10, the startup defaults were changed
assuming ./configure --disable-modern-top wasn't used.
This was done in the hope of introducing some users to
unknown capabilities such as colors, forest view, etc.

The purpose of this commit is to coax a few more users
into possibly exploring another capability: scrolling.
We do so by tweaking the default startup display so as
to show full command lines. Now, when things no longer
fit in 80x24, horizontal scrolling might be exploited.

[ of course, this can be reversed with the -c switch ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Jim Warner
89db82d143 top: provide -1 command line switch as 'Cpu(s)' toggle
If built without ./configure --disable-modern-top, the
program displays each cpu individually providing there
is sufficient vertical screen real estate. For massive
SMP environments this will necessitate use of a config
file where the cpu summary toggle ('1') could be saved
via the 'W' command. But, an rcfile may not be viable.

So this commit introduces a '1' command line switch to
emulate exactly the effects of the interactive toggle.

And since it is our first numeric switch some existing
parsing logic had to be changed slightly. Such changes
are, in truth, an improvement. For example, instead of
seeing "inappropriate '2'" with ./top -2 we'll now see
the vastly more appropriate error "unknown option '2'.

References(s):
https://gitlab.com/procps-ng/procps/issues/55

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Jim Warner
fb48b5d9fb top: provide -E command line switch for memory scaling
In their 3.2.7 version of top, Redhat introduced an -M
switch to automatically scale Summary Area memory data
to avoid truncation (and the resulting '+' indicator).

The procps-ng top does not employ suffixes with memory
data nor does it allow for different scaling with each
separate value. Rather, scaling appears at line start.

If built without ./configure --disable-modern-top, the
Summary Area memory will be scaled at GiB which should
lessen chance of truncation. Otherwise KiB was used to
reflect such memory, increasing the truncation chance.

And while 'W' can be used to preserve some appropriate
scaling value, there are arguments against such rcfile
approaches as cited in the issue and bug report below.

So this commit will bump the Summary Area memory scale
factor from KiB to MiB when using --disable-modern-top
as a concession to that Redhat bug report noted below.

And it also introduces a new command line switch which
can force any desired scaling regardless of the rcfile
or which ./configure option might have been specified.

[ for top's help text we'll show 'E' as if it were a ]
[ switch without arguments in order to keep the help ]
[ text displayable without wrap in an 80x24 terminal ]

[ the man page, however, will show all k-e arguments ]

Reference(s):
https://gitlab.com/procps-ng/procps/issues/53
https://bugzilla.redhat.com/show_bug.cgi?id=1034466

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Jim Warner
fe6e03d8a9 top: show fewer decimal places for memory (by default)
After much reflection I've come to the conclusion that
displaying 3 decimal places (usually) when memory data
had been scaled is no longer optimal with today's ever
increasing amounts. And given that not all task memory
fields are the same widths, inconsistencies can easily
arise as illustrated and discussed in the issue below.

Instead of unilaterally reducing the number of decimal
places, this commit will sneak in such a change via an
existing configure option that was very likely unused.

The former 'disable-wide-memory' option has now become
'enable-wide-memory', which can be used if the current
behavior (3 decimal places) is preferred. Without that
option, whenever memory is scaled beyond KiB, just one
decimal place will be shown in Summary and Task areas.

And Task area field width will no longer be changed by
this revised configure option. Instead, all such field
widths will now be fixed at the former maximum values.

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Jim Warner
ddcdba18b7 top: correct alphabetic ordering with some enumerators
Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Earnestly
af53e170b9 top: Add unobtrusive XDG support
By default the file HOME/.toprc will be prefered.  This ensures there
should be minimal breakage even if this file is later created by some
other means.  Otherwise we will follow the new behaviour described by
the XDG Base Directory Specification:

If the XDG_CONFIG_HOME environment variable is available we will attempt
to use this as XDG_CONFIG_HOME/procps/toprc otherwise we will fall-back
to HOME/.config/procps/toprc instead.

Signed-off-by: Earnestly <zibeon@gmail.com>
2017-01-17 23:47:40 +00:00
Jim Warner
398b83f40f top: make for consistent & enhanced cpu % calculations
That issue cited below prompted some changes under the
newlib branch to standardize the calculation involving
busy, idle, user & system accumulated plus delta tics.

This patch will bring our master branch version of top
into agreement with that newlib version which exploits
some of those newly added library extended provisions.

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-01-04 08:14:42 +11:00
Jim Warner
5c78e785ee top: accumulated misc tweaks to code/comments/man page
Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-12-07 21:50:52 +11:00
Jim Warner
c6407ef125 top: make that 'forest view' just a tad more efficient
It makes no sense to begin our tracked nested level at
'1' then later require a '1' to be subtracted from the
level as artwork and indentation is added for display.

By beginning such tracked levels at zero, we can avoid
the need to adjust it & use it directly in a snprintf.

[ this commit parallels a patch in our newlib branch ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-10-16 08:18:31 +11:00
Jim Warner
98ed114c26 top: just some minor tweaks to the man document (only)
This patch just parallels some adjustments/corrections
which were also implemented under the 'newlib' branch.

[ remaining differences between man documents relate ]
[ to old kernels with topic '2b. TASK and CPU State' ]
[ and a note in '4c. SORTING' for TTY + WCHAN fields ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-10-09 21:34:05 +11:00
Jim Warner
18b1a887b7 top: finally circumvent that minor libnuma memory leak
Still unhappy with a minor memory leak associated with
libnuma, I experimented with omitting the dlclose that
was issued at module's end. For some reason which will
remain a mystery, the valgrind leak then went bye-bye.

So this patch just omits one use of dlclose and relies
on whatever kernel magic is at work to free the memory
when each process ends. We kept, however, the original
code (now commented-out) to serve as a future caution.

There remains one potential (but unlikely) dlclose use
near the original dlopen. But there will be no leak as
that 'numa_node_of_cpu' will not yet have been called.
This seems to be the culprit that triggers such leaks.

None of this libnuma shit would likely have come close
to hitting our fan had the numa developers provided us
with 'new' and 'unref' functions like our newlib does.

[ this commit parallels a patch in our newlib branch ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-09-18 20:39:12 +10:00
Jim Warner
5313852596 top: avoid yet more overhead of accessing /proc/status
After discovering those terrible costs associated with
/proc/status vs. /proc/stat, the build_header function
changed to favor the latter for a field found in both.

Well, low-and-behold, this top program still used some
flags that needlessly caused 'status' to still be read
when 'statm' could have served. And, while top's needs
require conversion from pages to KiB, that's still far
less costly than reading that gosh darn 'status' file.

[ this patch parallels similar changes to newlib top ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-23 21:12:32 +10:00
Jim Warner
7df87ea7cf top: when setting library flags favor stat over status
Long ago, in a galaxy far away, top was convinced that
/proc/stat was to be favored over /proc/status if some
field could be satisfied with either. This was done to
avoid extra costs of 64-bit math for 32-bit platforms.

Well, its time to acknowledge the prevalence of 64-bit
platforms. And in such an environment there is a large
hidden cost currently if using status instead of stat.
In fact, that cost difference can be as high as 1400%.

So, this commit will coax top into favoring that least
costly route while also fixing an EU_TGD library flag.

[ this patch parallels similar changes to newlib top ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-23 21:12:32 +10:00
Jim Warner
b4fdb27a05 top: provide for expanded potential displayable fields
This commit provides for raising the total displayable
fields from its current 70 to 86. It also bumps the id
in an rcfile representing the version from 'i' to 'j'.

The increase in number of fields will make sharing the
rcfile with an older top, once it's saved, impossible.

These changes are being done via a #define rather than
hard coded so any such sharing will still be possible.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-01 20:11:11 +10:00
Jim Warner
63f8c16fa4 top: make compilation possible under netbsd-curses too
Whoa, I had never considered an alternative to ncurses
until the issue referenced below was raised. Thus, I'm
surprised to find that 'tparm' was the only impediment
to ultimately utilizing this alternate curses library.

And, while we could have substituted that non-standard
'tiparm' with only 2 arguments, we'll utilize the full
parms compliment in the spirit of that original patch.

Frankly, the task of developing an alternative library
to that ncurses implementation really boggles my mind.

Congratulations to rofl0r, whoever that masked man is.

Reference(s):
. issue raised
https://gitlab.com/procps-ng/procps/issues/38
. netbsd-curses home
https://github.com/sabotage-linux/netbsd-curses

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-17 08:52:50 +10:00
Jim Warner
eca9168617 misc: adapted others to that new proc_t 'cgname' field
This patch adapts the ps program to a newly add proc_t
field and provides for new support in that top program
along with his man document (ps was already ok there).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-06 21:33:17 +10:00
Jim Warner
c15aea9d08 top: eliminate 2 author sections from the man document
We'll follow Craig's lead and whack some author stuff.

[ and we'll honor the SEE ALSO guideline for periods ]
[ but essentially ignore all the other busybody crap ]
[ which, to be honest, we pretty much follow already ]

[ actually, if you're told to follow a certain style ]
[ in program examples, you've gone way past busybody ]
[ crap and have entered the realm of anal retentive! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-06 21:33:17 +10:00
Jim Warner
5e33325f9a top: improved that #define PRETENDNOCAP implementation
This development (only) define can be used to turn top
into a simple text program, disabling termcap effects.
But input (at screen bottom) suffers from a line wrap.

So, this commit just makes the input prompt processing
a little more effective by adding one leading newline.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-06 21:33:17 +10:00
Jim Warner
29079d35e5 top: accommodate the loss of that OOMEM_ENABLE #define
Now that the conditional OOMEM_ENABLE has been removed
and all users exposed to those 'out of memory' fields,
it's about time we added them to the top man document.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
10503c03d4 top: make more responsive when toggling cpu off/online
Using the <STAT> api under the newlib branch, that top
program is very responsive to changes in the number of
on-line cpus. However under the master branch this top
program is very responsive only to losses of some cpu.

When a cpu is brought back on-line potential delays of
60 seconds could be encountered. That delay was simply
an attempt to reduce costs and reflected the erroneous
assumption that adding a cpu required physical effort.

So without redesigning the cpu refresh code to emulate
that of newlib, this commit just reduces the potential
delay to 3 seconds (the same that is used for memory).

[ As an aside, if one wants to have their confidence ]
[ in that htop program badly shaken, try taking some ]
[ cpus off-line & on-line again while it is running. ]

[ Poor ol' htop just continues to report results for ]
[ whatever were the cpus when started. Nice feature, ]
[ but I wonder where those phantom results are from. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
ac8f49e79e top: miscellaneous accumulated tweaks of code/comments
This commit just tries to parallel that newlib branch.
It contains the following changes, which were prompted
by the newlib coverity analysis which Craig initiated:

. comment typo predicting 'String not null terminated'
. eliminate 'Logically dead code' from insp_make_row()

Some tweaks, unrelated to coverity, are also included:

. use more modern (recommended) approach for time call

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
5e26512980 top: extend 'zero suppression' scope to several fields
This commit just tries to parallel the implementations
in the newlib branch. The config file Rc.zero_suppress
will be extended to include both out-of-memory fields.

And while we're at it, we'll also extend zero suppress
to that NI (nice value) field, which already should've
had it. Plus we trade those namespaces custom suppress
logic for our now slightly enhanced make_num function.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
5892540819 top: man page now includes resident memory enhancement
Since support already exists in the newlib branch this
represents an equivalent master branch implementation,
and this commit message is shared with 2 more patches.

Beginning with linux-4.5, the following new fields are
being added under that /proc/<pid>/status pseudo file:
 . RssAnon - size of resident anonymous memory
 . RssFile - size of resident file mappings
 . RssShmem - size of resident shared memory

p.s. Locked resident memory support was also added but
isn't directly related to the kernel 4.5 enhancements.

p.p.s. Archlinux, Debian-stretch and Fedora-23 already
are currently using a 4.5 linux kernel (as of 6/2/16).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
6306050a65 top: exploit new linux-4.5 resident memory enhancement
Since support already exists in the newlib branch this
represents an equivalent master branch implementation,
and this commit message is shared with 2 more patches.

Beginning with linux-4.5, the following new fields are
being added under that /proc/<pid>/status pseudo file:
 . RssAnon - size of resident anonymous memory
 . RssFile - size of resident file mappings
 . RssShmem - size of resident shared memory

p.s. Locked resident memory support was also added but
isn't directly related to the kernel 4.5 enhancements.

p.p.s. Archlinux, Debian-stretch and Fedora-23 already
are currently using a 4.5 linux kernel (as of 6/2/16).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
dad56cc954 top: minimal necessary corrections to the man document
After experimenting with those 4.5 kernel enhancements
to /proc/<pid>/status, that newly added overview topic
'Memory Types' was found to be in need of some tweaks.

In addition, the 'DATA' description wasn't quite broad
enough since explicit private file mappings impact it.

( lastly, for the record, the 2nd commit referred to )
( below contained an incorrect reference that should )
( have been the original issue 21 commit. instead it )
( showed an invalid SHA-1 hash. i believe i have now )
( identified a flaw in my workflow that produced it. )

Reference(s):
. original patch responding to issue #21
commit e4bbd3ca1a
. subsequent patch with invalid commit ref
commit 5dcbcd00fe

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-14 21:04:20 +10:00
Jim Warner
5dcbcd00fe top: add additional memory information to the man page
In response to Issue #21, the commit referred to below
provided some much needed improvements and corrections
to topic `3a. DESCRIPTIONS of Fields' in the man page.
However, it assumed a reader possessed much background
knowledge that may not, in truth, actually be present.

So without, hopefully, insulting anyone's intelligence
this patch offers an expanded discussion of some terms
and concepts within a separate section under OVERVIEW.

[ plus it affords an opportunity to incorporate that ]
[ extremely useful table from Florent Bruneau's post ]

Reference(s):
commit f2a08cf16794ec6085bdecbaf8f7c2887cd4e87f
https://techtalk.intersec.com/2013/07/memory-part-1-memory-types/

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-03-23 22:25:59 +11:00
Jim Warner
e4bbd3ca1a top: improve/correct several memory fields in man page
Due to quirks in kernel memory management plus limited
information available from /proc/<pid>/status & statm,
some of the top resident memory fields were capable of
exceeding available physical memory. So this commit is
a bit of a band-aid until the kernel has been changed.

Such a change appears to be on the horizon in the form
of three new fields to be added to /proc/<pid>/status.
While not preventing 'resident' memory from apparently
exceeding physical memory, the new fields will help to
clarify any such contingency, if/when we exploit them.

Reference(s):
. original post by Samuel Thibault
https://gitlab.com/procps-ng/procps/issues/21
. informative memory analysis
https://techtalk.intersec.com/2013/07/memory-part-1-memory-types/
https://techtalk.intersec.com/2013/07/memory-part-2-understanding-process-memory/
. kernel changes to /proc/<pid>/status
commit 8cee852ec53fb530f10ccabf1596734209ae336b
commit eca56ff906bdd0239485e8b47154a6e73dd9a2f3

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-03-15 21:25:33 +11:00
Jim Warner
717d73f1dd top: tweaks to vertical scroll management & 'i' toggle
The commit referenced below claims to disable vertical
scrolling when idle tasks weren't being shown. However
it really addresses only a point in time when that 'i'
toggle is keyed. Left untouched were the up/down keys.

So this commit will simply finish the job of disabling
vertical scrolling whenever tasks which have used some
CPU are the only ones which are currently being shown.

Reference(s):
commit c07f6c5e6d

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-03-12 14:50:57 +11:00
Craig Small
da715e3ca0 Replace %Lu with standard %llu
Multiple scanf()s use the GNU-permitted %Lu. This is not supported in
other libraries and isn't to the POSIX specification. The L modifier
is only used for floats in POSIX.

Replacing %Lu with %llu is the same for GNU libc (scanf(3) says as much)
but means other libraries will work fine.

Closes: #19

References:
 http://pubs.opengroup.org/onlinepubs/009695399/functions/fscanf.html
2016-03-03 21:43:52 +11:00
Jim Warner
94e4749be3 top: extend '=' key to include active 'locate' request
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>
2015-10-28 21:01:49 +11:00
Jim Warner
489d23a132 top: ATEOJ_RPTHSH prints hash table entries less often
We'll following the newlib <pids> approach to hashing:

. a 'PIDs at max depth:' portion of that UNREF_RPTHASH
enabled #define is now published only when the maximum
depth of hash table entry chains exceed depths of one.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-28 21:01:28 +11:00
Jim Warner
e1cd74eec9 top: do not co-mingle strings/numbers under namespaces
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>
2015-10-28 21:01:23 +11:00
Jim Warner
c7201d52eb top: miscellaneous accumulated tweaks to code/comments
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 ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-28 21:01:16 +11:00
Jim Warner
b1f7b2a509 top: update the man document reporting bugs suggestion
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-28 21:00:21 +11:00
Jim Warner
3da298c1d6 top: fix unlikely edge case wherein all fields are off
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>
2015-08-06 21:56:27 +10:00
Jim Warner
8226ca9838 top: avoid an unnecessary conversion for 'USED' column
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'.

Reference(s):
commit 709785e20b

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-08-06 21:56:02 +10:00
Jim Warner
9ba65bad8e top: miscellaneous accumulated tweaks to code/comments
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>
2015-08-06 21:52:11 +10:00
Jim Warner
9cc6ed10c8 top: eliminate 'user' from the inspection view headers
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>
2015-08-06 21:50:49 +10:00
Jim Warner
c07f6c5e6d top: improve vertical scroll management for 'i' toggle
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>
2015-07-21 21:23:44 +10:00
Jim Warner
88fe45ef68 top: sacrifice a redundant procps_linux_version() call
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>
2015-06-21 08:05:59 +10:00
Craig Small
56d9d5e7e7 library: Change linux version
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.
2015-06-19 21:00:46 +10:00
Jim Warner
3600f652e8 documentation: fix man pages due to refactor for wchan
This patch will bring three of our man pages into line
with the recent refactor of the libprocps wchan logic.

[ and also eliminates more damn eol whitespace which ]
[ snuck in our repo with the commit referenced below ]

Reference(s):
http://www.freelists.org/post/procps/WCHAN,11
commit cf4788c28d

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-19 19:09:21 +10:00
Jim Warner
93666da62c top: adapt to a simplified library interface for wchan
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>
2015-06-19 19:09:20 +10:00
Jim Warner
932f54b19d top: correct an alphabetic field error in man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-19 19:09:20 +10:00
Craig Small
505f257a8c library: remove procps_version functions
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
2015-06-18 22:37:24 +10:00
Jim Warner
d8aee1a809 top: update man document to support the LXC containers
[ in addition to the primary 'lxc' business, i found ]
[ numerous apostrophes used instead of that back-tic ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-14 15:36:06 +10:00
Jim Warner
2ba7aa8b7d top: add support exploiting new library LXC containers
Reference(s):
https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1424253
https://bugs.launchpad.net/ubuntu/+source/procps/+bug/1424253

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-14 15:36:06 +10:00
Filipe Brandenburger
c1c73c0d00 build-sys: merge automake subdirs into toplevel
This will be required for subdir-objects, otherwise automake will have
problems with more than one Makefile.am having rules to build the same
files.

Tested that it builds and both `make check` and `make distcheck` work.

Tested `make install` and compared the tree with the one installed
before this commit, both installed the binaries to the same locations.
The binaries are also in the same location in the build tree (for
instance, ps/pscommand is still there.)

Checked the binaries for the correct libraries linked into them. Binary
sizes matched before and after this change.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2015-05-01 23:19:31 -07:00
Filipe Brandenburger
90cc5460aa build-sys: add $(top_srcdir) to include search dir
This is required for out-of-tree build to work, since many source files
include e.g. proc/*.h which is not under the include/ directory.

Tested that `make distcheck` starts working after this patch.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2015-05-01 17:09:55 -07:00
Tobias Stoeckmann
c7abb6a6ed top: correct a small typo in manual page
Reference(s)
http://www.freelists.org/post/procps/PATCH-typo-in-top1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-04-07 20:46:15 +10:00
Jim Warner
e107f5d63b top: miscellaneous accumulated changes to program code
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>
2015-04-07 20:46:15 +10:00
Jim Warner
8bcdd2145d top: miscellaneous accumulated changes to man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-04-07 20:46:15 +10:00
Jim Warner
da06b8fa59 top: tweak forest view protections for forking anomaly
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>
2014-10-29 17:00:03 +01:00
Jim Warner
ce70017eb1 top: provide some protection against forking anomalies
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=1153642
http://www.freelists.org/post/procps/Bug-in-the-forrest-view,6

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-10-27 17:18:47 +01:00
Jim Warner
b0767bd391 top: ensure previously saved rcfile honored completely
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=762928
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=762947
. new startup defaults
commit 8ef6cd91fc

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-09-29 08:22:13 +10:00
Jim Warner
8adf4acc03 top: final tweak to recent changes for new graph modes
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-08-11 16:39:51 +02:00
Jim Warner
e92b692932 top: swat a potential buglet affecting new graph modes
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>
2014-08-08 22:14:21 +02:00
Fredrik Fornwall
dfe1f7d104 top: replace <values.h> with <limits.h> plus <float.h>
This fixes a compilation problem on Android which lacks values.h.

Reference(s):
https://gitorious.org/procps/procps/merge_requests/26

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-08-08 22:14:21 +02:00
Jim Warner
5380ef9022 top: adapt global memory support to new library format
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-31 15:10:42 +02:00
Jaromir Capik
cbba7ad7a7 top: exclude reclaimable slabs from used 2014-07-22 14:07:45 +02:00
Jim Warner
c437faf8d3 library: evolve MenAvailable algorithm on older kernel
Let's not report zero for kb_main_available when older
kernels don't have MemAvailable. Instead, if we simply
duplicate the 'free' amount we can avoid all ancillary
problems, such as those involving top's graphing mode.

Reference(s):
http://www.freelists.org/post/procps/kb-main-available-etc,3

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-21 16:17:52 +02:00
Jim Warner
7391699b07 top: correct one grammatical error in the man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-18 20:49:58 +02:00
Jim Warner
d310a18fc2 top: exploit new kb_main_available, make Jaromir happy
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>
2014-07-18 20:49:57 +02:00
Jim Warner
9500dc198c top: trade Page_size for that newly exposed page_bytes
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>
2014-07-18 20:49:57 +02:00
Jaromir Capik
6dbe8fd18e docs: top.1 minor fix
RES - memory task has used -> is using
2014-07-17 13:08:29 +02:00
Jim Warner
6cd8691720 top: fix potential 'nan', should a system have no Swap
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>
2014-07-07 18:43:52 +02:00
Jim Warner
1dd0c4d07f top: as with ps, distinguish between 'T' and 't' state
Wow, even the linux/Documentation/filesystems/proc.txt
document doesn't provide us with that level of detail.

Thank you, Jaromir, for your additional clarification!

Reference(s):
commit 411d218793

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-07 18:43:52 +02:00
Jim Warner
a7741055f1 top: add another translation hint for graphs alignment
This should be the last of this kind of crap. I'll get
to work on some means to no longer burden a translator
with lengths requirements. Ideally each word should be
allowed to stand alone and the minimum/maximum lengths
handled programmatically when our ol' top is executed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-07 18:43:52 +02:00
Jim Warner
206570e8c4 top: with new startup defaults, tweak the man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-07 18:43:52 +02:00
Jim Warner
c75586f523 top: eliminated unreferenced macros & an error message
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-07 18:43:52 +02:00
Jim Warner
8ef6cd91fc top: retire old stale startup defaults in favor of new
For over a decade top has used a startup configuration
mimicking the original redhat top. This decision dates
back to when the forked Sourceforge version was trying
to win over users in battles with that ancient kludge.

Will anybody deny that those defaults are coyote ugly?

Well, it is time that top presented a more modern look
at startup, providing that no saved rcfile exists. But
just in case some distro prefers that old, comfortable
look, there's the '--disable-modern-top' build option.

[ Pssst. With the widened memory fields it turns out ]
[ the 'Mem' default window had become almost useless ]
[ on an 80x24 terminal since %CPU & COMMAND were out ]
[ of view. So some other defaults were tweaked a bit ]
[ whether or not --disable-modern-top was specified. ]

Reference(s)
http://www.freelists.org/post/procps/tops-graph-mode-saga-continues,3

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-01 21:30:46 +10:00
Jim Warner
2199af404a top: maximize recent locale aware numeric enhancements
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 f7b84f45c7
http://www.freelists.org/post/procps/topwatch-floating-point-input,2

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-01 21:30:45 +10:00
Jim Warner
96c330e3b3 top: afford each window its own cpu/memory graph modes
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>
2014-06-28 23:46:40 +10:00
Jim Warner
805532ac32 top: fix translation hint to preserve graphs alignment
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-28 23:46:40 +10:00
Jim Warner
f7b84f45c7 top: tweak argument parsing for some locale situations
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-input
http://www.freelists.org/post/procps/topwatch-floating-point-input,1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-25 13:58:31 +02:00
Jim Warner
cec1976511 top: let's not pretend top can catch SIGKILL & SIGSTOP
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>
2014-06-25 13:58:30 +02:00
Jim Warner
db6381ae04 top: scale length for new graphs to a terminal's width
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>
2014-06-24 20:38:30 +10:00
Jim Warner
41ab7f005e top: with new bar graphs, make 'b' toggle unrestricted
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>
2014-06-24 20:38:30 +10:00
Jim Warner
d8a8822b5f top: reflect current graph modes state in man document
This patch just beefs up the man documentation for the
new graphs modes while also reflecting the most recent
program changes, prompted by the feedback shown below.

Reference(s):
http://www.freelists.org/post/procps/latest-top-enhancements,1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-24 20:35:20 +10:00
Jim Warner
b8614adcb5 top: make '#define GRAPHS_ALIGN' an immutable solution
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>
2014-06-24 20:35:20 +10:00
Jim Warner
f33d49c6cf top: shorten some lines by changing a few declarations
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>
2014-06-24 20:35:20 +10:00
Jim Warner
77376e5c67 top: add graphs modes for cpu and memory, man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-22 21:39:55 +10:00
Jim Warner
1d171ec741 top: add graphs modes for cpu and memory, program code
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>
2014-06-22 21:39:55 +10:00
Jim Warner
318919094d top: rearrange Mem & Swap lines and standardize 'used'
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>
2014-06-22 21:39:55 +10:00
Jim Warner
23ebb9f44d top: tweak hotplugged response and frame refresh logic
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>
2014-05-28 06:53:19 +10:00