]> granicus.if.org Git - sysstat/commitdiff
pidstat: Add scheduling priority and policy information
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 17 May 2014 14:17:07 +0000 (16:17 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 17 May 2014 14:17:07 +0000 (16:17 +0200)
Display task scheduling priority and policy along with task switching
activity (-w option).

Signed-off-by: Cedric Marie <cedric.marie@openmailbox.org>
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
pidstat.c
pidstat.h

index 9e88a6f9a1cbb0732fdf40644cf637f055aae0a2..04047ef67938eac36c328413ffcef7037ec34332 100644 (file)
--- a/pidstat.c
+++ b/pidstat.c
@@ -30,6 +30,7 @@
 #include <pwd.h>
 #include <sys/utsname.h>
 #include <regex.h>
+#include <linux/sched.h>
 
 #include "version.h"
 #include "pidstat.h"
@@ -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);
@@ -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;
                                }
                        }
@@ -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");
@@ -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)) {
@@ -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++) {
@@ -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;
        }
index 41c39990d86b5cb290100d8dea1395e2fb60854f..9876d50627c388b938dd4743a07ca2d5987e815b 100644 (file)
--- a/pidstat.h
+++ b/pidstat.h
                                                        }                                       \
                                                } 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));
@@ -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));