Provide the -G option to display the swap consumption of the thread group leader in a thread group. For example: crash> pswap -k -G | head PID SWAP COMM 1 136k systemd 469 284k zsh 599 148k systemd-journal 608 1192k lvmetad 637 1712k systemd-udevd 822 308k auditd 836 104k audispd 838 156k sedispatch 842 92k alsactl The complete file can be found here: http://people.redhat.com/~atomlin/crash/extensions/swap_usage.c Signed-off-by: Aaron Tomlin <atomlin@xxxxxxxxxx> --- extensions/swap_usage.c | 70 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/extensions/swap_usage.c b/extensions/swap_usage.c index 4f92e8c..d9467ca 100644 --- a/extensions/swap_usage.c +++ b/extensions/swap_usage.c @@ -19,6 +19,7 @@ #include "defs.h" #define DISPLAY_KB (0x2) +#define DISPLAY_TG (0x4) #ifdef ARM #define _PAGE_FILE (1 << 2) @@ -138,8 +139,8 @@ show_swap_usage(struct task_context *tc, ulong exists, ulong flag) if (flag & DISPLAY_KB) swap_usage <<= (PAGESHIFT()-10); - fprintf(fp, "%5ld %5ld%s%5s\n", - tc->pid, swap_usage, (flag & DISPLAY_KB) ? "k\t" : "\t", tc->comm); + fprintf(fp, "%3ld %6ld%s%5s\n", tc->pid, swap_usage, + (flag & DISPLAY_KB) ? "k\t" : "\t", tc->comm); } @@ -151,6 +152,7 @@ cmd_pswap(void) int c; ulong value; ulong flag = 0; + ulong tgid; int subsequent = 0; ulong exists = MEMBER_NOT_FOUND; @@ -159,11 +161,14 @@ cmd_pswap(void) exists = MEMBER_FOUND; } - while ((c = getopt(argcnt, args, "k")) != EOF) { + while ((c = getopt(argcnt, args, "kG")) != EOF) { switch (c) { case 'k': flag |= DISPLAY_KB; break; + case 'G': + flag |= DISPLAY_TG; + break; default: argerrs++; break; @@ -177,9 +182,16 @@ cmd_pswap(void) PRINT_HEADER(); tc = FIRST_CONTEXT(); for (i = 0; i < RUNNING_TASKS(); i++, tc++) { - if (!is_kernel_thread(tc->task)) - show_swap_usage(tc, exists, flag); - } + if (!is_kernel_thread(tc->task)) { + if (flag & DISPLAY_TG) { + tgid = task_tgid(tc->task); + if (tc->pid != tgid) + continue; + tc = tgid_to_context(tgid); + } + show_swap_usage(tc, exists, flag); + } + } return; } @@ -189,6 +201,12 @@ cmd_pswap(void) case STR_PID: for (tc = pid_to_context(value); tc; tc = tc->tc_next) { if (!is_kernel_thread(tc->task)) { + if (flag & DISPLAY_TG) { + tgid = task_tgid(tc->task); + if (tc->pid != tgid) + continue; + tc = tgid_to_context(tgid); + } show_swap_usage(tc, exists, flag); } else { error(INFO, "only specify a user task or pid: %s\n", @@ -200,6 +218,12 @@ cmd_pswap(void) case STR_TASK: for (; tc; tc = tc->tc_next) { if (!is_kernel_thread(tc->task)) { + if (flag & DISPLAY_TG) { + tgid = task_tgid(tc->task); + if (tc->pid != tgid) + continue; + tc = tgid_to_context(tgid); + } show_swap_usage(tc, exists, flag); } else { error(INFO, "only specify a user task or pid: %s\n", @@ -222,19 +246,45 @@ cmd_pswap(void) char *help_pswap[] = { "pswap", "Returns the actual swap consumption of a user process", - "[-k] [pid | taskp]", + "[-k -G] [pid | taskp]", " This command obtains the swap consumption (in pages) of a user process.", - " The -k option can be used to print in kilobytes.\n" + " The process list may be restricted with the following options:\n", + " -k print in kilobytes.\n" + " -G show only the thread group leader in a thread group.\n" + " ", " If no arguments are specified, every user process will be checked.", " Supported on ARM, X86, X86_64, ALPHA, IA64 and S390 only.", "\nEXAMPLE", " Show the swap consumption for pid 1232, 1353 and 2275:\n", " crash> pswap 1232 1353 2275", - " PID SWAP COMM", + " PID SWAP COMM", " 1232 34 auditd", " 1353 526 vi", " 2275 30237 gnome-shell", - " crash>", + " crash>", + " ", + " Show the swap consumption for thread group leaders only:\n", + " crash> pswap -G", + " PID SWAP COMM", + " 469 71 zsh", + " 599 37 systemd-journal", + " 608 298 lvmetad", + " 637 428 systemd-udevd", + " 822 77 auditd", + " 836 26 audispd", + " 838 39 sedispatch", + " 842 23 alsactl", + " 844 44 bluetoothd", + " 851 46 rtkit-daemon", + " 852 59 accounts-daemon", + " 855 23 avahi-daemon", + " 857 96 rsyslogd", + " 858 179 restorecond", + " 859 144 smartd", + " 862 33 irqbalance", + " 867 41 systemd-logind", + " 868 37 dbus-daemon", + " crash>", NULL }; -- 1.8.5.3 -- Crash-utility mailing list Crash-utility@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/crash-utility