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