📄 top.h
字号:
// top.h - Header file: show Linux processes//// Copyright (c) 2002, by: James C. Warner// All rights reserved. 8921 Hilloway Road// Eden Prairie, Minnesota 55347 USA// <warnerjc@worldnet.att.net>//// This file may be used subject to the terms and conditions of the// GNU Library General Public License Version 2, or any later version// at your option, as published by the Free Software Foundation.// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU Library General Public License for more details.// // For their contributions to this program, the author wishes to thank:// Albert D. Cahalan, <albert@users.sf.net>// Craig Small, <csmall@small.dropbear.id.au>//// Changes by Albert Cahalan, 2002, 2004.#ifndef _Itop#define _Itop// Defines intended to be experimented with ------------------------//#define CASEUP_HEXES // show any hex values in upper case//#define CASEUP_SCALE // show scaled time/num suffix upper case//#define CASEUP_SUMMK // show memory summary kilobytes with 'K'//#define SORT_SUPRESS // *attempt* to reduce qsort overhead//#define WARN_NOT_SMP // restrict '1' & 'I' commands to true smp// Development/Debugging defines -----------------------------------//#define ATEOJ_REPORT // report a bunch of stuff, at end-of-job//#define PRETEND2_5_X // pretend we're linux 2.5.x (for IO-wait)//#define PRETENDNOCAP // use a terminal without essential caps//#define STDOUT_IOLBF // disable our own stdout _IOFBF override#ifdef PRETEND2_5_X#define linux_version_code LINUX_VERSION(2,5,43)#endif/*###### Some Miscellaneous constants ##################################*/// The default delay twix updates#define DEF_DELAY 3.0// The length of time a 'message' is displayed#define MSG_SLEEP 2// The default value for the 'k' (kill) request#define DEF_SIGNAL SIGTERM// Specific process id monitoring support (command line only)#define MONPIDMAX 20// Power-of-two sizes lead to trouble; the largest power of// two factor should be the cache line size. It'll mean the// array indexing math gets slower, but cache aliasing is// avoided.#define CACHE_TWEAK_FACTOR 64// Miscellaneous buffer sizes with liberal values -- mostly// just to pinpoint source code usage/dependancies#define SCREENMAX ( 512 + CACHE_TWEAK_FACTOR)// the above might seem pretty stingy, until you consider that with every// one of top's fields displayed we're talking a 160 byte column header --// so that will provide for all fields plus a 350+ byte command line#define WINNAMSIZ 4#define CAPTABMAX 9#define PFLAGSSIZ 32#define CAPBUFSIZ 32#define CLRBUFSIZ 64#define GETBUFSIZ 32#define TNYBUFSIZ 32#define SMLBUFSIZ ( 256 + CACHE_TWEAK_FACTOR)#define OURPATHSZ (1024 + CACHE_TWEAK_FACTOR)#define MEDBUFSIZ (1024 + CACHE_TWEAK_FACTOR)#define BIGBUFSIZ (2048 + CACHE_TWEAK_FACTOR)#define USRNAMSIZ GETBUFSIZ#define ROWBUFSIZ SCREENMAX + CLRBUFSIZ/*###### Some Miscellaneous Macro definitions ##########################*/// Yield table size as 'int'#define MAXTBL(t) (int)(sizeof(t) / sizeof(t[0]))// Used as return arguments in *some* of the sort callbacks#define SORT_lt ( Frame_srtflg > 0 ? 1 : -1 )#define SORT_gt ( Frame_srtflg > 0 ? -1 : 1 )#define SORT_eq 0// Used to create *most* of the sort callback functions#define SCB_NUM1(f,n) \ static int sort_ ## f (const proc_t **P, const proc_t **Q) { \ if ( (*P)->n < (*Q)->n ) return SORT_lt; \ if (likely( (*P)->n > (*Q)->n )) return SORT_gt; \ return SORT_eq; }#define SCB_NUM2(f,n1,n2) \ static int sort_ ## f (const proc_t **P, const proc_t **Q) { \ if ( ((*P)->n1 - (*P)->n2) < ((*Q)->n1 - (*Q)->n2) ) return SORT_lt; \ if (likely( ((*P)->n1 - (*P)->n2) > ((*Q)->n1 - (*Q)->n2) )) return SORT_gt; \ return SORT_eq; }#define SCB_NUMx(f,n) \ static int sort_ ## f (const proc_t **P, const proc_t **Q) { \ return Frame_srtflg * ( (*Q)->n - (*P)->n ); }#define SCB_STRx(f,s) \ static int sort_ ## f (const proc_t **P, const proc_t **Q) { \ return Frame_srtflg * strcmp((*Q)->s, (*P)->s); }// The following two macros are used to 'inline' those portions of the// display process requiring formatting, while protecting against any// potential embedded 'millesecond delay' escape sequences.// PUTT - Put to Tty (used in many places)// - for temporary, possibly interactive, 'replacement' output// - may contain ANY valid terminfo escape sequences// - need NOT represent an entire screen row#define PUTT(fmt,arg...) do { \ char _str[ROWBUFSIZ]; \ snprintf(_str, sizeof(_str), fmt, ## arg); \ putp(_str); \ } while (0)// PUFF - Put for Frame (used in only 3 places)// - for more permanent frame-oriented 'update' output// - may NOT contain cursor motion terminfo escapes// - assumed to represent a complete screen ROW// - subject to optimization, thus MAY be discarded// The evil version (53892 byte stripped top, oddly enough)#define _PUFF(fmt,arg...) \do { \ char _str[ROWBUFSIZ]; \ int _len = 1 + snprintf(_str, sizeof(_str), fmt, ## arg); \ putp ( Batch ? _str : \ ({ \ char *restrict const _pse = &Pseudo_scrn[Pseudo_row++ * Pseudo_cols]; \ memcmp(_pse, _str, _len) ? memcpy(_pse, _str, _len) : "\n"; \ }) \ ); \} while (0)// The good version (53876 byte stripped top)#define PUFF(fmt,arg...) \do { \ char _str[ROWBUFSIZ]; \ char *_ptr; \ int _len = 1 + snprintf(_str, sizeof(_str), fmt, ## arg); \ if (Batch) _ptr = _str; \ else { \ _ptr = &Pseudo_scrn[Pseudo_row++ * Pseudo_cols]; \ if (memcmp(_ptr, _str, _len)) { \ memcpy(_ptr, _str, _len); \ } else { \ _ptr = "\n"; \ } \ } \ putp(_ptr); \} while (0)/*------ Special Macros (debug and/or informative) ---------------------*/// Orderly end, with any sort of message - see fmtmk#define debug_END(s) { \ static void std_err (const char *); \ fputs(Cap_clr_scr, stdout); \ std_err(s); \ }// A poor man's breakpoint, if he's too lazy to learn gdb#define its_YOUR_fault { *((char *)0) = '!'; }/*###### Some Typedef's and Enum's #####################################*/// This typedef just ensures consistent 'process flags' handlingtypedef unsigned FLG_t;// These typedefs attempt to ensure consistent 'ticks' handlingtypedef unsigned long long TIC_t;typedef long long SIC_t;// Sort support, callback funtion signaturetypedef int (*QFP_t)(const void *, const void *);// This structure consolidates the information that's used// in a variety of display roles.typedef struct FLD_t { const char keys [4]; // order: New-on New-off Old-on Old-off // misaligned on 64-bit, but part of a table -- oh well const char *head; // name for col heads + toggle/reorder fields const char *fmts; // sprintf format string for field display const int width; // field width, if applicable const int scale; // scale_num type, if applicable const QFP_t sort; // sort function const char *desc; // description for toggle/reorder fields const int lflg; // PROC_FILLxxx flag(s) needed by this field} FLD_t;// This structure stores one piece of critical 'history'// information from one frame to the next -- we don't calc// and save data that goes unusedtypedef struct HST_t { TIC_t tics; int pid;} HST_t;// This structure stores a frame's cpu tics used in history// calculations. It exists primarily for SMP support but serves// all environments.typedef struct CPU_t { TIC_t u, n, s, i, w, x, y, z; // as represented in /proc/stat TIC_t u_sav, s_sav, n_sav, i_sav, w_sav, x_sav, y_sav, z_sav; // in the order of our display unsigned id; // the CPU ID number} CPU_t;// These 2 types support rcfile compatibilitytypedef struct RCW_t { // the 'window' portion of an rcfile FLG_t sortindx; // sort field, represented as a procflag int winflags, // 'view', 'show' and 'sort' mode flags maxtasks, // user requested maximum, 0 equals all summclr, // color num used in summ info msgsclr, // " in msgs/pmts headclr, // " in cols head taskclr; // " in task rows char winname [WINNAMSIZ], // window name, user changeable fieldscur [PFLAGSSIZ]; // fields displayed and ordered} RCW_t;typedef struct RCF_t { // the complete rcfile (new style) int mode_altscr; // 'A' - Alt display mode (multi task windows) int mode_irixps; // 'I' - Irix vs. Solaris mode (SMP-only) float delay_time; // 'd' or 's' - How long to sleep twixt updates int win_index; // Curwin, as index RCW_t win [4]; // a 'WIN_t.rc' for each of the 4 windows} RCF_t;// The scaling 'type' used with scale_num() -- this is how// the passed number is interpreted should scaling be necessaryenum scale_num { SK_no, SK_Kb, SK_Mb, SK_Gb, SK_Tb};// Flags for each possible fieldenum pflag { P_PID, P_PPD, P_URR, P_UID, P_URE, P_GRP, P_TTY, P_PRI, P_NCE, P_CPN, P_CPU, P_TME, P_TM2, P_MEM, P_VRT, P_SWP, P_RES, P_COD, P_DAT, P_SHR, P_FLT, P_DRT, P_STA, P_CMD, P_WCH, P_FLG};///////////////////////////////////////////////////////////////////////////// Special Section: multiple windows/field groups -------------// (kind of a header within a header: constants, macros & types)#define GROUPSMAX 4 // the max number of simultaneous windows#define GRPNAMSIZ WINNAMSIZ+2 // window's name + number as in: '#:...'#define Flags_TOG 1 // these are used to direct wins_reflag#define Flags_SET 2#define Flags_OFF 3// The Persistent 'Mode' flags!// These are preserved in the rc file, as a single integer and the// letter shown is the corresponding 'command' toggle// 'View_' flags affect the summary (minimum), taken from 'Curwin'#define View_CPUSUM 0x8000 // '1' - show combined cpu stats (vs. each)#define View_LOADAV 0x4000 // 'l' - display load avg and uptime summary#define View_STATES 0x2000 // 't' - display task/cpu(s) states summary#define View_MEMORY 0x1000 // 'm' - display memory summary#define View_NOBOLD 0x0001 // 'B' - disable 'bold' attribute globally// 'Show_' & 'Qsrt_' flags are for task display in a visible window#define Show_THREADS 0x10000 // 'H' - show threads in each task#define Show_COLORS 0x0800 // 'z' - show in color (vs. mono)#define Show_HIBOLD 0x0400 // 'b' - rows and/or cols bold (vs. reverse)#define Show_HICOLS 0x0200 // 'x' - show sort column highlighted#define Show_HIROWS 0x0100 // 'y' - show running tasks highlighted
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -