Skip to content

Commit

Permalink
pidstat: Add option -R to display priority and policy information
Browse files Browse the repository at this point in the history
Processes' scheduling priority and policy information are no longer
displayed with context switches stats. Create a dedicated report
instead, which can be displayed using pidstat's new option -R.

Signed-off-by: Sebastien GODARD <[email protected]>
  • Loading branch information
sysstat committed Jun 11, 2014
1 parent 1526537 commit 6e82355
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 15 deletions.
102 changes: 88 additions & 14 deletions pidstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void usage(char *progname)
progname);

fprintf(stderr, _("Options are:\n"
"[ -d ] [ -h ] [ -I ] [ -l ] [ -r ] [ -s ] [ -t ] [ -U [ <username> ] ] [ -u ]\n"
"[ -V ] [ -v ] [ -w ] [ -C <command> ] [ -G <process_name> ]\n"
"[ -d ] [ -h ] [ -I ] [ -l ] [ -R ] [ -r ] [ -s ] [ -t ] [ -U [ <username> ] ]\n"
"[ -u ] [ -V ] [ -v ] [ -w ] [ -C <command> ] [ -G <process_name> ]\n"
"[ -p { <pid> [,...] | SELF | ALL } ] [ -T { TASK | CHILD | ALL } ]\n"));
exit(1);
}
Expand Down Expand Up @@ -205,7 +205,8 @@ void check_flags(void)

