top: add the field 'USED' to top's existing repertoire

After revisiting the issue of a new field, combining 2
existing fields (RES and SWAP), I've decided it indeed
makes sense. After all, with the vastly expanded field
capability and the ease of adding new fields, it would
save some precious horizontal screen real estate while
also eliminating some mental/manual user calculations.

(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-enhancements-i-hope
http://www.freelists.org/post/procps/top-regression-reports

Signed-off-by: Jim Warner <james.warner@comcast.net>

 top/top.1     |   23 ++++++++++++++---------
 top/top.c     |   14 ++++++++++++--
 top/top.h     |    6 ++++++
 top/top_nls.c |    3 +++
 4 files changed, 35 insertions(+), 11 deletions(-)
This commit is contained in:
Jim Warner 2013-02-28 00:00:00 -06:00 committed by Jaromir Capik
parent 9dd7251ca3
commit 709785e20b
4 changed files with 35 additions and 11 deletions

View File

@ -785,17 +785,22 @@ you'll see '?' displayed.
The\fI effective\fR user ID of the task's owner. The\fI effective\fR user ID of the task's owner.
.TP 4 .TP 4
34.\fB USER \*(Em User Name \fR 34.\fB USED \*(Em Memory in Use (KiB) \fR
This field represents the non-swapped \*(MP a task has used (RES) plus
the non-resident portion of its address space (SWAP).
.TP 4
35.\fB USER \*(Em User Name \fR
The\fI effective\fR user name of the task's owner. The\fI effective\fR user name of the task's owner.
.TP 4 .TP 4
35.\fB VIRT \*(Em Virtual Memory Size (KiB) \fR 36.\fB VIRT \*(Em Virtual Memory Size (KiB) \fR
The total amount of \*(MV used by the task. The total amount of \*(MV used by the task.
It includes all code, data and shared libraries plus pages that have been It includes all code, data and shared libraries plus pages that have been
swapped out and pages that have been mapped but not used. swapped out and pages that have been mapped but not used.
.TP 4 .TP 4
36.\fB WCHAN \*(Em Sleeping in Function \fR 37.\fB WCHAN \*(Em Sleeping in Function \fR
Depending on the availability of the kernel link map ('System.map'), this Depending on the availability of the kernel link map ('System.map'), this
field will show the name or the address of the kernel function in which the field will show the name or the address of the kernel function in which the
task is currently sleeping. task is currently sleeping.
@ -807,14 +812,14 @@ Should that occur, your only means of reducing that overhead will be to stop
and restart \*(We. and restart \*(We.
.TP 4 .TP 4
37.\fB nDRT \*(Em Dirty Pages Count \fR 38.\fB nDRT \*(Em Dirty Pages Count \fR
The number of pages that have been modified since they were last The number of pages that have been modified since they were last
written to \*(AS. written to \*(AS.
Dirty pages must be written to \*(AS before the corresponding physical Dirty pages must be written to \*(AS before the corresponding physical
memory location can be used for some other virtual page. memory location can be used for some other virtual page.
.TP 4 .TP 4
38.\fB nMaj \*(Em Major Page Fault Count \fR 39.\fB nMaj \*(Em Major Page Fault Count \fR
The number of\fB major\fR page faults that have occurred for a task. The number of\fB major\fR page faults that have occurred for a task.
A page fault occurs when a process attempts to read from or write to a A page fault occurs when a process attempts to read from or write to a
virtual page that is not currently present in its address space. virtual page that is not currently present in its address space.
@ -822,7 +827,7 @@ A major page fault is when \*(AS access is involved in making that
page available. page available.
.TP 4 .TP 4
39.\fB nMin \*(Em Minor Page Fault count \fR 40.\fB nMin \*(Em Minor Page Fault count \fR
The number of\fB minor\fR page faults that have occurred for a task. The number of\fB minor\fR page faults that have occurred for a task.
A page fault occurs when a process attempts to read from or write to a A page fault occurs when a process attempts to read from or write to a
virtual page that is not currently present in its address space. virtual page that is not currently present in its address space.
@ -830,16 +835,16 @@ A minor page fault does not involve \*(AS access in making that
page available. page available.
.TP 4 .TP 4
40.\fB nTH \*(Em Number of Threads \fR 41.\fB nTH \*(Em Number of Threads \fR
The number of threads associated with a process. The number of threads associated with a process.
.TP 4 .TP 4
41.\fB vMj \*(Em Major Page Fault Count Delta\fR 42.\fB vMj \*(Em Major Page Fault Count Delta\fR
The number of\fB major\fR page faults that have occurred since the The number of\fB major\fR page faults that have occurred since the
last update (see nMaj). last update (see nMaj).
.TP 4 .TP 4
42.\fB vMn \*(Em Minor Page Fault Count Delta\fR 43.\fB vMn \*(Em Minor Page Fault Count Delta\fR
The number of\fB minor\fR page faults that have occurred since the The number of\fB minor\fR page faults that have occurred since the
last update (see nMin). last update (see nMin).

View File

@ -275,6 +275,7 @@ SCB_STRS(UEN, euser)
SCB_NUMx(URD, ruid) SCB_NUMx(URD, ruid)
SCB_STRS(URN, ruser) SCB_STRS(URN, ruser)
SCB_NUMx(USD, suid) SCB_NUMx(USD, suid)
SCB_NUM2(USE, resident, vm_swap)
SCB_STRS(USN, suser) SCB_STRS(USN, suser)
SCB_NUM1(VRT, size) SCB_NUM1(VRT, size)
SCB_NUM1(WCH, wchan) SCB_NUM1(WCH, wchan)
@ -1557,6 +1558,7 @@ end_justifies:
#define L_OUSER PROC_FILLSTATUS | PROC_FILLUSR #define L_OUSER PROC_FILLSTATUS | PROC_FILLUSR
#define L_EGROUP PROC_FILLSTATUS | PROC_FILLGRP #define L_EGROUP PROC_FILLSTATUS | PROC_FILLGRP
#define L_SUPGRP PROC_FILLSTATUS | PROC_FILLSUPGRP #define L_SUPGRP PROC_FILLSTATUS | PROC_FILLSUPGRP
#define L_USED PROC_FILLSTATUS | PROC_FILLMEM
// make 'none' non-zero (used to be important to Frames_libflags) // make 'none' non-zero (used to be important to Frames_libflags)
#define L_NONE PROC_SPARE_1 #define L_NONE PROC_SPARE_1
// from either 'stat' or 'status' (preferred), via bits not otherwise used // from either 'stat' or 'status' (preferred), via bits not otherwise used
@ -1645,7 +1647,12 @@ static FLD_t Fieldstab[] = {
#endif #endif
{ -1, -1, A_left, SF(ENV), L_ENVIRON }, { -1, -1, A_left, SF(ENV), L_ENVIRON },
{ 3, -1, A_right, SF(FV1), L_stat }, { 3, -1, A_right, SF(FV1), L_stat },
{ 3, -1, A_right, SF(FV2), L_stat } { 3, -1, A_right, SF(FV2), L_stat },
#ifndef NOBOOST_MEMS
{ 6, SK_Kb, A_right, SF(USE), L_USED }
#else
{ 4, SK_Kb, A_right, SF(USE), L_USED }
#endif
#undef SF #undef SF
#undef A_left #undef A_left
#undef A_right #undef A_right
@ -2183,7 +2190,7 @@ static void zap_fieldstab (void) {
Fieldstab[P_VRT].scale = Fieldstab[P_SWP].scale Fieldstab[P_VRT].scale = Fieldstab[P_SWP].scale
= Fieldstab[P_RES].scale = Fieldstab[P_COD].scale = Fieldstab[P_RES].scale = Fieldstab[P_COD].scale
= Fieldstab[P_DAT].scale = Fieldstab[P_SHR].scale = Fieldstab[P_DAT].scale = Fieldstab[P_SHR].scale
= Rc.task_mscale; = Fieldstab[P_USE].scale = Rc.task_mscale;
// lastly, ensure we've got proper column headers... // lastly, ensure we've got proper column headers...
calibrate_fields(); calibrate_fields();
@ -4981,6 +4988,9 @@ static const char *task_show (const WIN_t *q, const proc_t *p) {
case P_USD: case P_USD:
cp = make_num(p->suid, W, Jn, P_USD); cp = make_num(p->suid, W, Jn, P_USD);
break; break;
case P_USE:
cp = scale_mem(S, (p->vm_swap + pages2K(p->resident)), W, Jn);
break;
case P_USN: case P_USN:
cp = make_str(p->suser, W, Js, P_USN); cp = make_str(p->suser, W, Js, P_USN);
break; break;

View File

@ -185,6 +185,7 @@ enum pflag {
#endif #endif
P_ENV, P_ENV,
P_FV1, P_FV2, P_FV1, P_FV2,
P_USE,
#ifdef USE_X_COLHDR #ifdef USE_X_COLHDR
// not really pflags, used with tbl indexing // not really pflags, used with tbl indexing
P_MAXPFLGS P_MAXPFLGS
@ -462,6 +463,11 @@ typedef struct WIN_t {
if ( (*P)->n < (*Q)->n ) return SORT_lt; \ if ( (*P)->n < (*Q)->n ) return SORT_lt; \
if ( (*P)->n > (*Q)->n ) return SORT_gt; \ if ( (*P)->n > (*Q)->n ) return SORT_gt; \
return SORT_eq; } return SORT_eq; }
#define SCB_NUM2(f,n1,n2) \
static int SCB_NAME(f) (const proc_t **P, const proc_t **Q) { \
if ( ((*P)->n1+(*P)->n2) < ((*Q)->n1+(*Q)->n2) ) return SORT_lt; \
if ( ((*P)->n1+(*P)->n2) > ((*Q)->n1+(*Q)->n2) ) return SORT_gt; \
return SORT_eq; }
#define SCB_NUMx(f,n) \ #define SCB_NUMx(f,n) \
static int SCB_NAME(f) (const proc_t **P, const proc_t **Q) { \ static int SCB_NAME(f) (const proc_t **P, const proc_t **Q) { \
return Frame_srtflg * ( (*Q)->n - (*P)->n ); } return Frame_srtflg * ( (*Q)->n - (*P)->n ); }

View File

@ -254,6 +254,9 @@ static void build_two_nlstabs (void) {
/* Translation Hint: maximum 'vMn' = 3 */ /* Translation Hint: maximum 'vMn' = 3 */
Head_nlstab[P_FV2] = _("vMn"); Head_nlstab[P_FV2] = _("vMn");
Desc_nlstab[P_FV2] = _("Minor Faults delta"); Desc_nlstab[P_FV2] = _("Minor Faults delta");
/* Translation Hint: maximum 'USED' = 4 */
Head_nlstab[P_USE] = _("USED");
Desc_nlstab[P_USE] = _("Res+Swap Size (KiB)");
} }