Skip to content

Commit

Permalink
pidstat: Add scheduling priority and policy information
Browse files Browse the repository at this point in the history
Display task scheduling priority and policy along with task switching
activity (-w option).

Signed-off-by: Cedric Marie <[email protected]>
Signed-off-by: Sebastien GODARD <[email protected]>
  • Loading branch information
sysstat committed May 17, 2014
1 parent 1be2d06 commit 35c2242
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pidstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <pwd.h>
#include <sys/utsname.h>
#include <regex.h>
#include <linux/sched.h>

#include "version.h"
#include "pidstat.h"
Expand Down Expand Up @@ -324,12 +325,13 @@ int read_proc_pid_stat(unsigned int pid, struct pid_stats *pst,
sprintf(format, "%%*d (%%%ds %%*s %%*d %%*d %%*d %%*d %%*d %%*u %%lu %%lu"
" %%lu %%lu %%lu %%lu %%lu %%lu %%*d %%*d %%u %%*u %%*d %%lu %%lu"
" %%*u %%*u %%*u %%*u %%*u %%*u %%*u %%*u %%*u %%*u %%*u %%*u %%*u"
" %%*u %%u %%*u %%*u %%llu %%lu %%lu\\n", MAX_COMM_LEN);
" %%*u %%u %%u %%u %%llu %%lu %%lu\\n", MAX_COMM_LEN);

fscanf(fp, format, comm,
&pst->minflt, &pst->cminflt, &pst->majflt, &pst->cmajflt,
&pst->utime, &pst->stime, &pst->cutime, &pst->cstime,
thread_nr, &pst->vsz, &pst->rss, &pst->processor,
&pst->priority, &pst->policy,
&pst->blkio_swapin_delays, &pst->gtime, &pst->cgtime);

fclose(fp);
Expand Down Expand Up @@ -1096,7 +1098,9 @@ 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)->nivcsw != (*pstp)->nivcsw) ||
((*pstc)->priority != (*pstp)->priority) ||
((*pstc)->policy != (*pstp)->policy)) {
isActive = TRUE;
}
}
Expand Down Expand Up @@ -1251,7 +1255,7 @@ 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");
printf(" cswch/s nvcswch/s prio policy");
}
if (DISPLAY_KTAB(actflag)) {
printf(" threads fd-nr");
Expand Down Expand Up @@ -1322,9 +1326,11 @@ int write_pid_task_all_stats(int prev, int curr, int dis,
}

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

if (DISPLAY_KTAB(actflag)) {
Expand Down Expand Up @@ -1904,7 +1910,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 Command\n");
printf(" cswch/s nvcswch/s prio policy Command\n");
}

for (p = 0; p < pid_nr; p++) {
Expand All @@ -1914,9 +1920,11 @@ int write_pid_ctxswitch_stats(int prev, int curr, int dis,
continue;

print_line_id(curr_string, pstc);
printf(" %9.2f %9.2f",
printf(" %9.2f %9.2f %4u %6s",
S_VALUE(pstp->nvcsw, pstc->nvcsw, itv),
S_VALUE(pstp->nivcsw, pstc->nivcsw, itv));
S_VALUE(pstp->nivcsw, pstc->nivcsw, itv),
pstc->priority,
PRINT_POLICY(pstc->policy));
print_comm(pstc);
again = 1;
}
Expand Down
10 changes: 10 additions & 0 deletions pidstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@
} \
} while (0)

#define PRINT_POLICY(p) \
(p == SCHED_NORMAL ? "NORMAL" : \
(p == SCHED_FIFO ? "FIFO" : \
(p == SCHED_RR ? "RR" : \
(p == SCHED_BATCH ? "BATCH" : \
(p == SCHED_IDLE ? "IDLE" : \
"?")))))

struct pid_stats {
unsigned long long read_bytes __attribute__ ((aligned (8)));
unsigned long long write_bytes __attribute__ ((packed));
Expand Down Expand Up @@ -143,6 +151,8 @@ struct pid_stats {
unsigned int sk_asum_count __attribute__ ((packed));
unsigned int delay_asum_count __attribute__ ((packed));
unsigned int processor __attribute__ ((packed));
unsigned int priority __attribute__ ((packed));
unsigned int policy __attribute__ ((packed));
unsigned int flags __attribute__ ((packed));
unsigned int uid __attribute__ ((packed));
unsigned int threads __attribute__ ((packed));
Expand Down

0 comments on commit 35c2242

Please sign in to comment.