procps/top/top.h

701 lines
32 KiB
C
Raw Normal View History

2011-03-31 16:45:12 +05:30
/* top.h - Header file: show Linux processes */
/*
* Copyright (c) 2002-2015, by: James C. Warner
2011-03-31 16:45:12 +05:30
* All rights reserved. 8921 Hilloway Road
* Eden Prairie, Minnesota 55347 USA
*
* This file may be used subject to the terms and conditions of the
* GNU Library General Public License Version 2, or any later version
* at your option, as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*/
/* For contributions to this program, the author wishes to thank:
* Craig Small, <csmall@small.dropbear.id.au>
* Albert D. Cahalan, <albert@users.sf.net>
* Sami Kerola, <kerolasa@iki.fi>
2011-03-31 16:45:12 +05:30
*/
2002-05-30 09:14:46 +05:30
#ifndef _Itop
#define _Itop
2002-02-02 04:17:29 +05:30
#include <proc/pids.h>
#include <proc/readstat.h>
#include "../proc/readproc.h"
/* Defines represented in configure.ac ----------------------------- */
//#define BOOST_PERCNT /* enable extra precision for two % fields */
//#define NOBOOST_MEMS /* disable extra precision for mem fields */
//#define NUMA_DISABLE /* disable summary area NUMA/Nodes display */
//#define ORIG_TOPDEFS /* with no rcfile retain original defaults */
//#define SIGNALS_LESS /* favor reduced signal load over response */
2011-03-31 16:45:12 +05:30
/* Development/Debugging defines ----------------------------------- */
//#define ATEOJ_RPTSTD /* report on misc stuff, at end-of-job */
2011-03-31 16:45:12 +05:30
//#define CASEUP_HEXES /* show any hex values in upper case */
//#define CASEUP_SUFIX /* show time/mem/cnts suffix in upper case */
//#define EQUCOLHDRYES /* yes, do equalize column header lengths */
//#define INSP_JUSTNOT /* don't smooth unprintable right margins */
top: add a flexible 'Inspect' capability This commit introduces an extremely powerful, flexible brand new capability. Now, users can pause the normal iterative display and inspect the contents of any file or output from any script, command, or even pipelines. It's invoked via the 'Y' interactive command which, in turn, is supported with simple user supplied additions as new entries in the top personal configuration file. A separate new 'Inspect' window supports scrolling and searching, similar to the main top display. Except it extends existing 'L'/'&' (locate/locate-next) commands so that an out-of-view match automatically adjusts the horizontal position bringing such data into view. And it provides for multiple successive same line matches. Also, the basic 'more/less' navigation keys are active in this new 'Inspect' window, to ease user transition. There are no program changes required when entries are added to or deleted from the rcfile. And there are no known limits to the complexity of a script, command or pipeline, other than the unidirectional nature imposed by the 'popen' function call which top cannot violate. Since it's impossible to predict exactly what contents will be generated, top treats all output as raw binary data. Any control characters display in '^C' notation while all other unprintable characters show as '<AB>'. The biggest problem encountered was with the find/next capability since that strstr guy was really diminished given the possibility that numerous 'strings' could be encountered *within* many of top's raw, binary 'rows'. Oh, and another problem was in maintaining the perfect left & right text justification of this commit message along with all of the commit summaries. Some of those summaries (like this very one) are of course, slightly shorter, to make room for the 'man document' addition. Enjoy! Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-11-25 10:30:05 +05:30
//#define INSP_OFFDEMO /* disable demo screens, issue msg instead */
//#define INSP_SAVEBUF /* preserve 'Insp_buf' contents in a file */
//#define INSP_SLIDE_1 /* when scrolling left/right don't move 8 */
//#define MEMGRAPH_OLD /* don't use 'available' when graphing Mem */
top: provide for discontinuous (not active) NUMA nodes Apparently there are occasions when NUMA nodes may not always be contiguous. Under such conditions nodes that were not used would still occupy precious Summary Area space showing 100% idle, under the '2' command toggle. With this commit top will no longer display numa nodes that have no associated cpu when the '2' toggle is on. But just in case we wish to return to former behavior, a new #define called OFF_NUMASKIP has been introduced. And as an aside, a recent refactor mentioned below set the stage for this patch to be 'self-tuning'. In other words, if an inactive/non-displayed node should become active (if even possible), then top will begin showing such a node automatically with the next screen update. Unfortunately, all inactive nodes now 'suppressed' are still accessible via the '3' command. Those nodes will just be displayed as empty (no associated cpus shown). This is not really a top problem but more of a libnuma and/or user deficiency. The library lacks the means to validate a node id and the user then input a node that was not even shown under a '2' toggle Summary display. ( too bad libnuma does not offer an 'is_node_active' ) ( type function so top could warn a user when such a ) ( discontinuous node was requested using his '3' cmd ) ( sure, top could achieve this objective himself but ) ( that would require making yet another array global ) ( which i'm just not in the mood to do - besides, we ) ( have already made enough concessions to libnuma.so ) Lastly, an existing #define (PRETEND_NUMA) was changed to 'disable' node #1 so as to simulate a discontinuous node. This allows testing of the '2' and '3' commands. Reference(s): http://www.spinics.net/lists/util-linux-ng/msg08671.html . set stage for self tuning commit f12c0d5c6e84f9409ac3a73c066841a8ff5aab0b Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-01-05 11:30:00 +05:30
//#define OFF_NUMASKIP /* do NOT skip numa nodes if discontinuous */
top: enable screen contents preservation at end-of-job The title of this commit is actually quite misleading. Were it more accurate, it would at least mention a tty emulator's scrollback buffer, which was the cumulation of a long pursuit to reduce the SIGWINCH overhead when a window manager carelessly floods an application with that signal *while* a user is still resizing a window! Disabling and enabling that scrollback buffer resulted in the final top display replaced with original screen contents, a phenomenon acknowledged at the time but it also represented a user interface change which has now produced the first request for return to old behavior. After the SIGWINCH dust settled, another problem arose regarding behaviors under the 'screen' window manager. In response, top was refactored a bit to avoid display corruption. That was before discovering 'screen' could duplicate the scrollback buffer behavior top expected. As it turns out, the 'screen' refactoring had probably made scrollback buffer manipulation unnecessary. Still one could argue that a window should not be allowed to scroll while a constantly updating program was active. The solution represented in this commit returns former behavior at program end (retaining top's last screen). And if we ever wish to disable scrollback buffers, the associated logic was retained but made conditional. It is not reflected in configure.ac but might be someday. Lastly, this commit corrects cursor positioning when a ^C is issued under 'Fields Management' at any terminal that didn't have a scrollback buffer (i.e. a console). Reference(s): https://bugzilla.redhat.com/show_bug.cgi?id=977561 http://www.freelists.org/post/procps/top-library-miscellaneous-tweaks,1 . screen program refactor commit 0fe393ff270922cd4f6edbcaabba006314e73a37 . scrollback buffer disabled commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d . sigwinch management defines commit adca737758e5afc7be344a736953931894cbc19f commit 4f33b6b8c56464b4044deb29a3bb0e32622e108f Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-06-28 10:30:00 +05:30
//#define OFF_SCROLLBK /* disable tty emulators scrollback buffer */
top: restore the former behavior after stderr redirect When top originally responded to the potential libnuma stderr write, the library was consistently called with each refresh cycle. That, in turn, guaranteed that any warning message would be seen at program end by virtue of: 1) having been issued before the 2nd refresh cycle and; 2) benefiting from inherited /dev/null buffering. A later efficiency refactor meant the numa library may not always be called with every refresh cycle. Rather, it was only called if top was in one of two numa views (the '2' or '3' toggles). That, in turn, resulted in a loss of any warning message at program end unless numa mode had been preserved in the rcfile. In other words, if top was started normally then a single cycle stderr redirect would have long passed by the time the '2' or '3' toggle was activated. The warning message actually was spewed but quickly lost to the full screen refresh which follows all keyboard interactions with the user. This commit simply moves the restoration of our stderr redirect to program end (instead of that first display refresh). Now, any libnuma stderr warning message will appear as the concluding output line upon quitting top without regard to when any numa mode view was invoked. And since this technique might be useful in some other context (as an example of how to 'buffer' stderr) it's been generalized with its own #define. But to maximize its usefulness, the original redirect should be issued much earlier in pgm startup than top has chosen to do. Reference(s): . original libnuma stderr response (msg seen) commit 35dc6dcc49cc9cf8cff4300cb03a38dbe44c05db . numa refractoring for efficiency (msg lost) commit f12c0d5c6e84f9409ac3a73c066841a8ff5aab0b Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-02-20 11:30:00 +05:30
//#define OFF_STDERROR /* disable our stderr buffering (redirect) */
2011-03-31 16:45:12 +05:30
//#define OFF_STDIOLBF /* disable our own stdout _IOFBF override */
//#define PRETEND8CPUS /* pretend we're smp with 8 ticsers (sic) */
2011-03-31 16:45:12 +05:30
//#define PRETENDNOCAP /* use a terminal without essential caps */
top: provide for discontinuous (not active) NUMA nodes Apparently there are occasions when NUMA nodes may not always be contiguous. Under such conditions nodes that were not used would still occupy precious Summary Area space showing 100% idle, under the '2' command toggle. With this commit top will no longer display numa nodes that have no associated cpu when the '2' toggle is on. But just in case we wish to return to former behavior, a new #define called OFF_NUMASKIP has been introduced. And as an aside, a recent refactor mentioned below set the stage for this patch to be 'self-tuning'. In other words, if an inactive/non-displayed node should become active (if even possible), then top will begin showing such a node automatically with the next screen update. Unfortunately, all inactive nodes now 'suppressed' are still accessible via the '3' command. Those nodes will just be displayed as empty (no associated cpus shown). This is not really a top problem but more of a libnuma and/or user deficiency. The library lacks the means to validate a node id and the user then input a node that was not even shown under a '2' toggle Summary display. ( too bad libnuma does not offer an 'is_node_active' ) ( type function so top could warn a user when such a ) ( discontinuous node was requested using his '3' cmd ) ( sure, top could achieve this objective himself but ) ( that would require making yet another array global ) ( which i'm just not in the mood to do - besides, we ) ( have already made enough concessions to libnuma.so ) Lastly, an existing #define (PRETEND_NUMA) was changed to 'disable' node #1 so as to simulate a discontinuous node. This allows testing of the '2' and '3' commands. Reference(s): http://www.spinics.net/lists/util-linux-ng/msg08671.html . set stage for self tuning commit f12c0d5c6e84f9409ac3a73c066841a8ff5aab0b Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-01-05 11:30:00 +05:30
//#define PRETEND_NUMA /* pretend 4 (or 3 w/o OFF_NUMASKIP) Nodes */
//#define QUICK_GRAPHS /* use fast algorithm, accept +2% distort */
//#define RCFILE_NOERR /* rcfile errs silently default, vs. fatal */
//#define RECALL_FIXED /* don't reorder saved strings if recalled */
2011-03-31 16:45:12 +05:30
//#define RMAN_IGNORED /* don't consider auto right margin glitch */
//#define SCROLLVAR_NO /* disable intra-column horizontal scroll */
//#define STRINGCASENO /* case insenstive compare/locate versions */
//#define TERMIOS_ONLY /* just limp along with native input only */
2011-08-30 17:35:45 +05:30
//#define TREE_NORESET /* sort keys do NOT force forest view OFF */
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 ce70017eb1927be51f73cbe0a0b4babcc502607e Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-10-28 10:30:00 +05:30
//#define TREE_SCANALL /* rescan array w/ forest view, avoid sort */
//#define USE_X_COLHDR /* emphasize header vs. whole col, for 'x' */
//#define VALIDATE_NLS /* validate the integrity of all nls tbls */
/*###### Notes, etc. ###################################################*/
/* The following convention is used to identify those areas where
adaptations for hotplugging are to be found ...
*** hotplug_acclimated ***
( hopefully libproc will also be supportive of our efforts ) */
/* For introducing inaugural cgroup support, thanks to:
Jan Gorig <jgorig@redhat.com> - April, 2011 */
2004-07-07 01:35:30 +05:30
/* For the motivation and path to nls support, thanks to:
Sami Kerola, <kerolasa@iki.fi> - December, 2011 */
/* There are still some short strings that may yet be candidates
for nls support inclusion. They're identified with:
// nls_maybe */
2002-02-02 04:17:29 +05:30
/* For the impetus and NUMA/Node prototype design, thanks to:
Lance Shelton <LShelton@fusionio.com> - April, 2013 */
// pretend as if #define _GNU_SOURCE
char *strcasestr(const char *haystack, const char *needle);
#ifdef STRINGCASENO
#define STRSTR strcasestr
#define STRCMP strcasecmp
2011-03-31 16:45:12 +05:30
#else
#define STRSTR strstr
#define STRCMP strcmp
2011-03-31 16:45:12 +05:30
#endif
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
/*###### Some Miscellaneous constants ##################################*/
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
/* The default delay twix updates */
#ifdef ORIG_TOPDEFS
2011-03-31 16:45:12 +05:30
#define DEF_DELAY 3.0
#else
#define DEF_DELAY 1.5
#endif
2002-06-19 05:15:30 +05:30
/* Length of time a message is displayed and the duration
of a 'priming' wait during library startup (in microseconds) */
#define MSG_USLEEP 1250000
#define LIB_USLEEP 150000
2004-07-07 01:35:30 +05:30
2011-03-31 16:45:12 +05:30
/* Specific process id monitoring support (command line only) */
#define MONPIDMAX 20
2002-06-19 05:15:30 +05:30
/* Output override minimums (the -w switch and/or env vars) */
#define W_MIN_COL 3
#define W_MIN_ROW 3
2011-03-31 16:45:12 +05:30
/* Miscellaneous buffers with liberal values and some other defines
-- mostly just to pinpoint source code usage/dependancies */
#define SCREENMAX 512
/* the above might seem pretty stingy, until you consider that with every
field displayed the column header would be approximately 250 bytes
-- so SCREENMAX provides for all fields plus a 250+ byte command line */
2011-03-31 16:45:12 +05:30
#define CAPBUFSIZ 32
#define CLRBUFSIZ 64
#define PFLAGSSIZ 80
#define SMLBUFSIZ 128
2011-03-31 16:45:12 +05:30
#define MEDBUFSIZ 256
#define LRGBUFSIZ 512
2011-03-31 16:45:12 +05:30
#define OURPATHSZ 1024
#define BIGBUFSIZ 2048
/* in addition to the actual display data, our row might have to accommodate
many termcap/color transitions - these definitions ensure we have room */
#define ROWMINSIZ ( SCREENMAX + 4 * (CAPBUFSIZ + CLRBUFSIZ) )
#define ROWMAXSIZ ( SCREENMAX + 16 * (CAPBUFSIZ + CLRBUFSIZ) )
top: add a flexible 'Inspect' capability This commit introduces an extremely powerful, flexible brand new capability. Now, users can pause the normal iterative display and inspect the contents of any file or output from any script, command, or even pipelines. It's invoked via the 'Y' interactive command which, in turn, is supported with simple user supplied additions as new entries in the top personal configuration file. A separate new 'Inspect' window supports scrolling and searching, similar to the main top display. Except it extends existing 'L'/'&' (locate/locate-next) commands so that an out-of-view match automatically adjusts the horizontal position bringing such data into view. And it provides for multiple successive same line matches. Also, the basic 'more/less' navigation keys are active in this new 'Inspect' window, to ease user transition. There are no program changes required when entries are added to or deleted from the rcfile. And there are no known limits to the complexity of a script, command or pipeline, other than the unidirectional nature imposed by the 'popen' function call which top cannot violate. Since it's impossible to predict exactly what contents will be generated, top treats all output as raw binary data. Any control characters display in '^C' notation while all other unprintable characters show as '<AB>'. The biggest problem encountered was with the find/next capability since that strstr guy was really diminished given the possibility that numerous 'strings' could be encountered *within* many of top's raw, binary 'rows'. Oh, and another problem was in maintaining the perfect left & right text justification of this commit message along with all of the commit summaries. Some of those summaries (like this very one) are of course, slightly shorter, to make room for the 'man document' addition. Enjoy! Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-11-25 10:30:05 +05:30
// minimum size guarantee for dynamically acquired 'readfile' buffer
#define READMINSZ 2048
// size of preallocated search string buffers, same as ioline()
#define FNDBUFSIZ MEDBUFSIZ
2011-03-31 16:45:12 +05:30
// space between task fields/columns
#define COLPADSTR " "
#define COLPADSIZ ( sizeof(COLPADSTR) - 1 )
// continuation ch when field/column truncated
#define COLPLUSCH '+'
2011-03-31 16:45:12 +05:30
// support for keyboard stuff (cursor motion keystrokes, mostly)
#define kbd_ESC '\033'
#define kbd_SPACE ' '
#define kbd_ENTER '\n'
#define kbd_UP 129
#define kbd_DOWN 130
#define kbd_LEFT 131
#define kbd_RIGHT 132
#define kbd_PGUP 133
#define kbd_PGDN 134
#define kbd_HOME 135
#define kbd_END 136
#define kbd_BKSP 137
#define kbd_INS 138
#define kbd_DEL 139
#define kbd_CtrlO '\017'
2011-03-31 16:45:12 +05:30
/* Special value in Pseudo_row to force an additional procs refresh
-- used at startup and for task/thread mode transitions */
#define PROC_XTRA -1
2011-03-31 16:45:12 +05:30
/* ##### Enum's and Typedef's ############################################ */
/* Flags for each possible field (and then some) --
these MUST be kept in sync with the FLD_t Fieldstab[] array !! */
enum pflag {
EU_PID = 0, EU_PPD,
EU_UED, EU_UEN, EU_URD, EU_URN, EU_USD, EU_USN,
EU_GID, EU_GRP, EU_PGD, EU_TTY, EU_TPG, EU_SID,
EU_PRI, EU_NCE, EU_THD,
EU_CPN, EU_CPU, EU_TME, EU_TM2,
EU_MEM, EU_VRT, EU_SWP, EU_RES, EU_COD, EU_DAT, EU_SHR,
EU_FL1, EU_FL2, EU_DRT,
EU_STA, EU_CMD, EU_WCH, EU_FLG, EU_CGR,
EU_SGD, EU_SGN, EU_TGD,
EU_OOA, EU_OOM,
EU_ENV,
EU_FV1, EU_FV2,
EU_USE,
EU_NS1, EU_NS2, EU_NS3, EU_NS4, EU_NS5, EU_NS6,
EU_LXC, EU_CGN,
#ifdef USE_X_COLHDR
// not really pflags, used with tbl indexing
EU_MAXPFLGS
#else
2011-03-31 16:45:12 +05:30
// not really pflags, used with tbl indexing & col highlighting
EU_MAXPFLGS, EU_XON, EU_XOF
#endif
2011-03-31 16:45:12 +05:30
};
2002-06-19 05:15:30 +05:30
top: provide the means to adjust scaled process memory This commit is an unrequested outgrowth of the earlier change dealing with summary area memory field scaling. That user selectable scaling provision is now extended to include 6 (at present) task oriented memory fields. The new companion 'e' (lower case) interactive command has been added and, like the 'E' command, it can cycle each of the currently displayed memory columns between KiB through TiB. There are, however, some differences. Where '+' indicates summary area truncation at a given radix, task memory fields are automatically scaled for their column. Thus, not all rows use the same scaling. And, while summary area field widths were not changed, the task memory columns were widened in order to offer more meaningful data when the radix was increased. The precision is automatically increased in step with each radix: MiB displays 2 decimal places, GiB 3 and TiB 4. To compliment that additional precision, both the %CPU and %MEM fields were widened by 1 column and now offer precision up to 3 decimal places. But, unique to %CPU, widening could already have occurred due to the number of processors in some massively parallel boxes. At any rate, total extra width for both memory and percentage fields could amount to twenty (precious) columns more. So for both the memory and % fields the original width (along with loss of precision) can be restored via new compiler conditionals which this commit also provides. p.s. and it will be rcfile preserved for any restarts! (now that we know a '.' + 2 spaces is squeezed to one) (everything's perfectly justified, but it's just luck) Reference(s): http://www.freelists.org/post/procps/top-regression-reports Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-12-14 11:30:00 +05:30
/* The scaling 'target' used with memory fields */
enum scale_enum {
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-18 10:30:00 +05:30
SK_Kb, SK_Mb, SK_Gb, SK_Tb, SK_Pb, SK_Eb
2011-03-31 16:45:12 +05:30
};
2002-05-30 09:14:46 +05:30
/* Used to manipulate (and document) the Frames_signal states */
enum resize_states {
BREAK_off = 0, BREAK_kbd, BREAK_sig
};
2011-03-31 16:45:12 +05:30
/* This typedef just ensures consistent 'process flags' handling */
2011-08-30 17:35:45 +05:30
typedef unsigned char FLG_t;
2002-09-13 17:12:44 +05:30
2011-03-31 16:45:12 +05:30
/* These typedefs attempt to ensure consistent 'ticks' handling */
2002-12-05 04:18:30 +05:30
typedef unsigned long long TIC_t;
typedef long long SIC_t;
2002-05-30 09:14:46 +05:30
2002-09-13 17:12:44 +05:30
2011-03-31 16:45:12 +05:30
/* /////////////////////////////////////////////////////////////// */
/* Special Section: multiple windows/field groups --------------- */
/* ( kind of a header within a header: constants, types & macros ) */
#define CAPTABMAX 9 /* max entries in each win's caps table */
#define GROUPSMAX 4 /* the max number of simultaneous windows */
#define WINNAMSIZ 4 /* size of RCW_t winname buf (incl '\0') */
#define GRPNAMSIZ WINNAMSIZ+2 /* window's name + number as in: '#:...' */
/* The Persistent 'Mode' flags!
These are preserved in the rc file, as a single integer and the
letter shown is the corresponding 'command' toggle */
// 'View_' flags affect the summary (minimum), taken from 'Curwin'
#define View_CPUSUM 0x008000 // '1' - show combined cpu stats (vs. each)
#define View_CPUNOD 0x400000 // '2' - show numa node cpu stats ('3' also)
2011-03-31 16:45:12 +05:30
#define View_LOADAV 0x004000 // 'l' - display load avg and uptime summary
#define View_STATES 0x002000 // 't' - display task/cpu(s) states summary
#define View_MEMORY 0x001000 // 'm' - display memory summary
#define View_NOBOLD 0x000008 // 'B' - disable 'bold' attribute globally
#define View_SCROLL 0x080000 // 'C' - enable coordinates msg w/ scrolling
// 'Show_' & 'Qsrt_' flags are for task display in a visible window
#define Show_COLORS 0x000800 // 'z' - show in color (vs. mono)
#define Show_HIBOLD 0x000400 // 'b' - rows and/or cols bold (vs. reverse)
#define Show_HICOLS 0x000200 // 'x' - show sort column emphasized
2011-03-31 16:45:12 +05:30
#define Show_HIROWS 0x000100 // 'y' - show running tasks highlighted
#define Show_CMDLIN 0x000080 // 'c' - show cmdline vs. name
#define Show_CTIMES 0x000040 // 'S' - show times as cumulative
#define Show_IDLEPS 0x000020 // 'i' - show idle processes (all tasks)
#define Show_TASKON 0x000010 // '-' - tasks showable when Mode_altscr
2011-08-30 17:35:45 +05:30
#define Show_FOREST 0x000002 // 'V' - show cmd/cmdlines with ascii art
2011-03-31 16:45:12 +05:30
#define Qsrt_NORMAL 0x000004 // 'R' - reversed column sort (high to low)
#define Show_JRSTRS 0x040000 // 'j' - right justify "string" data cols
#define Show_JRNUMS 0x020000 // 'J' - right justify "numeric" data cols
2011-03-31 16:45:12 +05:30
// these flag(s) have no command as such - they're for internal use
#define INFINDS_xxx 0x010000 // build rows for find_string, not display
#define EQUWINS_xxx 0x000001 // rebalance all wins & tasks (off i,n,u/U)
#ifndef USE_X_COLHDR
#define NOHISEL_xxx 0x200000 // restrict Show_HICOLS for osel temporarily
#define NOHIFND_xxx 0x100000 // restrict Show_HICOLS for find temporarily
#endif
2011-03-31 16:45:12 +05:30
// Default flags if there's no rcfile to provide user customizations
#ifdef ORIG_TOPDEFS
2011-03-31 16:45:12 +05:30
#define DEF_WINFLGS ( View_LOADAV | View_STATES | View_CPUSUM | View_MEMORY \
| Show_HIBOLD | Show_HIROWS | Show_IDLEPS | Show_TASKON | Show_JRNUMS \
| Qsrt_NORMAL )
#define DEF_GRAPHS2 0, 0
#define DEF_SCALES2 SK_Kb, SK_Kb
#define ALT_WINFLGS DEF_WINFLGS
#define ALT_GRAPHS2 0, 0
#else
#define DEF_WINFLGS ( View_LOADAV | View_STATES | View_MEMORY \
| Show_COLORS | Show_FOREST | Show_HIROWS | Show_IDLEPS | Show_JRNUMS | Show_TASKON \
| Qsrt_NORMAL )
#define DEF_GRAPHS2 1, 2
#define DEF_SCALES2 SK_Gb, SK_Mb
#define ALT_WINFLGS (DEF_WINFLGS | Show_HIBOLD) & ~Show_FOREST
#define ALT_GRAPHS2 2, 0
#endif
2011-03-31 16:45:12 +05:30
/* These are used to direct wins_reflag */
enum reflag_enum {
Flags_TOG, Flags_SET, Flags_OFF
};
/* These are used to direct win_warn */
enum warn_enum {
Warn_ALT, Warn_VIZ
};
/* This type helps support both a window AND the rcfile */
2002-12-05 04:18:30 +05:30
typedef struct RCW_t { // the 'window' portion of an rcfile
int sortindx, // sort field (represented as procflag)
winflags, // 'view', 'show' and 'sort' mode flags
maxtasks, // user requested maximum, 0 equals all
graph_cpus, // 't' - View_STATES supplementary vals
graph_mems, // 'm' - View_MEMORY supplememtary vals
summclr, // a colors 'number' used for summ info
msgsclr, // " in msgs/pmts
headclr, // " in cols head
taskclr; // " in task rows
char winname [WINNAMSIZ], // name for the window, user changeable
fieldscur [PFLAGSSIZ]; // the fields for display & their order
2002-12-05 04:18:30 +05:30
} RCW_t;
2011-03-31 16:45:12 +05:30
/* This represents the complete rcfile */
typedef struct RCF_t {
char id; // rcfile version id
2002-12-05 04:18:30 +05:30
int mode_altscr; // 'A' - Alt display mode (multi task windows)
int mode_irixps; // 'I' - Irix vs. Solaris mode (SMP-only)
2011-03-31 16:45:12 +05:30
float delay_time; // 'd'/'s' - How long to sleep twixt updates
2002-12-05 04:18:30 +05:30
int win_index; // Curwin, as index
2011-03-31 16:45:12 +05:30
RCW_t win [GROUPSMAX]; // a 'WIN_t.rc' for each window
int fixed_widest; // 'X' - wider non-scalable col addition
int summ_mscale; // 'E' - scaling of summary memory values
top: provide the means to adjust scaled process memory This commit is an unrequested outgrowth of the earlier change dealing with summary area memory field scaling. That user selectable scaling provision is now extended to include 6 (at present) task oriented memory fields. The new companion 'e' (lower case) interactive command has been added and, like the 'E' command, it can cycle each of the currently displayed memory columns between KiB through TiB. There are, however, some differences. Where '+' indicates summary area truncation at a given radix, task memory fields are automatically scaled for their column. Thus, not all rows use the same scaling. And, while summary area field widths were not changed, the task memory columns were widened in order to offer more meaningful data when the radix was increased. The precision is automatically increased in step with each radix: MiB displays 2 decimal places, GiB 3 and TiB 4. To compliment that additional precision, both the %CPU and %MEM fields were widened by 1 column and now offer precision up to 3 decimal places. But, unique to %CPU, widening could already have occurred due to the number of processors in some massively parallel boxes. At any rate, total extra width for both memory and percentage fields could amount to twenty (precious) columns more. So for both the memory and % fields the original width (along with loss of precision) can be restored via new compiler conditionals which this commit also provides. p.s. and it will be rcfile preserved for any restarts! (now that we know a '.' + 2 spaces is squeezed to one) (everything's perfectly justified, but it's just luck) Reference(s): http://www.freelists.org/post/procps/top-regression-reports Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-12-14 11:30:00 +05:30
int task_mscale; // 'e' - scaling of process memory values
int zero_suppress; // '0' - suppress scaled zeros toggle
2002-12-05 04:18:30 +05:30
} RCF_t;
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/* This structure stores configurable information for each window.
By expending a little effort in its creation and user requested
maintenance, the only real additional per frame cost of having
2011-03-31 16:45:12 +05:30
windows is an extra sort -- but that's just on pointers! */
typedef struct WIN_t {
FLG_t pflgsall [PFLAGSSIZ], // all 'active/on' fieldscur, as enum
procflgs [PFLAGSSIZ]; // fieldscur subset, as enum
RCW_t rc; // stuff that gets saved in the rcfile
int winnum, // a window's number (array pos + 1)
winlines, // current task window's rows (volatile)
maxpflgs, // number of displayed procflgs ("on" in fieldscur)
2011-03-31 16:45:12 +05:30
totpflgs, // total of displayable procflgs in pflgsall array
begpflg, // scrolled beginning pos into pflgsall array
endpflg, // scrolled ending pos into pflgsall array
begtask, // scrolled beginning pos into Frame_maxtask
#ifndef SCROLLVAR_NO
varcolbeg, // scrolled position within variable width col
#endif
varcolsz, // max length of variable width column(s)
usrseluid, // validated uid for 'u/U' user selection
usrseltyp, // the basis for matching above uid
usrselflg, // flag denoting include/exclude matches
hdrcaplen; // column header xtra caps len, if any
2011-03-31 16:45:12 +05:30
char capclr_sum [CLRBUFSIZ], // terminfo strings built from
capclr_msg [CLRBUFSIZ], // RCW_t colors (& rebuilt too),
capclr_pmt [CLRBUFSIZ], // but NO recurring costs !
capclr_hdr [CLRBUFSIZ], // note: sum, msg and pmt strs
capclr_rowhigh [CLRBUFSIZ], // are only used when this
capclr_rownorm [CLRBUFSIZ], // window is the 'Curwin'!
cap_bold [CAPBUFSIZ], // support for View_NOBOLD toggle
grpname [GRPNAMSIZ], // window number:name, printable
#ifdef USE_X_COLHDR
columnhdr [ROWMINSIZ], // column headings for procflgs
#else
columnhdr [SCREENMAX], // column headings for procflgs
#endif
*captab [CAPTABMAX]; // captab needed by show_special()
struct osel_s *osel_1st; // other selection criteria anchor
int osel_tot; // total of other selection criteria
char *osel_prt; // other stuff printable as status line
char *findstr; // window's current/active search string
int findlen; // above's strlen, without call overhead
struct pids_stack **ppt; // this window's stacks ptr array
2011-03-31 16:45:12 +05:30
struct WIN_t *next, // next window in window stack
*prev; // prior window in window stack
} WIN_t;
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
// Used to test/manipulate the window flags
#define CHKw(q,f) (int)((q)->rc.winflags & (f))
#define TOGw(q,f) (q)->rc.winflags ^= (f)
#define SETw(q,f) (q)->rc.winflags |= (f)
#define OFFw(q,f) (q)->rc.winflags &= ~(f)
#define ALTCHKw (Rc.mode_altscr ? 1 : win_warn(Warn_ALT))
#define VIZISw(q) (!Rc.mode_altscr || CHKw(q,Show_TASKON))
#define VIZCHKw(q) (VIZISw(q)) ? 1 : win_warn(Warn_VIZ)
#define VIZTOGw(q,f) (VIZISw(q)) ? TOGw(q,(f)) : win_warn(Warn_VIZ)
2002-02-02 04:17:29 +05:30
2011-03-31 16:45:12 +05:30
// Used to test/manipulte fieldscur values
#define FLDon(c) ((c) |= 0x80)
2011-03-31 16:45:12 +05:30
#define FLDget(q,i) ((FLG_t)((q)->rc.fieldscur[i] & 0x7f) - FLD_OFFSET)
#define FLDtog(q,i) ((q)->rc.fieldscur[i] ^= 0x80)
#define FLDviz(q,i) ((q)->rc.fieldscur[i] & 0x80)
2011-08-30 17:35:45 +05:30
#define ENUviz(w,E) (NULL != memchr((w)->procflgs, E, (w)->maxpflgs))
#define ENUpos(w,E) ((int)((FLG_t*)memchr((w)->pflgsall, E, (w)->totpflgs) - (w)->pflgsall))
2011-08-30 17:35:45 +05:30
// Support for variable width columns (and potentially scrolling too)
#define VARcol(E) (-1 == Fieldstab[E].width)
#ifndef SCROLLVAR_NO
#ifdef USE_X_COLHDR
#define VARright(w) (1 == w->maxpflgs && VARcol(w->procflgs[0]))
#else
#define VARright(w) ((1 == w->maxpflgs && VARcol(w->procflgs[0])) || \
(3 == w->maxpflgs && EU_XON == w->procflgs[0] && VARcol(w->procflgs[1])))
#endif
#define VARleft(w) (w->varcolbeg && VARright(w))
#define SCROLLAMT 8
#endif
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/* Special Section: end ------------------------------------------ */
/* /////////////////////////////////////////////////////////////// */
2002-06-19 05:15:30 +05:30
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/*###### Some Miscellaneous Macro definitions ##########################*/
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/* Yield table size as 'int' */
#define MAXTBL(t) (int)(sizeof(t) / sizeof(t[0]))
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/* A null-terminating strncpy, assuming strlcpy is not available.
( and assuming callers don't need the string length returned ) */
#define STRLCPY(dst,src) { strncpy(dst, src, sizeof(dst)); dst[sizeof(dst) - 1] = '\0'; }
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
/* Used to clear all or part of our Pseudo_screen */
#define PSU_CLREOS(y) memset(&Pseudo_screen[ROWMAXSIZ*y], '\0', Pseudo_size-(ROWMAXSIZ*y))
2002-12-05 04:18:30 +05:30
2011-03-31 16:45:12 +05:30
/* Used as return arguments in *some* of the sort callbacks */
#define SORT_lt ( Frame_srtflg > 0 ? 1 : -1 )
#define SORT_gt ( Frame_srtflg > 0 ? -1 : 1 )
#define SORT_eq 0
/* Used to create *most* of the sort callback functions
note: some of the callbacks are NOT your father's callbacks, they're
highly optimized to save them ol' precious cycles! */
#define SCB_NAME(f) sort_EU_ ## f
2011-03-31 16:45:12 +05:30
#define SCB_NUM1(f,n) \
static int SCB_NAME(f) (const proc_t **P, const proc_t **Q) { \
if ( (*P)->n < (*Q)->n ) return SORT_lt; \
if ( (*P)->n > (*Q)->n ) return SORT_gt; \
return SORT_eq; }
#define SCB_NUM2(f,n1,n2) \
static int SCB_NAME(f) (const proc_t **P, const proc_t **Q) { \
if ( ((*P)->n1+(*P)->n2) < ((*Q)->n1+(*Q)->n2) ) return SORT_lt; \
if ( ((*P)->n1+(*P)->n2) > ((*Q)->n1+(*Q)->n2) ) return SORT_gt; \
return SORT_eq; }
2011-03-31 16:45:12 +05:30
#define SCB_NUMx(f,n) \
static int SCB_NAME(f) (const proc_t **P, const proc_t **Q) { \
return Frame_srtflg * ( (*Q)->n - (*P)->n ); }
#define SCB_STRS(f,s) \
static int SCB_NAME(f) (const proc_t **P, const proc_t **Q) { \
if (!(*P)->s || !(*Q)->s) return SORT_eq; \
return Frame_srtflg * STRCMP((*Q)->s, (*P)->s); }
enhanced libproc cgroup/cmdline support, exploited by top Library Changes . added PROC_EDITCMDLCVT flag . added an internal (static) fill_cmdline_cvt function: - reads and "escapes" /proc/#/cmdline - returns result as a single string in a single vector - callers are guaranteed a cmdline (no more NULL) . added vectorize_this_str function, exploited by fill_cgroup_cvt, fill_cmdline_cvt . generalized read_cmdline function as read_unvectored, now exploited by fill_cgroup_cvt, fill_cmdline_cvt, read_cmdline ( cgroup and cmdline no longer need be converted to string ) ( vectors before being transformed to final representation ) . fixed bug regarding skipped group numbers (when enabled) . escape_str made responsible for all single byte translation with distinction between control chars + other unprintable . added escaped_copy function for already escaped strings . reorganized parts of proc_t to restore formatting standards ( displacement changes shouldn't matter with new version # ) . former ZAP_SUSEONLY #define now OOMEM_ENABLE . added to library.map: escaped_copy; read_cmdline Top Program Changes . exploited the new PROC_EDITCMDLCVT provision . eliminated now obsolete #include "proc/escape.h" . changed the P_WCH display format if no kernel symbol table . fixed very old bug in lflgs for out-of-view sort fields . former ZAP_SUSEONLY #define now OOMEM_ENABLE Ps Program Changes . exploited the new PROC_EDITCMDLCVT provision . exploited the new escaped_copy function . consolidated pr_args and pr_comm into pr_argcom Signed-off-by: Jan Görig <jgorig@redhat.com>
2011-05-18 14:03:44 +05:30
#define SCB_STRV(f,b,v,s) \
static int SCB_NAME(f) (const proc_t **P, const proc_t **Q) { \
enhanced libproc cgroup/cmdline support, exploited by top Library Changes . added PROC_EDITCMDLCVT flag . added an internal (static) fill_cmdline_cvt function: - reads and "escapes" /proc/#/cmdline - returns result as a single string in a single vector - callers are guaranteed a cmdline (no more NULL) . added vectorize_this_str function, exploited by fill_cgroup_cvt, fill_cmdline_cvt . generalized read_cmdline function as read_unvectored, now exploited by fill_cgroup_cvt, fill_cmdline_cvt, read_cmdline ( cgroup and cmdline no longer need be converted to string ) ( vectors before being transformed to final representation ) . fixed bug regarding skipped group numbers (when enabled) . escape_str made responsible for all single byte translation with distinction between control chars + other unprintable . added escaped_copy function for already escaped strings . reorganized parts of proc_t to restore formatting standards ( displacement changes shouldn't matter with new version # ) . former ZAP_SUSEONLY #define now OOMEM_ENABLE . added to library.map: escaped_copy; read_cmdline Top Program Changes . exploited the new PROC_EDITCMDLCVT provision . eliminated now obsolete #include "proc/escape.h" . changed the P_WCH display format if no kernel symbol table . fixed very old bug in lflgs for out-of-view sort fields . former ZAP_SUSEONLY #define now OOMEM_ENABLE Ps Program Changes . exploited the new PROC_EDITCMDLCVT provision . exploited the new escaped_copy function . consolidated pr_args and pr_comm into pr_argcom Signed-off-by: Jan Görig <jgorig@redhat.com>
2011-05-18 14:03:44 +05:30
if (b) { \
if (!(*P)->v || !(*Q)->v) return SORT_eq; \
return Frame_srtflg * STRCMP((*Q)->v[0], (*P)->v[0]); } \
return Frame_srtflg * STRCMP((*Q)->s, (*P)->s); }
#define SCB_STRX(f,s) \
int strverscmp(const char *s1, const char *s2); \
static int SCB_NAME(f) (const proc_t **P, const proc_t **Q) { \
if (!(*P)->s || !(*Q)->s) return SORT_eq; \
return Frame_srtflg * strverscmp((*Q)->s, (*P)->s); }
2011-03-31 16:45:12 +05:30
/*
* The following three macros are used to 'inline' those portions of the
* display process involved in formatting, while protecting against any
2011-03-31 16:45:12 +05:30
* potential embedded 'millesecond delay' escape sequences.
*/
/** PUTT - Put to Tty (used in many places)
. for temporary, possibly interactive, 'replacement' output
. may contain ANY valid terminfo escape sequences
. need NOT represent an entire screen row */
#define PUTT(fmt,arg...) do { \
char _str[ROWMAXSIZ]; \
2011-03-31 16:45:12 +05:30
snprintf(_str, sizeof(_str), fmt, ## arg); \
putp(_str); \
} while (0)
/** PUFF - Put for Frame (used in only 3 places)
. for more permanent frame-oriented 'update' output
. may NOT contain cursor motion terminfo escapes
. assumed to represent a complete screen ROW
. subject to optimization, thus MAY be discarded */
#define PUFF(fmt,arg...) do { \
char _str[ROWMAXSIZ], *_eol; \
_eol = _str + snprintf(_str, sizeof(_str), fmt, ## arg); \
if (Batch) { \
while (*(--_eol) == ' '); *(++_eol) = '\0'; putp(_str); } \
2011-03-31 16:45:12 +05:30
else { \
char *_ptr = &Pseudo_screen[Pseudo_row * ROWMAXSIZ]; \
2011-03-31 16:45:12 +05:30
if (Pseudo_row + 1 < Screen_rows) ++Pseudo_row; \
if (!strcmp(_ptr, _str)) putp("\n"); \
else { \
strcpy(_ptr, _str); \
putp(_ptr); } } \
} while (0)
/** POOF - Pulled Out of Frame (used in only 1 place)
. for output that is/was sent directly to the terminal
but would otherwise have been counted as a Pseudo_row */
#define POOF(str,cap) do { \
putp(str); putp(cap); \
Pseudo_screen[Pseudo_row * ROWMAXSIZ] = '\0'; \
if (Pseudo_row + 1 < Screen_rows) ++Pseudo_row; \
} while (0)
2011-03-31 16:45:12 +05:30
/* Orderly end, with any sort of message - see fmtmk */
#define debug_END(s) { \
void error_exit (const char *); \
2011-03-31 16:45:12 +05:30
fputs(Cap_clr_scr, stdout); \
error_exit(s); \
}
/* A poor man's breakpoint, if he's too lazy to learn gdb */
#define its_YOUR_fault { *((char *)0) = '!'; }
/*###### Display Support *Data* ########################################*/
/*###### Some Display Support *Data* ###################################*/
/* ( see module top_nls.c for the nls translatable data ) */
2011-03-31 16:45:12 +05:30
/* Configuration files support */
#define SYS_RCFILESPEC "/etc/toprc"
#define RCF_EYECATCHER "Config File (Linux processes with windows)\n"
#define RCF_VERSION_ID 'i'
#define RCF_PLUS_H "\\]^_`abcdefghij"
2011-03-31 16:45:12 +05:30
/* The default fields displayed and their order, if nothing is
specified by the loser, oops user.
note: any *contiguous* ascii sequence can serve as fieldscur
characters as long as the initial value is coordinated
with that specified for FLD_OFFSET
( we're providing for up to 70 fields currently, )
( with just one escaped value, the '\' character ) */
2011-03-31 16:45:12 +05:30
#define FLD_OFFSET '%'
// seq_fields "%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghij"
#ifdef ORIG_TOPDEFS
#define DEF_FIELDS "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>&')*+,-./012568<>?ABCFGHIJKLMNOPQRSTUVWXYZ[" RCF_PLUS_H
#else
#define DEF_FIELDS "<22>&K<><4B><EFBFBD><EFBFBD><EFBFBD>@<40><><EFBFBD>56<35>F<EFBFBD>')*+,-./0128<>?ABCGHIJLMNOPQRSTUVWXYZ[" RCF_PLUS_H
#endif
2011-03-31 16:45:12 +05:30
/* Pre-configured windows/field groups */
#define JOB_FIELDS "<22><><EFBFBD><EFBFBD><EFBFBD>(<28><>Ļ<EFBFBD>@<<3C><>)*+,-./012568>?ABCFGHIJKLMNOPQRSTUVWXYZ[" RCF_PLUS_H
#define MEM_FIELDS "<22><><EFBFBD><<3C><><EFBFBD><EFBFBD><EFBFBD>MBN<42>D34<33><34>&'()*+,-./0125689FGHIJKLOPQRSTUVWXYZ[" RCF_PLUS_H
#define USR_FIELDS "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)+,-./1234568;<=>?@ABCFGHIJKLMNOPQRSTUVWXYZ[" RCF_PLUS_H
// old top fields ( 'a'-'z' ) in positions 0-25
// other suse old top fields ( '{|' ) in positions 26-27
#define CVT_FIELDS "%&*'(-0346789:;<=>?@ACDEFGML)+,./125BHIJKNOPQRSTUVWXYZ["
#define CVT_FLDMAX 28
2011-03-31 16:45:12 +05:30
/* The default values for the local config file */
2002-12-05 04:18:30 +05:30
#define DEF_RCFILE { \
RCF_VERSION_ID, 0, 1, DEF_DELAY, 0, { \
{ EU_CPU, DEF_WINFLGS, 0, DEF_GRAPHS2, \
2002-12-05 04:18:30 +05:30
COLOR_RED, COLOR_RED, COLOR_YELLOW, COLOR_RED, \
"Def", DEF_FIELDS }, \
{ EU_PID, ALT_WINFLGS, 0, ALT_GRAPHS2, \
2002-12-05 04:18:30 +05:30
COLOR_CYAN, COLOR_CYAN, COLOR_WHITE, COLOR_CYAN, \
"Job", JOB_FIELDS }, \
{ EU_MEM, ALT_WINFLGS, 0, ALT_GRAPHS2, \
2002-12-05 04:18:30 +05:30
COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLUE, COLOR_MAGENTA, \
"Mem", MEM_FIELDS }, \
{ EU_UEN, ALT_WINFLGS, 0, ALT_GRAPHS2, \
2002-12-05 04:18:30 +05:30
COLOR_YELLOW, COLOR_YELLOW, COLOR_GREEN, COLOR_YELLOW, \
"Usr", USR_FIELDS } \
}, 0, DEF_SCALES2, 0 }
2002-12-05 04:18:30 +05:30
2011-03-31 16:45:12 +05:30
/* Summary Lines specially formatted string(s) --
see 'show_special' for syntax details + other cautions. */
2002-06-19 05:15:30 +05:30
#define LOADAV_line "%s -%s\n"
#define LOADAV_line_alt "%s~6 -%s\n"
2002-06-19 05:15:30 +05:30
2002-11-29 04:39:48 +05:30
2002-11-29 21:31:04 +05:30
/*###### For Piece of mind #############################################*/
2002-11-29 04:39:48 +05:30
/* just sanity check(s)... */
#if defined(RECALL_FIXED) && defined(TERMIOS_ONLY)
# error 'RECALL_FIXED' conflicts with 'TERMIOS_ONLY'
#endif
#if defined(PRETEND_NUMA) && defined(NUMA_DISABLE)
# error 'PRETEND_NUMA' confilcts with 'NUMA_DISABLE'
#endif
top: provide for discontinuous (not active) NUMA nodes Apparently there are occasions when NUMA nodes may not always be contiguous. Under such conditions nodes that were not used would still occupy precious Summary Area space showing 100% idle, under the '2' command toggle. With this commit top will no longer display numa nodes that have no associated cpu when the '2' toggle is on. But just in case we wish to return to former behavior, a new #define called OFF_NUMASKIP has been introduced. And as an aside, a recent refactor mentioned below set the stage for this patch to be 'self-tuning'. In other words, if an inactive/non-displayed node should become active (if even possible), then top will begin showing such a node automatically with the next screen update. Unfortunately, all inactive nodes now 'suppressed' are still accessible via the '3' command. Those nodes will just be displayed as empty (no associated cpus shown). This is not really a top problem but more of a libnuma and/or user deficiency. The library lacks the means to validate a node id and the user then input a node that was not even shown under a '2' toggle Summary display. ( too bad libnuma does not offer an 'is_node_active' ) ( type function so top could warn a user when such a ) ( discontinuous node was requested using his '3' cmd ) ( sure, top could achieve this objective himself but ) ( that would require making yet another array global ) ( which i'm just not in the mood to do - besides, we ) ( have already made enough concessions to libnuma.so ) Lastly, an existing #define (PRETEND_NUMA) was changed to 'disable' node #1 so as to simulate a discontinuous node. This allows testing of the '2' and '3' commands. Reference(s): http://www.spinics.net/lists/util-linux-ng/msg08671.html . set stage for self tuning commit f12c0d5c6e84f9409ac3a73c066841a8ff5aab0b Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-01-05 11:30:00 +05:30
#if defined(OFF_NUMASKIP) && defined(NUMA_DISABLE)
# error 'OFF_NUMASKIP' confilcts with 'NUMA_DISABLE'
#endif
#if (LRGBUFSIZ < SCREENMAX)
# error 'LRGBUFSIZ' must NOT be less than 'SCREENMAX'
#endif
#if defined(TERMIOS_ONLY)
# warning 'TERMIOS_ONLY' disables input recall and makes man doc incorrect
#endif
#if defined(MEMGRAPH_OLD)
# warning 'MEMGRAPH_OLD' will make the man document Section 2c. misleading
#endif
2002-11-29 04:39:48 +05:30
2011-03-31 16:45:12 +05:30
/*###### Some Prototypes (ha!) #########################################*/
/* These 'prototypes' are here exclusively for documentation purposes. */
/* ( see the find_string function for the one true required protoype ) */
2011-03-31 16:45:12 +05:30
/*------ Tiny useful routine(s) ----------------------------------------*/
//atic const char *fmtmk (const char *fmts, ...);
//atic inline char *scat (char *dst, const char *src);
//atic const char *tg2 (int x, int y);
/*------ Exit/Interrput routines ---------------------------------------*/
//atic void at_eoj (void);
2011-03-31 16:45:12 +05:30
//atic void bye_bye (const char *str);
//atic void error_exit (const char *str);
//atic void sig_abexit (int sig);
2011-03-31 16:45:12 +05:30
//atic void sig_endpgm (int dont_care_sig);
//atic void sig_paused (int dont_care_sig);
//atic void sig_resize (int dont_care_sig);
/*------ Misc Color/Display support ------------------------------------*/
//atic void capsmk (WIN_t *q);
//atic void show_msg (const char *str);
//atic int show_pmt (const char *str);
//atic void show_special (int interact, const char *glob);
//atic void updt_scroll_msg (void);
top: add a flexible 'Inspect' capability This commit introduces an extremely powerful, flexible brand new capability. Now, users can pause the normal iterative display and inspect the contents of any file or output from any script, command, or even pipelines. It's invoked via the 'Y' interactive command which, in turn, is supported with simple user supplied additions as new entries in the top personal configuration file. A separate new 'Inspect' window supports scrolling and searching, similar to the main top display. Except it extends existing 'L'/'&' (locate/locate-next) commands so that an out-of-view match automatically adjusts the horizontal position bringing such data into view. And it provides for multiple successive same line matches. Also, the basic 'more/less' navigation keys are active in this new 'Inspect' window, to ease user transition. There are no program changes required when entries are added to or deleted from the rcfile. And there are no known limits to the complexity of a script, command or pipeline, other than the unidirectional nature imposed by the 'popen' function call which top cannot violate. Since it's impossible to predict exactly what contents will be generated, top treats all output as raw binary data. Any control characters display in '^C' notation while all other unprintable characters show as '<AB>'. The biggest problem encountered was with the find/next capability since that strstr guy was really diminished given the possibility that numerous 'strings' could be encountered *within* many of top's raw, binary 'rows'. Oh, and another problem was in maintaining the perfect left & right text justification of this commit message along with all of the commit summaries. Some of those summaries (like this very one) are of course, slightly shorter, to make room for the 'man document' addition. Enjoy! Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-11-25 10:30:05 +05:30
/*------ Low Level Memory/Keyboard/File I/O support --------------------*/
//atic void *alloc_c (size_t num);
//atic void *alloc_r (void *ptr, size_t num);
//atic char *alloc_s (const char *str);
2013-01-16 11:30:00 +05:30
//atic inline int ioa (struct timespec *ts);
//atic int ioch (int ech, char *buf, unsigned cnt);
//atic int iokey (int action);
//atic char *ioline (const char *prompt);
//atic int mkfloat (const char *str, float *num, int whole);
//atic int readfile (FILE *fp, char **baddr, size_t *bsize, size_t *bread);
2011-03-31 16:45:12 +05:30
/*------ Small Utility routines ----------------------------------------*/
//atic float get_float (const char *prompt);
//atic int get_int (const char *prompt);
//atic inline const char *hex_make (KLONG num, int noz);
//atic void osel_clear (WIN_t *q);
//atic inline int osel_matched (const WIN_t *q, FLG_t enu, const char *str);
2011-03-31 16:45:12 +05:30
//atic const char *user_certify (WIN_t *q, const char *str, char typ);
/*------ Basic Formatting support --------------------------------------*/
//atic inline const char *justify_pad (const char *str, int width, int justr);
//atic inline const char *make_chr (const char ch, int width, int justr);
//atic inline const char *make_num (long num, int width, int justr, int col);
//atic inline const char *make_str (const char *str, int width, int justr, int col);
top: provide the means to adjust scaled process memory This commit is an unrequested outgrowth of the earlier change dealing with summary area memory field scaling. That user selectable scaling provision is now extended to include 6 (at present) task oriented memory fields. The new companion 'e' (lower case) interactive command has been added and, like the 'E' command, it can cycle each of the currently displayed memory columns between KiB through TiB. There are, however, some differences. Where '+' indicates summary area truncation at a given radix, task memory fields are automatically scaled for their column. Thus, not all rows use the same scaling. And, while summary area field widths were not changed, the task memory columns were widened in order to offer more meaningful data when the radix was increased. The precision is automatically increased in step with each radix: MiB displays 2 decimal places, GiB 3 and TiB 4. To compliment that additional precision, both the %CPU and %MEM fields were widened by 1 column and now offer precision up to 3 decimal places. But, unique to %CPU, widening could already have occurred due to the number of processors in some massively parallel boxes. At any rate, total extra width for both memory and percentage fields could amount to twenty (precious) columns more. So for both the memory and % fields the original width (along with loss of precision) can be restored via new compiler conditionals which this commit also provides. p.s. and it will be rcfile preserved for any restarts! (now that we know a '.' + 2 spaces is squeezed to one) (everything's perfectly justified, but it's just luck) Reference(s): http://www.freelists.org/post/procps/top-regression-reports Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-12-14 11:30:00 +05:30
//atic const char *scale_mem (int target, unsigned long num, int width, int justr);
//atic const char *scale_num (unsigned long num, int width, int justr);
//atic const char *scale_pcnt (float num, int width, int justr);
//atic const char *scale_tics (TIC_t tics, int width, int justr);
2011-03-31 16:45:12 +05:30
/*------ Fields Management support -------------------------------------*/
/*atic FLD_t Fieldstab[] = { ... } */
//atic void adj_geometry (void);
//atic void build_headers (void);
2011-03-31 16:45:12 +05:30
//atic void calibrate_fields (void);
//atic void display_fields (int focus, int extend);
2011-03-31 16:45:12 +05:30
//atic void fields_utility (void);
//atic inline void widths_resize (void);
2011-03-31 16:45:12 +05:30
//atic void zap_fieldstab (void);
/*------ Library Interface ---------------------------------------------*/
//atic void cpus_refresh (void);
2011-08-30 17:35:45 +05:30
//atic void procs_refresh (void);
//atic void sysinfo_refresh (int forced);
top: add a flexible 'Inspect' capability This commit introduces an extremely powerful, flexible brand new capability. Now, users can pause the normal iterative display and inspect the contents of any file or output from any script, command, or even pipelines. It's invoked via the 'Y' interactive command which, in turn, is supported with simple user supplied additions as new entries in the top personal configuration file. A separate new 'Inspect' window supports scrolling and searching, similar to the main top display. Except it extends existing 'L'/'&' (locate/locate-next) commands so that an out-of-view match automatically adjusts the horizontal position bringing such data into view. And it provides for multiple successive same line matches. Also, the basic 'more/less' navigation keys are active in this new 'Inspect' window, to ease user transition. There are no program changes required when entries are added to or deleted from the rcfile. And there are no known limits to the complexity of a script, command or pipeline, other than the unidirectional nature imposed by the 'popen' function call which top cannot violate. Since it's impossible to predict exactly what contents will be generated, top treats all output as raw binary data. Any control characters display in '^C' notation while all other unprintable characters show as '<AB>'. The biggest problem encountered was with the find/next capability since that strstr guy was really diminished given the possibility that numerous 'strings' could be encountered *within* many of top's raw, binary 'rows'. Oh, and another problem was in maintaining the perfect left & right text justification of this commit message along with all of the commit summaries. Some of those summaries (like this very one) are of course, slightly shorter, to make room for the 'man document' addition. Enjoy! Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-11-25 10:30:05 +05:30
/*------ Inspect Other Output ------------------------------------------*/
//atic void insp_cnt_nl (void);
#ifndef INSP_OFFDEMO
//atic void insp_do_demo (char *fmts, int pid);
#endif
//atic void insp_do_file (char *fmts, int pid);
//atic void insp_do_pipe (char *fmts, int pid);
//atic inline int insp_find_ofs (int col, int row);
//atic void insp_find_str (int ch, int *col, int *row);
//atic inline void insp_make_row (int col, int row);
//atic void insp_show_pgs (int col, int row, int max);
//atic int insp_view_choice (struct pids_stack *obj);
top: add a flexible 'Inspect' capability This commit introduces an extremely powerful, flexible brand new capability. Now, users can pause the normal iterative display and inspect the contents of any file or output from any script, command, or even pipelines. It's invoked via the 'Y' interactive command which, in turn, is supported with simple user supplied additions as new entries in the top personal configuration file. A separate new 'Inspect' window supports scrolling and searching, similar to the main top display. Except it extends existing 'L'/'&' (locate/locate-next) commands so that an out-of-view match automatically adjusts the horizontal position bringing such data into view. And it provides for multiple successive same line matches. Also, the basic 'more/less' navigation keys are active in this new 'Inspect' window, to ease user transition. There are no program changes required when entries are added to or deleted from the rcfile. And there are no known limits to the complexity of a script, command or pipeline, other than the unidirectional nature imposed by the 'popen' function call which top cannot violate. Since it's impossible to predict exactly what contents will be generated, top treats all output as raw binary data. Any control characters display in '^C' notation while all other unprintable characters show as '<AB>'. The biggest problem encountered was with the find/next capability since that strstr guy was really diminished given the possibility that numerous 'strings' could be encountered *within* many of top's raw, binary 'rows'. Oh, and another problem was in maintaining the perfect left & right text justification of this commit message along with all of the commit summaries. Some of those summaries (like this very one) are of course, slightly shorter, to make room for the 'man document' addition. Enjoy! Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-11-25 10:30:05 +05:30
//atic void inspection_utility (int pid);
2011-03-31 16:45:12 +05:30
/*------ Startup routines ----------------------------------------------*/
//atic void before (char *me);
//atic int config_cvt (WIN_t *q);
2011-03-31 16:45:12 +05:30
//atic void configs_read (void);
//atic void parse_args (char **args);
//atic void whack_terminal (void);
/*------ Windows/Field Groups support ----------------------------------*/
//atic void win_names (WIN_t *q, const char *name);
//atic void win_reset (WIN_t *q);
//atic WIN_t *win_select (int ch);
2011-03-31 16:45:12 +05:30
//atic int win_warn (int what);
//atic void wins_clrhlp (WIN_t *q, int save);
2011-03-31 16:45:12 +05:30
//atic void wins_colors (void);
//atic void wins_reflag (int what, int flg);
//atic void wins_stage_1 (void);
//atic void wins_stage_2 (void);
//atic inline int wins_usrselect (const WIN_t *q, struct pids_stack *p);
/*------ Interactive Input Tertiary support ----------------------------*/
//atic inline int find_ofs (const WIN_t *q, const char *buf);
2011-12-17 01:34:38 +05:30
//atic void find_string (int ch);
2011-03-31 16:45:12 +05:30
//atic void help_view (void);
//atic void other_selection (int ch);
//atic void write_rcfile (void);
/*------ Interactive Input Secondary support (do_key helpers) ----------*/
2011-03-31 16:45:12 +05:30
//atic void keys_global (int ch);
//atic void keys_summary (int ch);
//atic void keys_task (int ch);
//atic void keys_window (int ch);
//atic void keys_xtra (int ch);
2011-08-30 17:35:45 +05:30
/*------ Forest View support -------------------------------------------*/
//atic void forest_begin (const int self, int level);
2011-08-30 17:35:45 +05:30
//atic void forest_create (WIN_t *q);
//atic inline const char *forest_display (const WIN_t *q, struct pids_stack *p);
2011-03-31 16:45:12 +05:30
/*------ Main Screen routines ------------------------------------------*/
//atic void do_key (int ch);
//atic void summary_hlp (struct procps_jiffs_hist *cpu, const char *pfx);
2011-08-30 17:35:45 +05:30
//atic void summary_show (void);
//atic const char *task_show (const WIN_t *q, struct pids_stack *p);
2011-08-30 17:35:45 +05:30
//atic int window_show (WIN_t *q, int wmax);
2011-03-31 16:45:12 +05:30
/*------ Entry point plus two ------------------------------------------*/
//atic void frame_hlp (int wix, int max);
2011-03-31 16:45:12 +05:30
//atic void frame_make (void);
// int main (int dont_care_argc, char **argv);
2002-05-30 09:14:46 +05:30
#endif /* _Itop */
2011-03-31 16:45:12 +05:30