/* Check that requested activities are available */
if (DISPLAY_TASK_STATS(tskflag)) {
act |= P_A_CPU + P_A_MEM + P_A_IO + P_A_CTXSW + P_A_STACK + P_A_KTAB;
act |= P_A_CPU + P_A_MEM + P_A_IO + P_A_CTXSW
+ P_A_STACK + P_A_KTAB + P_A_RT;
}
if (DISPLAY_CHILD_STATS(tskflag)) {
act |= P_A_CPU + P_A_MEM;
Expand Down Expand Up @@ -1103,8 +1104,13 @@ int get_pid_to_display(int prev, int curr, int p, unsigned int activity,

if (DISPLAY_CTXSW(activity) && (!isActive)) {
if (((*pstc)->nvcsw != (*pstp)->nvcsw) ||
((*pstc)->nivcsw != (*pstp)->nivcsw) ||
((*pstc)->priority != (*pstp)->priority) ||
((*pstc)->nivcsw != (*pstp)->nivcsw)) {
isActive = TRUE;
}
}

if (DISPLAY_RT(activity) && (!isActive)) {
if (((*pstc)->priority != (*pstp)->priority) ||
((*pstc)->policy != (*pstp)->policy)) {
isActive = TRUE;
}
Expand Down Expand Up @@ -1291,11 +1297,14 @@ int write_pid_task_all_stats(int prev, int curr, int dis,
printf(" kB_rd/s kB_wr/s kB_ccwr/s iodelay");
}
if (DISPLAY_CTXSW(actflag)) {
printf(" cswch/s nvcswch/s prio policy");
printf(" cswch/s nvcswch/s");
}
if (DISPLAY_KTAB(actflag)) {
printf(" threads fd-nr");
}
if (DISPLAY_RT(actflag)) {
printf(" prio policy");
}
printf(" Command\n");
}

Expand Down Expand Up @@ -1362,11 +1371,9 @@ int write_pid_task_all_stats(int prev, int curr, int dis,
}

if (DISPLAY_CTXSW(actflag)) {
printf(" %9.2f %9.2f %4u %6s",
printf(" %9.2f %9.2f",
S_VALUE(pstp->nvcsw, pstc->nvcsw, itv),
S_VALUE(pstp->nivcsw, pstc->nivcsw, itv),
pstc->priority,
PRINT_POLICY(pstc->policy));
S_VALUE(pstp->nivcsw, pstc->nivcsw, itv));
}

if (DISPLAY_KTAB(actflag)) {
Expand All @@ -1380,6 +1387,12 @@ int write_pid_task_all_stats(int prev, int curr, int dis,
}
}

if (DISPLAY_RT(actflag)) {
printf(" %4u %6s",
pstc->priority,
GET_POLICY(pstc->policy));
}

print_comm(pstc);
again = 1;
}
Expand Down Expand Up @@ -1946,7 +1959,7 @@ int write_pid_ctxswitch_stats(int prev, int curr, int dis,

if (dis) {
PRINT_ID_HDR(prev_string, pidflag);
printf(" cswch/s nvcswch/s prio policy Command\n");
printf(" cswch/s nvcswch/s Command\n");
}

for (p = 0; p < pid_nr; p++) {
Expand All @@ -1956,11 +1969,60 @@ int write_pid_ctxswitch_stats(int prev, int curr, int dis,
continue;

print_line_id(curr_string, pstc);
printf(" %9.2f %9.2f %4u %6s",
printf(" %9.2f %9.2f",
S_VALUE(pstp->nvcsw, pstc->nvcsw, itv),
S_VALUE(pstp->nivcsw, pstc->nivcsw, itv),
S_VALUE(pstp->nivcsw, pstc->nivcsw, itv));
print_comm(pstc);
again = 1;
}

return again;
}

/*
***************************************************************************
* Display scheduling priority and policy information.
*
* IN:
* @prev Index in array where stats used as reference are.
* @curr Index in array for current sample statistics.
* @dis TRUE if a header line must be printed.
* @prev_string String displayed at the beginning of a header line. This is
* the timestamp of the previous sample, or "Average" when
* displaying average stats.
* @curr_string String displayed at the beginning of current sample stats.
* This is the timestamp of the current sample, or "Average"
* when displaying average stats.
* @itv Interval of time in jiffies.
*
* RETURNS:
* 0 if all the processes to display have terminated.
* <> 0 if there are still some processes left to display.
***************************************************************************
*/
int write_pid_rt_stats(int prev, int curr, int dis,
char *prev_string, char *curr_string,
unsigned long long itv)
{
struct pid_stats *pstc, *pstp;
unsigned int p;
int again = 0;

if (dis) {
PRINT_ID_HDR(prev_string, pidflag);
printf(" prio policy Command\n");
}

for (p = 0; p < pid_nr; p++) {

if (get_pid_to_display(prev, curr, p, P_A_RT, P_NULL,
&pstc, &pstp) <= 0)
continue;

print_line_id(curr_string, pstc);
printf(" %4u %6s",
pstc->priority,
PRINT_POLICY(pstc->policy));
GET_POLICY(pstc->policy));
print_comm(pstc);
again = 1;
}
Expand Down Expand Up @@ -2154,6 +2216,12 @@ int write_stats_core(int prev, int curr, int dis, int disp_avg,
again += write_pid_ktab_stats(prev, curr, dis, disp_avg,
prev_string, curr_string, itv);
}

/* Display scheduling priority and policy information */
if (DISPLAY_RT(actflag)) {
again += write_pid_rt_stats(prev, curr, dis, prev_string,
curr_string, itv);
}
}

if (DISPLAY_ALL_PID(pidflag)) {
Expand Down Expand Up @@ -2492,6 +2560,12 @@ int main(int argc, char **argv)
pidflag |= P_D_CMDLINE;
break;

case 'R':
/* Display priority and policy info */
actflag |= P_A_RT;
dis_hdr++;
break;

case 'r':
/* Display memory usage */
actflag |= P_A_MEM;
Expand Down
4 changes: 3 additions & 1 deletion pidstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
#define P_A_CTXSW 0x08
#define P_A_STACK 0x10
#define P_A_KTAB 0x20
#define P_A_RT 0x40

#define DISPLAY_CPU(m) (((m) & P_A_CPU) == P_A_CPU)
#define DISPLAY_MEM(m) (((m) & P_A_MEM) == P_A_MEM)
#define DISPLAY_IO(m) (((m) & P_A_IO) == P_A_IO)
#define DISPLAY_CTXSW(m) (((m) & P_A_CTXSW) == P_A_CTXSW)
#define DISPLAY_STACK(m) (((m) & P_A_STACK) == P_A_STACK)
#define DISPLAY_KTAB(m) (((m) & P_A_KTAB) == P_A_KTAB)
#define DISPLAY_RT(m) (((m) & P_A_RT) == P_A_RT)

/* TASK/CHILD */
#define P_NULL 0x00
Expand Down Expand Up @@ -107,7 +109,7 @@
} \
} while (0)

#define PRINT_POLICY(p) \
#define GET_POLICY(p) \
(p == SCHED_NORMAL ? "NORMAL" : \
(p == SCHED_FIFO ? "FIFO" : \
(p == SCHED_RR ? "RR" : \
Expand Down

0 comments on commit 6e82355

Please sign in to comment.