]> granicus.if.org Git - sysstat/blob - pidstat.h
SVG: Fix how bar graphs are displayed for fs statistics
[sysstat] / pidstat.h
1 /*
2  * pidstat: Display per-process statistics.
3  * (C) 2007-2016 by Sebastien Godard (sysstat <at> orange.fr)
4  */
5
6 #ifndef _PIDSTAT_H
7 #define _PIDSTAT_H
8
9
10 #define K_SELF          "SELF"
11
12 #define K_P_TASK        "TASK"
13 #define K_P_CHILD       "CHILD"
14 #define K_P_ALL         "ALL"
15
16 #define NR_PID_PREALLOC 100
17
18 #define MAX_COMM_LEN    128
19 #define MAX_CMDLINE_LEN 128
20 #define MAX_USER_LEN    32
21
22 /* Activities */
23 #define P_A_CPU         0x01
24 #define P_A_MEM         0x02
25 #define P_A_IO          0x04
26 #define P_A_CTXSW       0x08
27 #define P_A_STACK       0x10
28 #define P_A_KTAB        0x20
29 #define P_A_RT          0x40
30
31 #define DISPLAY_CPU(m)          (((m) & P_A_CPU) == P_A_CPU)
32 #define DISPLAY_MEM(m)          (((m) & P_A_MEM) == P_A_MEM)
33 #define DISPLAY_IO(m)           (((m) & P_A_IO) == P_A_IO)
34 #define DISPLAY_CTXSW(m)        (((m) & P_A_CTXSW) == P_A_CTXSW)
35 #define DISPLAY_STACK(m)        (((m) & P_A_STACK) == P_A_STACK)
36 #define DISPLAY_KTAB(m)         (((m) & P_A_KTAB) == P_A_KTAB)
37 #define DISPLAY_RT(m)           (((m) & P_A_RT) == P_A_RT)
38
39 /* TASK/CHILD */
40 #define P_NULL          0x00
41 #define P_TASK          0x01
42 #define P_CHILD         0x02
43
44 #define DISPLAY_TASK_STATS(m)   (((m) & P_TASK) == P_TASK)
45 #define DISPLAY_CHILD_STATS(m)  (((m) & P_CHILD) == P_CHILD)
46
47 #define P_D_PID         0x001
48 #define P_D_ALL_PID     0x002
49 #define P_F_IRIX_MODE   0x004
50 #define P_F_COMMSTR     0x008
51 #define P_D_ACTIVE_PID  0x010
52 #define P_D_TID         0x020
53 #define P_D_ONELINE     0x040
54 #define P_D_CMDLINE     0x080
55 #define P_D_USERNAME    0x100
56 #define P_F_USERSTR     0x200
57 #define P_F_PROCSTR     0x400
58
59 #define DISPLAY_PID(m)          (((m) & P_D_PID) == P_D_PID)
60 #define DISPLAY_ALL_PID(m)      (((m) & P_D_ALL_PID) == P_D_ALL_PID)
61 #define IRIX_MODE_OFF(m)        (((m) & P_F_IRIX_MODE) == P_F_IRIX_MODE)
62 #define COMMAND_STRING(m)       (((m) & P_F_COMMSTR) == P_F_COMMSTR)
63 #define DISPLAY_ACTIVE_PID(m)   (((m) & P_D_ACTIVE_PID) == P_D_ACTIVE_PID)
64 #define DISPLAY_TID(m)          (((m) & P_D_TID) == P_D_TID)
65 #define DISPLAY_ONELINE(m)      (((m) & P_D_ONELINE) == P_D_ONELINE)
66 #define DISPLAY_CMDLINE(m)      (((m) & P_D_CMDLINE) == P_D_CMDLINE)
67 #define DISPLAY_USERNAME(m)     (((m) & P_D_USERNAME) == P_D_USERNAME)
68 #define USER_STRING(m)          (((m) & P_F_USERSTR) == P_F_USERSTR)
69 #define PROCESS_STRING(m)       (((m) & P_F_PROCSTR) == P_F_PROCSTR)
70
71 /* Per-process flags */
72 #define F_NO_PID_IO     0x01
73 #define F_NO_PID_FD     0x02
74
75 #define NO_PID_IO(m)            (((m) & F_NO_PID_IO) == F_NO_PID_IO)
76 #define NO_PID_FD(m)            (((m) & F_NO_PID_FD) == F_NO_PID_FD)
77
78
79 #define PROC            "/proc"
80
81 #define PID_STAT        "/proc/%u/stat"
82 #define PID_STATUS      "/proc/%u/status"
83 #define PID_IO          "/proc/%u/io"
84 #define PID_CMDLINE     "/proc/%u/cmdline"
85 #define PID_SMAP        "/proc/%u/smaps"
86 #define PID_FD          "/proc/%u/fd"
87
88 #define PROC_TASK       "/proc/%u/task"
89 #define TASK_STAT       "/proc/%u/task/%u/stat"
90 #define TASK_STATUS     "/proc/%u/task/%u/status"
91 #define TASK_IO         "/proc/%u/task/%u/io"
92 #define TASK_CMDLINE    "/proc/%u/task/%u/cmdline"
93 #define TASK_SMAP       "/proc/%u/task/%u/smaps"
94 #define TASK_FD         "/proc/%u/task/%u/fd"
95
96 #define PRINT_ID_HDR(_timestamp_, _flag_)       do {                                            \
97                                                         printf("\n%-11s", _timestamp_); \
98                                                         if (DISPLAY_USERNAME(_flag_)) {         \
99                                                                 printf("     USER");            \
100                                                         }                                       \
101                                                         else {                                  \
102                                                                 printf("   UID");               \
103                                                         }                                       \
104                                                         if (DISPLAY_TID(_flag_)) {              \
105                                                                 printf("      TGID       TID"); \
106                                                         }                                       \
107                                                         else {                                  \
108                                                                 printf("       PID");           \
109                                                         }                                       \
110                                                 } while (0)
111
112 /* Normally defined in <linux/sched.h> */
113 #ifndef SCHED_NORMAL
114 #define SCHED_NORMAL    0
115 #endif
116 #ifndef SCHED_FIFO
117 #define SCHED_FIFO      1
118 #endif
119 #ifndef SCHED_RR
120 #define SCHED_RR        2
121 #endif
122 #ifndef SCHED_BATCH
123 #define SCHED_BATCH     3
124 #endif
125 /* SCHED_ISO not yet implemented */
126 #ifndef SCHED_IDLE
127 #define SCHED_IDLE      5
128 #endif
129 #ifndef SCHED_DEADLINE
130 #define SCHED_DEADLINE  6
131 #endif
132
133 #define GET_POLICY(p) \
134         (p == SCHED_NORMAL   ? "NORMAL" : \
135         (p == SCHED_FIFO     ? "FIFO" : \
136         (p == SCHED_RR       ? "RR" : \
137         (p == SCHED_BATCH    ? "BATCH" : \
138         (p == SCHED_IDLE     ? "IDLE" : \
139         (p == SCHED_DEADLINE ? "DEADLN" : \
140         "?"))))))
141
142 struct pid_stats {
143         unsigned long long read_bytes                   __attribute__ ((aligned (16)));
144         unsigned long long write_bytes                  __attribute__ ((packed));
145         unsigned long long cancelled_write_bytes        __attribute__ ((packed));
146         unsigned long long total_vsz                    __attribute__ ((packed));
147         unsigned long long total_rss                    __attribute__ ((packed));
148         unsigned long long total_stack_size             __attribute__ ((packed));
149         unsigned long long total_stack_ref              __attribute__ ((packed));
150         unsigned long long total_threads                __attribute__ ((packed));
151         unsigned long long total_fd_nr                  __attribute__ ((packed));
152         unsigned long long blkio_swapin_delays          __attribute__ ((packed));
153         unsigned long long minflt                       __attribute__ ((packed));
154         unsigned long long cminflt                      __attribute__ ((packed));
155         unsigned long long majflt                       __attribute__ ((packed));
156         unsigned long long cmajflt                      __attribute__ ((packed));
157         unsigned long long utime                        __attribute__ ((packed));
158         long long          cutime                       __attribute__ ((packed));
159         unsigned long long stime                        __attribute__ ((packed));
160         long long          cstime                       __attribute__ ((packed));
161         unsigned long long gtime                        __attribute__ ((packed));
162         long long          cgtime                       __attribute__ ((packed));
163         unsigned long long vsz                          __attribute__ ((packed));
164         unsigned long long rss                          __attribute__ ((packed));
165         unsigned long      nvcsw                        __attribute__ ((packed));
166         unsigned long      nivcsw                       __attribute__ ((packed));
167         unsigned long      stack_size                   __attribute__ ((packed));
168         unsigned long      stack_ref                    __attribute__ ((packed));
169         /* If pid is null, the process has terminated */
170         unsigned int       pid                          __attribute__ ((packed));
171         /* If tgid is not null, then this PID is in fact a TID */
172         unsigned int       tgid                         __attribute__ ((packed));
173         unsigned int       rt_asum_count                __attribute__ ((packed));
174         unsigned int       rc_asum_count                __attribute__ ((packed));
175         unsigned int       uc_asum_count                __attribute__ ((packed));
176         unsigned int       tf_asum_count                __attribute__ ((packed));
177         unsigned int       sk_asum_count                __attribute__ ((packed));
178         unsigned int       delay_asum_count             __attribute__ ((packed));
179         unsigned int       processor                    __attribute__ ((packed));
180         unsigned int       priority                     __attribute__ ((packed));
181         unsigned int       policy                       __attribute__ ((packed));
182         unsigned int       flags                        __attribute__ ((packed));
183         unsigned int       uid                          __attribute__ ((packed));
184         unsigned int       threads                      __attribute__ ((packed));
185         unsigned int       fd_nr                        __attribute__ ((packed));
186         char               comm[MAX_COMM_LEN];
187         char               cmdline[MAX_CMDLINE_LEN];
188 };
189
190 #define PID_STATS_SIZE  (sizeof(struct pid_stats))
191
192 #endif  /* _PIDSTAT_H */