The top program is carefully organized into sections
and those sections are carefully placed so as to avoid
the need for prototypes. *
Additionally, names of functions are carefully chosen
to maintain alphabetical order within each section.
The names of most 'helper' functions, which are always
placed immediately above the calling functions, often
only met the spirit of the alphabetical law, not the
actual letter of that law.
This commit alters the names of such helper functions
so as to mainatin strict ascii alphabetical order
within each section.
* the single exception to prototypes is find_string,
which calls the task_show function, and would have
prompted a massive reorganization.
Signed-off-by: Jim Warner <james.warner@comcast.net>
The recently added logic dealing with "missing" tics
is mutually exclusive with logic associated with a
define called CPU_ZEROTICS.
This commit expands the use of that define to exclude
such Nehalem logic as appropriate.
It also extends programmer notes in top.h to include
an attribution for initiating the topic of potential
Nehalem type % CPU distortions, acknowledging:
Jaromir Capik, <jcapik@redhat.com>
References
commit ce1410a51a
commit 9e7dd43ab7
commit a9041a5526
The mem and swap lines have enough room to show eight significant
digits, so switch to showing MB when >=100MB, not >=10MB.
The extra detail is valuable; it should not be elided.
Signed-off-by: James Cloos <cloos@jhcloos.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
Due to a poorly constructed temporary fprintf
used during development, an earlier commit went
a little too far in its computations. The net
result was the code looked nice but actually
accomplished nothing.
It is the /proc/stat line 1 (summary line)
whose tics must be used in establishing the
threshold boundary. And that calculation
need be performed just once per frame.
This commit ensures one threshold calculation
per delay interval no matter how many cpus
are ultimately displayed.
It also corrects scalability by factoring in
the total number of online processors.
Reference:
commit 9e7dd43ab7
Along the way to width override support (-w switch),
this top began clearing the screen far more often
than his predecessor. In fact, it happend with each
user keystroke.
This commit dramatically reduces those occurances.
The screen will now be cleared only when an actual
SIGWINCH is received.
Thanks for identifying this flaw belongs to:
James Cloos, cloos@jhcloos.com
References:
http://www.freelists.org/post/procps/Merge-request
Blame: c2dcbef482
Author: Jim Warner <james.warner@comcast.net>
Date: Thu May 26 11:33:32 2011 +0200
subject: added output width/height override support to top, + misc
The original approach to potential % CPU distortion due
to Nehalem type cores being turned off completely when
idle worked ok until the user typed something.
At that point, elapsed tics would no longer equal the
calculated value producing an undesirable 100% idle
condition until the next update or <Enter/Space> key.
This commit employs actual elapsed tics in determining
whether a cpu should be considered idle and thus makes
top's individual cpu display immune to user keystrokes.
This patch provides for cpu cores which can be turned
off completely when idle (Nehalem, etc.) thus registering
very few or no tics since the last update cycle.
When CPU_ZEROTICS is not defined (the default), any
displayed cpu with less than a certain amount of total
tics will show as 100% idle. That amount is tempered
by the delay interval and total number of cpus.
This commit also satisfies the Debian 'top_nohz' patch
(11/24/09) in a slightly more efficient manner. That
patch concerned kernels built with CONFIG_NO_HZ.
Reference:
http://www.freelists.org/post/procps/CStates-handling-new-switch,4
Prior to this patch, top was able to handle any hotplugged
cpus *added* to the system in two distinct ways.
1) Newly added cpus would be detected by sysinfo_refresh
calling the library's cpuinfo function, which occurs
at most every 5 minutes.
2) The user could force a refresh using either the
<Enter> or <Space> keys.
Unfortunately, the *loss* of a cpu would produce an early
exit due to a /proc/stat read failure. Such a failure
can be produced in the following way:
sudo echo 0 > /sys/devices/system/cpu/cpu??/online
This commit allows top to tolerate the loss of cpus.
It also provides for more efficient CPU_t management,
especially for massively parallel cpu environments.
Note: Changes to the cpu compliment can produce a single
cycle distortion of cpu percentages. Such distortion is
most visible when each cpu is being displayed. It can
be eliminated with a forced refresh via <Enter>/<Space>.
With the introduction of the 'locate string' provisions,
the precedent for calling tertiary helper functions from
secondary do_key helper functions was established.
This commit simply migrates some additional keys out of
the do_key function itself and into the more generalized
key table.
Normally, when the chosen sort column is displayed via the
'x' command toggle the entire column is highlighted. And
while this version of top substantially reduced the cost
of such highlighting, a small pathlength increase remained.
The USE_X_COLHDR define was an experimental alternative which
eliminated all recurring runtime costs for such emphasis by
highlighting the column header, not the entire column.
The previous implementation required colors to be turned on
(the 'z' toggle) for such highlighting to be visible. This
commit extends column header emphasis to include monochrome
displays as well.
Reference:
http://www.freelists.org/post/procps/post-nls-merge,6
Since its inception, this top has improperly handled an
empty HOME environment variable. Under those conditions
a path to the root directory would have been constructed.
That caused no real harm upon startup since the display
defaults would have been employed. However, except for
root, it would have been impossible to save the rc file.
This commit keeps the promise made in the documentation.
This commit addresses a long standing buglet (debian #441166) which
surfaces when the display mode is switched between task and threads.
An extra procps refresh is now forced upon such a transition which
parallels the approach used at startup for the exact same reason.
Reference: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=441166
Some of the latest changes to Makefile.am files are missing.
This patch restores the LOCALEDIR variable, among others,
and dispenses with the include directives in the ps/ and top/
subdirectories since they're no longer needed.
This commit corrects some outdated programmer comments.
Additionally, certain nls justifications might become
increasingly obscure with the passage of time so some
previous nls commit text has been added as comments.
This patch represents the final resting place for miscellaneous
changes not otherwise encountered or for which the resolution
was incomplete or incorrect.
The gettext documentation leads one to believe that
a printf type call is necessary for gettext string
extraction. That turns out to be misleading and
all one really needs is the runtime gettext string
address resolution.
Thus, we can avoid our original snprintf/strdup
overhead and establish an address for the original
or translated string just by issuing the _() macro.
We create these nls string tables so that:
1) top avoids the overhead of repeated
runtime function calls
2) we can control the order of top's
strings in the .pot file
3) translator comments don't obscure
and clutter the main program
Until this patch, top had used some strings with
special escape sequences to produce colors, normal
text, bold text, etc. They took the following form,
explained by an excerpt from program comments:
...
Our special formatting consists of:
"some text <_delimiter_> some more text <_delimiter_>...\n"
Where <_delimiter_> is a single byte in the range of:
\001 through \010 (in decimalizee, 1 - 8)
and is used to select an 'attribute' from a capabilities table
which is then applied to the *preceding* substring.
...
Unfortunately, these nonprinting values revealed
insurmountable inconsistencies in both the front-end
and back-end translation tools.
The xgettext (extraction) program would take those
special escapes, convert them and then output raw
binary values. Thus the .pot file would contain
lots of unprintable stuff making it unreadable.
If the following was added to po/Makevars, most of
those special escapes would be preserved in their
escape notation:
XGETTEXT_OPTIONS = ... --escape
But two escapes were converted from octal notation
and there was no way to prevent it:
\007 --> \a
\010 --> \b
After a pass through the msginit program, most of
the escapes were reconverted to raw binary values
making translation impossible. There was no
"--escape" option for the back-end programs like
there was for xgettext.
But the real killer was the escape \004, also used
in some of top's special strings. This value would
be silently accepted by xgettext, only to produce
the following fatal error in back-end programs like
msginit, msgfmt and msgen:
.pot:2647: context separator <EOT> within string
To quote from one of the references below:
"Would you create a suite of tools that silently
allow what is destined to become a fatal error
to pass unnoticed?"
So the bottom line was: top's special strings, in
use for the past nine years, had to be redesigned.
References:
http://www.freelists.org/post/procps/procpsng-nls-support,11http://www.freelists.org/post/procps/procpsng-nls-support,14
summary of changes:
. adopted relative paths to 'include' and 'proc'
dirs so that stand alone compiles are made
easier and no one need guess their locations
. corrected several names for enums and macro
usage reflecting fmt vs. txt
. expanded all octal escape sequences to a full
3 digits since one already required 3 digits
. finalized translator hints (for now)
programming note:
as an aside, by not including an argument for
the gettext --add-comments, any preceeding c
style comment will be propagated to the .pot
file, if the gettext macro isn't empty.
/* Need Not Say 'TRANSLATORS' ...
snprintf(buf, sizeof(buf), "%s", _( // unseen
/* Translator Hint: ...
snprintf(buf, sizeof(buf), "%s", _("" // seen