[Crash-utility] [PATCH] ps: Introduce -A option
Dave Anderson
anderson at redhat.com
Thu Mar 1 14:43:56 UTC 2018
Hi Aaron.
Cool! Queued for crash-7.2.2:
https://github.com/crash-utility/crash/commit/6de5d2c034a8977e5b2be8ae1b48c4b6754a2684
Thanks,
Dave
----- Original Message -----
> Show only details for the active task on each cpu:
>
> PID PPID CPU TASK ST %MEM VSZ RSS COMM
> > 79992 1 3 ffff882456ef6ab0 RU 0.0 42194276 32620 oracle
> > 80471 1 0 ffff886b080e0ab0 RU 0.0 42194276 36912 oracle
> > 86772 85179 2 ffff8811a8650040 RU 0.0 4072 588 fstab_import
> > 88643 1 1 ffff88069366a040 RU 0.0 42231192 55628 oracle
>
> The -A flag is mutually-exclusive in addition to: -a, -t, -c, -p, -g,
> -l, -m, -S and -r.
>
> Signed-off-by: Aaron Tomlin <atomlin at redhat.com>
> ---
> defs.h | 3 ++-
> help.c | 11 ++++++++++-
> task.c | 14 +++++++++++---
> 3 files changed, 23 insertions(+), 5 deletions(-)
>
> diff --git a/defs.h b/defs.h
> index 4d2fb2f..76827dc 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -4625,8 +4625,9 @@ extern long _ZOMBIE_;
> #define PS_MSECS (0x20000)
> #define PS_SUMMARY (0x40000)
> #define PS_POLICY (0x80000)
> +#define PS_ACTIVE (0x100000)
>
> -#define PS_EXCLUSIVE
> (PS_TGID_LIST|PS_ARGV_ENVP|PS_TIMES|PS_CHILD_LIST|PS_PPID_LIST|PS_LAST_RUN|PS_RLIMIT|PS_MSECS|PS_SUMMARY)
> +#define PS_EXCLUSIVE
> (PS_TGID_LIST|PS_ARGV_ENVP|PS_TIMES|PS_CHILD_LIST|PS_PPID_LIST|PS_LAST_RUN|PS_RLIMIT|PS_MSECS|PS_SUMMARY|PS_ACTIVE)
>
> #define MAX_PS_ARGS (100) /* maximum command-line specific requests */
>
> diff --git a/help.c b/help.c
> index 5b04b09..760fcb0 100644
> --- a/help.c
> +++ b/help.c
> @@ -1251,7 +1251,7 @@ NULL
> char *help_ps[] = {
> "ps",
> "display process status information",
> -"[-k|-u|-G|-y policy] [-s] [-p|-c|-t|-[l|m][-C cpu]|-a|-g|-r|-S]\n [pid
> | task | command] ...",
> +"[-k|-u|-G|-y policy] [-s] [-p|-c|-t|-[l|m][-C cpu]|-a|-g|-r|-S|-A]\n
> [pid | task | command] ...",
> " This command displays process status for selected, or all, processes" ,
> " in the system. If no arguments are entered, the process data is",
> " is displayed for all processes. Specific processes may be selected",
> @@ -1329,6 +1329,7 @@ char *help_ps[] = {
> " -g display tasks by thread group, of selected, or all, tasks.",
> " -r display resource limits (rlimits) of selected, or all, tasks.",
> " -S display a summary consisting of the number of tasks in a task
> state.",
> +" -A display only the active task, on each cpu.",
> "\nEXAMPLES",
> " Show the process status of all current tasks:\n",
> " %s> ps",
> @@ -1483,6 +1484,14 @@ char *help_ps[] = {
> " UN: 31",
> " ZO: 1",
> " ",
> +" Display only the active task, on each cpu:\n",
> +" %s> ps -A",
> +" PID PPID CPU TASK ST %MEM VSZ RSS COMM",
> +" > 10 2 1 ffff880212969710 IN 0.0 0 0
> [migration/1]",
> +" > 0 0 3 ffff884026d43520 RU 0.0 0 0
> [swapper]",
> +" > 6582 1 2 ffff880f49c52040 RU 0.0 42202472 33368
> oracle",
> +" > 9497 1 0 ffff880549ec2ab0 RU 0.0 42314692 138664
> oracle",
> +" ",
> " Show all tasks sorted by their task_struct's last_run, timestamp, or",
> " sched_entity last_arrival timestamp value, whichever applies:\n",
> " %s> ps -l",
> diff --git a/task.c b/task.c
> index db05ab4..be3b4f0 100644
> --- a/task.c
> +++ b/task.c
> @@ -3240,7 +3240,7 @@ parse_task_thread(int argcnt, char *arglist[], struct
> task_context *tc) {
> }
>
> static char *ps_exclusive =
> - "-a, -t, -c, -p, -g, -l, -m, -S and -r flags are all
> mutually-exclusive\n";
> + "-a, -t, -c, -p, -g, -l, -m, -S, -r and -A flags are all
> mutually-exclusive\n";
>
> static void
> check_ps_exclusive(ulong flag, ulong thisflag)
> @@ -3267,7 +3267,7 @@ cmd_ps(void)
> cpuspec = NULL;
> flag = 0;
>
> - while ((c = getopt(argcnt, args, "SgstcpkuGlmarC:y:")) != EOF) {
> + while ((c = getopt(argcnt, args, "ASgstcpkuGlmarC:y:")) != EOF) {
> switch(c)
> {
> case 'k':
> @@ -3372,6 +3372,10 @@ cmd_ps(void)
> flag |= PS_POLICY;
> psinfo.policy = make_sched_policy(optarg);
> break;
> + case 'A':
> + check_ps_exclusive(flag, PS_ACTIVE);
> + flag |= PS_ACTIVE;
> + break;
>
> default:
> argerrs++;
> @@ -3576,6 +3580,10 @@ show_ps_data(ulong flag, struct task_context *tc,
> struct psinfo *psi)
>
> task_active = is_task_active(tc->task);
>
> + if ((flag & PS_ACTIVE) && (flag & PS_SHOW_ALL) &&
> + !task_active)
> + return;
> +
> if (task_active) {
> if (hide_offline_cpu(tc->processor))
> fprintf(fp, "- ");
> @@ -3610,7 +3618,7 @@ show_ps(ulong flag, struct psinfo *psi)
> int print;
> char buf[BUFSIZE];
>
> - if (!(flag & (PS_EXCLUSIVE|PS_NO_HEADER)))
> + if (!(flag & ((PS_EXCLUSIVE & ~PS_ACTIVE)|PS_NO_HEADER)))
> fprintf(fp,
> " PID PPID CPU %s ST %%MEM VSZ RSS COMM\n",
> flag & PS_KSTACKP ?
> --
> 2.14.3
>
> --
> Crash-utility mailing list
> Crash-utility at redhat.com
> https://www.redhat.com/mailman/listinfo/crash-utility
>
More information about the Crash-utility
mailing list