From b05770d94a652fe131912fcd5a97ca227aa349a4 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Tue, 27 Apr 2021 00:00:00 -0500 Subject: [PATCH] top: exploit some of those new smaps_rollup provisions My, how time flies. Here we are finally attending to a 2 year old issue at long last (well, at least top is). In truth, this change was prompted by that more recent issue #201 and simply represents my initial picks from among those available with the new library provisions. Note: we have to bump that rcfile version whenever new fields are added. That will mean older top programs no longer can read this top's rcfile. But that's Ok since top offers a warning before replacing an older rcfile. Doubtless, more smaps_rollup fields will be introduced under top as we get more experience with this feature. However, any such usage comes with tremendoud costs as was reported for the previous patch and repeated here: Here is a small preview of just what you will discover when using this command line: time top/top -d0 -n1000. ------------------------------------ as a regular user with only PID + RES (statm) real 0m2.605s user 0m1.060s sys 0m1.377s with only PID + RSS (smaps) real 0m26.397s 10x more costly user 0m1.253s sys 0m24.915s ----------------- as a root (thus smaps for all tasks) with only PID + RES (statm) real 0m2.651s user 0m1.177s sys 0m1.286s with only PID + RSS (smaps) real 0m33.040s 12x more costly user 0m1.256s sys 0m31.533s Reference(s): . top/ps: add support for PSS reporting https://gitlab.com/procps-ng/procps/-/issues/112 . ps: expose shared/private memory separately https://gitlab.com/procps-ng/procps/-/issues/201 Signed-off-by: Jim Warner --- top/top.c | 23 +++++++++++++++++++---- top/top.h | 1 + top/top_nls.c | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/top/top.c b/top/top.c index 604d172b..3e22139a 100644 --- a/top/top.c +++ b/top/top.c @@ -1671,8 +1671,13 @@ static struct { { -1, -1, A_left, PIDS_CGNAME }, // str EU_CGN { 0, -1, A_right, PIDS_PROCESSOR_NODE }, // s_int EU_NMA { 5, -1, A_right, PIDS_ID_LOGIN }, // s_int EU_LID - { -1, -1, A_left, PIDS_EXE } // str EU_EXE -#define eu_LAST EU_EXE + { -1, -1, A_left, PIDS_EXE }, // str EU_EXE + { 6, SK_Kb, A_right, PIDS_SMAP_RSS }, // ul_int EU_RSS + { 6, SK_Kb, A_right, PIDS_SMAP_PSS }, // ul_int EU_PSS + { 6, SK_Kb, A_right, PIDS_SMAP_PSS_ANON }, // ul_int EU_PZA + { 6, SK_Kb, A_right, PIDS_SMAP_PSS_FILE }, // ul_int EU_PZF + { 6, SK_Kb, A_right, PIDS_SMAP_PSS_SHMEM } // ul_int EU_PZS +#define eu_LAST EU_PZS // xtra Fieldstab 'pseudo pflag' entries for the newlib interface . . . . . . . #define eu_CMDLINE eu_LAST +1 #define eu_TICS_ALL_C eu_LAST +2 @@ -2312,7 +2317,10 @@ static void zap_fieldstab (void) { = 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; + = Fieldstab[EU_RZS].scale = Fieldstab[EU_RSS].scale + = Fieldstab[EU_PSS].scale = Fieldstab[EU_PZA].scale + = Fieldstab[EU_PZF].scale = Fieldstab[EU_PZS].scale + = Rc.task_mscale; // lastly, ensure we've got proper column headers... calibrate_fields(); @@ -3589,8 +3597,10 @@ static const char *configs_file (FILE *fp, const char *name, float *delay) { // fall through case 'i': // from 3.3.10 thru 3.3.16 scat(w->rc.fieldscur, RCF_PLUS_J); + w->rc.double_up = w->rc.combine_cpus = 0; // fall through - case 'j': // current RCF_VERSION_ID + case 'j': // this is release 3.3.17 + case 'k': // current RCF_VERSION_ID default: if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1) return p; @@ -5872,7 +5882,12 @@ static const char *task_show (const WIN_t *q, struct pids_stack *p) { case EU_COD: // PIDS_MEM_CODE case EU_DAT: // PIDS_MEM_DATA case EU_DRT: // PIDS_noop, really # pgs, but always 0 since 2.6 + case EU_PZA: // PIDS_SMAP_PSS_ANON + case EU_PZF: // PIDS_SMAP_PSS_FILE + case EU_PZS: // PIDS_SMAP_PSS_SHMEM + case EU_PSS: // PIDS_SMAP_PSS case EU_RES: // PIDS_MEM_RES + case EU_RSS: // PIDS_SMAP_RSS case EU_RZA: // PIDS_VM_RSS_ANON case EU_RZF: // PIDS_VM_RSS_FILE case EU_RZL: // PIDS_VM_RSS_LOCKED diff --git a/top/top.h b/top/top.h index f738636f..77011534 100644 --- a/top/top.h +++ b/top/top.h @@ -189,6 +189,7 @@ enum pflag { EU_NMA, EU_LID, EU_EXE, + EU_RSS, EU_PSS, EU_PZA, EU_PZF, EU_PZS, #ifdef USE_X_COLHDR // not really pflags, used with tbl indexing EU_MAXPFLGS diff --git a/top/top_nls.c b/top/top_nls.c index b45669eb..607c4496 100644 --- a/top/top_nls.c +++ b/top/top_nls.c @@ -311,6 +311,24 @@ static void build_two_nlstabs (void) { /* Translation Hint: maximum 'EXE' = variable */ Head_nlstab[EU_EXE] = _("EXE"); Desc_nlstab[EU_EXE] = _("Executable Path"); +/* Translation Hint: With the next 5 fields, notice how an extra space + has been added ahead of one 'KiB' so that they all + align. You need not preserve such alignment. */ +/* Translation Hint: maximum 'RSS' = 6 */ + Head_nlstab[EU_RSS] = _("RSS"); + Desc_nlstab[EU_RSS] = _("Res Mem (smaps), KiB"); +/* Translation Hint: maximum 'PSS' = 6 */ + Head_nlstab[EU_PSS] = _("PSS"); + Desc_nlstab[EU_PSS] = _("Proportion RSS, KiB"); +/* Translation Hint: maximum 'PSan' = 6 */ + Head_nlstab[EU_PZA] = _("PSan"); + Desc_nlstab[EU_PZA] = _("Proportion Anon. KiB"); +/* Translation Hint: maximum 'PSfd' = 6 */ + Head_nlstab[EU_PZF] = _("PSfd"); + Desc_nlstab[EU_PZF] = _("Proportion File, KiB"); +/* Translation Hint: maximum 'PSsh' = 6 */ + Head_nlstab[EU_PZS] = _("PSsh"); + Desc_nlstab[EU_PZS] = _("Proportion Shrd, KiB"); } -- 2.40.0