2 * pidstat: Display per-process statistics.
3 * (C) 2007-2016 by Sebastien Godard (sysstat <at> orange.fr)
8 #ifdef HAVE_SYS_PARAM_H
10 /* sys/param.h defines HZ but needed for _POSIX_ARG_MAX and LOGIN_NAME_MAX */
16 #define K_P_TASK "TASK"
17 #define K_P_CHILD "CHILD"
20 #define NR_PID_PREALLOC 100
23 #define MAX_COMM_LEN _POSIX_ARG_MAX
24 #define MAX_CMDLINE_LEN _POSIX_ARG_MAX
26 #define MAX_COMM_LEN 128
27 #define MAX_CMDLINE_LEN 128
31 #define MAX_USER_LEN LOGIN_NAME_MAX
33 #define MAX_USER_LEN 32
40 #define P_A_CTXSW 0x08
41 #define P_A_STACK 0x10
45 #define DISPLAY_CPU(m) (((m) & P_A_CPU) == P_A_CPU)
46 #define DISPLAY_MEM(m) (((m) & P_A_MEM) == P_A_MEM)
47 #define DISPLAY_IO(m) (((m) & P_A_IO) == P_A_IO)
48 #define DISPLAY_CTXSW(m) (((m) & P_A_CTXSW) == P_A_CTXSW)
49 #define DISPLAY_STACK(m) (((m) & P_A_STACK) == P_A_STACK)
50 #define DISPLAY_KTAB(m) (((m) & P_A_KTAB) == P_A_KTAB)
51 #define DISPLAY_RT(m) (((m) & P_A_RT) == P_A_RT)
58 #define DISPLAY_TASK_STATS(m) (((m) & P_TASK) == P_TASK)
59 #define DISPLAY_CHILD_STATS(m) (((m) & P_CHILD) == P_CHILD)
62 #define P_D_ALL_PID 0x002
63 #define P_F_IRIX_MODE 0x004
64 #define P_F_COMMSTR 0x008
65 #define P_D_ACTIVE_PID 0x010
67 #define P_D_ONELINE 0x040
68 #define P_D_CMDLINE 0x080
69 #define P_D_USERNAME 0x100
70 #define P_F_USERSTR 0x200
71 #define P_F_PROCSTR 0x400
72 #define P_D_UNIT 0x800
74 #define DISPLAY_PID(m) (((m) & P_D_PID) == P_D_PID)
75 #define DISPLAY_ALL_PID(m) (((m) & P_D_ALL_PID) == P_D_ALL_PID)
76 #define IRIX_MODE_OFF(m) (((m) & P_F_IRIX_MODE) == P_F_IRIX_MODE)
77 #define COMMAND_STRING(m) (((m) & P_F_COMMSTR) == P_F_COMMSTR)
78 #define DISPLAY_ACTIVE_PID(m) (((m) & P_D_ACTIVE_PID) == P_D_ACTIVE_PID)
79 #define DISPLAY_TID(m) (((m) & P_D_TID) == P_D_TID)
80 #define DISPLAY_ONELINE(m) (((m) & P_D_ONELINE) == P_D_ONELINE)
81 #define DISPLAY_CMDLINE(m) (((m) & P_D_CMDLINE) == P_D_CMDLINE)
82 #define DISPLAY_USERNAME(m) (((m) & P_D_USERNAME) == P_D_USERNAME)
83 #define USER_STRING(m) (((m) & P_F_USERSTR) == P_F_USERSTR)
84 #define PROCESS_STRING(m) (((m) & P_F_PROCSTR) == P_F_PROCSTR)
85 #define DISPLAY_UNIT(m) (((m) & P_D_UNIT) == P_D_UNIT)
87 /* Per-process flags */
88 #define F_NO_PID_IO 0x01
89 #define F_NO_PID_FD 0x02
91 #define NO_PID_IO(m) (((m) & F_NO_PID_IO) == F_NO_PID_IO)
92 #define NO_PID_FD(m) (((m) & F_NO_PID_FD) == F_NO_PID_FD)
97 #define PID_STAT "/proc/%u/stat"
98 #define PID_STATUS "/proc/%u/status"
99 #define PID_IO "/proc/%u/io"
100 #define PID_CMDLINE "/proc/%u/cmdline"
101 #define PID_SMAP "/proc/%u/smaps"
102 #define PID_FD "/proc/%u/fd"
103 #define PID_SCHED "/proc/%u/schedstat"
105 #define PROC_TASK "/proc/%u/task"
106 #define TASK_STAT "/proc/%u/task/%u/stat"
107 #define TASK_SCHED "/proc/%u/task/%u/schedstat"
108 #define TASK_STATUS "/proc/%u/task/%u/status"
109 #define TASK_IO "/proc/%u/task/%u/io"
110 #define TASK_CMDLINE "/proc/%u/task/%u/cmdline"
111 #define TASK_SMAP "/proc/%u/task/%u/smaps"
112 #define TASK_FD "/proc/%u/task/%u/fd"
114 #define PRINT_ID_HDR(_timestamp_, _flag_) do { \
115 printf("\n%-11s", _timestamp_); \
116 if (DISPLAY_USERNAME(_flag_)) { \
122 if (DISPLAY_TID(_flag_)) { \
123 printf(" TGID TID"); \
130 /* Normally defined in <linux/sched.h> */
132 #define SCHED_NORMAL 0
141 #define SCHED_BATCH 3
143 /* SCHED_ISO not yet implemented */
147 #ifndef SCHED_DEADLINE
148 #define SCHED_DEADLINE 6
151 #define GET_POLICY(p) \
152 (p == SCHED_NORMAL ? "NORMAL" : \
153 (p == SCHED_FIFO ? "FIFO" : \
154 (p == SCHED_RR ? "RR" : \
155 (p == SCHED_BATCH ? "BATCH" : \
156 (p == SCHED_IDLE ? "IDLE" : \
157 (p == SCHED_DEADLINE ? "DEADLN" : \
161 unsigned long long read_bytes __attribute__ ((aligned (16)));
162 unsigned long long write_bytes __attribute__ ((packed));
163 unsigned long long cancelled_write_bytes __attribute__ ((packed));
164 unsigned long long total_vsz __attribute__ ((packed));
165 unsigned long long total_rss __attribute__ ((packed));
166 unsigned long long total_stack_size __attribute__ ((packed));
167 unsigned long long total_stack_ref __attribute__ ((packed));
168 unsigned long long total_threads __attribute__ ((packed));
169 unsigned long long total_fd_nr __attribute__ ((packed));
170 unsigned long long blkio_swapin_delays __attribute__ ((packed));
171 unsigned long long minflt __attribute__ ((packed));
172 unsigned long long cminflt __attribute__ ((packed));
173 unsigned long long majflt __attribute__ ((packed));
174 unsigned long long cmajflt __attribute__ ((packed));
175 unsigned long long utime __attribute__ ((packed));
176 long long cutime __attribute__ ((packed));
177 unsigned long long stime __attribute__ ((packed));
178 long long cstime __attribute__ ((packed));
179 unsigned long long gtime __attribute__ ((packed));
180 long long cgtime __attribute__ ((packed));
181 unsigned long long wtime __attribute__ ((packed));
182 unsigned long long vsz __attribute__ ((packed));
183 unsigned long long rss __attribute__ ((packed));
184 unsigned long nvcsw __attribute__ ((packed));
185 unsigned long nivcsw __attribute__ ((packed));
186 unsigned long stack_size __attribute__ ((packed));
187 unsigned long stack_ref __attribute__ ((packed));
188 /* If pid is null, the process has terminated */
189 unsigned int pid __attribute__ ((packed));
190 /* If tgid is not null, then this PID is in fact a TID */
191 unsigned int tgid __attribute__ ((packed));
192 unsigned int rt_asum_count __attribute__ ((packed));
193 unsigned int rc_asum_count __attribute__ ((packed));
194 unsigned int uc_asum_count __attribute__ ((packed));
195 unsigned int tf_asum_count __attribute__ ((packed));
196 unsigned int sk_asum_count __attribute__ ((packed));
197 unsigned int delay_asum_count __attribute__ ((packed));
198 unsigned int processor __attribute__ ((packed));
199 unsigned int priority __attribute__ ((packed));
200 unsigned int policy __attribute__ ((packed));
201 unsigned int flags __attribute__ ((packed));
202 unsigned int uid __attribute__ ((packed));
203 unsigned int threads __attribute__ ((packed));
204 unsigned int fd_nr __attribute__ ((packed));
205 char comm[MAX_COMM_LEN];
206 char cmdline[MAX_CMDLINE_LEN];
209 #define PID_STATS_SIZE (sizeof(struct pid_stats))
211 #endif /* _PIDSTAT_H */