Skip to content

Commit

Permalink
Implemented a new "ps -A" option that restricts the task output to
Browse files Browse the repository at this point in the history
just the active tasks on each cpu.
([email protected])
  • Loading branch information
Dave Anderson committed Mar 1, 2018
1 parent a002f07 commit 6de5d2c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4617,8 +4617,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 */

Expand Down
11 changes: 10 additions & 1 deletion help.c
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,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",
Expand Down Expand Up @@ -1331,6 +1331,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",
Expand Down Expand Up @@ -1485,6 +1486,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",
Expand Down
14 changes: 11 additions & 3 deletions task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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':
Expand Down Expand Up @@ -3373,6 +3373,11 @@ cmd_ps(void)
psinfo.policy = make_sched_policy(optarg);
break;

case 'A':
check_ps_exclusive(flag, PS_ACTIVE);
flag |= PS_ACTIVE;
break;

default:
argerrs++;
break;
Expand Down Expand Up @@ -3576,6 +3581,9 @@ 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, "- ");
Expand Down Expand Up @@ -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 ?
Expand Down

0 comments on commit 6de5d2c

Please sign in to comment.