procps/top/top.c

5764 lines
201 KiB
C
Raw Normal View History

2002-05-30 09:14:46 +05:30
/* top.c - Source file: show Linux processes */
2002-02-02 04:17:29 +05:30
/*
* Copyright (c) 2002-2017, by: James C. Warner
2002-06-19 05:15:30 +05:30
* All rights reserved. 8921 Hilloway Road
* Eden Prairie, Minnesota 55347 USA
*
2002-05-30 09:14:46 +05:30
* 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.
2011-03-31 16:45:12 +05:30
*/
/* For contributions to this program, the author wishes to thank:
2002-12-06 12:23:29 +05:30
* Craig Small, <csmall@small.dropbear.id.au>
2011-03-31 16:45:12 +05:30
* Albert D. Cahalan, <albert@users.sf.net>
* Sami Kerola, <kerolasa@iki.fi>
2002-06-19 05:15:30 +05:30
*/
2002-05-30 09:14:46 +05:30
#include <ctype.h>
#include <curses.h>
2002-02-02 04:17:29 +05:30
#include <errno.h>
2002-12-05 04:18:30 +05:30
#include <fcntl.h>
#include <float.h>
#include <limits.h>
2011-03-31 16:45:12 +05:30
#include <pwd.h>
2002-05-30 09:14:46 +05:30
#include <signal.h>
#include <stdarg.h>
2002-02-02 04:17:29 +05:30
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <term.h> // foul sob, defines all sorts of stuff...
2011-03-31 16:45:12 +05:30
#undef tab
#undef TTY
2002-02-02 04:17:29 +05:30
#include <termios.h>
2002-05-30 09:14:46 +05:30
#include <time.h>
#include <unistd.h>
2002-11-08 06:01:28 +05:30
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/select.h> // also available via <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h> // also available via <stdlib.h>
#include "../include/fileutils.h"
#include "../include/nls.h"
#include "../proc/devname.h"
#include "../proc/numa.h"
#include "../proc/procps.h"
#include "../proc/readproc.h"
#include "../proc/sig.h"
#include "../proc/sysinfo.h"
#include "../proc/version.h"
#include "../proc/wchan.h"
#include "../proc/whattime.h"
2002-02-02 04:17:29 +05:30
2002-05-30 09:14:46 +05:30
#include "top.h"
#include "top_nls.h"
2002-05-30 09:14:46 +05:30
2002-05-30 09:14:46 +05:30
/*###### Miscellaneous global stuff ####################################*/
2011-03-31 16:45:12 +05:30
/* The original and new terminal definitions
(only set when not in 'Batch' mode) */
static struct termios Tty_original, // our inherited terminal definition
#ifdef TERMIOS_ONLY
2011-03-31 16:45:12 +05:30
Tty_tweaked, // for interactive 'line' input
#endif
Tty_raw; // for unsolicited input
2002-12-05 04:18:30 +05:30
static int Ttychanged = 0;
2002-05-30 09:14:46 +05:30
top: correct cursor positioning for all ^Z or ^C cases Some more (very obscure) conditions where a suspension or program end might embed the shell prompt within top output have been uncovered beyond the 2 already known. We had already covered some suspend/end contingencies: 1. the users were using the 'fields management' screen 2. the users were prompted for any line oriented input However, there remained some situations where ^Z or ^C could still produce a misplaced cursor + shell prompt: 3. the 'g' command while waiting for the window choice 4. the 'W' command if about to overwrite an old rcfile 5. the '=' command when exploiting the Inspect feature 6. the period during which any error message was shown But, even when all those bases are covered there still remains a remote possibility that such interrupts will occur during a top repaint cycle. So rather than throw yet more code at these self-inflicted problems perhaps it is better if we just throw in the proverbial towel. Thus, I'll take the only sane approach and restore the results expected ever since top's inception and before scrollback buffers entered the picture. Namely, with a ^Z or ^C the cursor will be placed on the final screen row. That usually means it will immediately follow the last output line but it may follow many blank lines if the user interrupts top when *not* on the main screen. Reference(s): . expanded repositioning (for line oriented input) commit 33104a2bcc321495107d72e4cfee4090b1d90f76 . introduced repositioning (for fields management) commit 5c974ff44da4fbbb9170dd15bdd81555c62c31a9 . scrollback buffers (the cursor handling changes) commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-07-06 10:30:00 +05:30
/* Last established cursor state/shape */
static const char *Cursor_state = "";
2002-08-26 06:25:30 +05:30
/* Program name used in error messages and local 'rc' file name */
2002-06-19 05:15:30 +05:30
static char *Myname;
2002-05-30 09:14:46 +05:30
2013-01-16 11:30:00 +05:30
/* Our constant sigset, so we need initialize it but once */
static sigset_t Sigwinch_set;
2011-03-31 16:45:12 +05:30
/* The 'local' config file support */
2002-12-05 04:18:30 +05:30
static char Rc_name [OURPATHSZ];
static RCF_t Rc = DEF_RCFILE;
static int Rc_questions;
2002-12-05 04:18:30 +05:30
2011-03-31 16:45:12 +05:30
/* The run-time acquired page stuff */
static unsigned Pg2K_shft = 0;
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/* SMP, Irix/Solaris mode, Linux 2.5.xx support */
static CPU_t *Cpu_tics;
static int Cpu_faux_tot;
2011-08-30 17:35:45 +05:30
static float Cpu_pmax;
static const char *Cpu_States_fmts;
2002-05-30 09:14:46 +05:30
/* Specific process id monitoring support */
2002-12-05 04:18:30 +05:30
static pid_t Monpids [MONPIDMAX] = { 0 };
static int Monpidsidx = 0;
2002-05-30 09:14:46 +05:30
2002-06-19 05:15:30 +05:30
/* Current screen dimensions.
note: the number of processes displayed is tracked on a per window
basis (see the WIN_t). Max_lines is the total number of
screen rows after deducting summary information overhead. */
/* Current terminal screen size. */
2002-12-05 04:18:30 +05:30
static int Screen_cols, Screen_rows, Max_lines;
2002-06-19 05:15:30 +05:30
/* This is really the number of lines needed to display the summary
information (0 - nn), but is used as the relative row where we
stick the cursor between frames. */
2002-12-05 04:18:30 +05:30
static int Msg_row;
2002-11-30 21:26:53 +05:30
/* The nearly complete scroll coordinates message for the current
window, built at the time column headers are constructed */
static char Scroll_fmts [SMLBUFSIZ];
2002-06-19 05:15:30 +05:30
/* Global/Non-windows mode stuff that is NOT persistent */
static int Batch = 0, // batch mode, collect no input, dumb output
2002-12-05 04:18:30 +05:30
Loops = -1, // number of iterations, -1 loops forever
2011-03-31 16:45:12 +05:30
Secure_mode = 0, // set if some functionality restricted
Thread_mode = 0, // set w/ 'H' - show threads via readeither()
Width_mode = 0; // set w/ 'w' - potential output override
2011-03-31 16:45:12 +05:30
/* Unchangeable cap's stuff built just once (if at all) and
thus NOT saved in a WIN_t's RCW_t. To accommodate 'Batch'
2011-03-31 16:45:12 +05:30
mode, they begin life as empty strings so the overlying
logic need not change ! */
static char Cap_clr_eol [CAPBUFSIZ] = "", // global and/or static vars
Cap_nl_clreos [CAPBUFSIZ] = "", // are initialized to zeros!
Cap_clr_scr [CAPBUFSIZ] = "", // the assignments used here
Cap_curs_norm [CAPBUFSIZ] = "", // cost nothing but DO serve
Cap_curs_huge [CAPBUFSIZ] = "", // to remind people of those
Cap_curs_hide [CAPBUFSIZ] = "", // batch requirements!
Cap_clr_eos [CAPBUFSIZ] = "",
2011-03-31 16:45:12 +05:30
Cap_home [CAPBUFSIZ] = "",
Cap_norm [CAPBUFSIZ] = "",
Cap_reverse [CAPBUFSIZ] = "",
Caps_off [CAPBUFSIZ] = "",
Caps_endline [CAPBUFSIZ] = "";
#ifndef RMAN_IGNORED
static char Cap_rmam [CAPBUFSIZ] = "",
Cap_smam [CAPBUFSIZ] = "";
/* set to 1 if writing to the last column would be troublesome
(we don't distinguish the lowermost row from the other rows) */
static int Cap_avoid_eol = 0;
#endif
2002-06-19 05:15:30 +05:30
static int Cap_can_goto = 0;
2002-05-30 09:14:46 +05:30
2002-12-05 04:18:30 +05:30
/* Some optimization stuff, to reduce output demands...
2011-03-31 16:45:12 +05:30
The Pseudo_ guys are managed by adj_geometry and frame_make. They
2002-11-27 05:54:01 +05:30
are exploited in a macro and represent 90% of our optimization.
The Stdout_buf is transparent to our code and regardless of whose
buffer is used, stdout is flushed at frame end or if interactive. */
2011-03-31 16:45:12 +05:30
static char *Pseudo_screen;
static int Pseudo_row = PROC_XTRA;
2011-03-31 16:45:12 +05:30
static size_t Pseudo_size;
#ifndef OFF_STDIOLBF
2002-11-27 05:54:01 +05:30
// less than stdout's normal buffer but with luck mostly '\n' anyway
static char Stdout_buf[2048];
#endif
2011-03-31 16:45:12 +05:30
/* Our four WIN_t's, and which of those is considered the 'current'
window (ie. which window is associated with any summ info displayed
and to which window commands are directed) */
static WIN_t Winstk [GROUPSMAX];
static WIN_t *Curwin;
2002-06-19 05:15:30 +05:30
/* Frame oriented stuff that can't remain local to any 1 function
and/or that would be too cumbersome managed as parms,
2002-12-05 04:18:30 +05:30
and/or that are simply more efficiently handled as globals
2011-03-31 16:45:12 +05:30
[ 'Frames_...' (plural) stuff persists beyond 1 frame ]
[ or are used in response to async signals received ! ] */
static volatile int Frames_signal; // time to rebuild all column headers
2011-03-31 16:45:12 +05:30
static int Frames_libflags; // PROC_FILLxxx flags
static int Frame_maxtask; // last known number of active tasks
// ie. current 'size' of proc table
static float Frame_etscale; // so we can '*' vs. '/' WHEN 'pcpu'
static unsigned Frame_running, // state categories for this frame
Frame_sleepin,
Frame_stopped,
Frame_zombied;
static int Frame_srtflg, // the subject window's sort direction
Frame_ctimes, // the subject window's ctimes flag
Frame_cmdlin; // the subject window's cmdlin flag
/* Support for 'history' processing so we can calculate %cpu */
static int HHist_siz; // max number of HST_t structs
static HST_t *PHist_sav, // alternating 'old/new' HST_t anchors
*PHist_new;
#ifndef OFF_HST_HASH
#define HHASH_SIZ 1024
static int HHash_one [HHASH_SIZ], // actual hash tables ( hereafter known
HHash_two [HHASH_SIZ], // as PHash_sav/PHash_new )
HHash_nul [HHASH_SIZ]; // 'empty' hash table image
static int *PHash_sav = HHash_one, // alternating 'old/new' hash tables
*PHash_new = HHash_two;
#endif
/* Support for automatically sized fixed-width column expansions.
* (hopefully, the macros help clarify/document our new 'feature') */
static int Autox_array [EU_MAXPFLGS],
Autox_found;
#define AUTOX_NO EU_MAXPFLGS
#define AUTOX_COL(f) if (EU_MAXPFLGS > f) Autox_array[f] = Autox_found = 1
#define AUTOX_MODE (0 > Rc.fixed_widest)
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
/* Support for scale_mem and scale_num (to avoid duplication. */
#ifdef CASEUP_SUFIX // nls_maybe
static char Scaled_sfxtab[] = { 'K', 'M', 'G', 'T', 'P', 'E', 0 };
#else // nls_maybe
static char Scaled_sfxtab[] = { 'k', 'm', 'g', 't', 'p', 'e', 0 };
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
#endif
/* Support for NUMA Node display and node expansion/targeting */
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
#ifndef OFF_STDERROR
static int Stderr_save = -1;
#endif
static int Numa_node_tot;
static int Numa_node_sel = -1;
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
/* Support for Graphing of the View_STATES ('t') and View_MEMORY ('m')
commands -- which are now both 4-way toggles */
#define GRAPH_prefix 25 // beginning text + opening '['
#define GRAPH_actual 100 // the actual bars or blocks
#define GRAPH_suffix 2 // ending ']' + trailing space
static float Graph_adj; // bars/blocks scaling factor
static int Graph_len; // scaled length (<= GRAPH_actual)
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
static const char Graph_blks[] = " ";
static const char Graph_bars[] = "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||";
2002-05-30 09:14:46 +05:30
/*###### Sort callbacks ################################################*/
2002-10-02 05:40:30 +05:30
/*
2011-03-31 16:45:12 +05:30
* These happen to be coded in the enum identifier alphabetic order,
* not the order of the enum 'pflgs' value. Also note that a callback
* routine may serve more than one column.
2002-10-02 05:40:30 +05:30
*/
2002-12-06 12:23:29 +05:30
SCB_STRS(CGN, cgname)
SCB_STRS(CGR, cgroup[0])
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
SCB_STRV(CMD, Frame_cmdlin, cmdline, cmd)
2011-03-31 16:45:12 +05:30
SCB_NUM1(COD, trs)
SCB_NUMx(CPN, processor)
SCB_NUM1(CPU, pcpu)
SCB_NUM1(DAT, drs)
SCB_NUM1(DRT, dt)
SCB_STRS(ENV, environ[0])
2011-03-31 16:45:12 +05:30
SCB_NUM1(FL1, maj_flt)
SCB_NUM1(FL2, min_flt)
SCB_NUM1(FLG, flags)
SCB_NUM1(FV1, maj_delta)
SCB_NUM1(FV2, min_delta)
2011-03-31 16:45:12 +05:30
SCB_NUMx(GID, egid)
SCB_STRS(GRP, egroup)
SCB_STRS(LXC, lxcname)
2011-03-31 16:45:12 +05:30
SCB_NUMx(NCE, nice)
static int SCB_NAME(NMA) (const proc_t **P, const proc_t **Q) {
/* this is a terrible cost to pay for sorting on numa nodes, but it's
necessary if we're to avoid ABI breakage via changes to the proc_t */
int p = numa_node_of_cpu((*P)->processor);
int q = numa_node_of_cpu((*Q)->processor);
return Frame_srtflg * ( q - p );
}
SCB_NUM1(NS1, ns[IPCNS])
SCB_NUM1(NS2, ns[MNTNS])
SCB_NUM1(NS3, ns[NETNS])
SCB_NUM1(NS4, ns[PIDNS])
SCB_NUM1(NS5, ns[USERNS])
SCB_NUM1(NS6, ns[UTSNS])
SCB_NUM1(OOA, oom_adj)
SCB_NUM1(OOM, oom_score)
2011-03-31 16:45:12 +05:30
SCB_NUMx(PGD, pgrp)
SCB_NUMx(PID, tid)
SCB_NUMx(PPD, ppid)
SCB_NUMx(PRI, priority)
SCB_NUM1(RES, resident) // also serves MEM !
SCB_NUM1(RZA, vm_rss_anon)
SCB_NUM1(RZF, vm_rss_file)
SCB_NUM1(RZL, vm_lock)
SCB_NUM1(RZS, vm_rss_shared)
SCB_STRX(SGD, supgid)
SCB_STRS(SGN, supgrp)
2011-03-31 16:45:12 +05:30
SCB_NUM1(SHR, share)
SCB_NUM1(SID, session)
SCB_NUMx(STA, state)
SCB_NUM1(SWP, vm_swap)
SCB_NUMx(TGD, tgid)
2011-03-31 16:45:12 +05:30
SCB_NUMx(THD, nlwp)
// also serves TM2 !
static int SCB_NAME(TME) (const proc_t **P, const proc_t **Q) {
if (Frame_ctimes) {
if (((*P)->cutime + (*P)->cstime + (*P)->utime + (*P)->stime)
< ((*Q)->cutime + (*Q)->cstime + (*Q)->utime + (*Q)->stime))
return SORT_lt;
if (((*P)->cutime + (*P)->cstime + (*P)->utime + (*P)->stime)
> ((*Q)->cutime + (*Q)->cstime + (*Q)->utime + (*Q)->stime))
return SORT_gt;
} else {
if (((*P)->utime + (*P)->stime) < ((*Q)->utime + (*Q)->stime))
return SORT_lt;
if (((*P)->utime + (*P)->stime) > ((*Q)->utime + (*Q)->stime))
return SORT_gt;
}
return SORT_eq;
2002-05-30 09:14:46 +05:30
}
2011-03-31 16:45:12 +05:30
SCB_NUM1(TPG, tpgid)
SCB_NUMx(TTY, tty)
SCB_NUMx(UED, euid)
SCB_STRS(UEN, euser)
SCB_NUMx(URD, ruid)
SCB_STRS(URN, ruser)
SCB_NUMx(USD, suid)
SCB_NUM2(USE, vm_rss, vm_swap)
2011-03-31 16:45:12 +05:30
SCB_STRS(USN, suser)
SCB_NUM1(VRT, size)
SCB_NUM1(WCH, wchan)
#ifdef OFF_HST_HASH
/* special sort for procs_hlp() ! ------------------------ */
2011-03-31 16:45:12 +05:30
static int sort_HST_t (const HST_t *P, const HST_t *Q) {
2002-12-09 04:21:09 +05:30
return P->pid - Q->pid;
2002-11-08 06:01:28 +05:30
}
2011-03-31 16:45:12 +05:30
#endif
2002-05-30 09:14:46 +05:30
/*###### Tiny useful routine(s) ########################################*/
/*
2011-03-31 16:45:12 +05:30
* This routine simply formats whatever the caller wants and
* returns a pointer to the resulting 'const char' string... */
2006-06-25 06:44:24 +05:30
static const char *fmtmk (const char *fmts, ...) __attribute__((format(printf,1,2)));
2011-03-31 16:45:12 +05:30
static const char *fmtmk (const char *fmts, ...) {
2004-07-07 22:57:26 +05:30
static char buf[BIGBUFSIZ]; // with help stuff, our buffer
2011-03-31 16:45:12 +05:30
va_list va; // requirements now exceed 1k
2002-05-30 09:14:46 +05:30
va_start(va, fmts);
2002-09-13 17:12:44 +05:30
vsnprintf(buf, sizeof(buf), fmts, va);
2002-05-30 09:14:46 +05:30
va_end(va);
return (const char *)buf;
2011-03-31 16:45:12 +05:30
} // end: fmtmk
2002-02-02 04:17:29 +05:30
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/*
* This guy is just our way of avoiding the overhead of the standard
* strcat function (should the caller choose to participate) */
static inline char *scat (char *dst, const char *src) {
while (*dst) dst++;
while ((*(dst++) = *(src++)));
return --dst;
2011-03-31 16:45:12 +05:30
} // end: scat
2011-03-31 16:45:12 +05:30
/*
* This guy just facilitates Batch and protects against dumb ttys
* -- we'd 'inline' him but he's only called twice per frame,
* yet used in many other locations. */
static const char *tg2 (int x, int y) {
// it's entirely possible we're trying for an invalid row...
2002-10-02 05:40:30 +05:30
return Cap_can_goto ? tgoto(cursor_address, x, y) : "";
2011-03-31 16:45:12 +05:30
} // end: tg2
2002-06-19 05:15:30 +05:30
/*###### Exit/Interrput routines #######################################*/
2011-03-31 16:45:12 +05:30
/*
* Reset the tty, if necessary */
static void at_eoj (void) {
2011-03-31 16:45:12 +05:30
if (Ttychanged) {
tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_original);
if (keypad_local) putp(keypad_local);
top: correct cursor positioning for all ^Z or ^C cases Some more (very obscure) conditions where a suspension or program end might embed the shell prompt within top output have been uncovered beyond the 2 already known. We had already covered some suspend/end contingencies: 1. the users were using the 'fields management' screen 2. the users were prompted for any line oriented input However, there remained some situations where ^Z or ^C could still produce a misplaced cursor + shell prompt: 3. the 'g' command while waiting for the window choice 4. the 'W' command if about to overwrite an old rcfile 5. the '=' command when exploiting the Inspect feature 6. the period during which any error message was shown But, even when all those bases are covered there still remains a remote possibility that such interrupts will occur during a top repaint cycle. So rather than throw yet more code at these self-inflicted problems perhaps it is better if we just throw in the proverbial towel. Thus, I'll take the only sane approach and restore the results expected ever since top's inception and before scrollback buffers entered the picture. Namely, with a ^Z or ^C the cursor will be placed on the final screen row. That usually means it will immediately follow the last output line but it may follow many blank lines if the user interrupts top when *not* on the main screen. Reference(s): . expanded repositioning (for line oriented input) commit 33104a2bcc321495107d72e4cfee4090b1d90f76 . introduced repositioning (for fields management) commit 5c974ff44da4fbbb9170dd15bdd81555c62c31a9 . scrollback buffers (the cursor handling changes) commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-07-06 10:30:00 +05:30
putp(tg2(0, Screen_rows));
top: inoculated against a window manager like 'screen' If top were invoked under the 'screen' window manager, writing the terminfo string 'exit_ca_mode' at top exit would not restore the display to the state existing at the time top was started. That's what occurs normally. The net result of that failure was a corrupted screen. However, there is a 'screen' configuration option that will produce proper 'rmcup' behavior, but it is off by default. That screencr option is known as 'altscreen'. I stumbled across this provision by cloning the screen git repository then searching for references to 'cup'. If 'altscreen on' had been in either the /etc/screenrc or the $HOME/.screenrc configuration file, my poor old top would never have been accused of such corruptions. Of course, the Programming Gods decree that any simple solution for our problem must always be revealed last. So before discovering that rc option, another approach was taken involving top only. With just a little extra refactoring of top display logic he was made immune to any such quirk in the implementation of 'smcup/rmcup'. I always feel good about any enhancement that actually reduces the total number of lines of code. Even though this change involved mostly rearranging some logic, it yielded one less line (can't judge by diffstat because of braces & notes). Anyway, rather than requiring some change to a screenrc file, now we are self-sufficient. Reference(s): procps --------------------------------------------- https://bugzilla.redhat.com/show_bug.cgi?id=962022 http://www.freelists.org/post/procps/top-procpsng337-no-screen-cleaning-at-exit,3 . top : disable tty scrollback buffer to improve SIGWINCH commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d screen --------------------------------------------- git://git.sv.gnu.org/screen.git . Improve cursor store/restore on smcup/rmcup. commit f95352946080be803b794c9f2733d8c809c1a39a . Fix using alternate screen buffers in some cases. commit ad56f746c6243d45124485d198d577bdbb78071c http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=558724 Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-05-18 10:30:00 +05:30
putp("\n");
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
#ifdef OFF_SCROLLBK
top: inoculated against a window manager like 'screen' If top were invoked under the 'screen' window manager, writing the terminfo string 'exit_ca_mode' at top exit would not restore the display to the state existing at the time top was started. That's what occurs normally. The net result of that failure was a corrupted screen. However, there is a 'screen' configuration option that will produce proper 'rmcup' behavior, but it is off by default. That screencr option is known as 'altscreen'. I stumbled across this provision by cloning the screen git repository then searching for references to 'cup'. If 'altscreen on' had been in either the /etc/screenrc or the $HOME/.screenrc configuration file, my poor old top would never have been accused of such corruptions. Of course, the Programming Gods decree that any simple solution for our problem must always be revealed last. So before discovering that rc option, another approach was taken involving top only. With just a little extra refactoring of top display logic he was made immune to any such quirk in the implementation of 'smcup/rmcup'. I always feel good about any enhancement that actually reduces the total number of lines of code. Even though this change involved mostly rearranging some logic, it yielded one less line (can't judge by diffstat because of braces & notes). Anyway, rather than requiring some change to a screenrc file, now we are self-sufficient. Reference(s): procps --------------------------------------------- https://bugzilla.redhat.com/show_bug.cgi?id=962022 http://www.freelists.org/post/procps/top-procpsng337-no-screen-cleaning-at-exit,3 . top : disable tty scrollback buffer to improve SIGWINCH commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d screen --------------------------------------------- git://git.sv.gnu.org/screen.git . Improve cursor store/restore on smcup/rmcup. commit f95352946080be803b794c9f2733d8c809c1a39a . Fix using alternate screen buffers in some cases. commit ad56f746c6243d45124485d198d577bdbb78071c http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=558724 Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-05-18 10:30:00 +05:30
if (exit_ca_mode) {
top: disable tty scrollback buffer to improve SIGWINCH A scrollback buffer used in several terminal emulators could be a real inconvenience to a user following some resize operations. Extra keystroke(s) would frequently be required in order to properly render top's display. After much sleuthing we unearthed two terminfo strings which have the effect of disabling/restoring that darn scrollback buffer. They were well hidden under a title of strings 'to start/end programs using cup'. In turn, 'cup' deals with a tty's cursor addressing capability. We don't care what you call them or what they refer to so long as they get the job done. And these really do! Be advised, however, that there are some side effects, several of which can even be considered as beneficial: . enter_ca_mode/smcup/ti disables scrollback buffering ( and that's good, it's what we had always hoped for ) . exit_ca_mode/rmcup/te restores the scrollback buffer ( but also restores screen contents existing pre-top ) ( which is different from former program end results ) ( where that last rendered screen was left untouched ) . the above screen replacement would impact ^Z suspend ( thus we keep the scrollback buffer disabled during ) ( the suspend/resume sequence so that the users will ) ( have a visual clue that top is suspended not ended ) If a terminal does not support these terminfo strings, we will revert to top's former behavior at program end where we position the cursor at screen bottom and then output a single newline character. This will prevent a shell prompt from embedding within top's final screen. This commit's approach has been tested under a variety of emulators and window managers, many of which linked with libvte and others that employed their own scheme. Examples are: gnome_terminal; kde konsole; lxterminal; terminator; terminology; urxvt; xfce4-terminal; xterm. I do now believe that the whole SIGWINCH deal is done! (everything is perfectly justified plus right margins) (are completely filled, but of course it must be luck) Reference(s): http://www.freelists.org/post/procps/top-won-the-sigwinch-war http://www.freelists.org/post/procps/top-won-the-sigwinch-war,4 Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-31 11:30:00 +05:30
// this next will also replace top's most recent screen with the
// original display contents that were visible at our invocation
putp(exit_ca_mode);
}
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
#endif
2011-03-31 16:45:12 +05:30
putp(Cap_curs_norm);
top: inoculated against a window manager like 'screen' If top were invoked under the 'screen' window manager, writing the terminfo string 'exit_ca_mode' at top exit would not restore the display to the state existing at the time top was started. That's what occurs normally. The net result of that failure was a corrupted screen. However, there is a 'screen' configuration option that will produce proper 'rmcup' behavior, but it is off by default. That screencr option is known as 'altscreen'. I stumbled across this provision by cloning the screen git repository then searching for references to 'cup'. If 'altscreen on' had been in either the /etc/screenrc or the $HOME/.screenrc configuration file, my poor old top would never have been accused of such corruptions. Of course, the Programming Gods decree that any simple solution for our problem must always be revealed last. So before discovering that rc option, another approach was taken involving top only. With just a little extra refactoring of top display logic he was made immune to any such quirk in the implementation of 'smcup/rmcup'. I always feel good about any enhancement that actually reduces the total number of lines of code. Even though this change involved mostly rearranging some logic, it yielded one less line (can't judge by diffstat because of braces & notes). Anyway, rather than requiring some change to a screenrc file, now we are self-sufficient. Reference(s): procps --------------------------------------------- https://bugzilla.redhat.com/show_bug.cgi?id=962022 http://www.freelists.org/post/procps/top-procpsng337-no-screen-cleaning-at-exit,3 . top : disable tty scrollback buffer to improve SIGWINCH commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d screen --------------------------------------------- git://git.sv.gnu.org/screen.git . Improve cursor store/restore on smcup/rmcup. commit f95352946080be803b794c9f2733d8c809c1a39a . Fix using alternate screen buffers in some cases. commit ad56f746c6243d45124485d198d577bdbb78071c http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=558724 Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-05-18 10:30:00 +05:30
putp(Cap_clr_eol);
2011-03-31 16:45:12 +05:30
#ifndef RMAN_IGNORED
putp(Cap_smam);
#endif
}
fflush(stdout);
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
#ifndef OFF_STDERROR
/* we gotta reverse the stderr redirect which was employed during start up
and needed because the two libnuma 'weak' functions were useless to us! */
if (-1 < Stderr_save) {
dup2(Stderr_save, fileno(stderr));
close(Stderr_save);
Stderr_save = -1; // we'll be ending soon anyway but what the heck
}
#endif
} // end: at_eoj
2002-06-19 05:15:30 +05:30
/*
* The real program end */
static void bye_bye (const char *str) NORETURN;
static void bye_bye (const char *str) {
at_eoj(); // restore tty in preparation for exit
#ifdef ATEOJ_RPTSTD
2011-03-31 16:45:12 +05:30
{ proc_t *p;
if (!str && !Frames_signal && Ttychanged) { fprintf(stderr,
"\n%s's Summary report:"
"\n\tProgram"
"\n\t %s"
"\n\t Hertz = %u (%u bytes, %u-bit time)"
"\n\t page_bytes = %d, Cpu_faux_tot = %d, smp_num_cpus = %d"
"\n\t sizeof(CPU_t) = %u, sizeof(HST_t) = %u (%d HST_t's/Page), HHist_siz = %u"
"\n\t sizeof(proc_t) = %u, sizeof(proc_t.cmd) = %u, sizeof(proc_t*) = %u"
"\n\t Frames_libflags = %08lX"
"\n\t SCREENMAX = %u, ROWMINSIZ = %u, ROWMAXSIZ = %u"
"\n\t PACKAGE = '%s', LOCALEDIR = '%s'"
"\n\tTerminal: %s"
"\n\t device = %s, ncurses = v%s"
"\n\t max_colors = %d, max_pairs = %d"
"\n\t Cap_can_goto = %s"
"\n\t Screen_cols = %d, Screen_rows = %d"
"\n\t Max_lines = %d, most recent Pseudo_size = %u"
2011-03-31 16:45:12 +05:30
#ifndef OFF_STDIOLBF
"\n\t Stdout_buf = %u, BUFSIZ = %u"
2011-03-31 16:45:12 +05:30
#endif
"\n\tWindows and Curwin->"
"\n\t sizeof(WIN_t) = %u, GROUPSMAX = %d"
"\n\t winname = %s, grpname = %s"
2011-03-31 16:45:12 +05:30
#ifdef CASEUP_HEXES
"\n\t winflags = %08X, maxpflgs = %d"
2011-03-31 16:45:12 +05:30
#else
"\n\t winflags = %08x, maxpflgs = %d"
2011-03-31 16:45:12 +05:30
#endif
"\n\t sortindx = %d, fieldscur = %s"
"\n\t maxtasks = %d, varcolsz = %d, winlines = %d"
"\n\t strlen(columnhdr) = %d"
"\n"
2011-03-31 16:45:12 +05:30
, __func__
, PACKAGE_STRING
2011-03-31 16:45:12 +05:30
, (unsigned)Hertz, (unsigned)sizeof(Hertz), (unsigned)sizeof(Hertz) * 8
, (int)page_bytes, Cpu_faux_tot, (int)smp_num_cpus, (unsigned)sizeof(CPU_t)
, (unsigned)sizeof(HST_t), ((int)page_bytes / (int)sizeof(HST_t)), HHist_siz
2011-08-30 17:35:45 +05:30
, (unsigned)sizeof(proc_t), (unsigned)sizeof(p->cmd), (unsigned)sizeof(proc_t*)
2011-03-31 16:45:12 +05:30
, (long)Frames_libflags
, (unsigned)SCREENMAX, (unsigned)ROWMINSIZ, (unsigned)ROWMAXSIZ
, PACKAGE, LOCALEDIR
2002-06-19 05:15:30 +05:30
#ifdef PRETENDNOCAP
, "dumb"
#else
, termname()
#endif
, ttyname(STDOUT_FILENO), NCURSES_VERSION
, max_colors, max_pairs
, Cap_can_goto ? "yes" : "No!"
, Screen_cols, Screen_rows
2011-03-31 16:45:12 +05:30
, Max_lines, (unsigned)Pseudo_size
#ifndef OFF_STDIOLBF
, (unsigned)sizeof(Stdout_buf), (unsigned)BUFSIZ
#endif
2011-03-31 16:45:12 +05:30
, (unsigned)sizeof(WIN_t), GROUPSMAX
2002-11-30 06:52:01 +05:30
, Curwin->rc.winname, Curwin->grpname
, Curwin->rc.winflags, Curwin->maxpflgs
, Curwin->rc.sortindx, Curwin->rc.fieldscur
, Curwin->rc.maxtasks, Curwin->varcolsz, Curwin->winlines
2011-03-31 16:45:12 +05:30
, (int)strlen(Curwin->columnhdr)
2004-07-07 22:57:26 +05:30
);
2011-03-31 16:45:12 +05:30
}
2002-06-19 05:15:30 +05:30
}
#endif // end: ATEOJ_RPTSTD
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
#ifndef OFF_HST_HASH
#ifdef ATEOJ_RPTHSH
if (!str && !Frames_signal && Ttychanged) {
int i, j, pop, total_occupied, maxdepth, maxdepth_sav, numdepth
, cross_foot, sz = HHASH_SIZ * (unsigned)sizeof(int);
int depths[HHASH_SIZ];
for (i = 0, total_occupied = 0, maxdepth = 0; i < HHASH_SIZ; i++) {
int V = PHash_new[i];
j = 0;
if (-1 < V) {
++total_occupied;
while (-1 < V) {
V = PHist_new[V].lnk;
if (-1 < V) j++;
}
2011-03-31 16:45:12 +05:30
}
depths[i] = j;
if (maxdepth < j) maxdepth = j;
2011-03-31 16:45:12 +05:30
}
maxdepth_sav = maxdepth;
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
fprintf(stderr,
"\n%s's Supplementary HASH report:"
"\n\tTwo Tables providing for %d entries each + 1 extra for 'empty' image"
"\n\t%dk (%d bytes) per table, %d total bytes (including 'empty' image)"
"\n\tResults from latest hash (PHash_new + PHist_new)..."
"\n"
"\n\tTotal hashed = %d"
"\n\tLevel-0 hash entries = %d (%d%% occupied)"
"\n\tMax Depth = %d"
"\n\n"
, __func__
, HHASH_SIZ, sz / 1024, sz, sz * 3
, Frame_maxtask
, total_occupied, (total_occupied * 100) / HHASH_SIZ
, maxdepth + 1);
if (total_occupied) {
for (pop = total_occupied, cross_foot = 0; maxdepth; maxdepth--) {
for (i = 0, numdepth = 0; i < HHASH_SIZ; i++)
if (depths[i] == maxdepth) ++numdepth;
fprintf(stderr,
"\t %5d (%3d%%) hash table entries at depth %d\n"
, numdepth, (numdepth * 100) / total_occupied, maxdepth + 1);
pop -= numdepth;
cross_foot += numdepth;
if (0 == pop && cross_foot == total_occupied) break;
}
if (pop) {
fprintf(stderr, "\t %5d (%3d%%) unchained hash table entries\n"
, pop, (pop * 100) / total_occupied);
cross_foot += pop;
}
fprintf(stderr,
"\t -----\n"
"\t %5d total entries occupied\n", cross_foot);
if (maxdepth_sav > 1) {
fprintf(stderr, "\nPIDs at max depth: ");
for (i = 0; i < HHASH_SIZ; i++)
if (depths[i] == maxdepth_sav) {
j = PHash_new[i];
fprintf(stderr, "\n\tpos %4d: %05d", i, PHist_new[j].pid);
while (-1 < j) {
j = PHist_new[j].lnk;
if (-1 < j) fprintf(stderr, ", %05d", PHist_new[j].pid);
}
2011-03-31 16:45:12 +05:30
}
fprintf(stderr, "\n");
}
2011-03-31 16:45:12 +05:30
}
}
#endif // end: ATEOJ_RPTHSH
2011-03-31 16:45:12 +05:30
#endif // end: OFF_HST_HASH
2002-06-19 05:15:30 +05:30
numa_uninit();
2011-03-31 16:45:12 +05:30
if (str) {
fputs(str, stderr);
exit(EXIT_FAILURE);
2002-06-19 05:15:30 +05:30
}
if (Batch) fputs("\n", stdout);
exit(EXIT_SUCCESS);
2011-03-31 16:45:12 +05:30
} // end: bye_bye
/*
2011-03-31 16:45:12 +05:30
* Standard error handler to normalize the look of all err output */
static void error_exit (const char *str) NORETURN;
static void error_exit (const char *str) {
static char buf[MEDBUFSIZ];
/* we'll use our own buffer so callers can still use fmtmk() and, after
twelve long years, 2013 was the year we finally eliminated the leading
tab character -- now our message can get lost in screen clutter too! */
snprintf(buf, sizeof(buf), "%s: %s\n", Myname, str);
2011-03-31 16:45:12 +05:30
bye_bye(buf);
} // end: error_exit
2002-06-19 05:15:30 +05:30
/*
* Catches all remaining signals not otherwise handled */
static void sig_abexit (int sig) {
sigset_t ss;
// POSIX.1-2004 async-signal-safe: sigfillset, sigprocmask, signal, raise
sigfillset(&ss);
sigprocmask(SIG_BLOCK, &ss, NULL);
at_eoj(); // restore tty in preparation for exit
fprintf(stderr, N_fmt(EXIT_signals_fmt)
, sig, signal_number_to_name(sig), Myname);
signal(sig, SIG_DFL); // allow core dumps, if applicable
raise(sig); // ( plus set proper return code )
} // end: sig_abexit
2011-03-31 16:45:12 +05:30
/*
* Catches:
* SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM,
* SIGUSR1 and SIGUSR2 */
static void sig_endpgm (int dont_care_sig) NORETURN;
2011-03-31 16:45:12 +05:30
static void sig_endpgm (int dont_care_sig) {
sigset_t ss;
// POSIX.1-2004 async-signal-safe: sigfillset, sigprocmask
sigfillset(&ss);
sigprocmask(SIG_BLOCK, &ss, NULL);
Frames_signal = BREAK_sig;
bye_bye(NULL);
2011-03-31 16:45:12 +05:30
(void)dont_care_sig;
} // end: sig_endpgm
2002-05-30 09:14:46 +05:30
2002-05-30 09:14:46 +05:30
/*
2011-03-31 16:45:12 +05:30
* Catches:
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
* SIGTSTP, SIGTTIN and SIGTTOU */
2011-03-31 16:45:12 +05:30
static void sig_paused (int dont_care_sig) {
// POSIX.1-2004 async-signal-safe: tcsetattr, tcdrain, raise
if (-1 == tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_original))
error_exit(fmtmk(N_fmt(FAIL_tty_set_fmt), strerror(errno)));
if (keypad_local) putp(keypad_local);
top: correct cursor positioning for all ^Z or ^C cases Some more (very obscure) conditions where a suspension or program end might embed the shell prompt within top output have been uncovered beyond the 2 already known. We had already covered some suspend/end contingencies: 1. the users were using the 'fields management' screen 2. the users were prompted for any line oriented input However, there remained some situations where ^Z or ^C could still produce a misplaced cursor + shell prompt: 3. the 'g' command while waiting for the window choice 4. the 'W' command if about to overwrite an old rcfile 5. the '=' command when exploiting the Inspect feature 6. the period during which any error message was shown But, even when all those bases are covered there still remains a remote possibility that such interrupts will occur during a top repaint cycle. So rather than throw yet more code at these self-inflicted problems perhaps it is better if we just throw in the proverbial towel. Thus, I'll take the only sane approach and restore the results expected ever since top's inception and before scrollback buffers entered the picture. Namely, with a ^Z or ^C the cursor will be placed on the final screen row. That usually means it will immediately follow the last output line but it may follow many blank lines if the user interrupts top when *not* on the main screen. Reference(s): . expanded repositioning (for line oriented input) commit 33104a2bcc321495107d72e4cfee4090b1d90f76 . introduced repositioning (for fields management) commit 5c974ff44da4fbbb9170dd15bdd81555c62c31a9 . scrollback buffers (the cursor handling changes) commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-07-06 10:30:00 +05:30
putp(tg2(0, Screen_rows));
putp(Cap_curs_norm);
#ifndef RMAN_IGNORED
putp(Cap_smam);
#endif
top: disable tty scrollback buffer to improve SIGWINCH A scrollback buffer used in several terminal emulators could be a real inconvenience to a user following some resize operations. Extra keystroke(s) would frequently be required in order to properly render top's display. After much sleuthing we unearthed two terminfo strings which have the effect of disabling/restoring that darn scrollback buffer. They were well hidden under a title of strings 'to start/end programs using cup'. In turn, 'cup' deals with a tty's cursor addressing capability. We don't care what you call them or what they refer to so long as they get the job done. And these really do! Be advised, however, that there are some side effects, several of which can even be considered as beneficial: . enter_ca_mode/smcup/ti disables scrollback buffering ( and that's good, it's what we had always hoped for ) . exit_ca_mode/rmcup/te restores the scrollback buffer ( but also restores screen contents existing pre-top ) ( which is different from former program end results ) ( where that last rendered screen was left untouched ) . the above screen replacement would impact ^Z suspend ( thus we keep the scrollback buffer disabled during ) ( the suspend/resume sequence so that the users will ) ( have a visual clue that top is suspended not ended ) If a terminal does not support these terminfo strings, we will revert to top's former behavior at program end where we position the cursor at screen bottom and then output a single newline character. This will prevent a shell prompt from embedding within top's final screen. This commit's approach has been tested under a variety of emulators and window managers, many of which linked with libvte and others that employed their own scheme. Examples are: gnome_terminal; kde konsole; lxterminal; terminator; terminology; urxvt; xfce4-terminal; xterm. I do now believe that the whole SIGWINCH deal is done! (everything is perfectly justified plus right margins) (are completely filled, but of course it must be luck) Reference(s): http://www.freelists.org/post/procps/top-won-the-sigwinch-war http://www.freelists.org/post/procps/top-won-the-sigwinch-war,4 Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-31 11:30:00 +05:30
// tcdrain(STDOUT_FILENO) was not reliable prior to ncurses-5.9.20121017,
// so we'll risk POSIX's wrath with good ol' fflush, lest 'Stopped' gets
// co-mingled with our most recent output...
fflush(stdout);
raise(SIGSTOP);
// later, after SIGCONT...
if (-1 == tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_raw))
error_exit(fmtmk(N_fmt(FAIL_tty_set_fmt), strerror(errno)));
#ifndef RMAN_IGNORED
putp(Cap_rmam);
#endif
if (keypad_xmit) putp(keypad_xmit);
putp(Cursor_state);
Frames_signal = BREAK_sig;
(void)dont_care_sig;
2011-03-31 16:45:12 +05:30
} // end: sig_paused
/*
* Catches:
* SIGCONT and SIGWINCH */
static void sig_resize (int dont_care_sig) {
// POSIX.1-2004 async-signal-safe: tcdrain
tcdrain(STDOUT_FILENO);
Frames_signal = BREAK_sig;
2011-03-31 16:45:12 +05:30
(void)dont_care_sig;
} // end: sig_resize
/*###### Misc Color/Display support ####################################*/
/*
* Make the appropriate caps/color strings for a window/field group.
2002-05-30 09:14:46 +05:30
* note: we avoid the use of background color so as to maximize
* compatibility with the user's xterm settings */
2011-03-31 16:45:12 +05:30
static void capsmk (WIN_t *q) {
/* macro to test if a basic (non-color) capability is valid
thanks: Floyd Davidson <floyd@ptialaska.net> */
#define tIF(s) s ? s : ""
/* macro to make compatible with netbsd-curses too
thanks: rofl0r <retnyg@gmx.net> */
#define tPM(a,b) tparm(a, b, 0, 0, 0, 0, 0, 0, 0, 0)
2002-05-30 09:14:46 +05:30
static int capsdone = 0;
// we must NOT disturb our 'empty' terminfo strings!
2002-05-30 09:14:46 +05:30
if (Batch) return;
// these are the unchangeable puppies, so we only do 'em once
2002-05-30 09:14:46 +05:30
if (!capsdone) {
2011-03-31 16:45:12 +05:30
STRLCPY(Cap_clr_eol, tIF(clr_eol))
STRLCPY(Cap_clr_eos, tIF(clr_eos))
2011-03-31 16:45:12 +05:30
STRLCPY(Cap_clr_scr, tIF(clear_screen))
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
// due to the leading newline, the following must be used with care
2011-03-31 16:45:12 +05:30
snprintf(Cap_nl_clreos, sizeof(Cap_nl_clreos), "\n%s", tIF(clr_eos));
STRLCPY(Cap_curs_huge, tIF(cursor_visible))
STRLCPY(Cap_curs_norm, tIF(cursor_normal))
STRLCPY(Cap_curs_hide, tIF(cursor_invisible))
STRLCPY(Cap_home, tIF(cursor_home))
STRLCPY(Cap_norm, tIF(exit_attribute_mode))
STRLCPY(Cap_reverse, tIF(enter_reverse_mode))
#ifndef RMAN_IGNORED
if (!eat_newline_glitch) {
STRLCPY(Cap_rmam, tIF(exit_am_mode))
STRLCPY(Cap_smam, tIF(enter_am_mode))
if (!*Cap_rmam || !*Cap_smam) {
*Cap_rmam = '\0';
*Cap_smam = '\0';
2011-03-31 16:45:12 +05:30
if (auto_right_margin)
Cap_avoid_eol = 1;
}
2011-03-31 16:45:12 +05:30
putp(Cap_rmam);
}
2011-03-31 16:45:12 +05:30
#endif
snprintf(Caps_off, sizeof(Caps_off), "%s%s", Cap_norm, tIF(orig_pair));
2011-03-31 16:45:12 +05:30
snprintf(Caps_endline, sizeof(Caps_endline), "%s%s", Caps_off, Cap_clr_eol);
2002-05-30 09:14:46 +05:30
if (tgoto(cursor_address, 1, 1)) Cap_can_goto = 1;
capsdone = 1;
}
2011-03-31 16:45:12 +05:30
/* the key to NO run-time costs for configurable colors -- we spend a
little time with the user now setting up our terminfo strings, and
the job's done until he/she/it has a change-of-heart */
2011-03-31 16:45:12 +05:30
STRLCPY(q->cap_bold, CHKw(q, View_NOBOLD) ? Cap_norm : tIF(enter_bold_mode))
2002-06-19 05:15:30 +05:30
if (CHKw(q, Show_COLORS) && max_colors > 0) {
STRLCPY(q->capclr_sum, tPM(set_a_foreground, q->rc.summclr))
snprintf(q->capclr_msg, sizeof(q->capclr_msg), "%s%s"
, tPM(set_a_foreground, q->rc.msgsclr), Cap_reverse);
snprintf(q->capclr_pmt, sizeof(q->capclr_pmt), "%s%s"
, tPM(set_a_foreground, q->rc.msgsclr), q->cap_bold);
snprintf(q->capclr_hdr, sizeof(q->capclr_hdr), "%s%s"
, tPM(set_a_foreground, q->rc.headclr), Cap_reverse);
snprintf(q->capclr_rownorm, sizeof(q->capclr_rownorm), "%s%s"
, Caps_off, tPM(set_a_foreground, q->rc.taskclr));
2002-05-30 09:14:46 +05:30
} else {
2002-06-19 05:15:30 +05:30
q->capclr_sum[0] = '\0';
#ifdef USE_X_COLHDR
snprintf(q->capclr_msg, sizeof(q->capclr_pmt), "%s%s"
, Cap_reverse, q->cap_bold);
#else
2011-03-31 16:45:12 +05:30
STRLCPY(q->capclr_msg, Cap_reverse)
#endif
2011-03-31 16:45:12 +05:30
STRLCPY(q->capclr_pmt, q->cap_bold)
STRLCPY(q->capclr_hdr, Cap_reverse)
STRLCPY(q->capclr_rownorm, Cap_norm)
2002-05-30 09:14:46 +05:30
}
2011-03-31 16:45:12 +05:30
// composite(s), so we do 'em outside and after the if
snprintf(q->capclr_rowhigh, sizeof(q->capclr_rowhigh), "%s%s"
, q->capclr_rownorm, CHKw(q, Show_HIBOLD) ? q->cap_bold : Cap_reverse);
2011-03-31 16:45:12 +05:30
#undef tIF
#undef tPM
2011-03-31 16:45:12 +05:30
} // end: capsmk
2002-02-02 04:17:29 +05:30
2002-05-30 09:14:46 +05:30
/*
2011-03-31 16:45:12 +05:30
* Show an error message (caller may include '\a' for sound) */
static void show_msg (const char *str) {
PUTT("%s%s %.*s %s%s%s"
2011-03-31 16:45:12 +05:30
, tg2(0, Msg_row)
, Curwin->capclr_msg
, Screen_cols - 2
2011-03-31 16:45:12 +05:30
, str
, Cap_curs_hide
2011-03-31 16:45:12 +05:30
, Caps_off
, Cap_clr_eol);
2002-05-30 09:14:46 +05:30
fflush(stdout);
2011-03-31 16:45:12 +05:30
usleep(MSG_USLEEP);
} // end: show_msg
2002-05-30 09:14:46 +05:30
/*
2011-03-31 16:45:12 +05:30
* Show an input prompt + larger cursor (if possible) */
static int show_pmt (const char *str) {
int rc;
#ifdef PRETENDNOCAP
PUTT("\n%s%s%.*s %s%s%s"
#else
PUTT("%s%s%.*s %s%s%s"
#endif
2011-03-31 16:45:12 +05:30
, tg2(0, Msg_row)
, Curwin->capclr_pmt
, Screen_cols - 2
2011-03-31 16:45:12 +05:30
, str
, Cap_curs_huge
, Caps_off
, Cap_clr_eol);
2002-05-30 09:14:46 +05:30
fflush(stdout);
// +1 for the space we added or -1 for the cursor...
return ((rc = (int)strlen(str)+1) < Screen_cols) ? rc : Screen_cols-1;
2011-03-31 16:45:12 +05:30
} // end: show_pmt
2002-05-30 09:14:46 +05:30
/*
* Show lines with specially formatted elements, but only output
* what will fit within the current screen width.
* Our special formatting consists of:
* "some text <_delimiter_> some more text <_delimiter_>...\n"
* Where <_delimiter_> is a two byte combination consisting of a
* tilde followed by an ascii digit in the range of 1 - 8.
top: redesign Uniq_nlstab/show_special (nls quirks) 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,11 http://www.freelists.org/post/procps/procpsng-nls-support,14
2011-10-20 00:44:37 +05:30
* examples: ~1, ~5, ~8, etc.
* The tilde is effectively stripped and the next digit
* converted to an index which is then used to select an
* 'attribute' from a capabilities table. That attribute
* is then applied to the *preceding* substring.
2002-05-30 09:14:46 +05:30
* Once recognized, the delimiter is replaced with a null character
* and viola, we've got a substring ready to output! Strings or
* substrings without delimiters will receive the Cap_norm attribute.
*
* Caution:
* This routine treats all non-delimiter bytes as displayable
* data subject to our screen width marching orders. If callers
* embed non-display data like tabs or terminfo strings in our
* glob, a line will truncate incorrectly at best. Worse case
* would be truncation of an embedded tty escape sequence.
*
* Tabs must always be avoided or our efforts are wasted and
* lines will wrap. To lessen but not eliminate the risk of
* terminfo string truncation, such non-display stuff should
top: redesign Uniq_nlstab/show_special (nls quirks) 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,11 http://www.freelists.org/post/procps/procpsng-nls-support,14
2011-10-20 00:44:37 +05:30
* be placed at the beginning of a "short" line. */
2011-03-31 16:45:12 +05:30
static void show_special (int interact, const char *glob) {
/* note: the following is for documentation only,
2002-06-19 05:15:30 +05:30
the real captab is now found in a group's WIN_t !
+------------------------------------------------------+
| char *captab[] = { : Cap's/Delim's |
| Cap_norm, Cap_norm, = \000, \001, |
| cap_bold, capclr_sum, = \002, \003, |
| capclr_msg, capclr_pmt, = \004, \005, |
| capclr_hdr, = \006, |
| capclr_rowhigh, = \007, |
| capclr_rownorm }; = \010 [octal!] |
2002-06-19 05:15:30 +05:30
+------------------------------------------------------+ */
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
/* ( Pssst, after adding the termcap transitions, row may )
( exceed 300+ bytes, even in an 80x24 terminal window! )
( And if we're no longer guaranteed lines created only )
( by top, we'll need larger buffs plus some protection )
( against overrunning them with this 'lin_end - glob'. ) */
char tmp[LRGBUFSIZ], lin[LRGBUFSIZ], row[ROWMAXSIZ];
top: redesign Uniq_nlstab/show_special (nls quirks) 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,11 http://www.freelists.org/post/procps/procpsng-nls-support,14
2011-10-20 00:44:37 +05:30
char *rp, *lin_end, *sub_beg, *sub_end;
2002-05-30 09:14:46 +05:30
int room;
2011-03-31 16:45:12 +05:30
// handle multiple lines passed in a bunch
2002-05-30 09:14:46 +05:30
while ((lin_end = strchr(glob, '\n'))) {
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 myMIN(a,b) (((a) < (b)) ? (a) : (b))
size_t lessor = myMIN((size_t)(lin_end - glob), sizeof(lin) -1);
2011-03-31 16:45:12 +05:30
// create a local copy we can extend and otherwise abuse
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
memcpy(lin, glob, lessor);
2011-03-31 16:45:12 +05:30
// zero terminate this part and prepare to parse substrings
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
lin[lessor] = '\0';
2002-05-30 09:14:46 +05:30
room = Screen_cols;
sub_beg = sub_end = lin;
*(rp = row) = '\0';
2002-05-30 09:14:46 +05:30
while (*sub_beg) {
top: redesign Uniq_nlstab/show_special (nls quirks) 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,11 http://www.freelists.org/post/procps/procpsng-nls-support,14
2011-10-20 00:44:37 +05:30
int ch = *sub_end;
if ('~' == ch) ch = *(sub_end + 1) - '0';
switch (ch) {
2011-03-31 16:45:12 +05:30
case 0: // no end delim, captab makes normal
*(sub_end + 1) = '\0'; // extend str end, then fall through
*(sub_end + 2) = '\0'; // ( +1 optimization for usual path )
case 1: case 2: case 3: case 4:
case 5: case 6: case 7: case 8:
2002-05-30 09:14:46 +05:30
*sub_end = '\0';
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
snprintf(tmp, sizeof(tmp), "%s%.*s%s"
, Curwin->captab[ch], room, sub_beg, Caps_off);
rp = scat(rp, tmp);
2002-05-30 09:14:46 +05:30
room -= (sub_end - sub_beg);
sub_beg = (sub_end += 2);
2002-05-30 09:14:46 +05:30
break;
2011-03-31 16:45:12 +05:30
default: // nothin' special, just text
2002-05-30 09:14:46 +05:30
++sub_end;
}
2011-03-31 16:45:12 +05:30
if (0 >= room) break; // skip substrings that won't fit
}
2011-03-31 16:45:12 +05:30
if (interact) PUTT("%s%s\n", row, Cap_clr_eol);
2011-03-31 16:45:12 +05:30
else PUFF("%s%s\n", row, Caps_endline);
glob = ++lin_end; // point to next line (maybe)
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
#undef myMIN
2011-03-31 16:45:12 +05:30
} // end: while 'lines'
2002-05-30 09:14:46 +05:30
/* If there's anything left in the glob (by virtue of no trailing '\n'),
2002-05-30 09:14:46 +05:30
it probably means caller wants to retain cursor position on this final
line. That, in turn, means we're interactive and so we'll just do our
'fit-to-screen' thingy while also leaving room for the cursor... */
if (*glob) PUTT("%.*s", Screen_cols -1, glob);
2011-03-31 16:45:12 +05:30
} // end: show_special
/*
* Create a nearly complete scroll coordinates message, but still
* a format string since we'll be missing the current total tasks. */
static void updt_scroll_msg (void) {
char tmp1[SMLBUFSIZ], tmp2[SMLBUFSIZ];
int totpflgs = Curwin->totpflgs;
int begpflgs = Curwin->begpflg + 1;
#ifndef USE_X_COLHDR
if (CHKw(Curwin, Show_HICOLS)) {
totpflgs -= 2;
if (ENUpos(Curwin, Curwin->rc.sortindx) < Curwin->begpflg) begpflgs -= 2;
}
#endif
if (1 > totpflgs) totpflgs = 1;
if (1 > begpflgs) begpflgs = 1;
snprintf(tmp1, sizeof(tmp1)
, N_fmt(SCROLL_coord_fmt), Curwin->begtask + 1, begpflgs, totpflgs);
strcpy(tmp2, tmp1);
#ifndef SCROLLVAR_NO
if (Curwin->varcolbeg)
snprintf(tmp2, sizeof(tmp2), "%s + %d", tmp1, Curwin->varcolbeg);
#endif
// this Scroll_fmts string no longer provides for termcap tgoto so that
// the usage timing is critical -- see frame_make() for additional info
snprintf(Scroll_fmts, sizeof(Scroll_fmts)
, "%s %.*s%s", Caps_off, Screen_cols - 3, tmp2, Cap_clr_eol);
} // end: updt_scroll_msg
2011-03-31 16:45:12 +05:30
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 ####################*/
/*
* Handle our own memory stuff without the risk of leaving the
* user's terminal in an ugly state should things go sour. */
static void *alloc_c (size_t num) MALLOC;
static void *alloc_c (size_t num) {
void *pv;
if (!num) ++num;
if (!(pv = calloc(1, num)))
error_exit(N_txt(FAIL_alloc_c_txt));
return pv;
} // end: alloc_c
static void *alloc_r (void *ptr, size_t num) MALLOC;
static void *alloc_r (void *ptr, size_t num) {
void *pv;
if (!num) ++num;
if (!(pv = realloc(ptr, num)))
error_exit(N_txt(FAIL_alloc_r_txt));
return pv;
} // end: alloc_r
2011-03-31 16:45:12 +05:30
static char *alloc_s (const char *str) MALLOC;
static char *alloc_s (const char *str) {
return strcpy(alloc_c(strlen(str) +1), str);
} // end: alloc_s
/*
* This function is used in connection with raw single byte
* unsolicited keyboard input that's susceptible to SIGWINCH
* interrupts (or any other signal). He also supports timout
* in the absence of user keystrokes or some signal interrupt. */
2013-01-16 11:30:00 +05:30
static inline int ioa (struct timespec *ts) {
fd_set fs;
int rc;
FD_ZERO(&fs);
FD_SET(STDIN_FILENO, &fs);
#ifdef SIGNALS_LESS // conditional comments are silly, but help in documenting
2013-01-16 11:30:00 +05:30
// hold here until we've got keyboard input, any signal except SIGWINCH
// or (optionally) we timeout with nanosecond granularity
#else
// hold here until we've got keyboard input, any signal (including SIGWINCH)
// or (optionally) we timeout with nanosecond granularity
#endif
2013-01-16 11:30:00 +05:30
rc = pselect(STDIN_FILENO + 1, &fs, NULL, NULL, ts, &Sigwinch_set);
if (rc < 0) rc = 0;
return rc;
} // end: ioa
2011-03-31 16:45:12 +05:30
/*
* This routine isolates ALL user INPUT and ensures that we
* wont be mixing I/O from stdio and low-level read() requests */
static int ioch (int ech, char *buf, unsigned cnt) {
2011-03-31 16:45:12 +05:30
int rc = -1;
#ifdef TERMIOS_ONLY
2011-03-31 16:45:12 +05:30
if (ech) {
tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_tweaked);
rc = read(STDIN_FILENO, buf, cnt);
tcsetattr(STDIN_FILENO, TCSAFLUSH, &Tty_raw);
} else {
if (ioa(NULL))
2011-03-31 16:45:12 +05:30
rc = read(STDIN_FILENO, buf, cnt);
}
#else
(void)ech;
if (ioa(NULL))
2011-03-31 16:45:12 +05:30
rc = read(STDIN_FILENO, buf, cnt);
#endif
// zero means EOF, might happen if we erroneously get detached from terminal
if (0 == rc) bye_bye(NULL);
// it may have been the beginning of a lengthy escape sequence
tcflush(STDIN_FILENO, TCIFLUSH);
// note: we do NOT produce a valid 'string'
2011-03-31 16:45:12 +05:30
return rc;
} // end: ioch
2011-03-31 16:45:12 +05:30
/*
* Support for single or multiple keystroke input AND
* escaped cursor motion keys.
2011-03-31 16:45:12 +05:30
* note: we support more keys than we currently need, in case
* we attract new consumers in the future */
static int iokey (int action) {
2011-03-31 16:45:12 +05:30
static char buf12[CAPBUFSIZ], buf13[CAPBUFSIZ]
, buf14[CAPBUFSIZ], buf15[CAPBUFSIZ];
static struct {
const char *str;
int key;
} tinfo_tab[] = {
{ "\033\n",kbd_ENTER }, { NULL, kbd_UP }, { NULL, kbd_DOWN },
{ NULL, kbd_LEFT }, { NULL, kbd_RIGHT }, { NULL, kbd_PGUP },
{ NULL, kbd_PGDN }, { NULL, kbd_HOME }, { NULL, kbd_END },
2011-03-31 16:45:12 +05:30
{ NULL, kbd_BKSP }, { NULL, kbd_INS }, { NULL, kbd_DEL },
// next 4 destined to be meta + arrow keys...
{ buf12, kbd_PGUP }, { buf13, kbd_PGDN },
{ buf14, kbd_HOME }, { buf15, kbd_END },
// remainder are alternatives for above, just in case...
// ( the k,j,l,h entries are the vim cursor motion keys )
{ "\033\\", kbd_UP }, { "\033/", kbd_DOWN }, /* meta+ \,/ */
{ "\033<", kbd_LEFT }, { "\033>", kbd_RIGHT }, /* meta+ <,> */
{ "\033k", kbd_UP }, { "\033j", kbd_DOWN }, /* meta+ k,j */
{ "\033h", kbd_LEFT }, { "\033l", kbd_RIGHT }, /* meta+ h,l */
{ "\033\013", kbd_PGUP }, { "\033\012", kbd_PGDN }, /* ctrl+meta+ k,j */
{ "\033\010", kbd_HOME }, { "\033\014", kbd_END } /* ctrl+meta+ h,l */
};
#ifdef TERMIOS_ONLY
char buf[SMLBUFSIZ], *pb;
#else
static char buf[SMLBUFSIZ];
static int pos, len;
char *pb;
#endif
2011-03-31 16:45:12 +05:30
int i;
if (action == 0) {
2011-03-31 16:45:12 +05:30
#define tOk(s) s ? s : ""
tinfo_tab[1].str = tOk(key_up);
tinfo_tab[2].str = tOk(key_down);
tinfo_tab[3].str = tOk(key_left);
tinfo_tab[4].str = tOk(key_right);
2011-03-31 16:45:12 +05:30
tinfo_tab[5].str = tOk(key_ppage);
tinfo_tab[6].str = tOk(key_npage);
tinfo_tab[7].str = tOk(key_home);
tinfo_tab[8].str = tOk(key_end);
2011-03-31 16:45:12 +05:30
tinfo_tab[9].str = tOk(key_backspace);
tinfo_tab[10].str = tOk(key_ic);
tinfo_tab[11].str = tOk(key_dc);
STRLCPY(buf12, fmtmk("\033%s", tOk(key_up)));
STRLCPY(buf13, fmtmk("\033%s", tOk(key_down)));
STRLCPY(buf14, fmtmk("\033%s", tOk(key_left)));
STRLCPY(buf15, fmtmk("\033%s", tOk(key_right)));
2011-03-31 16:45:12 +05:30
// next is critical so returned results match bound terminfo keys
putp(tOk(keypad_xmit));
// ( converse keypad_local issued at pause/pgm end, just in case )
2011-03-31 16:45:12 +05:30
return 0;
#undef tOk
}
if (action == 1) {
memset(buf, '\0', sizeof(buf));
if (1 > ioch(0, buf, sizeof(buf)-1)) return 0;
}
#ifndef TERMIOS_ONLY
if (action == 2) {
if (pos < len)
return buf[pos++]; // exhaust prior keystrokes
pos = len = 0;
memset(buf, '\0', sizeof(buf));
if (1 > ioch(0, buf, sizeof(buf)-1)) return 0;
if (isprint(buf[0])) { // no need for translation
len = strlen(buf);
pos = 1;
return buf[0];
}
}
#endif
2011-03-31 16:45:12 +05:30
/* some emulators implement 'key repeat' too well and we get duplicate
key sequences -- so we'll focus on the last escaped sequence, while
also allowing use of the meta key... */
if (!(pb = strrchr(buf, '\033'))) pb = buf;
else if (pb > buf && '\033' == *(pb - 1)) --pb;
for (i = 0; i < MAXTBL(tinfo_tab); i++)
if (!strcmp(tinfo_tab[i].str, pb))
return tinfo_tab[i].key;
2002-05-30 09:14:46 +05:30
// no match, so we'll return single non-escaped keystrokes only
if (buf[0] == '\033' && buf[1]) return 0;
2011-03-31 16:45:12 +05:30
return buf[0];
} // end: iokey
2011-03-31 16:45:12 +05:30
#ifdef TERMIOS_ONLY
2011-03-31 16:45:12 +05:30
/*
* Get line oriented interactive input from the user,
* using native tty support */
static char *ioline (const char *prompt) {
top: correct loss of keystrokes paste capability When top introduced true line input editing, the ability to paste keystrokes was lost. This remains a necessary evil so that top has an opportunity to translate cursor motion keystrokes into terminfo escapes during line input. Motion keys themselves, of course, can never be pasted. If pasting ever became more important than input editing, then native termios support should have been available via a define called TERMIOS_ONLY. But a recent commit, eliminating what was thought to be obsolete logic, rendered the alternate linein() function virtually useless. Similar to top-3.2.8, when native termios input is functional, these abberations can be experienced: . cursor motion keys will appear as escapes . excessive input can cause line wraps . ^Z during i/p is not be honored until <Enter> . SIGWINCH during i/p corrupts screen temporarily In hindsight, it now seems that the ability to paste keystrokes may indeed outweigh any shortcomings of native termios support. This is especially true if one is preparing to search ('L') for some lengthy process command line contined in the clipboard. Thus, this patch fixes the alternate linein() function and changes TERMIOS_ONLY to TERMIO_PROXY so that top now defaults to using native termios input. In turn, that will restore the paste keystrokes capability. Reference(s): commit: 045538e01b4588e33bacc1ac57abc799b6d24d7b Reported by: sergio <mailbox@sergio.spb.ru> Bug-Debian: http://bugs.debian.org/663334 Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-12 22:42:12 +05:30
static const char ws[] = "\b\f\n\r\t\v\x1b\x9b"; // 0x1b + 0x9b are escape
2011-03-31 16:45:12 +05:30
static char buf[MEDBUFSIZ];
top: correct loss of keystrokes paste capability When top introduced true line input editing, the ability to paste keystrokes was lost. This remains a necessary evil so that top has an opportunity to translate cursor motion keystrokes into terminfo escapes during line input. Motion keys themselves, of course, can never be pasted. If pasting ever became more important than input editing, then native termios support should have been available via a define called TERMIOS_ONLY. But a recent commit, eliminating what was thought to be obsolete logic, rendered the alternate linein() function virtually useless. Similar to top-3.2.8, when native termios input is functional, these abberations can be experienced: . cursor motion keys will appear as escapes . excessive input can cause line wraps . ^Z during i/p is not be honored until <Enter> . SIGWINCH during i/p corrupts screen temporarily In hindsight, it now seems that the ability to paste keystrokes may indeed outweigh any shortcomings of native termios support. This is especially true if one is preparing to search ('L') for some lengthy process command line contined in the clipboard. Thus, this patch fixes the alternate linein() function and changes TERMIOS_ONLY to TERMIO_PROXY so that top now defaults to using native termios input. In turn, that will restore the paste keystrokes capability. Reference(s): commit: 045538e01b4588e33bacc1ac57abc799b6d24d7b Reported by: sergio <mailbox@sergio.spb.ru> Bug-Debian: http://bugs.debian.org/663334 Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-12 22:42:12 +05:30
char *p;
2002-05-30 09:14:46 +05:30
show_pmt(prompt);
memset(buf, '\0', sizeof(buf));
ioch(1, buf, sizeof(buf)-1);
2002-02-02 04:17:29 +05:30
top: correct loss of keystrokes paste capability When top introduced true line input editing, the ability to paste keystrokes was lost. This remains a necessary evil so that top has an opportunity to translate cursor motion keystrokes into terminfo escapes during line input. Motion keys themselves, of course, can never be pasted. If pasting ever became more important than input editing, then native termios support should have been available via a define called TERMIOS_ONLY. But a recent commit, eliminating what was thought to be obsolete logic, rendered the alternate linein() function virtually useless. Similar to top-3.2.8, when native termios input is functional, these abberations can be experienced: . cursor motion keys will appear as escapes . excessive input can cause line wraps . ^Z during i/p is not be honored until <Enter> . SIGWINCH during i/p corrupts screen temporarily In hindsight, it now seems that the ability to paste keystrokes may indeed outweigh any shortcomings of native termios support. This is especially true if one is preparing to search ('L') for some lengthy process command line contined in the clipboard. Thus, this patch fixes the alternate linein() function and changes TERMIOS_ONLY to TERMIO_PROXY so that top now defaults to using native termios input. In turn, that will restore the paste keystrokes capability. Reference(s): commit: 045538e01b4588e33bacc1ac57abc799b6d24d7b Reported by: sergio <mailbox@sergio.spb.ru> Bug-Debian: http://bugs.debian.org/663334 Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-03-12 22:42:12 +05:30
if ((p = strpbrk(buf, ws))) *p = '\0';
2011-03-31 16:45:12 +05:30
// note: we DO produce a vaid 'string'
return buf;
} // end: ioline
2011-03-31 16:45:12 +05:30
#else
/*
* Get line oriented interactive input from the user,
* going way beyond native tty support by providing:
2011-03-31 16:45:12 +05:30
* . true line editing, not just destructive backspace
* . an input limit sensitive to current screen dimensions
* . ability to recall prior strings for re-input/re-editing */
static char *ioline (const char *prompt) {
#define savMAX 50
2011-03-31 16:45:12 +05:30
// thank goodness memmove allows the two strings to overlap
#define sqzSTR { memmove(&buf[pos], &buf[pos+1], bufMAX-pos); \
buf[sizeof(buf)-1] = '\0'; }
#define expSTR if (len+1 < bufMAX && len+beg+1 < Screen_cols) { \
2011-03-31 16:45:12 +05:30
memmove(&buf[pos+1], &buf[pos], bufMAX-pos); buf[pos] = ' '; }
#define logCOL (pos+1)
#define phyCOL (beg+pos+1)
#define bufMAX ((int)sizeof(buf)-2) // -1 for '\0' string delimeter
static char buf[MEDBUFSIZ+1]; // +1 for '\0' string delimeter
static int ovt;
int beg, pos, len, key, i;
struct lin_s {
struct lin_s *bkw; // ptr to older saved strs
struct lin_s *fwd; // ptr to newer saved strs
char *str; // the saved string
};
static struct lin_s *anchor, *plin;
2011-03-31 16:45:12 +05:30
if (!anchor) {
anchor = alloc_c(sizeof(struct lin_s));
anchor->str = alloc_s(""); // top-of-stack == empty str
}
plin = anchor;
pos = 0;
2011-03-31 16:45:12 +05:30
beg = show_pmt(prompt);
memset(buf, '\0', sizeof(buf));
putp(ovt ? Cap_curs_huge : Cap_curs_norm);
2011-03-31 16:45:12 +05:30
do {
fflush(stdout);
2011-03-31 16:45:12 +05:30
len = strlen(buf);
key = iokey(2);
switch (key) {
case 0:
buf[0] = '\0';
return buf;
2011-03-31 16:45:12 +05:30
case kbd_ESC:
buf[0] = kbd_ESC;
return buf;
2011-03-31 16:45:12 +05:30
case kbd_ENTER:
continue;
case kbd_INS:
ovt = !ovt;
putp(ovt ? Cap_curs_huge : Cap_curs_norm);
break;
2011-03-31 16:45:12 +05:30
case kbd_DEL:
sqzSTR
break;
case kbd_BKSP :
if (0 < pos) { --pos; sqzSTR }
break;
case kbd_LEFT:
if (0 < pos) --pos;
break;
case kbd_RIGHT:
if (pos < len) ++pos;
break;
case kbd_HOME:
pos = 0;
break;
case kbd_END:
pos = len;
break;
case kbd_UP:
if (plin->bkw) {
plin = plin->bkw;
memset(buf, '\0', sizeof(buf));
pos = snprintf(buf, sizeof(buf), "%.*s", Screen_cols - beg - 1, plin->str);
}
break;
case kbd_DOWN:
memset(buf, '\0', sizeof(buf));
if (plin->fwd) plin = plin->fwd;
pos = snprintf(buf, sizeof(buf), "%.*s", Screen_cols - beg - 1, plin->str);
break;
2011-03-31 16:45:12 +05:30
default: // what we REALLY wanted (maybe)
if (isprint(key) && logCOL < bufMAX && phyCOL < Screen_cols) {
if (!ovt) expSTR
2011-03-31 16:45:12 +05:30
buf[pos++] = key;
}
2011-03-31 16:45:12 +05:30
break;
}
putp(fmtmk("%s%s%s", tg2(beg, Msg_row), Cap_clr_eol, buf));
putp(tg2(beg+pos, Msg_row));
} while (key != kbd_ENTER);
2011-03-31 16:45:12 +05:30
// weed out duplicates, including empty strings (top-of-stack)...
for (i = 0, plin = anchor; ; i++) {
#ifdef RECALL_FIXED
if (!STRCMP(plin->str, buf)) // if matched, retain original order
return buf;
#else
if (!STRCMP(plin->str, buf)) { // if matched, rearrange stack order
if (i > 1) { // but not null str or if already #2
if (plin->bkw) // splice around this matched string
plin->bkw->fwd = plin->fwd; // if older exists link to newer
plin->fwd->bkw = plin->bkw; // newer linked to older or NULL
anchor->bkw->fwd = plin; // stick matched on top of former #2
plin->bkw = anchor->bkw; // keep empty string at top-of-stack
plin->fwd = anchor; // then prepare to be the 2nd banana
anchor->bkw = plin; // by sliding us in below the anchor
}
return buf;
}
#endif
if (!plin->bkw) break; // let i equal total stacked strings
plin = plin->bkw; // ( with plin representing bottom )
}
if (i < savMAX)
plin = alloc_c(sizeof(struct lin_s));
else { // when a new string causes overflow
plin->fwd->bkw = NULL; // make next-to-last string new last
free(plin->str); // and toss copy but keep the struct
}
plin->str = alloc_s(buf); // copy user's new unique input line
plin->bkw = anchor->bkw; // keep empty string as top-of-stack
if (plin->bkw) // did we have some already stacked?
plin->bkw->fwd = plin; // yep, so point prior to new string
plin->fwd = anchor; // and prepare to be a second banana
anchor->bkw = plin; // by sliding it in as new number 2!
return buf; // protect our copy, return original
#undef savMAX
2011-03-31 16:45:12 +05:30
#undef sqzSTR
#undef expSTR
#undef logCOL
#undef phyCOL
#undef bufMAX
} // end: ioline
2011-03-31 16:45:12 +05:30
#endif
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
/*
* Make locale unaware float (but maybe restrict to whole numbers). */
static int mkfloat (const char *str, float *num, int whole) {
char tmp[SMLBUFSIZ], *ep;
if (whole) {
*num = (float)strtol(str, &ep, 0);
if (ep != str && *ep == '\0' && *num < INT_MAX)
return 1;
return 0;
}
snprintf(tmp, sizeof(tmp), "%s", str);
*num = strtof(tmp, &ep);
if (*ep != '\0') {
// fallback - try to swap the floating point separator
if (*ep == '.') *ep = ',';
else if (*ep == ',') *ep = '.';
*num = strtof(tmp, &ep);
}
if (ep != tmp && *ep == '\0' && *num < INT_MAX)
return 1;
return 0;
} // end: mkfloat
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
/*
* This routine provides the i/o in support of files whose size
* cannot be determined in advance. Given a stream pointer, he'll
* try to slurp in the whole thing and return a dynamically acquired
* buffer supporting that single string glob.
*
* He always creates a buffer at least READMINSZ big, possibly
* all zeros (an empty string), even if the file wasn't read. */
static int readfile (FILE *fp, char **baddr, size_t *bsize, size_t *bread) {
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
char chunk[4096*16];
size_t num;
*bread = 0;
*bsize = READMINSZ;
*baddr = alloc_c(READMINSZ);
if (fp) {
while (0 < (num = fread(chunk, 1, sizeof(chunk), fp))) {
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
*baddr = alloc_r(*baddr, num + *bsize);
memcpy(*baddr + *bread, chunk, num);
*bread += num;
*bsize += num;
};
*(*baddr + *bread) = '\0';
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
return ferror(fp);
}
return ENOENT;
} // end: readfile
2011-03-31 16:45:12 +05:30
/*###### Small Utility routines ########################################*/
2002-02-02 04:17:29 +05:30
#define GET_NUM_BAD INT_MIN
#define GET_NUM_ESC (INT_MIN + 1)
#define GET_NUM_NOT (INT_MIN + 2)
2011-03-31 16:45:12 +05:30
/*
* Get a float from the user */
static float get_float (const char *prompt) {
2002-05-30 09:14:46 +05:30
char *line;
float f;
line = ioline(prompt);
if (line[0] == kbd_ESC || Frames_signal) return GET_NUM_ESC;
if (!line[0]) return GET_NUM_NOT;
2002-11-08 06:01:28 +05:30
// note: we're not allowing negative floats
if (!mkfloat(line, &f, 0) || f < 0) {
show_msg(N_txt(BAD_numfloat_txt));
return GET_NUM_BAD;
2002-05-30 09:14:46 +05:30
}
return f;
2011-03-31 16:45:12 +05:30
} // end: get_float
2002-02-02 04:17:29 +05:30
2011-03-31 16:45:12 +05:30
/*
* Get an integer from the user, returning INT_MIN for error */
static int get_int (const char *prompt) {
2002-05-30 09:14:46 +05:30
char *line;
float f;
2002-05-30 09:14:46 +05:30
line = ioline(prompt);
if (line[0] == kbd_ESC || Frames_signal) return GET_NUM_ESC;
if (!line[0]) return GET_NUM_NOT;
2002-11-08 06:01:28 +05:30
// note: we've got to allow negative ints (renice)
if (!mkfloat(line, &f, 1)) {
show_msg(N_txt(BAD_integers_txt));
return GET_NUM_BAD;
2002-05-30 09:14:46 +05:30
}
return (int)f;
2011-03-31 16:45:12 +05:30
} // end: get_int
2002-02-02 04:17:29 +05:30
2002-05-30 09:14:46 +05:30
/*
* Make a hex value, and maybe suppress zeroes. */
static inline const char *hex_make (KLONG num, int noz) {
2011-03-31 16:45:12 +05:30
static char buf[SMLBUFSIZ];
int i;
2002-02-02 04:17:29 +05:30
#ifdef CASEUP_HEXES
snprintf(buf, sizeof(buf), "%08" KLF "X", num);
2002-05-30 09:14:46 +05:30
#else
snprintf(buf, sizeof(buf), "%08" KLF "x", num);
2002-05-30 09:14:46 +05:30
#endif
if (noz)
for (i = 0; buf[i]; i++)
if ('0' == buf[i])
buf[i] = '.';
return buf;
} // end: hex_make
2002-10-07 01:42:08 +05:30
2002-12-10 08:31:17 +05:30
/*
* This sructure is hung from a WIN_t when other filtering is active */
struct osel_s {
struct osel_s *nxt; // the next criteria or NULL.
int (*rel)(const char *, const char *); // relational strings compare
char *(*sel)(const char *, const char *); // for selection str compares
char *raw; // raw user input (dup check)
char *val; // value included or excluded
int ops; // filter delimiter/operation
int inc; // include == 1, exclude == 0
int enu; // field (procflag) to filter
};
/*
* A function to turn off entire other filtering in the given window */
static void osel_clear (WIN_t *q) {
struct osel_s *osel = q->osel_1st;
while (osel) {
struct osel_s *nxt = osel->nxt;
free(osel->val);
free(osel->raw);
free(osel);
osel = nxt;
}
q->osel_tot = 0;
q->osel_1st = NULL;
free (q->osel_prt);
q->osel_prt = NULL;
#ifndef USE_X_COLHDR
OFFw(Curwin, NOHISEL_xxx);
#endif
} // end: osel_clear
/*
* Determine if there are matching values or relationships among the
* other criteria in this passed window -- it's called from only one
* place, and likely inlined even without the directive */
static inline int osel_matched (const WIN_t *q, FLG_t enu, const char *str) {
struct osel_s *osel = q->osel_1st;
while (osel) {
if (osel->enu == enu) {
int r;
switch (osel->ops) {
case '<': // '<' needs the r < 0 unless
r = osel->rel(str, osel->val); // '!' which needs an inverse
if ((r >= 0 && osel->inc) || (r < 0 && !osel->inc)) return 0;
break;
case '>': // '>' needs the r > 0 unless
r = osel->rel(str, osel->val); // '!' which needs an inverse
if ((r <= 0 && osel->inc) || (r > 0 && !osel->inc)) return 0;
break;
default:
{ char *p = osel->sel(str, osel->val);
if ((!p && osel->inc) || (p && !osel->inc)) return 0;
}
break;
}
}
osel = osel->nxt;
}
return 1;
} // end: osel_matched
2011-03-31 16:45:12 +05:30
/*
* Validate the passed string as a user name or number,
* and/or update the window's 'u/U' selection stuff. */
static const char *user_certify (WIN_t *q, const char *str, char typ) {
struct passwd *pwd;
2002-12-10 08:31:17 +05:30
char *endp;
2011-03-31 16:45:12 +05:30
uid_t num;
q->usrseltyp = 0;
q->usrselflg = 1;
2011-03-31 16:45:12 +05:30
Monpidsidx = 0;
if (*str) {
if ('!' == *str) { ++str; q->usrselflg = 0; }
2011-03-31 16:45:12 +05:30
num = (uid_t)strtoul(str, &endp, 0);
if ('\0' == *endp) {
2011-03-31 16:45:12 +05:30
pwd = getpwuid(num);
if (!pwd) {
/* allow foreign users, from e.g within chroot
( thanks Dr. Werner Fink <werner@suse.de> ) */
q->usrseluid = num;
q->usrseltyp = typ;
return NULL;
}
} else
2011-03-31 16:45:12 +05:30
pwd = getpwnam(str);
if (!pwd) return N_txt(BAD_username_txt);
2011-03-31 16:45:12 +05:30
q->usrseluid = pwd->pw_uid;
q->usrseltyp = typ;
2002-12-10 08:31:17 +05:30
}
2011-03-31 16:45:12 +05:30
return NULL;
} // end: user_certify
2002-12-10 08:31:17 +05:30
2002-02-02 04:17:29 +05:30
2002-05-30 09:14:46 +05:30
/*
2011-03-31 16:45:12 +05:30
* Determine if this proc_t matches the 'u/U' selection criteria
* for a given window -- it's called from only one place, and
* likely inlined even without the directive */
static inline int user_matched (const WIN_t *q, const proc_t *p) {
2011-03-31 16:45:12 +05:30
switch(q->usrseltyp) {
case 0: // uid selection inactive
return 1;
2011-03-31 16:45:12 +05:30
case 'U': // match any uid
if (p->ruid == q->usrseluid) return q->usrselflg;
if (p->suid == q->usrseluid) return q->usrselflg;
if (p->fuid == q->usrseluid) return q->usrselflg;
2011-03-31 16:45:12 +05:30
// fall through...
case 'u': // match effective uid
if (p->euid == q->usrseluid) return q->usrselflg;
2011-03-31 16:45:12 +05:30
// fall through...
default: // no match...
2011-03-31 16:45:12 +05:30
;
}
return !q->usrselflg;
2011-03-31 16:45:12 +05:30
} // end: user_matched
/*###### Basic Formatting support ######################################*/
/*
* Just do some justify stuff, then add post column padding. */
static inline const char *justify_pad (const char *str, int width, int justr) {
static char l_fmt[] = "%-*.*s%s", r_fmt[] = "%*.*s%s";
static char buf[SCREENMAX];
snprintf(buf, sizeof(buf), justr ? r_fmt : l_fmt, width, width, str, COLPADSTR);
return buf;
} // end: justify_pad
/*
* Make and then justify a single character. */
static inline const char *make_chr (const char ch, int width, int justr) {
static char buf[SMLBUFSIZ];
snprintf(buf, sizeof(buf), "%c", ch);
return justify_pad(buf, width, justr);
} // end: make_chr
/*
* Make and then justify an integer NOT subject to scaling,
* and include a visual clue should tuncation be necessary. */
static inline const char *make_num (long num, int width, int justr, int col, int noz) {
static char buf[SMLBUFSIZ];
buf[0] = '\0';
if (noz && Rc.zero_suppress && 0 == num)
goto end_justifies;
if (width < snprintf(buf, sizeof(buf), "%ld", num)) {
buf[width-1] = COLPLUSCH;
AUTOX_COL(col);
}
end_justifies:
return justify_pad(buf, width, justr);
} // end: make_num
/*
* Make and then justify a character string,
* and include a visual clue should tuncation be necessary. */
static inline const char *make_str (const char *str, int width, int justr, int col) {
static char buf[SCREENMAX];
if (width < snprintf(buf, sizeof(buf), "%s", str)) {
buf[width-1] = COLPLUSCH;
AUTOX_COL(col);
}
return justify_pad(buf, width, justr);
} // end: make_str
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
/*
* Do some scaling then justify stuff.
* We'll interpret 'num' as a kibibytes quantity and try to
* format it to reach 'target' while also fitting 'width'. */
static const char *scale_mem (int target, unsigned long num, int width, int justr) {
// SK_Kb SK_Mb SK_Gb SK_Tb SK_Pb SK_Eb
#ifdef BOOST_MEMORY
static const char *fmttab[] = { "%.0f", "%#.1f%c", "%#.3f%c", "%#.3f%c", "%#.3f%c", NULL };
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
#else
static const char *fmttab[] = { "%.0f", "%.1f%c", "%.1f%c", "%.1f%c", "%.1f%c", NULL };
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
#endif
static char buf[SMLBUFSIZ];
float scaled_num;
char *psfx;
int i;
buf[0] = '\0';
if (Rc.zero_suppress && 0 >= num)
goto end_justifies;
scaled_num = num;
for (i = SK_Kb, psfx = Scaled_sfxtab; i < SK_Eb; psfx++, i++) {
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
if (i >= target
&& (width >= snprintf(buf, sizeof(buf), fmttab[i], scaled_num, *psfx)))
goto end_justifies;
scaled_num /= 1024.0;
}
// well shoot, this outta' fit...
snprintf(buf, sizeof(buf), "?");
end_justifies:
return justify_pad(buf, width, justr);
} // end: scale_mem
/*
* Do some scaling then justify stuff. */
static const char *scale_num (unsigned long num, int width, int justr) {
static char buf[SMLBUFSIZ];
float scaled_num;
char *psfx;
buf[0] = '\0';
if (Rc.zero_suppress && 0 >= num)
goto end_justifies;
if (width >= snprintf(buf, sizeof(buf), "%lu", num))
goto end_justifies;
scaled_num = num;
for (psfx = Scaled_sfxtab; 0 < *psfx; psfx++) {
scaled_num /= 1024.0;
if (width >= snprintf(buf, sizeof(buf), "%.1f%c", scaled_num, *psfx))
goto end_justifies;
if (width >= snprintf(buf, sizeof(buf), "%.0f%c", scaled_num, *psfx))
goto end_justifies;
}
// well shoot, this outta' fit...
snprintf(buf, sizeof(buf), "?");
end_justifies:
return justify_pad(buf, width, justr);
} // end: scale_num
/*
* Make and then justify a percentage, with decreasing precision. */
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
static const char *scale_pcnt (float num, int width, int justr) {
static char buf[SMLBUFSIZ];
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
buf[0] = '\0';
if (Rc.zero_suppress && 0 >= num)
goto end_justifies;
#ifdef BOOST_PERCNT
if (width >= snprintf(buf, sizeof(buf), "%#.3f", num))
goto end_justifies;
if (width >= snprintf(buf, sizeof(buf), "%#.2f", num))
goto end_justifies;
#endif
if (width >= snprintf(buf, sizeof(buf), "%#.1f", num))
goto end_justifies;
if (width >= snprintf(buf, sizeof(buf), "%*.0f", width, num))
goto end_justifies;
// well shoot, this outta' fit...
snprintf(buf, sizeof(buf), "?");
end_justifies:
return justify_pad(buf, width, justr);
} // end: scale_pcnt
/*
* Do some scaling stuff.
* Format 'tics' to fit 'width', then justify it. */
static const char *scale_tics (TIC_t tics, int width, int justr) {
#ifdef CASEUP_SUFIX
#define HH "%uH" // nls_maybe
#define DD "%uD"
#define WW "%uW"
#else
#define HH "%uh" // nls_maybe
#define DD "%ud"
#define WW "%uw"
#endif
static char buf[SMLBUFSIZ];
unsigned long nt; // narrow time, for speed on 32-bit
unsigned cc; // centiseconds
unsigned nn; // multi-purpose whatever
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
buf[0] = '\0';
nt = (tics * 100ull) / Hertz; // up to 68 weeks of cpu time
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
if (Rc.zero_suppress && 0 >= nt)
goto end_justifies;
cc = nt % 100; // centiseconds past second
nt /= 100; // total seconds
nn = nt % 60; // seconds past the minute
nt /= 60; // total minutes
if (width >= snprintf(buf, sizeof(buf), "%lu:%02u.%02u", nt, nn, cc))
goto end_justifies;
if (width >= snprintf(buf, sizeof(buf), "%lu:%02u", nt, nn))
goto end_justifies;
nn = nt % 60; // minutes past the hour
nt /= 60; // total hours
if (width >= snprintf(buf, sizeof(buf), "%lu,%02u", nt, nn))
goto end_justifies;
nn = nt; // now also hours
if (width >= snprintf(buf, sizeof(buf), HH, nn))
goto end_justifies;
nn /= 24; // now days
if (width >= snprintf(buf, sizeof(buf), DD, nn))
goto end_justifies;
nn /= 7; // now weeks
if (width >= snprintf(buf, sizeof(buf), WW, nn))
goto end_justifies;
// well shoot, this outta' fit...
snprintf(buf, sizeof(buf), "?");
end_justifies:
return justify_pad(buf, width, justr);
#undef HH
#undef DD
#undef WW
} // end: scale_tics
2011-03-31 16:45:12 +05:30
/*###### Fields Management support #####################################*/
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/* These are the Fieldstab.lflg values used here and in calibrate_fields.
(own identifiers as documentation and protection against changes) */
#define L_stat PROC_FILLSTAT
#define L_statm PROC_FILLMEM
#define L_status PROC_FILLSTATUS
#define L_CGROUP PROC_EDITCGRPCVT | PROC_FILLCGROUP
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 L_CMDLINE PROC_EDITCMDLCVT | PROC_FILLARG
#define L_ENVIRON PROC_EDITENVRCVT | PROC_FILLENV
2011-03-31 16:45:12 +05:30
#define L_EUSER PROC_FILLUSR
#define L_OUSER PROC_FILLSTATUS | PROC_FILLUSR
#define L_EGROUP PROC_FILLSTATUS | PROC_FILLGRP
#define L_SUPGRP PROC_FILLSTATUS | PROC_FILLSUPGRP
#define L_NS PROC_FILLNS
#define L_LXC PROC_FILL_LXC
#define L_OOM PROC_FILLOOM
2011-03-31 16:45:12 +05:30
// make 'none' non-zero (used to be important to Frames_libflags)
#define L_NONE PROC_SPARE_1
// from 'status' or 'stat' (favor stat), via bits not otherwise used
2011-03-31 16:45:12 +05:30
#define L_EITHER PROC_SPARE_2
// for calibrate_fields and summary_show 1st pass
#define L_DEFAULT PROC_FILLSTAT
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/* These are our gosh darn 'Fields' !
They MUST be kept in sync with pflags !! */
2011-03-31 16:45:12 +05:30
static FLD_t Fieldstab[] = {
// a temporary macro, soon to be undef'd...
#define SF(f) (QFP_t)SCB_NAME(f)
// these identifiers reflect the default column alignment but they really
// contain the WIN_t flag used to check/change justification at run-time!
#define A_right Show_JRNUMS /* toggled with upper case 'J' */
#define A_left Show_JRSTRS /* toggled with lower case 'j' */
2011-03-31 16:45:12 +05:30
/* .width anomalies:
a -1 width represents variable width columns
a 0 width represents columns set once at startup (see zap_fieldstab)
.lflg anomalies:
EU_UED, L_NONE - natural outgrowth of 'stat()' in readproc (euid)
EU_CPU, L_stat - never filled by libproc, but requires times (pcpu)
EU_CMD, L_stat - may yet require L_CMDLINE in calibrate_fields (cmd/cmdline)
L_EITHER - favor L_stat (L_status == ++cost of gpref & hash scheme)
.width .scale .align .sort .lflg
------ ------ -------- -------- -------- */
{ 0, -1, A_right, SF(PID), L_NONE },
{ 0, -1, A_right, SF(PPD), L_EITHER },
{ 5, -1, A_right, SF(UED), L_NONE },
{ 8, -1, A_left, SF(UEN), L_EUSER },
{ 5, -1, A_right, SF(URD), L_status },
{ 8, -1, A_left, SF(URN), L_OUSER },
{ 5, -1, A_right, SF(USD), L_status },
{ 8, -1, A_left, SF(USN), L_OUSER },
{ 5, -1, A_right, SF(GID), L_NONE },
{ 8, -1, A_left, SF(GRP), L_EGROUP },
{ 0, -1, A_right, SF(PGD), L_stat },
{ 8, -1, A_left, SF(TTY), L_stat },
{ 0, -1, A_right, SF(TPG), L_stat },
{ 0, -1, A_right, SF(SID), L_stat },
{ 3, -1, A_right, SF(PRI), L_stat },
{ 3, -1, A_right, SF(NCE), L_stat },
{ 3, -1, A_right, SF(THD), L_EITHER },
{ 0, -1, A_right, SF(CPN), L_stat },
{ 0, -1, A_right, SF(CPU), L_stat },
{ 6, -1, A_right, SF(TME), L_stat },
{ 9, -1, A_right, SF(TME), L_stat }, // EU_TM2 slot
#ifdef BOOST_PERCNT
{ 5, -1, A_right, SF(RES), L_statm }, // EU_MEM slot
2011-03-31 16:45:12 +05:30
#else
{ 4, -1, A_right, SF(RES), L_statm }, // EU_MEM slot
#endif
{ 7, SK_Kb, A_right, SF(VRT), L_statm },
{ 6, SK_Kb, A_right, SF(SWP), L_status },
{ 6, SK_Kb, A_right, SF(RES), L_statm },
{ 6, SK_Kb, A_right, SF(COD), L_statm },
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
{ 7, SK_Kb, A_right, SF(DAT), L_statm },
{ 6, SK_Kb, A_right, SF(SHR), L_statm },
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
{ 4, -1, A_right, SF(FL1), L_stat },
{ 4, -1, A_right, SF(FL2), L_stat },
{ 4, -1, A_right, SF(DRT), L_statm },
{ 1, -1, A_right, SF(STA), L_EITHER },
{ -1, -1, A_left, SF(CMD), L_EITHER },
{ 10, -1, A_left, SF(WCH), L_stat },
{ 8, -1, A_left, SF(FLG), L_stat },
{ -1, -1, A_left, SF(CGR), L_CGROUP },
{ -1, -1, A_left, SF(SGD), L_status },
{ -1, -1, A_left, SF(SGN), L_SUPGRP },
{ 0, -1, A_right, SF(TGD), L_NONE },
{ 5, -1, A_right, SF(OOA), L_OOM },
{ 4, -1, A_right, SF(OOM), L_OOM },
{ -1, -1, A_left, SF(ENV), L_ENVIRON },
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
{ 3, -1, A_right, SF(FV1), L_stat },
{ 3, -1, A_right, SF(FV2), L_stat },
{ 6, SK_Kb, A_right, SF(USE), L_status },
{ 10, -1, A_right, SF(NS1), L_NS }, // IPCNS
{ 10, -1, A_right, SF(NS2), L_NS }, // MNTNS
{ 10, -1, A_right, SF(NS3), L_NS }, // NETNS
{ 10, -1, A_right, SF(NS4), L_NS }, // PIDNS
{ 10, -1, A_right, SF(NS5), L_NS }, // USERNS
{ 10, -1, A_right, SF(NS6), L_NS }, // UTSNS
{ 8, -1, A_left, SF(LXC), L_LXC },
{ 6, SK_Kb, A_right, SF(RZA), L_status },
{ 6, SK_Kb, A_right, SF(RZF), L_status },
{ 6, SK_Kb, A_right, SF(RZL), L_status },
{ 6, SK_Kb, A_right, SF(RZS), L_status },
{ -1, -1, A_left, SF(CGN), L_CGROUP },
{ 0, -1, A_right, SF(NMA), L_stat },
2011-03-31 16:45:12 +05:30
#undef SF
#undef A_left
#undef A_right
2011-03-31 16:45:12 +05:30
};
/*
* A calibrate_fields() *Helper* function to refresh the
* cached screen geometry and related variables */
static void adj_geometry (void) {
static size_t pseudo_max = 0;
static int w_set = 0, w_cols = 0, w_rows = 0;
2011-03-31 16:45:12 +05:30
struct winsize wz;
2002-02-02 04:17:29 +05:30
2011-03-31 16:45:12 +05:30
Screen_cols = columns; // <term.h>
Screen_rows = lines; // <term.h>
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
if (-1 != ioctl(STDOUT_FILENO, TIOCGWINSZ, &wz)
&& 0 < wz.ws_col && 0 < wz.ws_row) {
Screen_cols = wz.ws_col;
Screen_rows = wz.ws_row;
}
#ifndef RMAN_IGNORED
// be crudely tolerant of crude tty emulators
if (Cap_avoid_eol) Screen_cols--;
#endif
// we might disappoint some folks (but they'll deserve it)
if (SCREENMAX < Screen_cols) Screen_cols = SCREENMAX;
if (!w_set) {
if (Width_mode > 0) // -w with arg, we'll try to honor
w_cols = Width_mode;
else
if (Width_mode < 0) { // -w without arg, try environment
char *env_columns = getenv("COLUMNS"),
*env_lines = getenv("LINES"),
*ep;
if (env_columns && *env_columns) {
long t, tc = 0;
t = strtol(env_columns, &ep, 0);
if (!*ep && (t > 0) && (t <= 0x7fffffffL)) tc = t;
if (0 < tc) w_cols = (int)tc;
}
if (env_lines && *env_lines) {
long t, tr = 0;
t = strtol(env_lines, &ep, 0);
if (!*ep && (t > 0) && (t <= 0x7fffffffL)) tr = t;
if (0 < tr) w_rows = (int)tr;
}
if (!w_cols) w_cols = SCREENMAX;
if (w_cols && w_cols < W_MIN_COL) w_cols = W_MIN_COL;
if (w_rows && w_rows < W_MIN_ROW) w_rows = W_MIN_ROW;
}
if (w_cols > SCREENMAX) w_cols = SCREENMAX;
w_set = 1;
}
2011-03-31 16:45:12 +05:30
/* keep our support for output optimization in sync with current reality
note: when we're in Batch mode, we don't really need a Pseudo_screen
and when not Batch, our buffer will contain 1 extra 'line' since
Msg_row is never represented -- but it's nice to have some space
between us and the great-beyond... */
if (Batch) {
if (w_cols) Screen_cols = w_cols;
Screen_rows = w_rows ? w_rows : INT_MAX;
Pseudo_size = (sizeof(*Pseudo_screen) * ROWMAXSIZ);
} else {
if (w_cols && w_cols < Screen_cols) Screen_cols = w_cols;
if (w_rows && w_rows < Screen_rows) Screen_rows = w_rows;
Pseudo_size = (sizeof(*Pseudo_screen) * ROWMAXSIZ) * Screen_rows;
}
2011-03-31 16:45:12 +05:30
// we'll only grow our Pseudo_screen, never shrink it
if (pseudo_max < Pseudo_size) {
pseudo_max = Pseudo_size;
Pseudo_screen = alloc_r(Pseudo_screen, pseudo_max);
2011-03-31 16:45:12 +05:30
}
// ensure each row is repainted (just in case)
2011-03-31 16:45:12 +05:30
PSU_CLREOS(0);
// prepare to customize potential cpu/memory graphs
Graph_len = Screen_cols - GRAPH_prefix - GRAPH_actual - GRAPH_suffix;
if (Graph_len >= 0) Graph_len = GRAPH_actual;
else if (Screen_cols > 80) Graph_len = Screen_cols - GRAPH_prefix - GRAPH_suffix;
else Graph_len = 80 - GRAPH_prefix - GRAPH_suffix;
Graph_adj = (float)Graph_len / 100.0;
fflush(stdout);
Frames_signal = BREAK_off;
2011-03-31 16:45:12 +05:30
} // end: adj_geometry
/*
* A calibrate_fields() *Helper* function to build the
* actual column headers and required library flags */
static void build_headers (void) {
2011-03-31 16:45:12 +05:30
FLG_t f;
char *s;
WIN_t *w = Curwin;
#ifdef EQUCOLHDRYES
int x, hdrmax = 0;
#endif
int i;
2011-03-31 16:45:12 +05:30
Frames_libflags = 0;
do {
if (VIZISw(w)) {
memset((s = w->columnhdr), 0, sizeof(w->columnhdr));
if (Rc.mode_altscr) s = scat(s, fmtmk("%d", w->winnum));
for (i = 0; i < w->maxpflgs; i++) {
f = w->procflgs[i];
#ifdef USE_X_COLHDR
if (CHKw(w, Show_HICOLS) && f == w->rc.sortindx) {
s = scat(s, fmtmk("%s%s", Caps_off, w->capclr_msg));
w->hdrcaplen += strlen(Caps_off) + strlen(w->capclr_msg);
}
#else
if (EU_MAXPFLGS <= f) continue;
#endif
if (EU_CMD == f && CHKw(w, Show_CMDLIN)) Frames_libflags |= L_CMDLINE;
Frames_libflags |= Fieldstab[f].lflg;
s = scat(s, justify_pad(N_col(f)
, VARcol(f) ? w->varcolsz : Fieldstab[f].width
, CHKw(w, Fieldstab[f].align)));
#ifdef USE_X_COLHDR
if (CHKw(w, Show_HICOLS) && f == w->rc.sortindx) {
s = scat(s, fmtmk("%s%s", Caps_off, w->capclr_hdr));
w->hdrcaplen += strlen(Caps_off) + strlen(w->capclr_hdr);
}
#endif
2011-03-31 16:45:12 +05:30
}
#ifdef EQUCOLHDRYES
// prepare to even out column header lengths...
if (hdrmax + w->hdrcaplen < (x = strlen(w->columnhdr))) hdrmax = x - w->hdrcaplen;
2011-03-31 16:45:12 +05:30
#endif
// with forest view mode, we'll need tgid, ppid & start_time...
if (CHKw(w, Show_FOREST)) Frames_libflags |= L_stat;
// for 'busy' only processes, we'll need pcpu (utime & stime)...
2011-08-30 17:35:45 +05:30
if (!CHKw(w, Show_IDLEPS)) Frames_libflags |= L_stat;
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
// we must also accommodate an out of view sort field...
f = w->rc.sortindx;
Frames_libflags |= Fieldstab[f].lflg;
if (EU_CMD == f && CHKw(w, Show_CMDLIN)) Frames_libflags |= L_CMDLINE;
// for 'U' filtering we need the other user ids too
if (w->usrseltyp == 'U') Frames_libflags |= L_status;
2011-03-31 16:45:12 +05:30
} // end: VIZISw(w)
2011-03-31 16:45:12 +05:30
if (Rc.mode_altscr) w = w->next;
} while (w != Curwin);
#ifdef EQUCOLHDRYES
/* now we can finally even out column header lengths
(we're assuming entire columnhdr was memset to '\0') */
if (Rc.mode_altscr && SCREENMAX > Screen_cols)
for (i = 0; i < GROUPSMAX; i++) {
w = &Winstk[i];
if (CHKw(w, Show_TASKON))
if (hdrmax + w->hdrcaplen > (x = strlen(w->columnhdr)))
memset(&w->columnhdr[x], ' ', hdrmax + w->hdrcaplen - x);
}
2011-03-31 16:45:12 +05:30
#endif
// finalize/touchup the libproc PROC_FILLxxx flags for current config...
if (Frames_libflags & L_EITHER) {
if (!(Frames_libflags & (L_stat | L_status)))
Frames_libflags |= L_stat;
}
2011-03-31 16:45:12 +05:30
if (!Frames_libflags) Frames_libflags = L_DEFAULT;
if (Monpidsidx) Frames_libflags |= PROC_PID;
} // end: build_headers
/*
* This guy coordinates the activities surrounding the maintenance
* of each visible window's columns headers and the library flags
* required for the openproc interface. */
static void calibrate_fields (void) {
FLG_t f;
char *s;
const char *h;
WIN_t *w = Curwin;
int i, varcolcnt, len;
adj_geometry();
do {
if (VIZISw(w)) {
w->hdrcaplen = 0; // really only used with USE_X_COLHDR
// build window's pflgsall array, establish upper bounds for maxpflgs
for (i = 0, w->totpflgs = 0; i < EU_MAXPFLGS; i++) {
if (FLDviz(w, i)) {
f = FLDget(w, i);
#ifdef USE_X_COLHDR
w->pflgsall[w->totpflgs++] = f;
#else
if (CHKw(w, Show_HICOLS) && f == w->rc.sortindx) {
w->pflgsall[w->totpflgs++] = EU_XON;
w->pflgsall[w->totpflgs++] = f;
w->pflgsall[w->totpflgs++] = EU_XOF;
} else
w->pflgsall[w->totpflgs++] = f;
#endif
}
}
if (!w->totpflgs) w->pflgsall[w->totpflgs++] = EU_PID;
/* build a preliminary columns header not to exceed screen width
while accounting for a possible leading window number */
w->varcolsz = varcolcnt = 0;
*(s = w->columnhdr) = '\0';
if (Rc.mode_altscr) s = scat(s, " ");
for (i = 0; i + w->begpflg < w->totpflgs; i++) {
f = w->pflgsall[i + w->begpflg];
w->procflgs[i] = f;
#ifndef USE_X_COLHDR
if (EU_MAXPFLGS <= f) continue;
#endif
h = N_col(f);
len = (VARcol(f) ? (int)strlen(h) : Fieldstab[f].width) + COLPADSIZ;
// oops, won't fit -- we're outta here...
if (Screen_cols < ((int)(s - w->columnhdr) + len)) break;
if (VARcol(f)) { ++varcolcnt; w->varcolsz += strlen(h); }
s = scat(s, fmtmk("%*.*s", len, len, h));
}
#ifndef USE_X_COLHDR
if (EU_XON == w->procflgs[i - 1]) --i;
#endif
/* establish the final maxpflgs and prepare to grow the variable column
heading(s) via varcolsz - it may be a fib if their pflags weren't
encountered, but that's ok because they won't be displayed anyway */
w->maxpflgs = i;
w->varcolsz += Screen_cols - strlen(w->columnhdr);
if (varcolcnt) w->varcolsz /= varcolcnt;
/* establish the field where all remaining fields would still
fit within screen width, including a leading window number */
*(s = w->columnhdr) = '\0';
if (Rc.mode_altscr) s = scat(s, " ");
for (i = w->totpflgs - 1; -1 < i; i--) {
f = w->pflgsall[i];
#ifndef USE_X_COLHDR
if (EU_MAXPFLGS <= f) { w->endpflg = i; continue; }
#endif
h = N_col(f);
len = (VARcol(f) ? (int)strlen(h) : Fieldstab[f].width) + COLPADSIZ;
if (Screen_cols < ((int)(s - w->columnhdr) + len)) break;
s = scat(s, fmtmk("%*.*s", len, len, h));
w->endpflg = i;
}
#ifndef USE_X_COLHDR
if (EU_XOF == w->pflgsall[w->endpflg]) ++w->endpflg;
#endif
} // end: if (VIZISw(w))
if (Rc.mode_altscr) w = w->next;
} while (w != Curwin);
build_headers();
if (CHKw(Curwin, View_SCROLL))
updt_scroll_msg();
2011-03-31 16:45:12 +05:30
} // end: calibrate_fields
2002-02-02 04:17:29 +05:30
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/*
* Display each field represented in the current window's fieldscur
* array along with its description. Mark with bold and a leading
* asterisk those fields associated with the "on" or "active" state.
*
2011-03-31 16:45:12 +05:30
* Special highlighting will be accorded the "focus" field with such
* highlighting potentially extended to include the description.
*
* Below is the current Fieldstab space requirement and how
* we apportion it. The xSUFX is considered sacrificial,
* something we can reduce or do without.
* 0 1 2 3
* 12345678901234567890123456789012
* * HEADING = Longest Description!
* xPRFX ----------______________________ xSUFX
* ( xPRFX has pos 2 & 10 for 'extending' when at minimums )
*
* The first 4 screen rows are reserved for explanatory text, and
* the maximum number of columns is Screen_cols / xPRFX + 1 space
* between columns. Thus, for example, with 42 fields a tty will
* still remain useable under these extremes:
* rows columns what's
* tty top tty top displayed
* --- --- --- --- ------------------
* 46 42 10 1 xPRFX only
* 46 42 32 1 full xPRFX + xSUFX
* 6 2 231 21 xPRFX only
* 10 6 231 7 full xPRFX + xSUFX
*/
static void display_fields (int focus, int extend) {
#define mkERR { putp("\n"); putp(N_txt(XTRA_winsize_txt)); return; }
#define mxCOL ( (Screen_cols / 11) > 0 ? (Screen_cols / 11) : 1 )
2011-03-31 16:45:12 +05:30
#define yRSVD 4
#define xSUFX 22
#define xPRFX (10 + xadd)
#define xTOTL (xPRFX + xSUFX)
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
int i; // utility int (a row, tot cols, ix)
int smax; // printable width of xSUFX
int xadd = 0; // spacing between data columns
int cmax = Screen_cols; // total data column width
int rmax = Screen_rows - yRSVD; // total useable rows
static int col_sav, row_sav;
2011-03-31 16:45:12 +05:30
i = (EU_MAXPFLGS % mxCOL) ? 1 : 0;
if (rmax < i + (EU_MAXPFLGS / mxCOL)) mkERR;
i = EU_MAXPFLGS / rmax;
if (EU_MAXPFLGS % rmax) ++i;
if (i > 1) { cmax /= i; xadd = 1; }
if (cmax > xTOTL) cmax = xTOTL;
smax = cmax - xPRFX;
if (smax < 0) mkERR;
2011-03-31 16:45:12 +05:30
/* we'll go the extra distance to avoid any potential screen flicker
which occurs under some terminal emulators (but it was our fault) */
if (col_sav != Screen_cols || row_sav != Screen_rows) {
col_sav = Screen_cols;
row_sav = Screen_rows;
putp(Cap_clr_eos);
}
fflush(stdout);
for (i = 0; i < EU_MAXPFLGS; ++i) {
int b = FLDviz(w, i), x = (i / rmax) * cmax, y = (i % rmax) + yRSVD;
const char *e = (i == focus && extend) ? w->capclr_hdr : "";
FLG_t f = FLDget(w, i);
char sbuf[xSUFX+1];
2011-03-31 16:45:12 +05:30
// prep sacrificial suffix
snprintf(sbuf, sizeof(sbuf), "= %s", N_fld(f));
PUTT("%s%c%s%s %s%-7.7s%s%s%s %-*.*s%s"
, tg2(x, y)
2011-03-31 16:45:12 +05:30
, b ? '*' : ' '
, b ? w->cap_bold : Cap_norm
, e
, i == focus ? w->capclr_hdr : ""
, N_col(f)
2011-03-31 16:45:12 +05:30
, Cap_norm
, b ? w->cap_bold : ""
, e
, smax, smax
, sbuf
, Cap_norm);
2011-03-31 16:45:12 +05:30
}
putp(Caps_off);
#undef mkERR
#undef mxCOL
2011-03-31 16:45:12 +05:30
#undef yRSVD
#undef xSUFX
#undef xPRFX
#undef xTOTL
2011-03-31 16:45:12 +05:30
} // end: display_fields
/*
* Manage all fields aspects (order/toggle/sort), for all windows. */
static void fields_utility (void) {
#ifndef SCROLLVAR_NO
#define unSCRL { w->begpflg = w->varcolbeg = 0; OFFw(w, Show_HICOLS); }
#else
#define unSCRL { w->begpflg = 0; OFFw(w, Show_HICOLS); }
#endif
#define swapEM { char c; unSCRL; c = w->rc.fieldscur[i]; \
2011-03-31 16:45:12 +05:30
w->rc.fieldscur[i] = *p; *p = c; p = &w->rc.fieldscur[i]; }
#define spewFI { char *t; f = w->rc.sortindx; t = strchr(w->rc.fieldscur, f + FLD_OFFSET); \
2011-03-31 16:45:12 +05:30
if (!t) t = strchr(w->rc.fieldscur, (f + FLD_OFFSET) | 0x80); \
i = (t) ? (int)(t - w->rc.fieldscur) : 0; }
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
const char *h = NULL;
char *p = NULL;
2011-03-31 16:45:12 +05:30
int i, key;
FLG_t f;
spewFI
signify_that:
putp(Cap_clr_scr);
adj_geometry();
2011-03-31 16:45:12 +05:30
do {
if (!h) h = N_col(f);
putp(Cap_home);
show_special(1, fmtmk(N_unq(FIELD_header_fmt)
, w->grpname, CHKw(w, Show_FOREST) ? N_txt(FOREST_views_txt) : h));
display_fields(i, (p != NULL));
fflush(stdout);
if (Frames_signal) goto signify_that;
key = iokey(1);
if (key < 1) goto signify_that;
switch (key) {
2011-03-31 16:45:12 +05:30
case kbd_UP:
if (i > 0) { --i; if (p) swapEM }
break;
case kbd_DOWN:
if (i + 1 < EU_MAXPFLGS) { ++i; if (p) swapEM }
2011-03-31 16:45:12 +05:30
break;
case kbd_LEFT:
case kbd_ENTER:
p = NULL;
break;
case kbd_RIGHT:
p = &w->rc.fieldscur[i];
break;
case kbd_HOME:
case kbd_PGUP:
if (!p) i = 0;
2011-03-31 16:45:12 +05:30
break;
case kbd_END:
case kbd_PGDN:
if (!p) i = EU_MAXPFLGS - 1;
2011-03-31 16:45:12 +05:30
break;
case kbd_SPACE:
case 'd':
if (!p) { FLDtog(w, i); unSCRL }
2011-03-31 16:45:12 +05:30
break;
case 's':
2011-08-30 17:35:45 +05:30
#ifdef TREE_NORESET
if (!p && !CHKw(w, Show_FOREST)) { w->rc.sortindx = f = FLDget(w, i); h = NULL; unSCRL }
#else
if (!p) { w->rc.sortindx = f = FLDget(w, i); h = NULL; unSCRL; OFFw(w, Show_FOREST); }
#endif
2011-03-31 16:45:12 +05:30
break;
case 'a':
case 'w':
Curwin = w = ('a' == key) ? w->next : w->prev;
spewFI
h = p = NULL;
2011-03-31 16:45:12 +05:30
break;
default: // keep gcc happy
break;
}
} while (key != 'q' && key != kbd_ESC);
#undef unSCRL
2011-03-31 16:45:12 +05:30
#undef swapEM
#undef spewFI
} // end: fields_utility
/*
* This routine takes care of auto sizing field widths
* if/when the user sets Rc.fixed_widest to -1. Along the
* way he reinitializes some things for the next frame. */
static inline void widths_resize (void) {
int i;
// next var may also be set by the guys that actually truncate stuff
Autox_found = 0;
for (i = 0; i < EU_MAXPFLGS; i++) {
if (Autox_array[i]) {
Fieldstab[i].width++;
Autox_array[i] = 0;
Autox_found = 1;
}
}
if (Autox_found) calibrate_fields();
} // end: widths_resize
/*
* This routine exists just to consolidate most of the messin'
* around with the Fieldstab array and some related stuff. */
2011-03-31 16:45:12 +05:30
static void zap_fieldstab (void) {
static int once;
unsigned digits;
2011-03-31 16:45:12 +05:30
char buf[8];
if (!once) {
Fieldstab[EU_PID].width = Fieldstab[EU_PPD].width
= Fieldstab[EU_PGD].width = Fieldstab[EU_SID].width
= Fieldstab[EU_TGD].width = Fieldstab[EU_TPG].width = 5;
if (5 < (digits = get_pid_digits())) {
if (10 < digits) error_exit(N_txt(FAIL_widepid_txt));
Fieldstab[EU_PID].width = Fieldstab[EU_PPD].width
= Fieldstab[EU_PGD].width = Fieldstab[EU_SID].width
= Fieldstab[EU_TGD].width = Fieldstab[EU_TPG].width = digits;
}
once = 1;
}
2011-03-31 16:45:12 +05:30
/*** hotplug_acclimated ***/
Fieldstab[EU_CPN].width = 1;
if (1 < (digits = (unsigned)snprintf(buf, sizeof(buf), "%u", (unsigned)smp_num_cpus))) {
if (5 < digits) error_exit(N_txt(FAIL_widecpu_txt));
Fieldstab[EU_CPN].width = digits;
2011-03-31 16:45:12 +05:30
}
Fieldstab[EU_NMA].width = 2;
if (2 < (digits = (unsigned)snprintf(buf, sizeof(buf), "%u", (unsigned)Numa_node_tot))) {
Fieldstab[EU_NMA].width = digits;
}
2011-03-31 16:45:12 +05:30
#ifdef BOOST_PERCNT
Cpu_pmax = 99.9;
Fieldstab[EU_CPU].width = 5;
if (Rc.mode_irixps && smp_num_cpus > 1 && !Thread_mode) {
Cpu_pmax = 100.0 * smp_num_cpus;
if (smp_num_cpus > 10) {
if (Cpu_pmax > 99999.0) Cpu_pmax = 99999.0;
} else {
if (Cpu_pmax > 999.9) Cpu_pmax = 999.9;
2011-08-30 17:35:45 +05:30
}
2011-03-31 16:45:12 +05:30
}
#else
Cpu_pmax = 99.9;
Fieldstab[EU_CPU].width = 4;
if (Rc.mode_irixps && smp_num_cpus > 1 && !Thread_mode) {
Cpu_pmax = 100.0 * smp_num_cpus;
if (smp_num_cpus > 10) {
if (Cpu_pmax > 99999.0) Cpu_pmax = 99999.0;
} else {
if (Cpu_pmax > 999.9) Cpu_pmax = 999.9;
}
Fieldstab[EU_CPU].width = 5;
}
#endif
2011-08-30 17:35:45 +05:30
/* and accommodate optional wider non-scalable columns (maybe) */
if (!AUTOX_MODE) {
int i;
Fieldstab[EU_UED].width = Fieldstab[EU_URD].width
= Fieldstab[EU_USD].width = Fieldstab[EU_GID].width
= Rc.fixed_widest ? 5 + Rc.fixed_widest : 5;
Fieldstab[EU_UEN].width = Fieldstab[EU_URN].width
= Fieldstab[EU_USN].width = Fieldstab[EU_GRP].width
= Rc.fixed_widest ? 8 + Rc.fixed_widest : 8;
Fieldstab[EU_TTY].width = Fieldstab[EU_LXC].width
= Rc.fixed_widest ? 8 + Rc.fixed_widest : 8;
Fieldstab[EU_WCH].width
= Rc.fixed_widest ? 10 + Rc.fixed_widest : 10;
for (i = EU_NS1; i < EU_NS1 + NUM_NS; i++)
Fieldstab[i].width
= Rc.fixed_widest ? 10 + Rc.fixed_widest : 10;
}
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
/* plus user selectable scaling */
Fieldstab[EU_VRT].scale = Fieldstab[EU_SWP].scale
= Fieldstab[EU_RES].scale = Fieldstab[EU_COD].scale
= Fieldstab[EU_DAT].scale = Fieldstab[EU_SHR].scale
= Fieldstab[EU_USE].scale = Fieldstab[EU_RZA].scale
= Fieldstab[EU_RZF].scale = Fieldstab[EU_RZL].scale
= Fieldstab[EU_RZS].scale = Rc.task_mscale;
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
2011-08-30 17:35:45 +05:30
// lastly, ensure we've got proper column headers...
calibrate_fields();
2011-03-31 16:45:12 +05:30
} // end: zap_fieldstab
/*###### Library Interface #############################################*/
2002-05-30 09:14:46 +05:30
/*
* This guy's modeled on libproc's 'eight_cpu_numbers' function except
2002-12-05 04:18:30 +05:30
* we preserve all cpu data in our CPU_t array which is organized
2002-10-02 05:40:30 +05:30
* as follows:
* Cpu_tics[0] thru Cpu_tics[n] == tics for each separate cpu
* Cpu_tics[sumSLOT] == tics from /proc/stat line #1
* [ and beyond sumSLOT == tics for each cpu NUMA node ] */
static void cpus_refresh (void) {
#define sumSLOT ( smp_num_cpus )
#define totSLOT ( 1 + smp_num_cpus + Numa_node_tot)
2002-10-02 05:40:30 +05:30
static FILE *fp = NULL;
2013-04-14 10:30:00 +05:30
static int siz, sav_slot = -1;
static char *buf;
CPU_t *sum_ptr; // avoid gcc subscript bloat
int i, num, tot_read;
int node;
2013-04-14 10:30:00 +05:30
char *bp;
2011-03-31 16:45:12 +05:30
/*** hotplug_acclimated ***/
if (sav_slot != sumSLOT) {
sav_slot = sumSLOT;
2011-03-31 16:45:12 +05:30
zap_fieldstab();
if (fp) { fclose(fp); fp = NULL; }
if (Cpu_tics) free(Cpu_tics);
2011-03-31 16:45:12 +05:30
}
2002-10-02 05:40:30 +05:30
2002-11-08 06:01:28 +05:30
/* by opening this file once, we'll avoid the hit on minor page faults
(sorry Linux, but you'll have to close it for us) */
2002-10-02 05:40:30 +05:30
if (!fp) {
if (!(fp = fopen("/proc/stat", "r")))
error_exit(fmtmk(N_fmt(FAIL_statopn_fmt), strerror(errno)));
/* note: we allocate one more CPU_t via totSLOT than 'cpus' so that a
slot can hold tics representing the /proc/stat cpu summary */
Cpu_tics = alloc_c(totSLOT * sizeof(CPU_t));
2002-10-02 05:40:30 +05:30
}
rewind(fp);
fflush(fp);
2013-04-14 10:30:00 +05:30
#define buffGRW 1024
/* we slurp in the entire directory thus avoiding repeated calls to fgets,
especially in a massively parallel environment. additionally, each cpu
line is then frozen in time rather than changing until we get around to
accessing it. this helps to minimize (not eliminate) most distortions. */
tot_read = 0;
if (buf) buf[0] = '\0';
else buf = alloc_c((siz = buffGRW));
while (0 < (num = fread(buf + tot_read, 1, (siz - tot_read), fp))) {
tot_read += num;
if (tot_read < siz) break;
buf = alloc_r(buf, (siz += buffGRW));
};
buf[tot_read] = '\0';
bp = buf;
#undef buffGRW
// remember from last time around
sum_ptr = &Cpu_tics[sumSLOT];
memcpy(&sum_ptr->sav, &sum_ptr->cur, sizeof(CT_t));
// then value the last slot with the cpu summary line
if (4 > sscanf(bp, "cpu %llu %llu %llu %llu %llu %llu %llu %llu"
, &sum_ptr->cur.u, &sum_ptr->cur.n, &sum_ptr->cur.s
, &sum_ptr->cur.i, &sum_ptr->cur.w, &sum_ptr->cur.x
, &sum_ptr->cur.y, &sum_ptr->cur.z))
error_exit(N_txt(FAIL_statget_txt));
#ifndef CPU_ZEROTICS
sum_ptr->cur.tot = sum_ptr->cur.u + sum_ptr->cur.s
+ sum_ptr->cur.n + sum_ptr->cur.i + sum_ptr->cur.w
+ sum_ptr->cur.x + sum_ptr->cur.y + sum_ptr->cur.z;
/* if a cpu has registered substantially fewer tics than those expected,
we'll force it to be treated as 'idle' so as not to present misleading
percentages. */
sum_ptr->edge =
((sum_ptr->cur.tot - sum_ptr->sav.tot) / smp_num_cpus) / (100 / TICS_EDGE);
#endif
// forget all of the prior node statistics (maybe)
if (CHKw(Curwin, View_CPUNOD) && Numa_node_tot)
memset(sum_ptr + 1, 0, Numa_node_tot * sizeof(CPU_t));
// now value each separate cpu's tics...
for (i = 0; i < sumSLOT; i++) {
CPU_t *cpu_ptr = &Cpu_tics[i]; // avoid gcc subscript bloat
#ifdef PRETEND8CPUS
2013-04-14 10:30:00 +05:30
bp = buf;
2011-03-31 16:45:12 +05:30
#endif
2013-04-14 10:30:00 +05:30
bp = 1 + strchr(bp, '\n');
// remember from last time around
memcpy(&cpu_ptr->sav, &cpu_ptr->cur, sizeof(CT_t));
if (4 > sscanf(bp, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu", &cpu_ptr->id
, &cpu_ptr->cur.u, &cpu_ptr->cur.n, &cpu_ptr->cur.s
, &cpu_ptr->cur.i, &cpu_ptr->cur.w, &cpu_ptr->cur.x
, &cpu_ptr->cur.y, &cpu_ptr->cur.z)) {
break; // tolerate cpus taken offline
2011-03-31 16:45:12 +05:30
}
#ifndef CPU_ZEROTICS
cpu_ptr->edge = sum_ptr->edge;
#endif
#ifdef PRETEND8CPUS
cpu_ptr->id = i;
#endif
/* henceforth, with just a little more arithmetic we can avoid
maintaining *any* node stats unless they're actually needed */
if (CHKw(Curwin, View_CPUNOD)
&& Numa_node_tot
&& -1 < (node = numa_node_of_cpu(cpu_ptr->id))) {
// use our own pointer to avoid gcc subscript bloat
CPU_t *nod_ptr = sum_ptr + 1 + node;
nod_ptr->cur.u += cpu_ptr->cur.u; nod_ptr->sav.u += cpu_ptr->sav.u;
nod_ptr->cur.n += cpu_ptr->cur.n; nod_ptr->sav.n += cpu_ptr->sav.n;
nod_ptr->cur.s += cpu_ptr->cur.s; nod_ptr->sav.s += cpu_ptr->sav.s;
nod_ptr->cur.i += cpu_ptr->cur.i; nod_ptr->sav.i += cpu_ptr->sav.i;
nod_ptr->cur.w += cpu_ptr->cur.w; nod_ptr->sav.w += cpu_ptr->sav.w;
nod_ptr->cur.x += cpu_ptr->cur.x; nod_ptr->sav.x += cpu_ptr->sav.x;
nod_ptr->cur.y += cpu_ptr->cur.y; nod_ptr->sav.y += cpu_ptr->sav.y;
nod_ptr->cur.z += cpu_ptr->cur.z; nod_ptr->sav.z += cpu_ptr->sav.z;
#ifndef CPU_ZEROTICS
/* yep, we re-value this repeatedly for each cpu encountered, but we
can then avoid a prior loop to selectively initialize each node */
nod_ptr->edge = sum_ptr->edge;
#endif
cpu_ptr->node = node;
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
#ifndef OFF_NUMASKIP
nod_ptr->id = -1;
#endif
}
} // end: for each cpu
Cpu_faux_tot = i; // tolerate cpus taken offline
#undef sumSLOT
#undef totSLOT
2011-03-31 16:45:12 +05:30
} // end: cpus_refresh
#ifdef OFF_HST_HASH
/*
* Binary Search for HST_t's put/get support */
static inline HST_t *hstbsrch (HST_t *hst, int max, int pid) {
int mid, min = 0;
while (min <= max) {
mid = (min + max) / 2;
if (pid < hst[mid].pid) max = mid - 1;
else if (pid > hst[mid].pid) min = mid + 1;
else return &hst[mid];
}
return NULL;
} // end: hstbsrch
#else
/*
* Hashing functions for HST_t's put/get support
* (not your normal 'chaining', those damn HST_t's might move!) */
#define _HASH_(K) (K & (HHASH_SIZ - 1))
static inline HST_t *hstget (int pid) {
int V = PHash_sav[_HASH_(pid)];
2002-10-02 05:40:30 +05:30
2011-03-31 16:45:12 +05:30
while (-1 < V) {
if (PHist_sav[V].pid == pid) return &PHist_sav[V];
V = PHist_sav[V].lnk; }
return NULL;
} // end: hstget
static inline void hstput (unsigned idx) {
int V = _HASH_(PHist_new[idx].pid);
PHist_new[idx].lnk = PHash_new[V];
PHash_new[V] = idx;
} // end: hstput
#undef _HASH_
#endif
2002-10-02 05:40:30 +05:30
2002-11-08 06:01:28 +05:30
/*
* Refresh procs *Helper* function to eliminate yet one more need
* to loop through our darn proc_t table. He's responsible for:
* 1) calculating the elapsed time since the previous frame
* 2) counting the number of tasks in each state (run, sleep, etc)
2002-12-05 04:18:30 +05:30
* 3) maintaining the HST_t's and priming the proc_t pcpu field
2002-11-08 06:01:28 +05:30
* 4) establishing the total number tasks for this frame */
static void procs_hlp (proc_t *this) {
#ifdef OFF_HST_HASH
2011-03-31 16:45:12 +05:30
static unsigned maxt_sav = 0; // prior frame's max tasks
#endif
2002-12-05 04:18:30 +05:30
TIC_t tics;
2011-03-31 16:45:12 +05:30
HST_t *h;
2002-11-08 06:01:28 +05:30
2011-03-31 16:45:12 +05:30
if (!this) {
top: protect against distortion when system time reset If a system's time is adjusted backwards, then elapsed time could appear as negative. This yielded a negative %CPU value. Alternately if zeros were suppressed ('0') the result was a blank %CPU column. In both cases that distortion would last for one display cycle or until a user forced a display refresh via some keyboard input. The original recommendation was trading gettimeofday() for clock_gettime() using CLOCK_MONOTONIC. But on some systems that might not be possible, forcing the use of CLOCK_REALTIME instead. Not only would that complicate the build system, but it may leave us with minus %CPU. Another approach was to ensure that elapsed time could never be negative. Of course, this produced distortion of %CPU values but it would be proportionally correct. This wasn't dissimilar to a distortion already present should the time be adjusted forward or backward within any 'remaining' top delay intervals. These aberrations would be avoided with clock_gettime & CLOCK_MONOTONIC, but that is a less than ideal solution as noted above. This final solution, which originated down under, will simply rely on the /proc/uptime seconds, which will be immune to *any* tampering with the system clock. Thus, we now have a fix for the distortion we didn't know we suffered plus a negative %CPU that began this odyssey. Thanks to: sk.alvin.x@gmail.com, for the original effort jcapik@redhat.com, for a heads up on CLOCK_MONOTONIC csmall-procps@enc.com.au, for the best suggestion of all Reference(s): . original post/patch http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday . heads up on CLOCK_MONOTONIC http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,2 . the final solution http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,11 Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-04-25 10:30:00 +05:30
static double uptime_sav;
double uptime_cur;
2002-11-08 06:01:28 +05:30
float et;
2011-03-31 16:45:12 +05:30
void *v;
2002-11-08 06:01:28 +05:30
top: protect against distortion when system time reset If a system's time is adjusted backwards, then elapsed time could appear as negative. This yielded a negative %CPU value. Alternately if zeros were suppressed ('0') the result was a blank %CPU column. In both cases that distortion would last for one display cycle or until a user forced a display refresh via some keyboard input. The original recommendation was trading gettimeofday() for clock_gettime() using CLOCK_MONOTONIC. But on some systems that might not be possible, forcing the use of CLOCK_REALTIME instead. Not only would that complicate the build system, but it may leave us with minus %CPU. Another approach was to ensure that elapsed time could never be negative. Of course, this produced distortion of %CPU values but it would be proportionally correct. This wasn't dissimilar to a distortion already present should the time be adjusted forward or backward within any 'remaining' top delay intervals. These aberrations would be avoided with clock_gettime & CLOCK_MONOTONIC, but that is a less than ideal solution as noted above. This final solution, which originated down under, will simply rely on the /proc/uptime seconds, which will be immune to *any* tampering with the system clock. Thus, we now have a fix for the distortion we didn't know we suffered plus a negative %CPU that began this odyssey. Thanks to: sk.alvin.x@gmail.com, for the original effort jcapik@redhat.com, for a heads up on CLOCK_MONOTONIC csmall-procps@enc.com.au, for the best suggestion of all Reference(s): . original post/patch http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday . heads up on CLOCK_MONOTONIC http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,2 . the final solution http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,11 Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-04-25 10:30:00 +05:30
uptime(&uptime_cur, NULL);
et = uptime_cur - uptime_sav;
if (et < 0.01) et = 0.005;
top: protect against distortion when system time reset If a system's time is adjusted backwards, then elapsed time could appear as negative. This yielded a negative %CPU value. Alternately if zeros were suppressed ('0') the result was a blank %CPU column. In both cases that distortion would last for one display cycle or until a user forced a display refresh via some keyboard input. The original recommendation was trading gettimeofday() for clock_gettime() using CLOCK_MONOTONIC. But on some systems that might not be possible, forcing the use of CLOCK_REALTIME instead. Not only would that complicate the build system, but it may leave us with minus %CPU. Another approach was to ensure that elapsed time could never be negative. Of course, this produced distortion of %CPU values but it would be proportionally correct. This wasn't dissimilar to a distortion already present should the time be adjusted forward or backward within any 'remaining' top delay intervals. These aberrations would be avoided with clock_gettime & CLOCK_MONOTONIC, but that is a less than ideal solution as noted above. This final solution, which originated down under, will simply rely on the /proc/uptime seconds, which will be immune to *any* tampering with the system clock. Thus, we now have a fix for the distortion we didn't know we suffered plus a negative %CPU that began this odyssey. Thanks to: sk.alvin.x@gmail.com, for the original effort jcapik@redhat.com, for a heads up on CLOCK_MONOTONIC csmall-procps@enc.com.au, for the best suggestion of all Reference(s): . original post/patch http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday . heads up on CLOCK_MONOTONIC http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,2 . the final solution http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,11 Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-04-25 10:30:00 +05:30
uptime_sav = uptime_cur;
2002-11-08 06:01:28 +05:30
// if in Solaris mode, adjust our scaling for all cpus
Frame_etscale = 100.0f / ((float)Hertz * (float)et * (Rc.mode_irixps ? 1 : smp_num_cpus));
#ifdef OFF_HST_HASH
2002-11-08 06:01:28 +05:30
maxt_sav = Frame_maxtask;
#endif
2002-11-08 06:01:28 +05:30
Frame_maxtask = Frame_running = Frame_sleepin = Frame_stopped = Frame_zombied = 0;
2011-03-31 16:45:12 +05:30
// prep for saving this frame's HST_t's (and reuse mem each time around)
v = PHist_sav;
PHist_sav = PHist_new;
PHist_new = v;
#ifdef OFF_HST_HASH
// prep for binary search by sorting the last frame's HST_t's
qsort(PHist_sav, maxt_sav, sizeof(HST_t), (QFP_t)sort_HST_t);
#else
v = PHash_sav;
PHash_sav = PHash_new;
PHash_new = v;
memcpy(PHash_new, HHash_nul, sizeof(HHash_nul));
#endif
2002-11-08 06:01:28 +05:30
return;
}
switch (this->state) {
case 'R':
Frame_running++;
break;
case 'S':
case 'D':
Frame_sleepin++;
break;
case 'T':
Frame_stopped++;
break;
case 'Z':
Frame_zombied++;
break;
2011-03-31 16:45:12 +05:30
default: // keep gcc happy
break;
2002-11-08 06:01:28 +05:30
}
2011-03-31 16:45:12 +05:30
if (Frame_maxtask+1 >= HHist_siz) {
HHist_siz = HHist_siz * 5 / 4 + 100;
PHist_sav = alloc_r(PHist_sav, sizeof(HST_t) * HHist_siz);
PHist_new = alloc_r(PHist_new, sizeof(HST_t) * HHist_siz);
2002-11-08 06:01:28 +05:30
}
2011-03-31 16:45:12 +05:30
2002-11-08 06:01:28 +05:30
/* calculate time in this process; the sum of user time (utime) and
system time (stime) -- but PLEASE dont waste time and effort on
calcs and saves that go unused, like the old top! */
2011-03-31 16:45:12 +05:30
PHist_new[Frame_maxtask].pid = this->tid;
PHist_new[Frame_maxtask].tics = tics = (this->utime + this->stime);
// finally, save major/minor fault counts in case the deltas are displayable
PHist_new[Frame_maxtask].maj = this->maj_flt;
PHist_new[Frame_maxtask].min = this->min_flt;
2011-03-31 16:45:12 +05:30
#ifdef OFF_HST_HASH
// find matching entry from previous frame and make stuff elapsed
if ((h = hstbsrch(PHist_sav, maxt_sav - 1, this->tid))) {
tics -= h->tics;
this->maj_delta = this->maj_flt - h->maj;
this->min_delta = this->min_flt - h->min;
}
2002-12-15 03:00:58 +05:30
#else
2011-03-31 16:45:12 +05:30
// hash & save for the next frame
hstput(Frame_maxtask);
// find matching entry from previous frame and make stuff elapsed
if ((h = hstget(this->tid))) {
tics -= h->tics;
this->maj_delta = this->maj_flt - h->maj;
this->min_delta = this->min_flt - h->min;
}
2002-12-15 03:00:58 +05:30
#endif
2011-03-31 16:45:12 +05:30
/* we're just saving elapsed tics, to be converted into %cpu if
this task wins it's displayable screen row lottery... */
2002-11-08 06:01:28 +05:30
this->pcpu = tics;
2011-03-31 16:45:12 +05:30
2002-11-08 06:01:28 +05:30
// shout this to the world with the final call (or us the next time in)
Frame_maxtask++;
} // end: procs_hlp
2002-11-08 06:01:28 +05:30
2002-10-02 05:40:30 +05:30
/*
* This guy's modeled on libproc's 'readproctab' function except
2002-06-19 05:15:30 +05:30
* we reuse and extend any prior proc_t's. He's been customized
* for our specific needs and to avoid the use of <stdarg.h> */
2011-08-30 17:35:45 +05:30
static void procs_refresh (void) {
#define n_used Frame_maxtask // maintained by procs_hlp()
static proc_t **private_ppt; // our base proc_t ptr table
static int n_alloc = 0; // size of our private_ppt
static int n_saved = 0; // last window ppt size
proc_t *ptask;
2002-06-19 05:15:30 +05:30
PROCTAB* PT;
2011-08-30 17:35:45 +05:30
int i;
proc_t*(*read_something)(PROCTAB*, proc_t*);
2002-06-19 05:15:30 +05:30
procs_hlp(NULL); // prep for a new frame
2011-03-31 16:45:12 +05:30
if (NULL == (PT = openproc(Frames_libflags, Monpids)))
error_exit(fmtmk(N_fmt(FAIL_openlib_fmt), strerror(errno)));
read_something = Thread_mode ? readeither : readproc;
2002-06-19 05:15:30 +05:30
for (;;) {
if (n_used == n_alloc) {
n_alloc = 10 + ((n_alloc * 5) / 4); // grow by over 25%
private_ppt = alloc_r(private_ppt, sizeof(proc_t*) * n_alloc);
// ensure NULL pointers for the additional memory just acquired
memset(private_ppt + n_used, 0, sizeof(proc_t*) * (n_alloc - n_used));
2002-11-08 06:01:28 +05:30
}
// on the way to n_alloc, the library will allocate the underlying
// proc_t storage whenever our private_ppt[] pointer is NULL...
if (!(ptask = read_something(PT, private_ppt[n_used]))) break;
procs_hlp((private_ppt[n_used] = ptask)); // tally this proc_t
2002-06-19 05:15:30 +05:30
}
2002-06-19 05:15:30 +05:30
closeproc(PT);
2011-08-30 17:35:45 +05:30
// lastly, refresh each window's proc pointers table...
if (n_saved == n_alloc)
for (i = 0; i < GROUPSMAX; i++)
memcpy(Winstk[i].ppt, private_ppt, sizeof(proc_t*) * n_used);
else {
n_saved = n_alloc;
for (i = 0; i < GROUPSMAX; i++) {
Winstk[i].ppt = alloc_r(Winstk[i].ppt, sizeof(proc_t*) * n_alloc);
memcpy(Winstk[i].ppt, private_ppt, sizeof(proc_t*) * n_used);
}
2002-06-19 05:15:30 +05:30
}
#undef n_used
2011-03-31 16:45:12 +05:30
} // end: procs_refresh
/*
* This serves as our interface to the memory & cpu count (sysinfo)
* portion of libproc. In support of those hotpluggable resources,
* the sampling frequencies are reduced so as to minimize overhead. */
static void sysinfo_refresh (int forced) {
static time_t sav_secs;
time_t cur_secs;
if (forced)
sav_secs = 0;
cur_secs = time(NULL);
/*** hotplug_acclimated ***/
if (3 <= cur_secs - sav_secs) {
meminfo();
#ifndef PRETEND8CPUS
cpuinfo();
Cpu_faux_tot = smp_num_cpus;
#endif
Numa_node_tot = numa_max_node() + 1;
sav_secs = cur_secs;
}
} // end: sysinfo_refresh
2011-03-31 16:45:12 +05:30
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 ##########################################*/
/*
* HOWTO Extend the top 'inspect' functionality:
*
* To exploit the 'Y' interactive command, one must add entries to
* the top personal configuration file. Such entries simply reflect
* a file to be read or command/pipeline to be executed whose results
* will then be displayed in a separate scrollable window.
*
* Entries beginning with a '#' character are ignored, regardless of
* content. Otherwise they consist of the following 3 elements, each
* of which must be separated by a tab character (thus 2 '\t' total):
* type: literal 'file' or 'pipe'
* name: selection shown on the Inspect screen
* fmts: string representing a path or command
*
* The two types of Inspect entries are not interchangeable.
* Those designated 'file' will be accessed using fopen/fread and must
* reference a single file in the 'fmts' element. Entries specifying
* 'pipe' will employ popen/fread, their 'fmts' element could contain
* many pipelined commands and, none can be interactive.
*
* Here are some examples of both types of inspection entries.
* The first entry will be ignored due to the initial '#' character.
* For clarity, the pseudo tab depictions (^I) are surrounded by an
* extra space but the actual tabs would not be.
*
* # pipe ^I Sockets ^I lsof -n -P -i 2>&1
* pipe ^I Open Files ^I lsof -P -p %d 2>&1
* file ^I NUMA Info ^I /proc/%d/numa_maps
* pipe ^I Log ^I tail -n100 /var/log/syslog | sort -Mr
*
* Caution: If the output contains unprintable characters they will
* be displayed in either the ^I notation or hexidecimal <FF> form.
* This applies to tab characters as well. So if one wants a more
* accurate display, any tabs should be expanded within the 'fmts'.
*
* The following example takes what could have been a 'file' entry
* but employs a 'pipe' instead so as to expand the tabs.
*
* # next would have contained '\t' ...
* # file ^I <your_name> ^I /proc/%d/status
* # but this will eliminate embedded '\t' ...
* pipe ^I <your_name> ^I cat /proc/%d/status | expand -
*/
/*
* Our driving table support, the basis for generalized inspection,
* built at startup (if at all) from rcfile or demo entries. */
struct I_ent {
void (*func)(char *, int); // a pointer to file/pipe/demo function
char *type; // the type of entry ('file' or 'pipe')
char *name; // the selection label for display
char *fmts; // format string to build path or command
int farg; // 1 = '%d' in fmts, 0 = not (future use)
const char *caps; // not really caps, show_special() delim's
char *fstr; // entry's current/active search string
int flen; // above's strlen, without call overhead
};
struct I_struc {
int demo; // do NOT save table entries in rcfile
int total; // total I_ent table entries
char *raw; // all entries for 'W', incl '#' & blank
struct I_ent *tab;
};
static struct I_struc Inspect;
static char **Insp_p; // pointers to each line start
static int Insp_nl; // total lines, total Insp_p entries
static char *Insp_buf; // the results from insp_do_file/pipe
static size_t Insp_bufsz; // allocated size of Insp_buf
static size_t Insp_bufrd; // bytes actually in Insp_buf
static struct I_ent *Insp_sel; // currently selected Inspect entry
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
// Our 'make status line' macro
#define INSP_MKSL(big,txt) { int _sz = big ? Screen_cols : 80; \
putp(tg2(0, (Msg_row = 3))); \
PUTT("%s%.*s", Curwin->capclr_hdr, Screen_cols -1 \
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
, fmtmk("%-*.*s%s", _sz, _sz, txt, Cap_clr_eol)); \
putp(Caps_off); fflush(stdout); }
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
// Our 'row length' macro, equivalent to a strlen() call
#define INSP_RLEN(idx) (int)(Insp_p[idx +1] - Insp_p[idx] -1)
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
// Our 'busy' (wait please) macro
#define INSP_BUSY { INSP_MKSL(0, N_txt(YINSP_workin_txt)); }
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
/*
* Establish the number of lines present in the Insp_buf glob plus
* build the all important row start array. It is that array that
* others will rely on since we dare not try to use strlen() on what
* is potentially raw binary data. Who knows what some user might
* name as a file or include in a pipeline (scary, ain't it?). */
static void insp_cnt_nl (void) {
char *beg = Insp_buf;
char *cur = Insp_buf;
char *end = Insp_buf + Insp_bufrd + 1;
#ifdef INSP_SAVEBUF
{
static int n = 1;
char fn[SMLBUFSIZ];
FILE *fd;
snprintf(fn, sizeof(fn), "%s.Insp_buf.%02d.txt", Myname, n++);
fd = fopen(fn, "w");
if (fd) {
fwrite(Insp_buf, 1, Insp_bufrd, fd);
fclose(fd);
}
}
#endif
Insp_p = alloc_c(sizeof(char*) * 2);
for (Insp_nl = 0; beg < end; beg++) {
if (*beg == '\n') {
Insp_p[Insp_nl++] = cur;
// keep our array ahead of next potential need (plus the 2 above)
Insp_p = alloc_r(Insp_p, (sizeof(char*) * (Insp_nl +3)));
cur = beg +1;
}
}
Insp_p[0] = Insp_buf;
Insp_p[Insp_nl++] = cur;
Insp_p[Insp_nl] = end;
if ((end - cur) == 1) // if there's an eof null delimiter,
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
--Insp_nl; // don't count it as a new line
} // end: insp_cnt_nl
#ifndef INSP_OFFDEMO
/*
* The pseudo output DEMO utility. */
static void insp_do_demo (char *fmts, int pid) {
(void)fmts; (void)pid;
/* next will put us on a par with the real file/pipe read buffers
( and also avoid a harmless, but evil sounding, valgrind warning ) */
Insp_bufsz = READMINSZ + strlen(N_txt(YINSP_dstory_txt));
Insp_buf = alloc_c(Insp_bufsz);
Insp_bufrd = snprintf(Insp_buf, Insp_bufsz, "%s", N_txt(YINSP_dstory_txt));
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
insp_cnt_nl();
} // end: insp_do_demo
#endif
/*
* The generalized FILE utility. */
static void insp_do_file (char *fmts, int pid) {
char buf[LRGBUFSIZ];
FILE *fp;
int rc;
snprintf(buf, sizeof(buf), fmts, pid);
fp = fopen(buf, "r");
rc = readfile(fp, &Insp_buf, &Insp_bufsz, &Insp_bufrd);
if (fp) fclose(fp);
if (rc) Insp_bufrd = snprintf(Insp_buf, Insp_bufsz, "%s"
, fmtmk(N_fmt(YINSP_failed_fmt), strerror(errno)));
insp_cnt_nl();
} // end: insp_do_file
/*
* The generalized PIPE utility. */
static void insp_do_pipe (char *fmts, int pid) {
char buf[LRGBUFSIZ];
FILE *fp;
int rc;
snprintf(buf, sizeof(buf), fmts, pid);
fp = popen(buf, "r");
rc = readfile(fp, &Insp_buf, &Insp_bufsz, &Insp_bufrd);
if (fp) pclose(fp);
if (rc) Insp_bufrd = snprintf(Insp_buf, Insp_bufsz, "%s"
, fmtmk(N_fmt(YINSP_failed_fmt), strerror(errno)));
insp_cnt_nl();
} // end: insp_do_pipe
/*
* This guy is a *Helper* function serving the following two masters:
* insp_find_str() - find the next Insp_sel->fstr match
* insp_make_row() - highlight any Insp_sel->fstr matches in-view
* If Insp_sel->fstr is found in the designated row, he returns the
* offset from the start of the row, otherwise he returns a huge
* integer so traditional fencepost usage can be employed. */
static inline int insp_find_ofs (int col, int row) {
#define begFS (int)(fnd - Insp_p[row])
char *p, *fnd = NULL;
if (Insp_sel->fstr[0]) {
// skip this row, if there's no chance of a match
if (memchr(Insp_p[row], Insp_sel->fstr[0], INSP_RLEN(row))) {
for ( ; col < INSP_RLEN(row); col++) {
if (!*(p = Insp_p[row] + col)) // skip any empty strings
continue;
fnd = STRSTR(p, Insp_sel->fstr); // with binary data, each
if (fnd) // row may have '\0'. so
break; // our scans must be done
col += strlen(p); // as individual strings.
}
if (fnd && fnd < Insp_p[row + 1]) // and, we must watch out
return begFS; // for potential overrun!
}
}
return INT_MAX;
#undef begFS
} // end: insp_find_ofs
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
/*
* This guy supports the inspect 'L' and '&' search provisions
* and returns the row and *optimal* column for viewing any match
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
* ( we'll always opt for left column justification since any )
* ( preceding ctrl chars appropriate an unpredictable amount ) */
static void insp_find_str (int ch, int *col, int *row) {
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 reDUX (found) ? N_txt(WORD_another_txt) : ""
static int found;
if ((ch == '&' || ch == 'n') && !Insp_sel->fstr[0]) {
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
show_msg(N_txt(FIND_no_next_txt));
return;
}
if (ch == 'L' || ch == '/') {
char *str = ioline(N_txt(GET_find_str_txt));
if (*str == kbd_ESC) return;
snprintf(Insp_sel->fstr, FNDBUFSIZ, "%s", str);
Insp_sel->flen = strlen(Insp_sel->fstr);
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
found = 0;
}
if (Insp_sel->fstr[0]) {
int xx, yy;
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
INSP_BUSY;
for (xx = *col, yy = *row; yy < Insp_nl; ) {
xx = insp_find_ofs(xx, yy);
if (xx < INSP_RLEN(yy)) {
found = 1;
if (xx == *col && yy == *row) { // matched where we were!
++xx; // ( was the user maybe )
continue; // ( trying to fool us? )
}
*col = xx;
*row = yy;
return;
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
}
xx = 0;
++yy;
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
}
show_msg(fmtmk(N_fmt(FIND_no_find_fmt), reDUX, Insp_sel->fstr));
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
}
#undef reDUX
} // end: insp_find_str
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
/*
* This guy is a *Helper* function responsible for positioning a
* single row in the current 'X axis', then displaying the results.
* Along the way, he makes sure control characters and/or unprintable
* characters display in a less-like fashion:
* '^A' for control chars
* '<BC>' for other unprintable stuff
* Those will be highlighted with the current windows's capclr_msg,
* while visible search matches display with capclr_hdr for emphasis.
* ( we hide ugly plumbing in macros to concentrate on the algorithm ) */
static inline void insp_make_row (int col, int row) {
#define maxSZ ( Screen_cols - (to + 1) )
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 capNO { if (hicap) { putp(Caps_off); hicap = 0; } }
#define mkFND { PUTT("%s%.*s%s", Curwin->capclr_hdr, maxSZ, Insp_sel->fstr, Caps_off); \
fr += Insp_sel->flen -1; to += Insp_sel->flen; hicap = 0; }
#ifndef INSP_JUSTNOT
#define mkCTL { int x = maxSZ; const char *p = fmtmk("^%c", uch + '@'); \
PUTT("%s%.*s", (!hicap) ? Curwin->capclr_msg : "", x, p); to += 2; hicap = 1; }
#define mkUNP { int x = maxSZ; const char *p = fmtmk("<%02X>", uch); \
PUTT("%s%.*s", (!hicap) ? Curwin->capclr_msg : "", x, p); to += 4; hicap = 1; }
#else
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 mkCTL { if ((to += 2) <= Screen_cols) \
PUTT("%s^%c", (!hicap) ? Curwin->capclr_msg : "", uch + '@'); hicap = 1; }
#define mkUNP { if ((to += 4) <= Screen_cols) \
PUTT("%s<%02X>", (!hicap) ? Curwin->capclr_msg : "", uch); hicap = 1; }
#endif
#define mkSTD { capNO; if (++to <= Screen_cols) { static char _str[2]; \
_str[0] = uch; putp(_str); } }
char tline[SCREENMAX];
int fr, to, ofs;
int hicap = 0;
if (col < INSP_RLEN(row))
memcpy(tline, Insp_p[row] + col, sizeof(tline));
else tline[0] = '\n';
for (fr = 0, to = 0, ofs = 0; to < Screen_cols -1; fr++) {
if (!ofs)
ofs = insp_find_ofs(col + fr, row);
if (col + fr < ofs) {
unsigned char uch = tline[fr];
if (uch == '\n') break; // a no show (he,he)
if (uch > 126) mkUNP // show as: '<AB>'
else if (uch < 32) mkCTL // show as: '^C'
else mkSTD // a show off (he,he)
} else { mkFND // a big show (he,he)
ofs = 0;
}
if (col + fr >= INSP_RLEN(row)) break;
}
capNO;
putp(Cap_clr_eol);
#undef maxSZ
#undef capNO
#undef mkFND
#undef mkCTL
#undef mkUNP
#undef mkSTD
} // end: insp_make_row
/*
* This guy is an insp_view_choice() *Helper* function who displays
* a page worth of of the user's damages. He also creates a status
* line based on maximum digits for the current selection's lines and
* hozizontal position (so it serves to inform, not distract, by
* otherwise being jumpy). */
static inline void insp_show_pgs (int col, int row, int max) {
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
char buf[SMLBUFSIZ];
int r = snprintf(buf, sizeof(buf), "%d", Insp_nl);
int c = snprintf(buf, sizeof(buf), "%d", col +Screen_cols);
int l = row +1, ls = Insp_nl;;
if (!Insp_bufrd)
l = ls = 0;
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
snprintf(buf, sizeof(buf), N_fmt(YINSP_status_fmt)
, Insp_sel->name
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
, r, l, r, ls
, c, col + 1, c, col + Screen_cols
, (unsigned long)Insp_bufrd);
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
INSP_MKSL(0, buf);
for ( ; max && row < Insp_nl; row++) {
putp("\n");
insp_make_row(col, row);
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
--max;
}
if (max)
putp(Cap_nl_clreos);
} // end: insp_show_pgs
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
/*
* This guy is responsible for displaying the Insp_buf contents and
* managing all scrolling/locate requests until the user gives up. */
static int insp_view_choice (proc_t *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
#ifdef INSP_SLIDE_1
#define hzAMT 1
#else
#define hzAMT 8
#endif
#define maxLN (Screen_rows - (Msg_row +1))
#define makHD(b1,b2) { \
snprintf(b1, sizeof(b1), "%d", obj->tid); \
snprintf(b2, sizeof(b2), "%s", obj->cmd); }
#define makFS(dst) { if (Insp_sel->flen < 22) \
snprintf(dst, sizeof(dst), "%s", Insp_sel->fstr); \
else snprintf(dst, sizeof(dst), "%.19s...", Insp_sel->fstr); }
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
char buf[SMLBUFSIZ];
int key, curlin = 0, curcol = 0;
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
signify_that:
putp(Cap_clr_scr);
adj_geometry();
for (;;) {
char pid[6], cmd[16];
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
if (curcol < 0) curcol = 0;
if (curlin >= Insp_nl) curlin = Insp_nl -1;
if (curlin < 0) curlin = 0;
makFS(buf)
makHD(pid,cmd)
putp(Cap_home);
show_special(1, fmtmk(N_unq(YINSP_hdview_fmt)
, pid, cmd, (Insp_sel->fstr[0]) ? buf : " N/A ")); // nls_maybe
insp_show_pgs(curcol, curlin, maxLN);
fflush(stdout);
/* fflush(stdin) didn't do the trick, so we'll just dip a little deeper
lest repeated <Enter> keys produce immediate re-selection in caller */
tcflush(STDIN_FILENO, TCIFLUSH);
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
if (Frames_signal) goto signify_that;
key = iokey(1);
if (key < 1) goto signify_that;
switch (key) {
case kbd_ENTER: // must force new iokey()
key = INT_MAX; // fall through !
case kbd_ESC:
case 'q':
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
putp(Cap_clr_scr);
return key;
case kbd_LEFT:
curcol -= hzAMT;
break;
case kbd_RIGHT:
curcol += hzAMT;
break;
case kbd_UP:
--curlin;
break;
case kbd_DOWN:
++curlin;
break;
case kbd_PGUP:
case 'b':
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
curlin -= maxLN -1; // keep 1 line for reference
break;
case kbd_PGDN:
case kbd_SPACE:
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
curlin += maxLN -1; // ditto
break;
case kbd_HOME:
case 'g':
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
curcol = curlin = 0;
break;
case kbd_END:
case 'G':
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
curcol = 0;
curlin = Insp_nl - maxLN;
break;
case 'L':
case '&':
case '/':
case 'n':
insp_find_str(key, &curcol, &curlin);
// must re-hide cursor in case a prompt for a string makes it huge
putp((Cursor_state = Cap_curs_hide));
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
break;
case '=':
snprintf(buf, sizeof(buf), "%s: %s", Insp_sel->type, Insp_sel->fmts);
INSP_MKSL(1, buf); // show an extended SL
if (iokey(1) < 1)
goto signify_that;
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
break;
default: // keep gcc happy
break;
}
}
#undef hzAMT
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
#undef maxLN
#undef makHD
#undef makFS
} // end: insp_view_choice
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
/*
* This is the main Inspect routine, responsible for:
* 1) validating the passed pid (required, but not always used)
* 2) presenting/establishing the target selection
* 3) arranging to fill Insp_buf (via the Inspect.tab[?].func)
* 4) invoking insp_view_choice for viewing/scrolling/searching
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
* 5) cleaning up the dynamically acquired memory afterwards */
static void inspection_utility (int pid) {
#define mkSEL(dst) { for (i = 0; i < Inspect.total; i++) Inspect.tab[i].caps = "~1"; \
Inspect.tab[sel].caps = "~4"; dst[0] = '\0'; \
for (i = 0; i < Inspect.total; i++) { char _s[SMLBUFSIZ]; \
snprintf(_s, sizeof(_s), " %s %s", Inspect.tab[i].name, Inspect.tab[i].caps); \
strcat(dst, _s); } }
char sels[MEDBUFSIZ];
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
static int sel;
int i, key;
proc_t *p;
for (i = 0, p = NULL; i < Frame_maxtask; i++)
if (pid == Curwin->ppt[i]->tid) {
p = Curwin->ppt[i];
break;
}
if (!p) {
show_msg(fmtmk(N_fmt(YINSP_pidbad_fmt), pid));
return;
}
// must re-hide cursor since the prompt for a pid made it huge
putp((Cursor_state = Cap_curs_hide));
signify_that:
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
putp(Cap_clr_scr);
adj_geometry();
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
key = INT_MAX;
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
do {
mkSEL(sels);
putp(Cap_home);
show_special(1, fmtmk(N_unq(YINSP_hdsels_fmt)
, pid, p->cmd, sels));
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
INSP_MKSL(0, " ");
if (Frames_signal) goto signify_that;
if (key == INT_MAX) key = iokey(1);
if (key < 1) goto signify_that;
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
switch (key) {
case 'q':
case kbd_ESC:
break;
case kbd_END:
sel = 0; // fall through !
case kbd_LEFT:
if (--sel < 0) sel = Inspect.total -1;
key = INT_MAX;
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
break;
case kbd_HOME:
sel = Inspect.total; // fall through !
case kbd_RIGHT:
if (++sel >= Inspect.total) sel = 0;
key = INT_MAX;
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
break;
case kbd_ENTER:
INSP_BUSY;
Insp_sel = &Inspect.tab[sel];
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.tab[sel].func(Inspect.tab[sel].fmts, pid);
key = insp_view_choice(p);
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
free(Insp_buf);
free(Insp_p);
break;
default:
goto signify_that;
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
}
} while (key != 'q' && key != kbd_ESC);
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
#undef mkSEL
} // end: inspection_utility
#undef INSP_MKSL
#undef INSP_RLEN
#undef INSP_BUSY
2002-12-05 04:18:30 +05:30
/*###### Startup routines ##############################################*/
2011-03-31 16:45:12 +05:30
/*
* No matter what *they* say, we handle the really really BIG and
2011-03-31 16:45:12 +05:30
* IMPORTANT stuff upon which all those lessor functions depend! */
static void before (char *me) {
struct sigaction sa;
proc_t p;
2002-11-30 21:26:53 +05:30
int i;
int linux_version_code = procps_linux_version();
2002-12-05 04:18:30 +05:30
atexit(close_stdout);
// is /proc mounted?
look_up_our_self(&p);
// setup our program name
2002-12-05 04:18:30 +05:30
Myname = strrchr(me, '/');
if (Myname) ++Myname; else Myname = me;
// accommodate nls/gettext potential translations
initialize_nls();
// establish cpu particulars
#ifdef PRETEND8CPUS
smp_num_cpus = 8;
2011-03-31 16:45:12 +05:30
#endif
Cpu_faux_tot = smp_num_cpus;
Cpu_States_fmts = N_unq(STATE_lin2x4_fmt);
2011-03-31 16:45:12 +05:30
if (linux_version_code > LINUX_VERSION(2, 5, 41))
Cpu_States_fmts = N_unq(STATE_lin2x5_fmt);
2011-03-31 16:45:12 +05:30
if (linux_version_code >= LINUX_VERSION(2, 6, 0))
Cpu_States_fmts = N_unq(STATE_lin2x6_fmt);
2011-03-31 16:45:12 +05:30
if (linux_version_code >= LINUX_VERSION(2, 6, 11))
Cpu_States_fmts = N_unq(STATE_lin2x7_fmt);
2002-12-05 08:47:32 +05:30
// get virtual page stuff
i = page_bytes; // from sysinfo.c, at lib init
2011-03-31 16:45:12 +05:30
while(i > 1024) { i >>= 1; Pg2K_shft++; }
2002-12-05 07:17:36 +05:30
2011-03-31 16:45:12 +05:30
#ifndef OFF_HST_HASH
// prep for HST_t's put/get hashing optimizations
for (i = 0; i < HHASH_SIZ; i++) HHash_nul[i] = -1;
memcpy(HHash_one, HHash_nul, sizeof(HHash_nul));
memcpy(HHash_two, HHash_nul, sizeof(HHash_nul));
#endif
numa_init();
Numa_node_tot = numa_max_node() + 1;
#ifndef SIGRTMAX // not available on hurd, maybe others too
#define SIGRTMAX 32
#endif
// lastly, establish a robust signals environment
sigemptyset(&sa.sa_mask);
// with user position preserved through SIGWINCH, we must avoid SA_RESTART
sa.sa_flags = 0;
for (i = SIGRTMAX; i; i--) {
switch (i) {
case SIGALRM: case SIGHUP: case SIGINT:
case SIGPIPE: case SIGQUIT: case SIGTERM:
case SIGUSR1: case SIGUSR2:
sa.sa_handler = sig_endpgm;
break;
case SIGTSTP: case SIGTTIN: case SIGTTOU:
sa.sa_handler = sig_paused;
break;
case SIGCONT: case SIGWINCH:
sa.sa_handler = sig_resize;
break;
default:
sa.sa_handler = sig_abexit;
break;
case SIGKILL: case SIGSTOP:
// because uncatchable, fall through
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
case SIGCHLD: // we can't catch this
continue; // when opening a pipe
}
sigaction(i, &sa, NULL);
}
2011-03-31 16:45:12 +05:30
} // end: before
2002-12-05 07:17:36 +05:30
2002-12-06 12:23:29 +05:30
/*
* A configs_read *Helper* function responsible for converting
* a single window's old rc stuff into a new style rcfile entry */
static int config_cvt (WIN_t *q) {
static struct {
int old, new;
} flags_tab[] = {
#define old_View_NOBOLD 0x000001
#define old_VISIBLE_tsk 0x000008
#define old_Qsrt_NORMAL 0x000010
#define old_Show_HICOLS 0x000200
#define old_Show_THREAD 0x010000
{ old_View_NOBOLD, View_NOBOLD },
{ old_VISIBLE_tsk, Show_TASKON },
{ old_Qsrt_NORMAL, Qsrt_NORMAL },
{ old_Show_HICOLS, Show_HICOLS },
{ old_Show_THREAD, 0 }
#undef old_View_NOBOLD
#undef old_VISIBLE_tsk
#undef old_Qsrt_NORMAL
#undef old_Show_HICOLS
#undef old_Show_THREAD
};
static const char fields_src[] = CVT_FIELDS;
char fields_dst[PFLAGSSIZ], *p1, *p2;
int i, j, x;
// first we'll touch up this window's winflags...
x = q->rc.winflags;
q->rc.winflags = 0;
for (i = 0; i < MAXTBL(flags_tab); i++) {
if (x & flags_tab[i].old) {
x &= ~flags_tab[i].old;
q->rc.winflags |= flags_tab[i].new;
}
}
q->rc.winflags |= x;
// now let's convert old top's more limited fields...
j = strlen(q->rc.fieldscur);
if (j > CVT_FLDMAX)
return 1;
strcpy(fields_dst, fields_src);
/* all other fields represent the 'on' state with a capitalized version
of a particular qwerty key. for the 2 additional suse out-of-memory
fields it makes perfect sense to do the exact opposite, doesn't it?
in any case, we must turn them 'off' temporarily... */
if ((p1 = strchr(q->rc.fieldscur, '['))) *p1 = '{';
if ((p2 = strchr(q->rc.fieldscur, '\\'))) *p2 = '|';
for (i = 0; i < j; i++) {
int c = q->rc.fieldscur[i];
x = tolower(c) - 'a';
if (x < 0 || x >= CVT_FLDMAX)
return 1;
fields_dst[i] = fields_src[x];
if (isupper(c))
FLDon(fields_dst[i]);
}
// if we turned any suse only fields off, turn 'em back on OUR way...
if (p1) FLDon(fields_dst[p1 - q->rc.fieldscur]);
if (p2) FLDon(fields_dst[p2 - q->rc.fieldscur]);
strcpy(q->rc.fieldscur, fields_dst);
// lastly, we must adjust the old sort field enum...
x = q->rc.sortindx;
q->rc.sortindx = fields_src[x] - FLD_OFFSET;
Rc_questions = 1;
return 0;
} // end: config_cvt
2011-03-31 16:45:12 +05:30
/*
* Build the local RC file name then try to read both of 'em.
* 'SYS_RCFILESPEC' contains two lines consisting of the secure
* mode switch and an update interval. It's presence limits what
* ordinary users are allowed to do.
* 'Rc_name' contains multiple lines - 3 global + 3 per window.
* line 1 : an eyecatcher and creating program/alias name
* line 2 : an id, Mode_altcsr, Mode_irixps, Delay_time, Curwin.
* For each of the 4 windows:
* line a: contains w->winname, fieldscur
* line b: contains w->winflags, sortindx, maxtasks, graph modes
* line c: contains w->summclr, msgsclr, headclr, taskclr
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
* line 15 : miscellaneous additional global settings
* Any remaining lines are devoted to the 'Inspect Other' feature */
2011-03-31 16:45:12 +05:30
static void configs_read (void) {
float tmp_delay = DEF_DELAY;
char fbuf[LRGBUFSIZ];
const char *p, *p_home;
2011-03-31 16:45:12 +05:30
FILE *fp;
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
int i;
2011-03-31 16:45:12 +05:30
fp = fopen(SYS_RCFILESPEC, "r");
if (fp) {
if (fgets(fbuf, sizeof(fbuf), fp)) { // sys rc file, line 1
Secure_mode = 1;
if (fgets(fbuf, sizeof(fbuf), fp)) // sys rc file, line 2
sscanf(fbuf, "%f", &Rc.delay_time);
}
fclose(fp);
2011-03-31 16:45:12 +05:30
}
// attempt to use the legacy file first, if we cannot access that file, use
// the new XDG basedir locations (XDG_CONFIG_HOME or HOME/.config) instead.
p_home = getenv("HOME");
if (!p_home || p_home[0] == '\0')
p_home = ".";
snprintf(Rc_name, sizeof(Rc_name), "%s/.%src", p_home, Myname);
if (access(Rc_name, F_OK)) {
p = getenv("XDG_CONFIG_HOME");
// ensure the path we get is absolute, fallback otherwise.
if (!p || p[0] != '/') {
p = fmtmk("%s/.config", p_home);
(void)mkdir(p, 0700);
}
snprintf(Rc_name, sizeof(Rc_name), "%s/procps", p);
(void)mkdir(Rc_name, 0700);
snprintf(Rc_name, sizeof(Rc_name), "%s/procps/%src", p, Myname);
}
2011-03-31 16:45:12 +05:30
fp = fopen(Rc_name, "r");
if (fp) {
int tmp_whole, tmp_fract;
if (fgets(fbuf, sizeof(fbuf), fp)) // ignore eyecatcher
; // avoid -Wunused-result
if (6 != fscanf(fp
, "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%d.%d, Curwin=%d\n"
, &Rc.id, &Rc.mode_altscr, &Rc.mode_irixps, &tmp_whole, &tmp_fract, &i)) {
p = fmtmk(N_fmt(RC_bad_files_fmt), Rc_name);
Rc_questions = -1;
goto try_inspect_entries; // maybe a faulty 'inspect' echo
}
2011-03-31 16:45:12 +05:30
// you saw that, right? (fscanf stickin' it to 'i')
Curwin = &Winstk[i];
// this may be ugly, but it keeps us locale independent...
tmp_delay = (float)tmp_whole + (float)tmp_fract / 1000;
2002-11-30 21:26:53 +05:30
2011-03-31 16:45:12 +05:30
for (i = 0 ; i < GROUPSMAX; i++) {
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
int x;
WIN_t *w = &Winstk[i];
p = fmtmk(N_fmt(RC_bad_entry_fmt), i+1, Rc_name);
// note: "fieldscur=%__s" on next line should equal (PFLAGSSIZ -1) !
if (2 != fscanf(fp, "%3s\tfieldscur=%99s\n"
, w->rc.winname, w->rc.fieldscur))
goto default_or_error;
#if PFLAGSSIZ != 100
2011-03-31 16:45:12 +05:30
// too bad fscanf is not as flexible with his format string as snprintf
# error Hey, fix the above fscanf 'PFLAGSSIZ' dependency !
2011-03-31 16:45:12 +05:30
#endif
// be tolerant of missing release 3.3.10 graph modes additions
if (3 > fscanf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d, graph_cpus=%d, graph_mems=%d\n"
, &w->rc.winflags, &w->rc.sortindx, &w->rc.maxtasks, &w->rc.graph_cpus, &w->rc.graph_mems))
goto default_or_error;
if (4 != fscanf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n"
, &w->rc.summclr, &w->rc.msgsclr
, &w->rc.headclr, &w->rc.taskclr))
goto default_or_error;
switch (Rc.id) {
case 'a': // 3.2.8 (former procps)
if (config_cvt(w))
goto default_or_error;
case 'f': // 3.3.0 thru 3.3.3 (ng)
SETw(w, Show_JRNUMS);
case 'g': // from 3.3.4 thru 3.3.8
scat(w->rc.fieldscur, RCF_PLUS_H);
case 'h': // this is release 3.3.9
w->rc.graph_cpus = w->rc.graph_mems = 0;
// these next 2 are really global, but best documented here
Rc.summ_mscale = Rc.task_mscale = SK_Kb;
case 'i': // actual RCF_VERSION_ID
scat(w->rc.fieldscur, RCF_PLUS_J);
case 'j': // and the next version
default:
if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1)
goto default_or_error;
for (x = 0; x < EU_MAXPFLGS; ++x)
if (EU_MAXPFLGS <= FLDget(w, x))
goto default_or_error;
break;
}
#ifndef USE_X_COLHDR
OFFw(w, NOHIFND_xxx | NOHISEL_xxx);
#endif
} // end: for (GROUPSMAX)
// any new addition(s) last, for older rcfiles compatibility...
if (fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n"
, &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress))
; // avoid -Wunused-result
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
try_inspect_entries:
// we'll start off Inspect stuff with 1 'potential' blank line
// ( only realized if we end up with Inspect.total > 0 )
for (i = 0, Inspect.raw = alloc_s("\n");;) {
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 iT(element) Inspect.tab[i].element
size_t lraw = strlen(Inspect.raw) +1;
char *s;
if (!fgets(fbuf, sizeof(fbuf), fp)) break;
lraw += strlen(fbuf) +1;
Inspect.raw = alloc_r(Inspect.raw, lraw);
strcat(Inspect.raw, fbuf);
if (fbuf[0] == '#' || fbuf[0] == '\n') continue;
Inspect.tab = alloc_r(Inspect.tab, sizeof(struct I_ent) * (i + 1));
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
if (!(s = strtok(fbuf, "\t\n"))) { Rc_questions = 1; continue; }
iT(type) = alloc_s(s);
if (!(s = strtok(NULL, "\t\n"))) { Rc_questions = 1; continue; }
iT(name) = alloc_s(s);
if (!(s = strtok(NULL, "\t\n"))) { Rc_questions = 1; continue; }
iT(fmts) = alloc_s(s);
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
switch (toupper(fbuf[0])) {
case 'F':
iT(func) = insp_do_file;
break;
case 'P':
iT(func) = insp_do_pipe;
break;
default:
Rc_questions = 1;
continue;
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
}
iT(farg) = (strstr(iT(fmts), "%d")) ? 1 : 0;
iT(fstr) = alloc_c(FNDBUFSIZ);
iT(flen) = 0;
if (Rc_questions < 0) Rc_questions = 1;
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
++i;
#undef iT
} // end: for ('inspect' entries)
Inspect.total = i;
#ifndef INSP_OFFDEMO
if (!Inspect.total) {
#define mkS(n) N_txt(YINSP_demo ## n ## _txt)
const char *sels[] = { mkS(01), mkS(02), mkS(03) };
Inspect.total = Inspect.demo = MAXTBL(sels);
Inspect.tab = alloc_c(sizeof(struct I_ent) * Inspect.total);
for (i = 0; i < Inspect.total; i++) {
Inspect.tab[i].type = alloc_s(N_txt(YINSP_deqtyp_txt));
Inspect.tab[i].name = alloc_s(sels[i]);
Inspect.tab[i].func = insp_do_demo;
Inspect.tab[i].fmts = alloc_s(N_txt(YINSP_deqfmt_txt));
Inspect.tab[i].fstr = alloc_c(FNDBUFSIZ);
}
#undef mkS
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
}
#endif
if (Rc_questions < 0) {
p = fmtmk(N_fmt(RC_bad_files_fmt), Rc_name);
goto default_or_error;
}
2011-03-31 16:45:12 +05:30
fclose(fp);
} // end: if (fp)
2002-12-05 04:18:30 +05:30
// lastly, establish the true runtime secure mode and delay time
2002-12-05 06:08:57 +05:30
if (!getuid()) Secure_mode = 0;
2011-03-31 16:45:12 +05:30
if (!Secure_mode) Rc.delay_time = tmp_delay;
return;
2002-02-02 04:17:29 +05:30
default_or_error:
#ifdef RCFILE_NOERR
{ RCF_t rcdef = DEF_RCFILE;
fclose(fp);
2011-03-31 16:45:12 +05:30
Rc = rcdef;
for (i = 0 ; i < GROUPSMAX; i++)
Winstk[i].rc = Rc.win[i];
Rc_questions = 1;
}
#else
error_exit(p);
2011-03-31 16:45:12 +05:30
#endif
} // end: configs_read
2002-12-05 04:18:30 +05:30
2011-03-31 16:45:12 +05:30
/*
* Parse command line arguments.
* Note: it's assumed that the rc file(s) have already been read
* and our job is to see if any of those options are to be
* overridden -- we'll force some on and negate others in our
* best effort to honor the loser's (oops, user's) wishes... */
static void parse_args (char **args) {
2002-06-19 05:15:30 +05:30
/* differences between us and the former top:
2002-09-13 17:12:44 +05:30
-C (separate CPU states for SMP) is left to an rcfile
2011-03-31 16:45:12 +05:30
-u (user monitoring) added to compliment interactive 'u'
2002-12-06 12:23:29 +05:30
-p (pid monitoring) allows a comma delimited list
2002-06-19 05:15:30 +05:30
-q (zero delay) eliminated as redundant, incomplete and inappropriate
use: "nice -n-10 top -d0" to achieve what was only claimed
2011-03-31 16:45:12 +05:30
. most switches act as toggles (not 'on' sw) for more user flexibility
2002-06-19 05:15:30 +05:30
. no deprecated/illegal use of 'breakargv:' with goto
. bunched args are actually handled properly and none are ignored
. we tolerate NO whitespace and NO switches -- maybe too tolerant? */
2011-03-31 16:45:12 +05:30
static const char numbs_str[] = "+,-.0123456789";
float tmp_delay = FLT_MAX;
int i;
2002-05-30 09:14:46 +05:30
2002-06-19 05:15:30 +05:30
while (*args) {
2002-11-29 04:39:48 +05:30
const char *cp = *(args++);
2002-05-30 09:14:46 +05:30
while (*cp) {
2011-03-31 16:45:12 +05:30
char ch;
float tmp;
2011-03-31 16:45:12 +05:30
switch ((ch = *cp)) {
2002-05-30 09:14:46 +05:30
case '\0':
break;
2011-03-31 16:45:12 +05:30
case '-':
if (cp[1]) ++cp;
else if (*args) cp = *args++;
if (strspn(cp, "+,-."))
error_exit(fmtmk(N_fmt(WRONG_switch_fmt)
, cp, Myname, N_txt(USAGE_abbrev_txt)));
2011-03-31 16:45:12 +05:30
continue;
case '1': // ensure behavior identical to run-time toggle
if (CHKw(Curwin, View_CPUNOD)) OFFw(Curwin, View_CPUSUM);
else TOGw(Curwin, View_CPUSUM);
OFFw(Curwin, View_CPUNOD);
SETw(Curwin, View_STATES);
goto bump_cp;
2002-05-30 09:14:46 +05:30
case 'b':
Batch = 1;
goto bump_cp;
2002-05-30 09:14:46 +05:30
case 'c':
2002-06-19 05:15:30 +05:30
TOGw(Curwin, Show_CMDLIN);
goto bump_cp;
2002-05-30 09:14:46 +05:30
case 'd':
if (cp[1]) ++cp;
2002-06-19 05:15:30 +05:30
else if (*args) cp = *args++;
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
if (!mkfloat(cp, &tmp_delay, 0))
error_exit(fmtmk(N_fmt(BAD_delayint_fmt), cp));
if (0 > tmp_delay)
error_exit(N_txt(DELAY_badarg_txt));
2002-05-30 09:14:46 +05:30
break;
2017-03-09 11:30:00 +05:30
case 'E':
{ const char *get = "kmgtpe", *got;
if (cp[1]) cp++;
else if (*args) cp = *args++;
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
if (!(got = strchr(get, tolower(*cp))))
error_exit(fmtmk(N_fmt(BAD_memscale_fmt), *cp));
Rc.summ_mscale = (int)(got - get);
} goto bump_cp;
2005-06-22 00:50:39 +05:30
case 'H':
2011-03-31 16:45:12 +05:30
Thread_mode = 1;
goto bump_cp;
2005-06-22 00:50:39 +05:30
case 'h':
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
case 'v':
puts(fmtmk(N_fmt(HELP_cmdline_fmt)
, PACKAGE_STRING, Myname, N_txt(USAGE_abbrev_txt)));
2011-03-31 16:45:12 +05:30
bye_bye(NULL);
2002-05-30 09:14:46 +05:30
case 'i':
2002-06-19 05:15:30 +05:30
TOGw(Curwin, Show_IDLEPS);
2002-11-30 06:52:01 +05:30
Curwin->rc.maxtasks = 0;
goto bump_cp;
2002-05-30 09:14:46 +05:30
case 'n':
if (cp[1]) cp++;
2002-06-19 05:15:30 +05:30
else if (*args) cp = *args++;
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
if (!mkfloat(cp, &tmp, 1) || 1.0 > tmp)
error_exit(fmtmk(N_fmt(BAD_niterate_fmt), cp));
Loops = (int)tmp;
2002-05-30 09:14:46 +05:30
break;
case 'o':
if (cp[1]) cp++;
else if (*args) cp = *args++;
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
if (*cp == '+') { SETw(Curwin, Qsrt_NORMAL); ++cp; }
else if (*cp == '-') { OFFw(Curwin, Qsrt_NORMAL); ++cp; }
for (i = 0; i < EU_MAXPFLGS; i++)
if (!STRCMP(cp, N_col(i))) break;
if (i == EU_MAXPFLGS)
error_exit(fmtmk(N_fmt(XTRA_badflds_fmt), cp));
OFFw(Curwin, Show_FOREST);
Curwin->rc.sortindx = i;
cp += strlen(cp);
break;
case 'O':
for (i = 0; i < EU_MAXPFLGS; i++)
puts(N_col(i));
bye_bye(NULL);
case 'p':
{ int pid; char *p;
if (Curwin->usrseltyp) error_exit(N_txt(SELECT_clash_txt));
do {
2002-06-19 05:15:30 +05:30
if (cp[1]) cp++;
else if (*args) cp = *args++;
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
2002-05-30 09:14:46 +05:30
if (Monpidsidx >= MONPIDMAX)
error_exit(fmtmk(N_fmt(LIMIT_exceed_fmt), MONPIDMAX));
if (1 != sscanf(cp, "%d", &pid)
|| strpbrk(cp, "+-."))
error_exit(fmtmk(N_fmt(BAD_mon_pids_fmt), cp));
if (!pid) pid = getpid();
for (i = 0; i < Monpidsidx; i++)
if (Monpids[i] == pid) goto next_pid;
Monpids[Monpidsidx++] = pid;
next_pid:
if (!(p = strchr(cp, ','))) break;
2002-06-19 05:15:30 +05:30
cp = p;
2002-05-30 09:14:46 +05:30
} while (*cp);
} break;
2002-05-30 09:14:46 +05:30
case 's':
Secure_mode = 1;
goto bump_cp;
2002-05-30 09:14:46 +05:30
case 'S':
2002-06-19 05:15:30 +05:30
TOGw(Curwin, Show_CTIMES);
goto bump_cp;
2002-12-10 08:31:17 +05:30
case 'u':
case 'U':
{ const char *errmsg;
if (Monpidsidx || Curwin->usrseltyp) error_exit(N_txt(SELECT_clash_txt));
2011-03-31 16:45:12 +05:30
if (cp[1]) cp++;
else if (*args) cp = *args++;
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
if ((errmsg = user_certify(Curwin, cp, ch))) error_exit(errmsg);
2011-03-31 16:45:12 +05:30
cp += strlen(cp);
} break;
case 'w':
{ const char *pn = NULL;
int ai = 0, ci = 0;
tmp = -1;
if (cp[1]) pn = &cp[1];
else if (*args) { pn = *args; ai = 1; }
if (pn && !(ci = strspn(pn, numbs_str))) { ai = 0; pn = NULL; }
if (pn && (!mkfloat(pn, &tmp, 1) || tmp < W_MIN_COL))
error_exit(fmtmk(N_fmt(BAD_widtharg_fmt), pn));
Width_mode = (int)tmp;
cp++;
args += ai;
if (pn) cp = pn + ci;
} continue;
2002-05-30 09:14:46 +05:30
default :
error_exit(fmtmk(N_fmt(UNKNOWN_opts_fmt)
, *cp, Myname, N_txt(USAGE_abbrev_txt)));
2011-03-31 16:45:12 +05:30
} // end: switch (*cp)
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
// advance cp and jump over any numerical args used above
if (*cp) cp += strspn(&cp[1], numbs_str);
bump_cp:
if (*cp) ++cp;
2011-03-31 16:45:12 +05:30
} // end: while (*cp)
} // end: while (*args)
// fixup delay time, maybe...
if (FLT_MAX > tmp_delay) {
2011-03-31 16:45:12 +05:30
if (Secure_mode)
error_exit(N_txt(DELAY_secure_txt));
2011-03-31 16:45:12 +05:30
Rc.delay_time = tmp_delay;
2002-05-30 09:14:46 +05:30
}
2011-03-31 16:45:12 +05:30
} // end: parse_args
2002-02-02 04:17:29 +05:30
2002-05-30 09:14:46 +05:30
/*
* Set up the terminal attributes */
2011-03-31 16:45:12 +05:30
static void whack_terminal (void) {
static char dummy[] = "dumb";
struct termios tmptty;
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
// the curses part...
2004-09-12 21:13:48 +05:30
if (Batch) {
2011-03-31 16:45:12 +05:30
setupterm(dummy, STDOUT_FILENO, NULL);
2004-09-12 21:13:48 +05:30
return;
}
2011-03-31 16:45:12 +05:30
#ifdef PRETENDNOCAP
setupterm(dummy, STDOUT_FILENO, NULL);
#else
2002-05-30 09:14:46 +05:30
setupterm(NULL, STDOUT_FILENO, NULL);
2011-03-31 16:45:12 +05:30
#endif
// our part...
if (-1 == tcgetattr(STDIN_FILENO, &Tty_original))
error_exit(N_txt(FAIL_tty_get_txt));
2011-03-31 16:45:12 +05:30
// ok, haven't really changed anything but we do have our snapshot
2004-09-12 21:13:48 +05:30
Ttychanged = 1;
2011-03-31 16:45:12 +05:30
// first, a consistent canonical mode for interactive line input
tmptty = Tty_original;
tmptty.c_lflag |= (ECHO | ECHOCTL | ECHOE | ICANON | ISIG);
tmptty.c_lflag &= ~NOFLSH;
tmptty.c_oflag &= ~TAB3;
tmptty.c_iflag |= BRKINT;
tmptty.c_iflag &= ~IGNBRK;
if (key_backspace && 1 == strlen(key_backspace))
tmptty.c_cc[VERASE] = *key_backspace;
#ifdef TERMIOS_ONLY
2011-03-31 16:45:12 +05:30
if (-1 == tcsetattr(STDIN_FILENO, TCSAFLUSH, &tmptty))
error_exit(fmtmk(N_fmt(FAIL_tty_set_fmt), strerror(errno)));
2011-03-31 16:45:12 +05:30
tcgetattr(STDIN_FILENO, &Tty_tweaked);
#endif
// lastly, a nearly raw mode for unsolicited single keystrokes
tmptty.c_lflag &= ~(ECHO | ECHOCTL | ECHOE | ICANON);
tmptty.c_cc[VMIN] = 1;
tmptty.c_cc[VTIME] = 0;
if (-1 == tcsetattr(STDIN_FILENO, TCSAFLUSH, &tmptty))
error_exit(fmtmk(N_fmt(FAIL_tty_set_fmt), strerror(errno)));
2011-03-31 16:45:12 +05:30
tcgetattr(STDIN_FILENO, &Tty_raw);
#ifndef OFF_STDIOLBF
2004-09-12 21:13:48 +05:30
// thanks anyway stdio, but we'll manage buffering at the frame level...
setbuffer(stdout, Stdout_buf, sizeof(Stdout_buf));
#endif
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
#ifdef OFF_SCROLLBK
top: disable tty scrollback buffer to improve SIGWINCH A scrollback buffer used in several terminal emulators could be a real inconvenience to a user following some resize operations. Extra keystroke(s) would frequently be required in order to properly render top's display. After much sleuthing we unearthed two terminfo strings which have the effect of disabling/restoring that darn scrollback buffer. They were well hidden under a title of strings 'to start/end programs using cup'. In turn, 'cup' deals with a tty's cursor addressing capability. We don't care what you call them or what they refer to so long as they get the job done. And these really do! Be advised, however, that there are some side effects, several of which can even be considered as beneficial: . enter_ca_mode/smcup/ti disables scrollback buffering ( and that's good, it's what we had always hoped for ) . exit_ca_mode/rmcup/te restores the scrollback buffer ( but also restores screen contents existing pre-top ) ( which is different from former program end results ) ( where that last rendered screen was left untouched ) . the above screen replacement would impact ^Z suspend ( thus we keep the scrollback buffer disabled during ) ( the suspend/resume sequence so that the users will ) ( have a visual clue that top is suspended not ended ) If a terminal does not support these terminfo strings, we will revert to top's former behavior at program end where we position the cursor at screen bottom and then output a single newline character. This will prevent a shell prompt from embedding within top's final screen. This commit's approach has been tested under a variety of emulators and window managers, many of which linked with libvte and others that employed their own scheme. Examples are: gnome_terminal; kde konsole; lxterminal; terminator; terminology; urxvt; xfce4-terminal; xterm. I do now believe that the whole SIGWINCH deal is done! (everything is perfectly justified plus right margins) (are completely filled, but of course it must be luck) Reference(s): http://www.freelists.org/post/procps/top-won-the-sigwinch-war http://www.freelists.org/post/procps/top-won-the-sigwinch-war,4 Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-31 11:30:00 +05:30
// this has the effect of disabling any troublesome scrollback buffer...
if (enter_ca_mode) putp(enter_ca_mode);
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
#endif
// and don't forget to ask iokey to initialize his tinfo_tab
iokey(0);
2011-03-31 16:45:12 +05:30
} // end: whack_terminal
2002-06-19 05:15:30 +05:30
/*###### Windows/Field Groups support #################################*/
2002-02-02 04:17:29 +05:30
2011-03-31 16:45:12 +05:30
/*
* Value a window's name and make the associated group name. */
static void win_names (WIN_t *q, const char *name) {
/* note: sprintf/snprintf results are "undefined" when src==dst,
according to C99 & POSIX.1-2001 (thanks adc) */
if (q->rc.winname != name)
snprintf(q->rc.winname, sizeof(q->rc.winname), "%s", name);
snprintf(q->grpname, sizeof(q->grpname), "%d:%s", q->winnum, name);
} // end: win_names
2002-02-02 04:17:29 +05:30
/*
* This guy just resets (normalizes) a single window
* and he ensures pid monitoring is no longer active. */
static void win_reset (WIN_t *q) {
SETw(q, Show_IDLEPS | Show_TASKON);
#ifndef SCROLLVAR_NO
q->rc.maxtasks = q->usrseltyp = q->begpflg = q->begtask = q->varcolbeg = 0;
#else
q->rc.maxtasks = q->usrseltyp = q->begpflg = q->begtask = 0;
#endif
Monpidsidx = 0;
osel_clear(q);
q->findstr[0] = '\0';
#ifndef USE_X_COLHDR
// NOHISEL_xxx is redundant (already turned off by osel_clear)
OFFw(q, NOHIFND_xxx | NOHISEL_xxx);
#endif
} // end: win_reset
2011-03-31 16:45:12 +05:30
/*
* Display a window/field group (ie. make it "current"). */
static WIN_t *win_select (int ch) {
2011-03-31 16:45:12 +05:30
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
2002-05-30 09:14:46 +05:30
2002-11-08 06:01:28 +05:30
/* if there's no ch, it means we're supporting the external interface,
2002-06-19 05:15:30 +05:30
so we must try to get our own darn ch by begging the user... */
if (!ch) {
show_pmt(N_txt(CHOOSE_group_txt));
if (1 > (ch = iokey(1))) return w;
2002-05-30 09:14:46 +05:30
}
2002-06-19 05:15:30 +05:30
switch (ch) {
case 'a': // we don't carry 'a' / 'w' in our
w = w->next; // pmt - they're here for a good
break; // friend of ours -- wins_colors.
case 'w': // (however those letters work via
w = w->prev; // the pmt too but gee, end-loser
break; // should just press the darn key)
case '1': case '2' : case '3': case '4':
2011-03-31 16:45:12 +05:30
w = &Winstk[ch - '1'];
break;
default: // keep gcc happy
2002-06-19 05:15:30 +05:30
break;
2002-05-30 09:14:46 +05:30
}
2011-03-31 16:45:12 +05:30
return Curwin = w;
} // end: win_select
2002-02-02 04:17:29 +05:30
2011-03-31 16:45:12 +05:30
/*
* Just warn the user when a command can't be honored. */
static int win_warn (int what) {
switch (what) {
case Warn_ALT:
show_msg(N_txt(DISABLED_cmd_txt));
2011-03-31 16:45:12 +05:30
break;
case Warn_VIZ:
show_msg(fmtmk(N_fmt(DISABLED_win_fmt), Curwin->grpname));
2011-03-31 16:45:12 +05:30
break;
default: // keep gcc happy
break;
}
/* we gotta' return false 'cause we're somewhat well known within
macro society, by way of that sassy little tertiary operator... */
2002-06-19 05:15:30 +05:30
return 0;
2011-03-31 16:45:12 +05:30
} // end: win_warn
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/*
* Change colors *Helper* function to save/restore settings;
* ensure colors will show; and rebuild the terminfo strings. */
static void wins_clrhlp (WIN_t *q, int save) {
2002-06-19 05:15:30 +05:30
static int flgssav, summsav, msgssav, headsav, tasksav;
2002-05-30 09:14:46 +05:30
2002-06-19 05:15:30 +05:30
if (save) {
2002-11-30 06:52:01 +05:30
flgssav = q->rc.winflags; summsav = q->rc.summclr;
msgssav = q->rc.msgsclr; headsav = q->rc.headclr; tasksav = q->rc.taskclr;
2002-06-19 05:15:30 +05:30
SETw(q, Show_COLORS);
} else {
2002-11-30 06:52:01 +05:30
q->rc.winflags = flgssav; q->rc.summclr = summsav;
q->rc.msgsclr = msgssav; q->rc.headclr = headsav; q->rc.taskclr = tasksav;
2002-05-30 09:14:46 +05:30
}
2002-06-19 05:15:30 +05:30
capsmk(q);
} // end: wins_clrhlp
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/*
* Change colors used in display */
static void wins_colors (void) {
#define kbdABORT 'q'
#define kbdAPPLY kbd_ENTER
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
int clr = w->rc.taskclr, *pclr = &w->rc.taskclr;
char tgt = 'T';
int key;
2002-05-30 09:14:46 +05:30
2002-06-19 05:15:30 +05:30
if (0 >= max_colors) {
show_msg(N_txt(COLORS_nomap_txt));
2002-06-19 05:15:30 +05:30
return;
}
wins_clrhlp(w, 1);
putp((Cursor_state = Cap_curs_huge));
signify_that:
putp(Cap_clr_scr);
adj_geometry();
2002-06-19 05:15:30 +05:30
do {
putp(Cap_home);
2011-03-31 16:45:12 +05:30
// this string is well above ISO C89's minimum requirements!
show_special(1, fmtmk(N_unq(COLOR_custom_fmt)
, PACKAGE_STRING, w->grpname
, CHKw(w, View_NOBOLD) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
, CHKw(w, Show_COLORS) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
, CHKw(w, Show_HIBOLD) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
2011-03-31 16:45:12 +05:30
, tgt, clr, w->grpname));
putp(Cap_clr_eos);
fflush(stdout);
if (Frames_signal) goto signify_that;
key = iokey(1);
if (key < 1) goto signify_that;
switch (key) {
2002-06-19 05:15:30 +05:30
case 'S':
2011-03-31 16:45:12 +05:30
pclr = &w->rc.summclr;
2002-06-19 05:15:30 +05:30
clr = *pclr;
tgt = key;
2002-06-19 05:15:30 +05:30
break;
case 'M':
2011-03-31 16:45:12 +05:30
pclr = &w->rc.msgsclr;
2002-06-19 05:15:30 +05:30
clr = *pclr;
tgt = key;
2002-06-19 05:15:30 +05:30
break;
case 'H':
2011-03-31 16:45:12 +05:30
pclr = &w->rc.headclr;
2002-06-19 05:15:30 +05:30
clr = *pclr;
tgt = key;
2002-06-19 05:15:30 +05:30
break;
case 'T':
2011-03-31 16:45:12 +05:30
pclr = &w->rc.taskclr;
2002-06-19 05:15:30 +05:30
clr = *pclr;
tgt = key;
2002-06-19 05:15:30 +05:30
break;
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
clr = key - '0';
2002-06-19 05:15:30 +05:30
*pclr = clr;
break;
case 'B':
2011-03-31 16:45:12 +05:30
TOGw(w, View_NOBOLD);
break;
2002-06-19 05:15:30 +05:30
case 'b':
2011-03-31 16:45:12 +05:30
TOGw(w, Show_HIBOLD);
2002-06-19 05:15:30 +05:30
break;
case 'z':
2011-03-31 16:45:12 +05:30
TOGw(w, Show_COLORS);
2002-06-19 05:15:30 +05:30
break;
case 'a':
case 'w':
wins_clrhlp((w = win_select(key)), 1);
2011-03-31 16:45:12 +05:30
clr = w->rc.taskclr, pclr = &w->rc.taskclr;
2002-06-19 05:15:30 +05:30
tgt = 'T';
break;
default:
break; // keep gcc happy
2002-06-19 05:15:30 +05:30
}
2011-03-31 16:45:12 +05:30
capsmk(w);
} while (key != kbdAPPLY && key != kbdABORT);
if (key == kbdABORT) wins_clrhlp(w, 0);
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
#undef kbdABORT
#undef kbdAPPLY
} // end: wins_colors
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
/*
* Manipulate flag(s) for all our windows. */
static void wins_reflag (int what, int flg) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
2002-06-19 05:15:30 +05:30
do {
switch (what) {
2002-06-27 05:26:49 +05:30
case Flags_TOG:
2002-06-19 05:15:30 +05:30
TOGw(w, flg);
break;
2011-03-31 16:45:12 +05:30
case Flags_SET: // Ummmm, i can't find anybody
SETw(w, flg); // who uses Flags_set ...
2002-10-02 05:40:30 +05:30
break;
2002-06-27 05:26:49 +05:30
case Flags_OFF:
2002-06-19 05:15:30 +05:30
OFFw(w, flg);
break;
2011-03-31 16:45:12 +05:30
default: // keep gcc happy
break;
2002-06-19 05:15:30 +05:30
}
2011-03-31 16:45:12 +05:30
/* a flag with special significance -- user wants to rebalance
display so we gotta' off some stuff then force on two flags... */
if (EQUWINS_xxx == flg)
win_reset(w);
2002-10-02 05:40:30 +05:30
w = w->next;
} while (w != Curwin);
2011-03-31 16:45:12 +05:30
} // end: wins_reflag
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
/*
* Set up the raw/incomplete field group windows --
* they'll be finished off after startup completes.
* [ and very likely that will override most/all of our efforts ]
* [ --- life-is-NOT-fair --- ] */
static void wins_stage_1 (void) {
2002-06-19 05:15:30 +05:30
WIN_t *w;
2002-11-08 06:01:28 +05:30
int i;
2002-06-19 05:15:30 +05:30
for (i = 0; i < GROUPSMAX; i++) {
2002-12-05 08:30:42 +05:30
w = &Winstk[i];
2002-06-27 05:26:49 +05:30
w->winnum = i + 1;
2002-12-05 04:18:30 +05:30
w->rc = Rc.win[i];
2002-06-19 05:15:30 +05:30
w->captab[0] = Cap_norm;
w->captab[1] = Cap_norm;
w->captab[2] = w->cap_bold;
2002-11-08 06:01:28 +05:30
w->captab[3] = w->capclr_sum;
w->captab[4] = w->capclr_msg;
w->captab[5] = w->capclr_pmt;
w->captab[6] = w->capclr_hdr;
w->captab[7] = w->capclr_rowhigh;
w->captab[8] = w->capclr_rownorm;
2002-06-19 05:15:30 +05:30
w->next = w + 1;
w->prev = w - 1;
}
2011-03-31 16:45:12 +05:30
// fixup the circular chains...
Winstk[GROUPSMAX - 1].next = &Winstk[0];
Winstk[0].prev = &Winstk[GROUPSMAX - 1];
2002-12-05 08:30:42 +05:30
Curwin = Winstk;
2011-03-31 16:45:12 +05:30
} // end: wins_stage_1
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
/*
* This guy just completes the field group windows after the
2013-01-16 11:30:00 +05:30
* rcfiles have been read and command line arguments parsed.
* And since he's the cabose of startup, he'll also tidy up
* a few final things... */
2011-03-31 16:45:12 +05:30
static void wins_stage_2 (void) {
2002-06-19 05:15:30 +05:30
int i;
for (i = 0; i < GROUPSMAX; i++) {
2002-12-05 08:30:42 +05:30
win_names(&Winstk[i], Winstk[i].rc.winname);
capsmk(&Winstk[i]);
Winstk[i].findstr = alloc_c(FNDBUFSIZ);
Winstk[i].findlen = 0;
2002-06-19 05:15:30 +05:30
}
if (!Batch)
putp((Cursor_state = Cap_curs_hide));
else {
OFFw(Curwin, View_SCROLL);
signal(SIGHUP, SIG_IGN); // allow running under nohup
}
2011-08-30 17:35:45 +05:30
// fill in missing Fieldstab members and build each window's columnhdr
zap_fieldstab();
2013-01-16 11:30:00 +05:30
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
#ifndef OFF_STDERROR
/* there's a chance that damn libnuma may spew to stderr so we gotta
make sure he does not corrupt poor ol' top's first output screen!
Yes, he provides some overridable 'weak' functions to change such
behavior but we can't exploit that since we don't follow a normal
ld route to symbol resolution (we use that dlopen() guy instead)! */
Stderr_save = dup(fileno(stderr));
if (-1 < Stderr_save && freopen("/dev/null", "w", stderr))
; // avoid -Wunused-result
#endif
2013-01-16 11:30:00 +05:30
// lastly, initialize a signal set used to throttle one troublesome signal
sigemptyset(&Sigwinch_set);
#ifdef SIGNALS_LESS
2013-01-16 11:30:00 +05:30
sigaddset(&Sigwinch_set, SIGWINCH);
#endif
2011-03-31 16:45:12 +05:30
} // end: wins_stage_2
/*###### Interactive Input Tertiary support ############################*/
2002-05-30 09:14:46 +05:30
/*
* This section exists so as to offer some function naming freedom
* while also maintaining the strict alphabetical order protocol
* within each section. */
2002-05-30 09:14:46 +05:30
/*
* This guy is a *Helper* function serving the following two masters:
* find_string() - find the next match in a given window
* task_show() - highlight all matches currently in-view
* If q->findstr is found in the designated buffer, he returns the
* offset from the start of the buffer, otherwise he returns -1. */
static inline int find_ofs (const WIN_t *q, const char *buf) {
char *fnd;
if (q->findstr[0] && (fnd = STRSTR(buf, q->findstr)))
return (int)(fnd - buf);
return -1;
} // end: find_ofs
/* This is currently the one true prototype require by top.
It is placed here, instead of top.h, so as to avoid a compiler
warning when top_nls.c is compiled. */
static const char *task_show (const WIN_t *q, const proc_t *p);
2011-12-17 01:34:38 +05:30
static void find_string (int ch) {
#define reDUX (found) ? N_txt(WORD_another_txt) : ""
2011-12-17 01:34:38 +05:30
static int found;
int i;
if ('&' == ch && !Curwin->findstr[0]) {
show_msg(N_txt(FIND_no_next_txt));
2011-12-17 01:34:38 +05:30
return;
}
if ('L' == ch) {
char *str = ioline(N_txt(GET_find_str_txt));
if (*str == kbd_ESC) return;
snprintf(Curwin->findstr, FNDBUFSIZ, "%s", str);
Curwin->findlen = strlen(Curwin->findstr);
2011-12-17 01:34:38 +05:30
found = 0;
#ifndef USE_X_COLHDR
if (Curwin->findstr[0]) SETw(Curwin, NOHIFND_xxx);
else OFFw(Curwin, NOHIFND_xxx);
#endif
2011-12-17 01:34:38 +05:30
}
if (Curwin->findstr[0]) {
SETw(Curwin, INFINDS_xxx);
2011-12-17 01:34:38 +05:30
for (i = Curwin->begtask; i < Frame_maxtask; i++) {
const char *row = task_show(Curwin, Curwin->ppt[i]);
if (*row && -1 < find_ofs(Curwin, row)) {
2011-12-17 01:34:38 +05:30
found = 1;
if (i == Curwin->begtask) continue;
Curwin->begtask = i;
return;
}
}
show_msg(fmtmk(N_fmt(FIND_no_find_fmt), reDUX, Curwin->findstr));
2011-12-17 01:34:38 +05:30
}
#undef reDUX
} // end: find_string
2011-03-31 16:45:12 +05:30
static void help_view (void) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
char key = 1;
2002-05-30 09:14:46 +05:30
putp((Cursor_state = Cap_curs_huge));
signify_that:
2011-03-31 16:45:12 +05:30
putp(Cap_clr_scr);
adj_geometry();
2002-05-30 09:14:46 +05:30
show_special(1, fmtmk(N_unq(KEYS_helpbas_fmt)
, PACKAGE_STRING
2011-03-31 16:45:12 +05:30
, w->grpname
, CHKw(w, Show_CTIMES) ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
2011-03-31 16:45:12 +05:30
, Rc.delay_time
, Secure_mode ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)
, Secure_mode ? "" : N_unq(KEYS_helpext_fmt)));
putp(Cap_clr_eos);
fflush(stdout);
2011-03-31 16:45:12 +05:30
if (Frames_signal) goto signify_that;
key = iokey(1);
if (key < 1) goto signify_that;
switch (key) {
case kbd_ESC: case 'q':
break;
case '?': case 'h': case 'H':
do {
putp(Cap_home);
show_special(1, fmtmk(N_unq(WINDOWS_help_fmt)
, w->grpname
, Winstk[0].rc.winname, Winstk[1].rc.winname
, Winstk[2].rc.winname, Winstk[3].rc.winname));
putp(Cap_clr_eos);
fflush(stdout);
if (Frames_signal || (key = iokey(1)) < 1) {
2013-01-16 11:30:00 +05:30
adj_geometry();
putp(Cap_clr_scr);
} else w = win_select(key);
} while (key != kbd_ENTER && key != kbd_ESC);
break;
default:
goto signify_that;
2011-03-31 16:45:12 +05:30
}
} // end: help_view
2002-05-30 09:14:46 +05:30
static void other_selection (int ch) {
int (*rel)(const char *, const char *);
char *(*sel)(const char *, const char *);
char raw[MEDBUFSIZ], ops, *glob, *pval;
struct osel_s *osel;
const char *typ;
int inc, enu;
if (ch == 'o') {
typ = N_txt(OSEL_casenot_txt);
rel = strcasecmp;
sel = strcasestr;
} else {
typ = N_txt(OSEL_caseyes_txt);
rel = strcmp;
sel = strstr;
}
glob = ioline(fmtmk(N_fmt(OSEL_prompts_fmt), Curwin->osel_tot + 1, typ));
if (*glob == kbd_ESC
|| !snprintf(raw, sizeof(raw), "%s", glob))
return;
for (osel = Curwin->osel_1st; osel; ) {
if (!strcmp(osel->raw, glob)) { // #1: is criteria duplicate?
show_msg(N_txt(OSEL_errdups_txt));
return;
}
osel = osel->nxt;
}
if (*glob != '!') inc = 1; // #2: is it include/exclude?
else { ++glob; inc = 0; }
if (!(pval = strpbrk(glob, "<=>"))) { // #3: do we see a delimiter?
show_msg(fmtmk(N_fmt(OSEL_errdelm_fmt)
, inc ? N_txt(WORD_include_txt) : N_txt(WORD_exclude_txt)));
return;
}
ops = *(pval);
*(pval++) = '\0';
for (enu = 0; enu < EU_MAXPFLGS; enu++) // #4: is this a valid field?
if (!STRCMP(N_col(enu), glob)) break;
if (enu == EU_MAXPFLGS) {
show_msg(fmtmk(N_fmt(XTRA_badflds_fmt), glob));
return;
}
if (!(*pval)) { // #5: did we get some value?
show_msg(fmtmk(N_fmt(OSEL_errvalu_fmt)
, inc ? N_txt(WORD_include_txt) : N_txt(WORD_exclude_txt)));
return;
}
osel = alloc_c(sizeof(struct osel_s));
osel->inc = inc;
osel->enu = enu;
osel->ops = ops;
if (ops == '=') osel->val = alloc_s(pval);
else osel->val = alloc_s(justify_pad(pval, Fieldstab[enu].width, Fieldstab[enu].align));
osel->rel = rel;
osel->sel = sel;
osel->raw = alloc_s(raw);
osel->nxt = Curwin->osel_1st;
Curwin->osel_1st = osel;
Curwin->osel_tot += 1;
if (!Curwin->osel_prt) Curwin->osel_prt = alloc_c(strlen(raw) + 3);
else Curwin->osel_prt = alloc_r(Curwin->osel_prt, strlen(Curwin->osel_prt) + strlen(raw) + 6);
strcat(Curwin->osel_prt, fmtmk("%s'%s'", (Curwin->osel_tot > 1) ? " + " : "", raw));
#ifndef USE_X_COLHDR
SETw(Curwin, NOHISEL_xxx);
#endif
} // end: other_selection
static void write_rcfile (void) {
FILE *fp;
int i;
if (Rc_questions) {
show_pmt(N_txt(XTRA_warncfg_txt));
if ('y' != tolower(iokey(1)))
return;
Rc_questions = 0;
}
if (!(fp = fopen(Rc_name, "w"))) {
show_msg(fmtmk(N_fmt(FAIL_rc_open_fmt), Rc_name, strerror(errno)));
return;
}
fprintf(fp, "%s's " RCF_EYECATCHER, Myname);
fprintf(fp, "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%d.%d, Curwin=%d\n"
, RCF_VERSION_ID
, Rc.mode_altscr, Rc.mode_irixps
// this may be ugly, but it keeps us locale independent...
, (int)Rc.delay_time, (int)((Rc.delay_time - (int)Rc.delay_time) * 1000)
, (int)(Curwin - Winstk));
for (i = 0 ; i < GROUPSMAX; i++) {
fprintf(fp, "%s\tfieldscur=%s\n"
, Winstk[i].rc.winname, Winstk[i].rc.fieldscur);
fprintf(fp, "\twinflags=%d, sortindx=%d, maxtasks=%d, graph_cpus=%d, graph_mems=%d\n"
, Winstk[i].rc.winflags, Winstk[i].rc.sortindx, Winstk[i].rc.maxtasks
, Winstk[i].rc.graph_cpus, Winstk[i].rc.graph_mems);
fprintf(fp, "\tsummclr=%d, msgsclr=%d, headclr=%d, taskclr=%d\n"
, Winstk[i].rc.summclr, Winstk[i].rc.msgsclr
, Winstk[i].rc.headclr, Winstk[i].rc.taskclr);
}
// any new addition(s) last, for older rcfiles compatibility...
fprintf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n"
, Rc.fixed_widest, Rc.summ_mscale, Rc.task_mscale, Rc.zero_suppress);
if (Inspect.raw)
fputs(Inspect.raw, fp);
fclose(fp);
show_msg(fmtmk(N_fmt(WRITE_rcfile_fmt), Rc_name));
} // end: write_rcfile
/*###### Interactive Input Secondary support (do_key helpers) ##########*/
/*
* These routines exist just to keep the do_key() function
* a reasonably modest size. */
2011-03-31 16:45:12 +05:30
static void keys_global (int ch) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
switch (ch) {
case '?':
case 'h':
help_view();
break;
2011-03-31 16:45:12 +05:30
case 'B':
TOGw(w, View_NOBOLD);
capsmk(w);
break;
2002-11-08 06:01:28 +05:30
case 'd':
case 's':
if (Secure_mode)
show_msg(N_txt(NOT_onsecure_txt));
2002-11-08 06:01:28 +05:30
else {
float tmp =
get_float(fmtmk(N_fmt(DELAY_change_fmt), Rc.delay_time));
if (tmp > -1) Rc.delay_time = tmp;
2002-05-30 09:14:46 +05:30
}
2002-11-08 06:01:28 +05:30
break;
case 'E':
if (++Rc.summ_mscale > SK_Eb) Rc.summ_mscale = SK_Kb;
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
break;
case 'e':
if (++Rc.task_mscale > SK_Pb) Rc.task_mscale = SK_Kb;
break;
2002-11-08 06:01:28 +05:30
case 'F':
2011-03-31 16:45:12 +05:30
case 'f':
fields_utility();
2002-11-08 06:01:28 +05:30
break;
case 'g':
win_select(0);
break;
2005-06-22 00:50:39 +05:30
case 'H':
2011-03-31 16:45:12 +05:30
Thread_mode = !Thread_mode;
2011-08-30 17:35:45 +05:30
if (!CHKw(w, View_STATES))
show_msg(fmtmk(N_fmt(THREADS_show_fmt)
, Thread_mode ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)));
// force an extra procs refresh to avoid %cpu distortions...
Pseudo_row = PROC_XTRA;
2002-11-08 06:01:28 +05:30
break;
case 'I':
if (Cpu_faux_tot > 1) {
2002-12-05 04:18:30 +05:30
Rc.mode_irixps = !Rc.mode_irixps;
show_msg(fmtmk(N_fmt(IRIX_curmode_fmt)
, Rc.mode_irixps ? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)));
2002-11-08 06:01:28 +05:30
} else
show_msg(N_txt(NOT_smp_cpus_txt));
2002-11-08 06:01:28 +05:30
break;
case 'k':
if (Secure_mode) {
show_msg(N_txt(NOT_onsecure_txt));
2002-11-08 06:01:28 +05:30
} else {
int sig = SIGTERM,
def = w->ppt[w->begtask]->tid,
pid = get_int(fmtmk(N_txt(GET_pid2kill_fmt), def));
if (pid > GET_NUM_ESC) {
char *str;
if (pid == GET_NUM_NOT) pid = def;
str = ioline(fmtmk(N_fmt(GET_sigs_num_fmt), pid, SIGTERM));
if (*str != kbd_ESC) {
if (*str) sig = signal_name_to_number(str);
if (Frames_signal) break;
if (0 < sig && kill(pid, sig))
show_msg(fmtmk(N_fmt(FAIL_signals_fmt)
, pid, sig, strerror(errno)));
else if (0 > sig) show_msg(N_txt(BAD_signalid_txt));
}
2002-11-08 06:01:28 +05:30
}
}
break;
2011-03-31 16:45:12 +05:30
case 'r':
if (Secure_mode)
show_msg(N_txt(NOT_onsecure_txt));
2011-03-31 16:45:12 +05:30
else {
int val,
def = w->ppt[w->begtask]->tid,
pid = get_int(fmtmk(N_txt(GET_pid2nice_fmt), def));
if (pid > GET_NUM_ESC) {
if (pid == GET_NUM_NOT) pid = def;
val = get_int(fmtmk(N_fmt(GET_nice_num_fmt), pid));
if (val > GET_NUM_NOT
&& setpriority(PRIO_PROCESS, (unsigned)pid, val))
show_msg(fmtmk(N_fmt(FAIL_re_nice_fmt)
, pid, val, strerror(errno)));
}
2011-03-31 16:45:12 +05:30
}
break;
case 'X':
{ int wide = get_int(fmtmk(N_fmt(XTRA_fixwide_fmt), Rc.fixed_widest));
if (wide > GET_NUM_NOT) {
if (wide > -1) Rc.fixed_widest = wide;
else Rc.fixed_widest = -1;
}
}
break;
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
case 'Y':
if (!Inspect.total)
ioline(N_txt(YINSP_noents_txt));
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
else {
int def = w->ppt[w->begtask]->tid,
pid = get_int(fmtmk(N_fmt(YINSP_pidsee_fmt), def));
if (pid > GET_NUM_ESC) {
if (pid == GET_NUM_NOT) pid = def;
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
if (pid) inspection_utility(pid);
}
}
break;
2011-03-31 16:45:12 +05:30
case 'Z':
wins_colors();
break;
case '0':
Rc.zero_suppress = !Rc.zero_suppress;
break;
case kbd_ENTER: // these two have the effect of waking us
case kbd_SPACE: // from 'pselect', refreshing the display
break; // and updating any hot-plugged resources
2011-03-31 16:45:12 +05:30
default: // keep gcc happy
break;
}
} // end: keys_global
static void keys_summary (int ch) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
switch (ch) {
case '1':
if (CHKw(w, View_CPUNOD)) OFFw(w, View_CPUSUM);
else TOGw(w, View_CPUSUM);
OFFw(w, View_CPUNOD);
SETw(w, View_STATES);
break;
case '2':
if (!Numa_node_tot)
show_msg(N_txt(NUMA_nodenot_txt));
else {
if (Numa_node_sel < 0) TOGw(w, View_CPUNOD);
if (!CHKw(w, View_CPUNOD)) SETw(w, View_CPUSUM);
SETw(w, View_STATES);
Numa_node_sel = -1;
}
break;
case '3':
if (!Numa_node_tot)
show_msg(N_txt(NUMA_nodenot_txt));
else {
int num = get_int(fmtmk(N_fmt(NUMA_nodeget_fmt), Numa_node_tot -1));
if (num > GET_NUM_NOT) {
if (num >= 0 && num < Numa_node_tot) {
Numa_node_sel = num;
SETw(w, View_CPUNOD | View_STATES);
OFFw(w, View_CPUSUM);
} else
show_msg(N_txt(NUMA_nodebad_txt));
}
}
2011-03-31 16:45:12 +05:30
break;
case 'C':
VIZTOGw(w, View_SCROLL);
break;
2002-11-08 06:01:28 +05:30
case 'l':
2011-03-31 16:45:12 +05:30
TOGw(w, View_LOADAV);
2002-11-08 06:01:28 +05:30
break;
case 'm':
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
if (!CHKw(w, View_MEMORY))
SETw(w, View_MEMORY);
else if (++w->rc.graph_mems > 2) {
w->rc.graph_mems = 0;;
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
OFFw(w, View_MEMORY);
}
2011-03-31 16:45:12 +05:30
break;
case 't':
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
if (!CHKw(w, View_STATES))
SETw(w, View_STATES);
else if (++w->rc.graph_cpus > 2) {
w->rc.graph_cpus = 0;;
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
OFFw(w, View_STATES);
}
2011-03-31 16:45:12 +05:30
break;
default: // keep gcc happy
2002-11-08 06:01:28 +05:30
break;
2011-03-31 16:45:12 +05:30
}
} // end: keys_summary
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
static void keys_task (int ch) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
switch (ch) {
2002-06-19 05:15:30 +05:30
case '#':
2011-03-31 16:45:12 +05:30
case 'n':
if (VIZCHKw(w)) {
int num = get_int(fmtmk(N_fmt(GET_max_task_fmt), w->rc.maxtasks));
if (num > GET_NUM_NOT) {
if (-1 < num ) w->rc.maxtasks = num;
else show_msg(N_txt(BAD_max_task_txt));
}
2002-06-19 05:15:30 +05:30
}
break;
2011-03-31 16:45:12 +05:30
case '<':
2011-08-30 17:35:45 +05:30
#ifdef TREE_NORESET
if (CHKw(w, Show_FOREST)) break;
#endif
2011-03-31 16:45:12 +05:30
if (VIZCHKw(w)) {
FLG_t *p = w->procflgs + w->maxpflgs - 1;
while (p > w->procflgs && *p != w->rc.sortindx) --p;
if (*p == w->rc.sortindx) {
--p;
#ifndef USE_X_COLHDR
if (EU_MAXPFLGS < *p) --p;
#endif
2011-08-30 17:35:45 +05:30
if (p >= w->procflgs) {
w->rc.sortindx = *p;
#ifndef TREE_NORESET
OFFw(w, Show_FOREST);
#endif
}
2011-03-31 16:45:12 +05:30
}
}
2002-06-19 05:15:30 +05:30
break;
2011-03-31 16:45:12 +05:30
case '>':
2011-08-30 17:35:45 +05:30
#ifdef TREE_NORESET
if (CHKw(w, Show_FOREST)) break;
#endif
2011-03-31 16:45:12 +05:30
if (VIZCHKw(w)) {
FLG_t *p = w->procflgs + w->maxpflgs - 1;
while (p > w->procflgs && *p != w->rc.sortindx) --p;
if (*p == w->rc.sortindx) {
++p;
#ifndef USE_X_COLHDR
if (EU_MAXPFLGS < *p) ++p;
#endif
2011-08-30 17:35:45 +05:30
if (p < w->procflgs + w->maxpflgs) {
w->rc.sortindx = *p;
#ifndef TREE_NORESET
OFFw(w, Show_FOREST);
#endif
}
2002-11-08 06:01:28 +05:30
}
2002-06-19 05:15:30 +05:30
}
break;
2011-03-31 16:45:12 +05:30
case 'b':
TOGw(w, Show_HIBOLD);
capsmk(w);
2011-03-31 16:45:12 +05:30
break;
case 'c':
VIZTOGw(w, Show_CMDLIN);
break;
case 'i':
{ static WIN_t *w_sav;
static int beg_sav;
if (w_sav != w) { beg_sav = 0; w_sav = w; }
if (CHKw(w, Show_IDLEPS)) { beg_sav = w->begtask; w->begtask = 0; }
else { w->begtask = beg_sav; beg_sav = 0; }
}
2011-03-31 16:45:12 +05:30
VIZTOGw(w, Show_IDLEPS);
break;
case 'J':
VIZTOGw(w, Show_JRNUMS);
break;
case 'j':
VIZTOGw(w, Show_JRSTRS);
break;
2002-06-19 05:15:30 +05:30
case 'R':
2011-08-30 17:35:45 +05:30
#ifdef TREE_NORESET
if (!CHKw(w, Show_FOREST)) VIZTOGw(w, Qsrt_NORMAL);
#else
if (VIZCHKw(w)) {
TOGw(w, Qsrt_NORMAL);
OFFw(w, Show_FOREST);
}
#endif
2002-06-19 05:15:30 +05:30
break;
case 'S':
2011-03-31 16:45:12 +05:30
if (VIZCHKw(w)) {
TOGw(w, Show_CTIMES);
show_msg(fmtmk(N_fmt(TIME_accumed_fmt) , CHKw(w, Show_CTIMES)
? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)));
2002-06-19 05:15:30 +05:30
}
break;
case 'O':
case 'o':
if (VIZCHKw(w)) other_selection(ch);
break;
2002-12-10 08:31:17 +05:30
case 'U':
2011-03-31 16:45:12 +05:30
case 'u':
if (VIZCHKw(w)) {
const char *errmsg, *str = ioline(N_txt(GET_user_ids_txt));
if (*str != kbd_ESC
&& (errmsg = user_certify(w, str, ch)))
show_msg(errmsg);
2011-03-31 16:45:12 +05:30
}
2002-06-19 05:15:30 +05:30
break;
2011-08-30 17:35:45 +05:30
case 'V':
if (VIZCHKw(w)) {
TOGw(w, Show_FOREST);
if (!ENUviz(w, EU_CMD))
show_msg(fmtmk(N_fmt(FOREST_modes_fmt) , CHKw(w, Show_FOREST)
? N_txt(ON_word_only_txt) : N_txt(OFF_one_word_txt)));
2011-08-30 17:35:45 +05:30
}
break;
2002-06-19 05:15:30 +05:30
case 'x':
2011-03-31 16:45:12 +05:30
if (VIZCHKw(w)) {
#ifdef USE_X_COLHDR
2011-03-31 16:45:12 +05:30
TOGw(w, Show_HICOLS);
capsmk(w);
#else
if (ENUviz(w, w->rc.sortindx)
&& !CHKw(w, NOHIFND_xxx | NOHISEL_xxx)) {
TOGw(w, Show_HICOLS);
if (ENUpos(w, w->rc.sortindx) < w->begpflg) {
if (CHKw(w, Show_HICOLS)) w->begpflg += 2;
else w->begpflg -= 2;
if (0 > w->begpflg) w->begpflg = 0;
}
capsmk(w);
}
#endif
2002-06-19 05:15:30 +05:30
}
break;
case 'y':
2011-03-31 16:45:12 +05:30
if (VIZCHKw(w)) {
TOGw(w, Show_HIROWS);
capsmk(w);
2002-06-19 05:15:30 +05:30
}
break;
case 'z':
2011-03-31 16:45:12 +05:30
if (VIZCHKw(w)) {
TOGw(w, Show_COLORS);
capsmk(w);
2002-06-19 05:15:30 +05:30
}
break;
case kbd_CtrlO:
if (VIZCHKw(w))
ioline(fmtmk(N_fmt(OSEL_statlin_fmt)
, w->osel_prt ? w->osel_prt : N_txt(WORD_noneone_txt)));
break;
2011-03-31 16:45:12 +05:30
default: // keep gcc happy
2002-06-19 05:15:30 +05:30
break;
2011-03-31 16:45:12 +05:30
}
} // end: keys_task
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
static void keys_window (int ch) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
switch (ch) {
case '+':
if (ALTCHKw) wins_reflag(Flags_OFF, EQUWINS_xxx);
break;
case '-':
if (ALTCHKw) TOGw(w, Show_TASKON);
break;
2002-10-02 05:40:30 +05:30
case '=':
win_reset(w);
2002-06-19 05:15:30 +05:30
break;
2011-03-31 16:45:12 +05:30
case '_':
if (ALTCHKw) wins_reflag(Flags_TOG, Show_TASKON);
2002-06-19 05:15:30 +05:30
break;
2011-12-17 01:34:38 +05:30
case '&':
case 'L':
if (VIZCHKw(w)) find_string(ch);
2011-12-17 01:34:38 +05:30
break;
2011-03-31 16:45:12 +05:30
case 'A':
Rc.mode_altscr = !Rc.mode_altscr;
break;
case 'a':
case 'w':
if (ALTCHKw) win_select(ch);
break;
case 'G':
if (ALTCHKw) {
char tmp[SMLBUFSIZ];
STRLCPY(tmp, ioline(fmtmk(N_fmt(NAME_windows_fmt), w->rc.winname)));
if (tmp[0] && tmp[0] != kbd_ESC) win_names(w, tmp);
2002-09-13 17:12:44 +05:30
}
2002-06-19 05:15:30 +05:30
break;
2011-03-31 16:45:12 +05:30
case kbd_UP:
if (VIZCHKw(w)) if (CHKw(w, Show_IDLEPS) && 0 < w->begtask) w->begtask -= 1;
2011-03-31 16:45:12 +05:30
break;
case kbd_DOWN:
if (VIZCHKw(w)) if (CHKw(w, Show_IDLEPS) && (w->begtask < Frame_maxtask - 1)) w->begtask += 1;
2011-03-31 16:45:12 +05:30
break;
#ifdef USE_X_COLHDR // ------------------------------------
case kbd_LEFT:
#ifndef SCROLLVAR_NO
if (VIZCHKw(w)) {
if (VARleft(w))
w->varcolbeg -= SCROLLAMT;
else if (0 < w->begpflg)
w->begpflg -= 1;
}
#else
if (VIZCHKw(w)) if (0 < w->begpflg) w->begpflg -= 1;
#endif
break;
case kbd_RIGHT:
#ifndef SCROLLVAR_NO
if (VIZCHKw(w)) {
if (VARright(w)) {
w->varcolbeg += SCROLLAMT;
if (0 > w->varcolbeg) w->varcolbeg = 0;
} else if (w->begpflg + 1 < w->totpflgs)
w->begpflg += 1;
}
#else
if (VIZCHKw(w)) if (w->begpflg + 1 < w->totpflgs) w->begpflg += 1;
#endif
break;
#else // USE_X_COLHDR ------------------------------------
2011-03-31 16:45:12 +05:30
case kbd_LEFT:
#ifndef SCROLLVAR_NO
if (VIZCHKw(w)) {
if (VARleft(w))
w->varcolbeg -= SCROLLAMT;
else if (0 < w->begpflg) {
w->begpflg -= 1;
if (EU_MAXPFLGS < w->pflgsall[w->begpflg]) w->begpflg -= 2;
}
}
#else
2011-03-31 16:45:12 +05:30
if (VIZCHKw(w)) if (0 < w->begpflg) {
w->begpflg -= 1;
if (EU_MAXPFLGS < w->pflgsall[w->begpflg]) w->begpflg -= 2;
2011-03-31 16:45:12 +05:30
}
#endif
2011-03-31 16:45:12 +05:30
break;
case kbd_RIGHT:
#ifndef SCROLLVAR_NO
if (VIZCHKw(w)) {
if (VARright(w)) {
w->varcolbeg += SCROLLAMT;
if (0 > w->varcolbeg) w->varcolbeg = 0;
} else if (w->begpflg + 1 < w->totpflgs) {
if (EU_MAXPFLGS < w->pflgsall[w->begpflg])
w->begpflg += (w->begpflg + 3 < w->totpflgs) ? 3 : 0;
else w->begpflg += 1;
}
}
#else
2011-03-31 16:45:12 +05:30
if (VIZCHKw(w)) if (w->begpflg + 1 < w->totpflgs) {
if (EU_MAXPFLGS < w->pflgsall[w->begpflg])
2011-03-31 16:45:12 +05:30
w->begpflg += (w->begpflg + 3 < w->totpflgs) ? 3 : 0;
else w->begpflg += 1;
}
#endif
break;
#endif // USE_X_COLHDR ------------------------------------
2011-03-31 16:45:12 +05:30
case kbd_PGUP:
if (VIZCHKw(w)) if (0 < w->begtask) {
w->begtask -= (w->winlines - 1);
if (0 > w->begtask) w->begtask = 0;
}
break;
case kbd_PGDN:
if (VIZCHKw(w)) if (w->begtask < Frame_maxtask - 1) {
w->begtask += (w->winlines - 1);
if (w->begtask > Frame_maxtask - 1) w->begtask = Frame_maxtask - 1;
if (0 > w->begtask) w->begtask = 0;
}
break;
case kbd_HOME:
#ifndef SCROLLVAR_NO
if (VIZCHKw(w)) w->begtask = w->begpflg = w->varcolbeg = 0;
#else
2011-03-31 16:45:12 +05:30
if (VIZCHKw(w)) w->begtask = w->begpflg = 0;
#endif
2011-03-31 16:45:12 +05:30
break;
case kbd_END:
if (VIZCHKw(w)) {
w->begtask = (Frame_maxtask - w->winlines) + 1;
if (0 > w->begtask) w->begtask = 0;
w->begpflg = w->endpflg;
#ifndef SCROLLVAR_NO
w->varcolbeg = 0;
#endif
2002-09-13 17:12:44 +05:30
}
2002-06-19 05:15:30 +05:30
break;
2011-03-31 16:45:12 +05:30
default: // keep gcc happy
break;
}
} // end: keys_window
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
static void keys_xtra (int ch) {
// const char *xmsg;
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
2011-08-30 17:35:45 +05:30
#ifdef TREE_NORESET
if (CHKw(w, Show_FOREST)) return;
#else
OFFw(w, Show_FOREST);
#endif
/* these keys represent old-top compatibility --
2011-03-31 16:45:12 +05:30
they're grouped here so that if users could ever be weaned,
we would just whack do_key's key_tab entry and this function... */
switch (ch) {
case 'M':
w->rc.sortindx = EU_MEM;
2011-03-31 16:45:12 +05:30
// xmsg = "Memory";
break;
case 'N':
w->rc.sortindx = EU_PID;
2011-03-31 16:45:12 +05:30
// xmsg = "Numerical";
break;
case 'P':
w->rc.sortindx = EU_CPU;
2011-03-31 16:45:12 +05:30
// xmsg = "CPU";
break;
2002-11-29 21:31:04 +05:30
case 'T':
w->rc.sortindx = EU_TM2;
2011-03-31 16:45:12 +05:30
// xmsg = "Time";
break;
default: // keep gcc happy
2002-11-29 21:31:04 +05:30
break;
2011-03-31 16:45:12 +05:30
}
// some have objected to this message, so we'll just keep silent...
// show_msg(fmtmk("%s sort compatibility key honored", xmsg));
2011-03-31 16:45:12 +05:30
} // end: keys_xtra
2011-08-30 17:35:45 +05:30
/*###### Forest View support ###########################################*/
/*
* We try to keep most existing code unaware of our activities
* ( plus, maintain alphabetical order with carefully chosen )
* ( function names: forest_a, forest_b, forest_c & forest_d )
* ( each with exactly one letter more than its predecessor! ) */
static proc_t **Seed_ppt; // temporary win ppt pointer
static proc_t **Tree_ppt; // forest_create will resize
static int Tree_idx; // frame_make resets to zero
2011-08-30 17:35:45 +05:30
/*
* This little recursive guy is the real forest view workhorse.
* He fills in the Tree_ppt array and also sets the child indent
* level which is stored in an unused proc_t padding byte. */
static void forest_adds (const int self, int level) {
2011-08-30 17:35:45 +05:30
int i;
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
if (Tree_idx < Frame_maxtask) { // immunize against insanity
if (level > 100) level = 101; // our arbitrary nests limit
Tree_ppt[Tree_idx] = Seed_ppt[self]; // add this as root or child
Tree_ppt[Tree_idx++]->pad_3 = level; // borrow 1 byte, 127 levels
#ifdef TREE_SCANALL
for (i = 0; i < Frame_maxtask; i++) {
if (i == self) continue;
#else
for (i = self + 1; i < Frame_maxtask; i++) {
#endif
if (Seed_ppt[self]->tid == Seed_ppt[i]->tgid
|| (Seed_ppt[self]->tid == Seed_ppt[i]->ppid && Seed_ppt[i]->tid == Seed_ppt[i]->tgid))
forest_adds(i, level + 1); // got one child any others?
}
2011-08-30 17:35:45 +05:30
}
} // end: forest_adds
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
#ifndef TREE_SCANALL
/*
* Our qsort callback to order a ppt by the non-display start_time
* which will make us immune from any pid, ppid or tgid anomalies
* if/when pid values are wrapped by the kernel! */
static int forest_based (const proc_t **x, const proc_t **y) {
if ( (*x)->start_time > (*y)->start_time ) return 1;
if ( (*x)->start_time < (*y)->start_time ) return -1;
return 0;
} // end: forest_based
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
#endif
2011-08-30 17:35:45 +05:30
/*
* This routine is responsible for preparing the proc_t's for
* a forest display in the designated window. Upon completion,
* he'll replace the original window ppt with our specially
* ordered forest version. */
static void forest_create (WIN_t *q) {
static int hwmsav;
int i;
2011-08-30 17:35:45 +05:30
Seed_ppt = q->ppt; // avoid passing WIN_t ptrs
if (!Tree_idx) { // do just once per frame
if (hwmsav < Frame_maxtask) { // grow, but never shrink
hwmsav = Frame_maxtask;
Tree_ppt = alloc_r(Tree_ppt, sizeof(proc_t*) * hwmsav);
2011-08-30 17:35:45 +05:30
}
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
#ifndef TREE_SCANALL
qsort(Seed_ppt, Frame_maxtask, sizeof(proc_t*), (QFP_t)forest_based);
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
#endif
for (i = 0; i < Frame_maxtask; i++) // avoid any hidepid distortions
if (!Seed_ppt[i]->pad_3) // identify real or pretend trees
forest_adds(i, 0); // add as parent plus its children
2011-08-30 17:35:45 +05:30
}
memcpy(Seed_ppt, Tree_ppt, sizeof(proc_t*) * Frame_maxtask);
} // end: forest_create
/*
* This guy adds the artwork to either p->cmd or p->cmdline
* when in forest view mode, otherwise he just returns 'em. */
static inline const char *forest_display (const WIN_t *q, const proc_t *p) {
#ifndef SCROLLVAR_NO
static char buf[1024*64*2]; // the same as readproc's MAX_BUFSZ
#else
2011-08-30 17:35:45 +05:30
static char buf[ROWMINSIZ];
#endif
2011-08-30 17:35:45 +05:30
const char *which = (CHKw(q, Show_CMDLIN)) ? *p->cmdline : p->cmd;
if (!CHKw(q, Show_FOREST) || !p->pad_3) return which;
if (p->pad_3 > 100) snprintf(buf, sizeof(buf), "%400s%s", " + ", which);
else snprintf(buf, sizeof(buf), "%*s%s", (4 * p->pad_3), " `- ", which);
2011-08-30 17:35:45 +05:30
return buf;
} // end: forest_display
2011-03-31 16:45:12 +05:30
/*###### Main Screen routines ##########################################*/
/*
* Process keyboard input during the main loop */
static void do_key (int ch) {
static struct {
void (*func)(int ch);
char keys[SMLBUFSIZ];
} key_tab[] = {
{ keys_global,
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
{ '?', 'B', 'd', 'E', 'e', 'F', 'f', 'g', 'H', 'h'
, 'I', 'k', 'r', 's', 'X', 'Y', 'Z', '0'
, kbd_ENTER, kbd_SPACE, '\0' } },
2011-03-31 16:45:12 +05:30
{ keys_summary,
{ '1', '2', '3', 'C', 'l', 'm', 't', '\0' } },
2011-03-31 16:45:12 +05:30
{ keys_task,
{ '#', '<', '>', 'b', 'c', 'i', 'J', 'j', 'n', 'O', 'o'
, 'R', 'S', 'U', 'u', 'V', 'x', 'y', 'z'
, kbd_CtrlO, '\0' } },
2011-03-31 16:45:12 +05:30
{ keys_window,
2011-12-17 01:34:38 +05:30
{ '+', '-', '=', '_', '&', 'A', 'a', 'G', 'L', 'w'
2011-03-31 16:45:12 +05:30
, kbd_UP, kbd_DOWN, kbd_LEFT, kbd_RIGHT, kbd_PGUP, kbd_PGDN
, kbd_HOME, kbd_END, '\0' } },
2011-03-31 16:45:12 +05:30
{ keys_xtra,
{ 'M', 'N', 'P', 'T', '\0'} }
2011-03-31 16:45:12 +05:30
};
int i;
2002-11-29 21:31:04 +05:30
2011-03-31 16:45:12 +05:30
switch (ch) {
case 0: // ignored (always)
case kbd_ESC: // ignored (sometimes)
goto all_done;
2011-03-31 16:45:12 +05:30
case 'q': // no return from this guy
bye_bye(NULL);
case 'W': // no need for rebuilds
write_rcfile();
goto all_done;
2011-03-31 16:45:12 +05:30
default: // and now, the real work...
for (i = 0; i < MAXTBL(key_tab); ++i)
if (strchr(key_tab[i].keys, ch)) {
key_tab[i].func(ch);
Frames_signal = BREAK_kbd;
goto all_done;
2011-03-31 16:45:12 +05:30
}
};
/* Frames_signal above will force a rebuild of all column headers and
2011-03-31 16:45:12 +05:30
the PROC_FILLxxx flags. It's NOT simply lazy programming. Here are
some keys that COULD require new column headers and/or libproc flags:
'A' - likely
'c' - likely when !Mode_altscr, maybe when Mode_altscr
'F' - likely
'f' - likely
2011-08-30 17:35:45 +05:30
'g' - likely
'H' - likely
'I' - likely
'J' - always
'j' - always
2011-03-31 16:45:12 +05:30
'Z' - likely, if 'Curwin' changed when !Mode_altscr
'-' - likely (restricted to Mode_altscr)
'_' - likely (restricted to Mode_altscr)
'=' - maybe, but only when Mode_altscr
'+' - likely (restricted to Mode_altscr)
PLUS, likely for FOUR of the EIGHT cursor motion keys (scrolled)
( At this point we have a human being involved and so have all the time )
( in the world. We can afford a few extra cpu cycles every now & then! )
*/
show_msg(N_txt(UNKNOWN_cmds_txt));
all_done:
sysinfo_refresh(1); // let's be more responsive to hot-pluggin'
putp((Cursor_state = Cap_curs_hide));
2011-03-31 16:45:12 +05:30
} // end: do_key
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/*
* State display *Helper* function to calc and display the state
* percentages for a single cpu. In this way, we can support
* the following environments without the usual code bloat.
* 1) single cpu machines
* 2) modest smp boxes with room for each cpu's percentages
* 3) massive smp guys leaving little or no room for process
* display and thus requiring the cpu summary toggle */
static void summary_hlp (CPU_t *cpu, const char *pfx) {
2011-03-31 16:45:12 +05:30
/* we'll trim to zero if we get negative time ticks,
which has happened with some SMP kernels (pre-2.4?)
and when cpus are dynamically added or removed */
2011-03-31 16:45:12 +05:30
#define TRIMz(x) ((tz = (SIC_t)(x)) < 0 ? 0 : tz)
// user syst nice idle wait hirg sirq steal
SIC_t u_frme, s_frme, n_frme, i_frme, w_frme, x_frme, y_frme, z_frme, tot_frme, tz;
2002-11-08 06:01:28 +05:30
float scale;
u_frme = TRIMz(cpu->cur.u - cpu->sav.u);
s_frme = TRIMz(cpu->cur.s - cpu->sav.s);
n_frme = TRIMz(cpu->cur.n - cpu->sav.n);
i_frme = TRIMz(cpu->cur.i - cpu->sav.i);
w_frme = TRIMz(cpu->cur.w - cpu->sav.w);
x_frme = TRIMz(cpu->cur.x - cpu->sav.x);
y_frme = TRIMz(cpu->cur.y - cpu->sav.y);
z_frme = TRIMz(cpu->cur.z - cpu->sav.z);
tot_frme = u_frme + s_frme + n_frme + i_frme + w_frme + x_frme + y_frme + z_frme;
#ifndef CPU_ZEROTICS
if (tot_frme < cpu->edge)
tot_frme = u_frme = s_frme = n_frme = i_frme = w_frme = x_frme = y_frme = z_frme = 0;
#endif
if (1 > tot_frme) i_frme = tot_frme = 1;
2002-11-08 06:01:28 +05:30
scale = 100.0 / (float)tot_frme;
2011-03-31 16:45:12 +05:30
/* display some kinda' cpu state percentages
(who or what is explained by the passed prefix) */
if (Curwin->rc.graph_cpus) {
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
static struct {
const char *user, *syst, *type;
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
} gtab[] = {
{ "%-.*s~7", "%-.*s~8", Graph_bars },
{ "%-.*s~4", "%-.*s~6", Graph_blks }
};
char user[SMLBUFSIZ], syst[SMLBUFSIZ], dual[MEDBUFSIZ];
int ix = Curwin->rc.graph_cpus - 1;
float pct_user = (float)(u_frme + n_frme) * scale,
pct_syst = (float)(s_frme + x_frme + y_frme) * scale;
#ifndef QUICK_GRAPHS
int num_user = (int)((pct_user * Graph_adj) + .5),
num_syst = (int)((pct_syst * Graph_adj) + .5);
if (num_user + num_syst > Graph_len) num_syst = Graph_len - num_user;
snprintf(user, sizeof(user), gtab[ix].user, num_user, gtab[ix].type);
snprintf(syst, sizeof(syst), gtab[ix].syst, num_syst, gtab[ix].type);
#else
snprintf(user, sizeof(user), gtab[ix].user, (int)((pct_user * Graph_adj) + .5), gtab[ix].type);
snprintf(syst, sizeof(syst), gtab[ix].syst, (int)((pct_syst * Graph_adj) + .4), gtab[ix].type);
#endif
snprintf(dual, sizeof(dual), "%s%s", user, syst);
show_special(0, fmtmk("%%%s ~3%#5.1f~2/%-#5.1f~3 %3.0f[~1%-*s]~1\n"
, pfx, pct_user, pct_syst, pct_user + pct_syst, Graph_len +4, dual));
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
} else {
show_special(0, fmtmk(Cpu_States_fmts, pfx
, (float)u_frme * scale, (float)s_frme * scale
, (float)n_frme * scale, (float)i_frme * scale
, (float)w_frme * scale, (float)x_frme * scale
, (float)y_frme * scale, (float)z_frme * scale));
}
2011-03-31 16:45:12 +05:30
#undef TRIMz
} // end: summary_hlp
2002-11-08 06:01:28 +05:30
2011-03-31 16:45:12 +05:30
/*
* In support of a new frame:
* 1) Display uptime and load average (maybe)
* 2) Display task/cpu states (maybe)
* 3) Display memory & swap usage (maybe) */
2011-08-30 17:35:45 +05:30
static void summary_show (void) {
2011-03-31 16:45:12 +05:30
#define isROOM(f,n) (CHKw(w, f) && Msg_row + (n) < Screen_rows - 1)
#define anyFLG 0xffffff
2011-03-31 16:45:12 +05:30
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
char tmp[MEDBUFSIZ];
int i;
2002-05-30 09:14:46 +05:30
2004-07-07 00:43:38 +05:30
// Display Uptime and Loadavg
2011-03-31 16:45:12 +05:30
if (isROOM(View_LOADAV, 1)) {
if (!Rc.mode_altscr)
show_special(0, fmtmk(LOADAV_line, Myname, sprint_uptime(0)));
2011-03-31 16:45:12 +05:30
else
show_special(0, fmtmk(CHKw(w, Show_TASKON)? LOADAV_line_alt : LOADAV_line
, w->grpname, sprint_uptime(0)));
2002-06-19 05:15:30 +05:30
Msg_row += 1;
} // end: View_LOADAV
2002-05-30 09:14:46 +05:30
2004-07-07 00:43:38 +05:30
// Display Task and Cpu(s) States
2011-03-31 16:45:12 +05:30
if (isROOM(View_STATES, 2)) {
show_special(0, fmtmk(N_unq(STATE_line_1_fmt)
, Thread_mode ? N_txt(WORD_threads_txt) : N_txt(WORD_process_txt)
2011-03-31 16:45:12 +05:30
, Frame_maxtask, Frame_running, Frame_sleepin
, Frame_stopped, Frame_zombied));
2002-11-08 06:01:28 +05:30
Msg_row += 1;
cpus_refresh();
if (!Numa_node_tot) goto numa_nope;
if (CHKw(w, View_CPUNOD)) {
if (Numa_node_sel < 0) {
// display the 1st /proc/stat line, then the nodes (if room)
summary_hlp(&Cpu_tics[smp_num_cpus], N_txt(WORD_allcpus_txt));
Msg_row += 1;
// display each cpu node's states
for (i = 0; i < Numa_node_tot; i++) {
CPU_t *nod_ptr = &Cpu_tics[1 + smp_num_cpus + i];
if (!isROOM(anyFLG, 1)) break;
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
#ifndef OFF_NUMASKIP
if (nod_ptr->id) {
#endif
snprintf(tmp, sizeof(tmp), N_fmt(NUMA_nodenam_fmt), i);
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
summary_hlp(nod_ptr, tmp);
Msg_row += 1;
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
#ifndef OFF_NUMASKIP
}
#endif
}
} else {
// display the node summary, then the associated cpus (if room)
snprintf(tmp, sizeof(tmp), N_fmt(NUMA_nodenam_fmt), Numa_node_sel);
summary_hlp(&Cpu_tics[1 + smp_num_cpus + Numa_node_sel], tmp);
Msg_row += 1;
for (i = 0; i < Cpu_faux_tot; i++) {
if (Numa_node_sel == Cpu_tics[i].node) {
if (!isROOM(anyFLG, 1)) break;
snprintf(tmp, sizeof(tmp), N_fmt(WORD_eachcpu_fmt), Cpu_tics[i].id);
summary_hlp(&Cpu_tics[i], tmp);
Msg_row += 1;
}
}
}
} else
numa_nope:
2011-03-31 16:45:12 +05:30
if (CHKw(w, View_CPUSUM)) {
// display just the 1st /proc/stat line
summary_hlp(&Cpu_tics[Cpu_faux_tot], N_txt(WORD_allcpus_txt));
2011-03-31 16:45:12 +05:30
Msg_row += 1;
} else {
2011-03-31 16:45:12 +05:30
// display each cpu's states separately, screen height permitting...
for (i = 0; i < Cpu_faux_tot; i++) {
snprintf(tmp, sizeof(tmp), N_fmt(WORD_eachcpu_fmt), Cpu_tics[i].id);
summary_hlp(&Cpu_tics[i], tmp);
2011-03-31 16:45:12 +05:30
Msg_row += 1;
if (!isROOM(anyFLG, 1)) break;
}
2002-11-08 06:01:28 +05:30
}
} // end: View_STATES
2002-06-19 05:15:30 +05:30
2004-07-07 00:43:38 +05:30
// Display Memory and Swap stats
2011-03-31 16:45:12 +05:30
if (isROOM(View_MEMORY, 2)) {
#define bfT(n) buftab[n].buf
#define scT(e) scaletab[Rc.summ_mscale]. e
#define mkM(x) (float)kb_main_ ## x / scT(div)
#define mkS(x) (float)kb_swap_ ## x / scT(div)
#define prT(b,z) { if (9 < snprintf(b, 10, scT(fmts), z)) b[8] = '+'; }
static struct {
float div;
const char *fmts;
const char *label;
} scaletab[] = {
{ 1, "%.0f ", NULL }, // kibibytes
#ifdef BOOST_MEMORY
{ 1024.0, "%#.3f ", NULL }, // mebibytes
{ 1024.0*1024, "%#.3f ", NULL }, // gibibytes
{ 1024.0*1024*1024, "%#.3f ", NULL }, // tebibytes
{ 1024.0*1024*1024*1024, "%#.3f ", NULL }, // pebibytes
{ 1024.0*1024*1024*1024*1024, "%#.3f ", NULL } // exbibytes
#else
{ 1024.0, "%#.1f ", NULL }, // mebibytes
{ 1024.0*1024, "%#.1f ", NULL }, // gibibytes
{ 1024.0*1024*1024, "%#.1f ", NULL }, // tebibytes
{ 1024.0*1024*1024*1024, "%#.1f ", NULL }, // pebibytes
{ 1024.0*1024*1024*1024*1024, "%#.1f ", NULL } // exbibytes
#endif
};
struct { // 0123456789
// snprintf contents of each buf (after SK_Kb): 'nnnn.nnn 0'
// and prT macro might replace space at buf[8] with: ------> +
char buf[10]; // MEMORY_lines_fmt provides for 8+1 bytes
} buftab[8];
if (!scaletab[0].label) {
scaletab[0].label = N_txt(AMT_kilobyte_txt);
scaletab[1].label = N_txt(AMT_megabyte_txt);
scaletab[2].label = N_txt(AMT_gigabyte_txt);
scaletab[3].label = N_txt(AMT_terabyte_txt);
scaletab[4].label = N_txt(AMT_petabyte_txt);
scaletab[5].label = N_txt(AMT_exxabyte_txt);
}
if (w->rc.graph_mems) {
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
static struct {
const char *used, *misc, *swap, *type;
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
} gtab[] = {
{ "%-.*s~7", "%-.*s~8", "%-.*s~8", Graph_bars },
{ "%-.*s~4", "%-.*s~6", "%-.*s~6", Graph_blks }
};
char used[SMLBUFSIZ], util[SMLBUFSIZ], dual[MEDBUFSIZ];
int ix = w->rc.graph_mems - 1;
float pct_used = (float)kb_main_used * (100.0 / (float)kb_main_total),
#ifdef MEMGRAPH_OLD
pct_misc = (float)(kb_main_buffers + kb_main_cached) * (100.0 / (float)kb_main_total),
#else
pct_misc = (float)(kb_main_total - kb_main_available - kb_main_used) * (100.0 / (float)kb_main_total),
#endif
pct_swap = kb_swap_total ? (float)kb_swap_used * (100.0 / (float)kb_swap_total) : 0;
#ifndef QUICK_GRAPHS
int num_used = (int)((pct_used * Graph_adj) + .5),
num_misc = (int)((pct_misc * Graph_adj) + .5);
if (num_used + num_misc > Graph_len) num_misc = Graph_len - num_used;
snprintf(used, sizeof(used), gtab[ix].used, num_used, gtab[ix].type);
snprintf(util, sizeof(util), gtab[ix].misc, num_misc, gtab[ix].type);
#else
snprintf(used, sizeof(used), gtab[ix].used, (int)((pct_used * Graph_adj) + .5), gtab[ix].type);
snprintf(util, sizeof(util), gtab[ix].misc, (int)((pct_misc * Graph_adj) + .4), gtab[ix].type);
#endif
snprintf(dual, sizeof(dual), "%s%s", used, util);
snprintf(util, sizeof(util), gtab[ix].swap, (int)((pct_swap * Graph_adj) + .5), gtab[ix].type);
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
prT(bfT(0), mkM(total)); prT(bfT(1), mkS(total));
show_special(0, fmtmk( "%s %s:~3%#5.1f~2/%-9.9s~3[~1%-*s]~1\n%s %s:~3%#5.1f~2/%-9.9s~3[~1%-*s]~1\n"
, scT(label), N_txt(WORD_abv_mem_txt), pct_used + pct_misc, bfT(0), Graph_len +4, dual
, scT(label), N_txt(WORD_abv_swp_txt), pct_swap, bfT(1), Graph_len +2, util));
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
} else {
unsigned long kb_main_my_misc = kb_main_buffers + kb_main_cached;
prT(bfT(0), mkM(total)); prT(bfT(1), mkM(free));
prT(bfT(2), mkM(used)); prT(bfT(3), mkM(my_misc));
prT(bfT(4), mkS(total)); prT(bfT(5), mkS(free));
prT(bfT(6), mkS(used)); prT(bfT(7), mkM(available));
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
show_special(0, fmtmk(N_unq(MEMORY_lines_fmt)
, scT(label), N_txt(WORD_abv_mem_txt), bfT(0), bfT(1), bfT(2), bfT(3)
, scT(label), N_txt(WORD_abv_swp_txt), bfT(4), bfT(5), bfT(6), bfT(7)
, N_txt(WORD_abv_mem_txt)));
}
2002-11-08 06:01:28 +05:30
Msg_row += 2;
#undef bfT
#undef scT
2011-03-31 16:45:12 +05:30
#undef mkM
#undef mkS
#undef prT
} // end: View_MEMORY
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
#undef isROOM
#undef anyFLG
2011-03-31 16:45:12 +05:30
} // end: summary_show
2002-11-08 06:01:28 +05:30
2011-03-31 16:45:12 +05:30
/*
2011-12-17 01:34:38 +05:30
* Build the information for a single task row and
* display the results or return them to the caller. */
static const char *task_show (const WIN_t *q, const proc_t *p) {
#ifndef SCROLLVAR_NO
#define makeVAR(v) { const char *pv = v; \
if (!q->varcolbeg) cp = make_str(pv, q->varcolsz, Js, AUTOX_NO); \
else cp = make_str(q->varcolbeg < (int)strlen(pv) ? pv + q->varcolbeg : "", q->varcolsz, Js, AUTOX_NO); }
#else
#define makeVAR(v) cp = make_str(v, q->varcolsz, Js, AUTOX_NO)
#endif
#define pages2K(n) (unsigned long)( (n) << Pg2K_shft )
static char rbuf[ROWMINSIZ];
char *rp;
int x;
2011-03-31 16:45:12 +05:30
// we must begin a row with a possible window number in mind...
*(rp = rbuf) = '\0';
if (Rc.mode_altscr) rp = scat(rp, " ");
2002-11-08 06:01:28 +05:30
for (x = 0; x < q->maxpflgs; x++) {
const char *cp;
FLG_t i = q->procflgs[x];
#define S Fieldstab[i].scale // these used to be variables
#define W Fieldstab[i].width // but it's much better if we
#define Js CHKw(q, Show_JRSTRS) // represent them as #defines
#define Jn CHKw(q, Show_JRNUMS) // and only exec code if used
2004-07-15 06:47:15 +05:30
2002-11-08 06:01:28 +05:30
switch (i) {
#ifndef USE_X_COLHDR
2011-03-31 16:45:12 +05:30
// these 2 aren't real procflgs, they're used in column highlighting!
case EU_XON:
case EU_XOF:
cp = NULL;
if (!CHKw(q, INFINDS_xxx | NOHIFND_xxx | NOHISEL_xxx)) {
/* treat running tasks specially - entire row may get highlighted
so we needn't turn it on and we MUST NOT turn it off */
if (!('R' == p->state && CHKw(q, Show_HIROWS)))
cp = (EU_XON == i ? q->capclr_rowhigh : q->capclr_rownorm);
}
break;
#endif
case EU_CGN:
makeVAR(p->cgname);
break;
case EU_CGR:
makeVAR(p->cgroup[0]);
break;
case EU_CMD:
2011-08-30 17:35:45 +05:30
makeVAR(forest_display(q, p));
break;
case EU_COD:
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
cp = scale_mem(S, pages2K(p->trs), W, Jn);
2002-11-08 06:01:28 +05:30
break;
case EU_CPN:
cp = make_num(p->processor, W, Jn, AUTOX_NO, 0);
2002-11-08 06:01:28 +05:30
break;
case EU_CPU:
{ float u = (float)p->pcpu * Frame_etscale;
/* process can't use more %cpu than number of threads it has
( thanks Jaromir Capik <jcapik@redhat.com> ) */
if (u > 100.0 * p->nlwp) u = 100.0 * p->nlwp;
2011-03-31 16:45:12 +05:30
if (u > Cpu_pmax) u = Cpu_pmax;
cp = scale_pcnt(u, W, Jn);
2002-11-08 06:01:28 +05:30
}
break;
case EU_DAT:
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
cp = scale_mem(S, pages2K(p->drs), W, Jn);
2002-11-08 06:01:28 +05:30
break;
case EU_DRT:
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
cp = scale_num(p->dt, W, Jn);
2002-11-08 06:01:28 +05:30
break;
case EU_ENV:
makeVAR(p->environ[0]);
break;
case EU_FL1:
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
cp = scale_num(p->maj_flt, W, Jn);
2011-03-31 16:45:12 +05:30
break;
case EU_FL2:
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
cp = scale_num(p->min_flt, W, Jn);
2011-03-31 16:45:12 +05:30
break;
case EU_FLG:
cp = make_str(hex_make(p->flags, 1), W, Js, AUTOX_NO);
break;
case EU_FV1:
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
cp = scale_num(p->maj_delta, W, Jn);
break;
case EU_FV2:
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
cp = scale_num(p->min_delta, W, Jn);
break;
case EU_GID:
cp = make_num(p->egid, W, Jn, EU_GID, 0);
2002-11-08 06:01:28 +05:30
break;
case EU_GRP:
cp = make_str(p->egroup, W, Js, EU_GRP);
2002-11-08 06:01:28 +05:30
break;
case EU_LXC:
cp = make_str(p->lxcname, W, Js, EU_LXC);
break;
case EU_MEM:
cp = scale_pcnt((float)pages2K(p->resident) * 100 / kb_main_total, W, Jn);
2002-11-08 06:01:28 +05:30
break;
case EU_NCE:
cp = make_num(p->nice, W, Jn, AUTOX_NO, 1);
break;
case EU_NMA:
cp = make_num(numa_node_of_cpu(p->processor), W, Jn, AUTOX_NO, 0);
break;
case EU_NS1: // IPCNS
case EU_NS2: // MNTNS
case EU_NS3: // NETNS
case EU_NS4: // PIDNS
case EU_NS5: // USERNS
case EU_NS6: // UTSNS
{ long ino = p->ns[i - EU_NS1];
cp = make_num(ino, W, Jn, i, 1);
}
break;
case EU_OOA:
cp = make_num(p->oom_adj, W, Jn, AUTOX_NO, 1);
break;
case EU_OOM:
cp = make_num(p->oom_score, W, Jn, AUTOX_NO, 1);
break;
case EU_PGD:
cp = make_num(p->pgrp, W, Jn, AUTOX_NO, 0);
2002-11-08 06:01:28 +05:30
break;
case EU_PID:
cp = make_num(p->tid, W, Jn, AUTOX_NO, 0);
2002-11-08 06:01:28 +05:30
break;
case EU_PPD:
cp = make_num(p->ppid, W, Jn, AUTOX_NO, 0);
2002-11-08 06:01:28 +05:30
break;
case EU_PRI:
2011-03-31 16:45:12 +05:30
if (-99 > p->priority || 999 < p->priority) {
cp = make_str("rt", W, Jn, AUTOX_NO);
2002-11-29 04:39:48 +05:30
} else
cp = make_num(p->priority, W, Jn, AUTOX_NO, 0);
2002-11-08 06:01:28 +05:30
break;
case EU_RES:
cp = scale_mem(S, pages2K(p->resident), W, Jn);
2002-11-08 06:01:28 +05:30
break;
case EU_RZA:
cp = scale_mem(S, p->vm_rss_anon, W, Jn);
break;
case EU_RZF:
cp = scale_mem(S, p->vm_rss_file, W, Jn);
break;
case EU_RZL:
cp = scale_mem(S, p->vm_lock, W, Jn);
break;
case EU_RZS:
cp = scale_mem(S, p->vm_rss_shared, W, Jn);
break;
case EU_SGD:
makeVAR(p->supgid);
break;
case EU_SGN:
makeVAR(p->supgrp);
break;
case EU_SHR:
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
cp = scale_mem(S, pages2K(p->share), W, Jn);
2011-03-31 16:45:12 +05:30
break;
case EU_SID:
cp = make_num(p->session, W, Jn, AUTOX_NO, 0);
2002-11-08 06:01:28 +05:30
break;
case EU_STA:
cp = make_chr(p->state, W, Js);
2002-11-08 06:01:28 +05:30
break;
case EU_SWP:
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
cp = scale_mem(S, p->vm_swap, W, Jn);
2011-03-31 16:45:12 +05:30
break;
case EU_TGD:
cp = make_num(p->tgid, W, Jn, AUTOX_NO, 0);
break;
case EU_THD:
cp = make_num(p->nlwp, W, Jn, AUTOX_NO, 0);
2002-11-08 06:01:28 +05:30
break;
case EU_TM2:
case EU_TME:
2002-12-05 04:18:30 +05:30
{ TIC_t t = p->utime + p->stime;
2011-03-31 16:45:12 +05:30
if (CHKw(q, Show_CTIMES)) t += (p->cutime + p->cstime);
cp = scale_tics(t, W, Jn);
2002-11-08 06:01:28 +05:30
}
break;
case EU_TPG:
cp = make_num(p->tpgid, W, Jn, AUTOX_NO, 0);
2011-03-31 16:45:12 +05:30
break;
case EU_TTY:
2011-03-31 16:45:12 +05:30
{ char tmp[SMLBUFSIZ];
dev_to_tty(tmp, W, p->tty, p->tid, ABBREV_DEV);
cp = make_str(tmp, W, Js, EU_TTY);
2002-11-08 06:01:28 +05:30
}
break;
case EU_UED:
cp = make_num(p->euid, W, Jn, EU_UED, 0);
2002-11-08 06:01:28 +05:30
break;
case EU_UEN:
cp = make_str(p->euser, W, Js, EU_UEN);
2002-11-08 06:01:28 +05:30
break;
case EU_URD:
cp = make_num(p->ruid, W, Jn, EU_URD, 0);
2011-03-31 16:45:12 +05:30
break;
case EU_URN:
cp = make_str(p->ruser, W, Js, EU_URN);
2011-03-31 16:45:12 +05:30
break;
case EU_USD:
cp = make_num(p->suid, W, Jn, EU_USD, 0);
2011-03-31 16:45:12 +05:30
break;
case EU_USE:
cp = scale_mem(S, (p->vm_swap + p->vm_rss), W, Jn);
break;
case EU_USN:
cp = make_str(p->suser, W, Js, EU_USN);
2002-12-06 12:23:29 +05:30
break;
case EU_VRT:
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
cp = scale_mem(S, pages2K(p->size), W, Jn);
2002-11-08 06:01:28 +05:30
break;
case EU_WCH:
cp = make_str(lookup_wchan(p->tid), W, Js, EU_WCH);
2002-11-08 06:01:28 +05:30
break;
2011-03-31 16:45:12 +05:30
default: // keep gcc happy
continue;
} // end: switch 'procflag'
2002-11-08 06:01:28 +05:30
if (cp) {
if (q->osel_tot && !osel_matched(q, i, cp)) return "";
rp = scat(rp, cp);
}
#undef S
#undef W
#undef Js
#undef Jn
2011-03-31 16:45:12 +05:30
} // end: for 'maxpflgs'
2002-11-08 06:01:28 +05:30
if (!CHKw(q, INFINDS_xxx)) {
const char *cap = ((CHKw(q, Show_HIROWS) && 'R' == p->state))
? q->capclr_rowhigh : q->capclr_rownorm;
char *row = rbuf;
int ofs;
/* since we can't predict what the search string will be and,
considering what a single space search request would do to
potential buffer needs, when any matches are found we skip
normal output routing and send all of the results directly
to the terminal (and we sound asthmatic: poof, putt, puff) */
if (-1 < (ofs = find_ofs(q, row))) {
POOF("\n", cap);
do {
row[ofs] = '\0';
PUTT("%s%s%s%s", row, q->capclr_hdr, q->findstr, cap);
row += (ofs + q->findlen);
ofs = find_ofs(q, row);
} while (-1 < ofs);
PUTT("%s%s", row, Caps_endline);
// with a corrupted rbuf, ensure row is 'counted' by window_show
rbuf[0] = '!';
} else
PUFF("\n%s%s%s", cap, row, Caps_endline);
}
return rbuf;
#undef makeVAR
2011-03-31 16:45:12 +05:30
#undef pages2K
} // end: task_show
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/*
* Squeeze as many tasks as we can into a single window,
* after sorting the passed proc table. */
2011-08-30 17:35:45 +05:30
static int window_show (WIN_t *q, int wmax) {
2011-03-31 16:45:12 +05:30
/* the isBUSY macro determines if a task is 'active' --
it returns true if some cpu was used since the last sample.
( actual 'running' tasks will be a subset of those selected ) */
#define isBUSY(x) (0 < x->pcpu)
2011-03-31 16:45:12 +05:30
#define winMIN(a,b) ((a < b) ? a : b)
2002-06-19 05:15:30 +05:30
int i, lwin;
2004-07-07 00:43:38 +05:30
// Display Column Headings -- and distract 'em while we sort (maybe)
PUFF("\n%s%s%s", q->capclr_hdr, q->columnhdr, Caps_endline);
2011-03-31 16:45:12 +05:30
2011-08-30 17:35:45 +05:30
if (CHKw(q, Show_FOREST))
forest_create(q);
else {
if (CHKw(q, Qsrt_NORMAL)) Frame_srtflg = 1; // this is always needed!
else Frame_srtflg = -1;
Frame_ctimes = CHKw(q, Show_CTIMES); // this & next, only maybe
Frame_cmdlin = CHKw(q, Show_CMDLIN);
qsort(q->ppt, Frame_maxtask, sizeof(proc_t*), Fieldstab[q->rc.sortindx].sort);
}
2011-03-31 16:45:12 +05:30
i = q->begtask;
2011-08-30 17:35:45 +05:30
lwin = 1; // 1 for the column header
wmax = winMIN(wmax, q->winlines + 1); // ditto for winlines, too
2011-03-31 16:45:12 +05:30
/* the least likely scenario is also the most costly, so we'll try to avoid
checking some stuff with each iteration and check it just once... */
if (CHKw(q, Show_IDLEPS) && !q->usrseltyp)
2011-08-30 17:35:45 +05:30
while (i < Frame_maxtask && lwin < wmax) {
if (*task_show(q, q->ppt[i++]))
++lwin;
2002-05-30 09:14:46 +05:30
}
2011-03-31 16:45:12 +05:30
else
2011-08-30 17:35:45 +05:30
while (i < Frame_maxtask && lwin < wmax) {
if ((CHKw(q, Show_IDLEPS) || isBUSY(q->ppt[i]))
&& user_matched(q, q->ppt[i])
top: swat bug impacting 'idle' mode & 'user' filtering When Other filtering was introduced the nature of what constituted a displayed row changed. No longer would a task_show() call guarantee that another line is shown. Rather, a non-empty string must have also been tested. Unfortunately, when any task window was being filtered for 'idle' mode or a particular 'user', the proc index was incremented twice due to the perils of copy/paste. Combining such an index increment with the new test of task_show results works fine if filtering is inactive. This was a particularly insidious bug which meant that an adjacent task would be skipped whenever the current task met 'idle' and/or 'user' filter criteria, and was not otherwise excluded due to 'Other' filter criteria. And, since it was the very next task that was ignored, the bug was very susceptible to a window's sort order. This could be illustrated when filtering on some user, while sorting on PID. Then, toggling Forest View could make otherwise unseen tasks appear and then disappear. User workarounds are possible via interactive commands trading the 'i' and 'u'/'U' provisions for the 'o'/'O' other filtering capability thus avoiding an extra i++. But that is certainly less than ideal and doesn't help the 3.3.7 and 3.3.8 distorted command line provisions. ( this little buggie may end up costing me my pocket ) ( protector, my coding badge & maybe even my cubicle ) Reference(s): http://www.freelists.org/post/procps/Idle-elides-nonidle-processes . bug originated with 'Other' filtering commit 5edc6fb3174f1fd02bbfca61ec6d8a3a2e12f71c Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-09-27 22:42:12 +05:30
&& *task_show(q, q->ppt[i]))
2011-03-31 16:45:12 +05:30
++lwin;
++i;
}
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
return lwin;
#undef winMIN
#undef isBUSY
} // end: window_show
2002-11-08 06:01:28 +05:30
/*###### Entry point plus two ##########################################*/
2011-03-31 16:45:12 +05:30
/*
* This guy's just a *Helper* function who apportions the
* remaining amount of screen real estate under multiple windows */
static void frame_hlp (int wix, int max) {
int i, size, wins;
2002-06-19 05:15:30 +05:30
// calc remaining number of visible windows
for (i = wix, wins = 0; i < GROUPSMAX; i++)
if (CHKw(&Winstk[i], Show_TASKON))
2002-06-19 05:15:30 +05:30
++wins;
2002-06-19 05:15:30 +05:30
if (!wins) wins = 1;
// deduct 1 line/window for the columns heading
2002-06-19 05:15:30 +05:30
size = (max - wins) / wins;
2011-03-31 16:45:12 +05:30
/* for subject window, set WIN_t winlines to either the user's
maxtask (1st choice) or our 'foxized' size calculation
(foxized adj. - 'fair and balanced') */
Winstk[wix].winlines =
Winstk[wix].rc.maxtasks ? Winstk[wix].rc.maxtasks : size;
} // end: frame_hlp
2002-05-30 09:14:46 +05:30
2002-06-19 05:15:30 +05:30
2011-03-31 16:45:12 +05:30
/*
* Initiate the Frame Display Update cycle at someone's whim!
* This routine doesn't do much, mostly he just calls others.
*
* (Whoa, wait a minute, we DO caretake those row guys, plus)
* (we CALCULATE that IMPORTANT Max_lines thingy so that the)
* (*subordinate* functions invoked know WHEN the user's had)
* (ENOUGH already. And at Frame End, it SHOULD be apparent)
* (WE am d'MAN -- clearing UNUSED screen LINES and ensuring)
top: inoculated against a window manager like 'screen' If top were invoked under the 'screen' window manager, writing the terminfo string 'exit_ca_mode' at top exit would not restore the display to the state existing at the time top was started. That's what occurs normally. The net result of that failure was a corrupted screen. However, there is a 'screen' configuration option that will produce proper 'rmcup' behavior, but it is off by default. That screencr option is known as 'altscreen'. I stumbled across this provision by cloning the screen git repository then searching for references to 'cup'. If 'altscreen on' had been in either the /etc/screenrc or the $HOME/.screenrc configuration file, my poor old top would never have been accused of such corruptions. Of course, the Programming Gods decree that any simple solution for our problem must always be revealed last. So before discovering that rc option, another approach was taken involving top only. With just a little extra refactoring of top display logic he was made immune to any such quirk in the implementation of 'smcup/rmcup'. I always feel good about any enhancement that actually reduces the total number of lines of code. Even though this change involved mostly rearranging some logic, it yielded one less line (can't judge by diffstat because of braces & notes). Anyway, rather than requiring some change to a screenrc file, now we are self-sufficient. Reference(s): procps --------------------------------------------- https://bugzilla.redhat.com/show_bug.cgi?id=962022 http://www.freelists.org/post/procps/top-procpsng337-no-screen-cleaning-at-exit,3 . top : disable tty scrollback buffer to improve SIGWINCH commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d screen --------------------------------------------- git://git.sv.gnu.org/screen.git . Improve cursor store/restore on smcup/rmcup. commit f95352946080be803b794c9f2733d8c809c1a39a . Fix using alternate screen buffers in some cases. commit ad56f746c6243d45124485d198d577bdbb78071c http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=558724 Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-05-18 10:30:00 +05:30
* (that those auto-sized columns are addressed, know what I)
2011-03-31 16:45:12 +05:30
* (mean? Huh, "doesn't DO MUCH"! Never, EVER think or say)
* (THAT about THIS function again, Ok? Good that's better.)
*
* (ps. we ARE the UNEQUALED justification KING of COMMENTS!)
* (No, I don't mean significance/relevance, only alignment.)
*/
static void frame_make (void) {
WIN_t *w = Curwin; // avoid gcc bloat with a local copy
2002-06-19 05:15:30 +05:30
int i, scrlins;
// deal with potential signal(s) since the last time around...
if (Frames_signal)
zap_fieldstab();
// whoa either first time or thread/task mode change, (re)prime the pump...
if (Pseudo_row == PROC_XTRA) {
cpus_refresh();
2011-08-30 17:35:45 +05:30
procs_refresh();
usleep(LIB_USLEEP);
putp(Cap_clr_scr);
2011-08-30 17:35:45 +05:30
} else
putp(Batch ? "\n\n" : Cap_home);
2011-03-31 16:45:12 +05:30
2011-08-30 17:35:45 +05:30
sysinfo_refresh(0);
procs_refresh();
2011-08-30 17:35:45 +05:30
Tree_idx = Pseudo_row = Msg_row = scrlins = 0;
summary_show();
2002-06-19 05:15:30 +05:30
Max_lines = (Screen_rows - Msg_row) - 1;
top: inoculated against a window manager like 'screen' If top were invoked under the 'screen' window manager, writing the terminfo string 'exit_ca_mode' at top exit would not restore the display to the state existing at the time top was started. That's what occurs normally. The net result of that failure was a corrupted screen. However, there is a 'screen' configuration option that will produce proper 'rmcup' behavior, but it is off by default. That screencr option is known as 'altscreen'. I stumbled across this provision by cloning the screen git repository then searching for references to 'cup'. If 'altscreen on' had been in either the /etc/screenrc or the $HOME/.screenrc configuration file, my poor old top would never have been accused of such corruptions. Of course, the Programming Gods decree that any simple solution for our problem must always be revealed last. So before discovering that rc option, another approach was taken involving top only. With just a little extra refactoring of top display logic he was made immune to any such quirk in the implementation of 'smcup/rmcup'. I always feel good about any enhancement that actually reduces the total number of lines of code. Even though this change involved mostly rearranging some logic, it yielded one less line (can't judge by diffstat because of braces & notes). Anyway, rather than requiring some change to a screenrc file, now we are self-sufficient. Reference(s): procps --------------------------------------------- https://bugzilla.redhat.com/show_bug.cgi?id=962022 http://www.freelists.org/post/procps/top-procpsng337-no-screen-cleaning-at-exit,3 . top : disable tty scrollback buffer to improve SIGWINCH commit dedaf6e1a81738ff08ee8e8523871e12f555ad6d screen --------------------------------------------- git://git.sv.gnu.org/screen.git . Improve cursor store/restore on smcup/rmcup. commit f95352946080be803b794c9f2733d8c809c1a39a . Fix using alternate screen buffers in some cases. commit ad56f746c6243d45124485d198d577bdbb78071c http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=558724 Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-05-18 10:30:00 +05:30
OFFw(w, INFINDS_xxx);
/* one way or another, rid us of any prior frame's msg
[ now that this is positioned after the call to summary_show(), ]
[ we no longer need or employ tg2(0, Msg_row) since all summary ]
[ lines end with a newline, and header lines begin with newline ] */
if (VIZISw(w) && CHKw(w, View_SCROLL)) PUTT(Scroll_fmts, Frame_maxtask);
else putp(Cap_clr_eol);
2002-06-19 05:15:30 +05:30
2002-12-05 04:18:30 +05:30
if (!Rc.mode_altscr) {
2002-11-08 06:01:28 +05:30
// only 1 window to show so, piece o' cake
2011-03-31 16:45:12 +05:30
w->winlines = w->rc.maxtasks ? w->rc.maxtasks : Max_lines;
2011-08-30 17:35:45 +05:30
scrlins = window_show(w, Max_lines);
2002-06-19 05:15:30 +05:30
} else {
2002-11-08 06:01:28 +05:30
// maybe NO window is visible but assume, pieces o' cakes
2002-06-19 05:15:30 +05:30
for (i = 0 ; i < GROUPSMAX; i++) {
2011-03-31 16:45:12 +05:30
if (CHKw(&Winstk[i], Show_TASKON)) {
frame_hlp(i, Max_lines - scrlins);
2011-08-30 17:35:45 +05:30
scrlins += window_show(&Winstk[i], Max_lines - scrlins);
2002-06-19 05:15:30 +05:30
}
if (Max_lines <= scrlins) break;
}
2002-05-30 09:14:46 +05:30
}
2011-03-31 16:45:12 +05:30
/* clear to end-of-screen - critical if last window is 'idleps off'
2011-03-31 16:45:12 +05:30
(main loop must iterate such that we're always called before sleep) */
if (scrlins < Max_lines) {
putp(Cap_nl_clreos);
PSU_CLREOS(Pseudo_row);
}
2002-06-19 05:15:30 +05:30
fflush(stdout);
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/* we'll deem any terminal not supporting tgoto as dumb and disable
the normal non-interactive output optimization... */
if (!Cap_can_goto) PSU_CLREOS(0);
/* lastly, check auto-sized width needs for the next iteration */
if (AUTOX_MODE && Autox_found)
widths_resize();
2011-03-31 16:45:12 +05:30
} // end: frame_make
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
/*
* duh... */
int main (int dont_care_argc, char **argv) {
2002-10-12 09:55:57 +05:30
(void)dont_care_argc;
2002-08-26 06:25:30 +05:30
before(*argv);
2002-11-08 06:01:28 +05:30
// +-------------+
2011-03-31 16:45:12 +05:30
wins_stage_1(); // top (sic) slice
2002-11-08 06:01:28 +05:30
configs_read(); // > spread etc, <
parse_args(&argv[1]); // > lean stuff, <
whack_terminal(); // > onions etc. <
2011-03-31 16:45:12 +05:30
wins_stage_2(); // as bottom slice
2002-11-08 06:01:28 +05:30
// +-------------+
2002-05-30 09:14:46 +05:30
2002-10-21 10:20:41 +05:30
for (;;) {
2013-01-16 11:30:00 +05:30
struct timespec ts;
2011-03-31 16:45:12 +05:30
2003-03-18 05:12:00 +05:30
frame_make();
2002-05-30 09:14:46 +05:30
2011-03-31 16:45:12 +05:30
if (0 < Loops) --Loops;
if (!Loops) bye_bye(NULL);
2002-05-30 09:14:46 +05:30
2013-01-16 11:30:00 +05:30
ts.tv_sec = Rc.delay_time;
ts.tv_nsec = (Rc.delay_time - (int)Rc.delay_time) * 1000000000;
2003-03-18 05:12:00 +05:30
2011-03-31 16:45:12 +05:30
if (Batch)
2013-01-16 11:30:00 +05:30
pselect(0, NULL, NULL, NULL, &ts, NULL);
2011-03-31 16:45:12 +05:30
else {
2013-01-16 11:30:00 +05:30
if (ioa(&ts))
do_key(iokey(1));
2002-05-30 09:14:46 +05:30
}
/* note: that above ioa routine exists to consolidate all logic
which is susceptible to signal interrupt and must then
produce a screen refresh. in this main loop frame_make
assumes responsibility for such refreshes. other logic
in contact with users must deal more obliquely with an
interrupt/refresh (hint: Frames_signal + return code)!
(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)
*/
2002-10-21 10:20:41 +05:30
}
2002-05-30 09:14:46 +05:30
return 0;
2011-03-31 16:45:12 +05:30
} // end: main