]> granicus.if.org Git - sysstat/blob - pidstat.h
pidstat: Display values in human readable format
[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 /* sys/param.h defines HZ but needed for _POSIX_ARG_MAX and LOGIN_NAME_MAX */
11 #undef HZ
12 #endif
13
14 #define K_SELF          "SELF"
15
16 #define K_P_TASK        "TASK"
17 #define K_P_CHILD       "CHILD"
18 #define K_P_ALL         "ALL"
19
20 #define NR_PID_PREALLOC 100
21
22 #ifdef _POSIX_ARG_MAX
23 #define MAX_COMM_LEN    _POSIX_ARG_MAX
24 #define MAX_CMDLINE_LEN _POSIX_ARG_MAX
25 #else
26 #define MAX_COMM_LEN    128
27 #define MAX_CMDLINE_LEN 128
28 #endif
29
30 #ifdef LOGIN_NAME_MAX
31 #define MAX_USER_LEN    LOGIN_NAME_MAX
32 #else
33 #define MAX_USER_LEN    32
34 #endif
35
36 /* Activities */
37 #define P_A_CPU         0x01
38 #define P_A_MEM         0x02
39 #define P_A_IO          0x04
40 #define P_A_CTXSW       0x08
41 #define P_A_STACK       0x10
42 #define P_A_KTAB        0x20
43 #define P_A_RT          0x40
44
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)
52
53 /* TASK/CHILD */
54 #define P_NULL          0x00
55 #define P_TASK          0x01
56 #define P_CHILD         0x02
57
58 #define DISPLAY_TASK_STATS(m)   (((m) & P_TASK) == P_TASK)
59 #define DISPLAY_CHILD_STATS(m)  (((m) & P_CHILD) == P_CHILD)
60
61 #define P_D_PID         0x001
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
66 #define P_D_TID         0x020
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
73
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)
86
87 /* Per-process flags */
88 #define F_NO_PID_IO     0x01
89 #define F_NO_PID_FD     0x02
90
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)
93
94
95 #define PROC            "/proc"
96
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
104 #define PROC_TASK       "/proc/%u/task"
105 #define TASK_STAT       "/proc/%u/task/%u/stat"
106 #define TASK_STATUS     "/proc/%u/task/%u/status"
107 #define TASK_IO         "/proc/%u/task/%u/io"
108 #define TASK_CMDLINE    "/proc/%u/task/%u/cmdline"
109 #define TASK_SMAP       "/proc/%u/task/%u/smaps"
110 #define TASK_FD         "/proc/%u/task/%u/fd"
111
112 #define PRINT_ID_HDR(_timestamp_, _flag_)       do {                                            \
113                                                         printf("\n%-11s", _timestamp_); \
114                                                         if (DISPLAY_USERNAME(_flag_)) {         \
115                                                                 printf("     USER");            \
116                                                         }                                       \
117                                                         else {                                  \
118                                                                 printf("   UID");               \
119                                                         }                                       \
120                                                         if (DISPLAY_TID(_flag_)) {              \
121                                                                 printf("      TGID       TID"); \
122                                                         }                                       \
123                                                         else {                                  \
124                                                                 printf("       PID");           \
125                                                         }                                       \
126                                                 } while (0)
127
128 /* Normally defined in <linux/sched.h> */
129 #ifndef SCHED_NORMAL
130 #define SCHED_NORMAL    0
131 #endif
132 #ifndef SCHED_FIFO
133 #define SCHED_FIFO      1
134 #endif
135 #ifndef SCHED_RR
136 #define SCHED_RR        2
137 #endif
138 #ifndef SCHED_BATCH
139 #define SCHED_BATCH     3
140 #endif
141 /* SCHED_ISO not yet implemented */
142 #ifndef SCHED_IDLE
143 #define SCHED_IDLE      5
144 #endif
145 #ifndef SCHED_DEADLINE
146 #define SCHED_DEADLINE  6
147 #endif
148
149 #define GET_POLICY(p) \
150         (p == SCHED_NORMAL   ? "NORMAL" : \
151         (p == SCHED_FIFO     ? "FIFO" : \
152         (p == SCHED_RR       ? "RR" : \
153         (p == SCHED_BATCH    ? "BATCH" : \
154         (p == SCHED_IDLE     ? "IDLE" : \
155         (p == SCHED_DEADLINE ? "DEADLN" : \
156         "?"))))))
157
158 struct pid_stats {
159         unsigned long long read_bytes                   __attribute__ ((aligned (16)));
160         unsigned long long write_bytes                  __attribute__ ((packed));
161         unsigned long long cancelled_write_bytes        __attribute__ ((packed));
162         unsigned long long total_vsz                    __attribute__ ((packed));
163         unsigned long long total_rss                    __attribute__ ((packed));
164         unsigned long long total_stack_size             __attribute__ ((packed));
165         unsigned long long total_stack_ref              __attribute__ ((packed));
166         unsigned long long total_threads                __attribute__ ((packed));
167         unsigned long long total_fd_nr                  __attribute__ ((packed));
168         unsigned long long blkio_swapin_delays          __attribute__ ((packed));
169         unsigned long long minflt                       __attribute__ ((packed));
170         unsigned long long cminflt                      __attribute__ ((packed));
171         unsigned long long majflt                       __attribute__ ((packed));
172         unsigned long long cmajflt                      __attribute__ ((packed));
173         unsigned long long utime                        __attribute__ ((packed));
174         long long          cutime                       __attribute__ ((packed));
175         unsigned long long stime                        __attribute__ ((packed));
176         long long          cstime                       __attribute__ ((packed));
177         unsigned long long gtime                        __attribute__ ((packed));
178         long long          cgtime                       __attribute__ ((packed));
179         unsigned long long vsz                          __attribute__ ((packed));
180         unsigned long long rss                          __attribute__ ((packed));
181         unsigned long      nvcsw                        __attribute__ ((packed));
182         unsigned long      nivcsw                       __attribute__ ((packed));
183         unsigned long      stack_size                   __attribute__ ((packed));
184         unsigned long      stack_ref                    __attribute__ ((packed));
185         /* If pid is null, the process has terminated */
186         unsigned int       pid                          __attribute__ ((packed));
187         /* If tgid is not null, then this PID is in fact a TID */
188         unsigned int       tgid                         __attribute__ ((packed));
189         unsigned int       rt_asum_count                __attribute__ ((packed));
190         unsigned int       rc_asum_count                __attribute__ ((packed));
191         unsigned int       uc_asum_count                __attribute__ ((packed));
192         unsigned int       tf_asum_count                __attribute__ ((packed));
193         unsigned int       sk_asum_count                __attribute__ ((packed));
194         unsigned int       delay_asum_count             __attribute__ ((packed));
195         unsigned int       processor                    __attribute__ ((packed));
196         unsigned int       priority                     __attribute__ ((packed));
197         unsigned int       policy                       __attribute__ ((packed));
198         unsigned int       flags                        __attribute__ ((packed));
199         unsigned int       uid                          __attribute__ ((packed));
200         unsigned int       threads                      __attribute__ ((packed));
201         unsigned int       fd_nr                        __attribute__ ((packed));
202         char               comm[MAX_COMM_LEN];
203         char               cmdline[MAX_CMDLINE_LEN];
204 };
205
206 #define PID_STATS_SIZE  (sizeof(struct pid_stats))
207
208 #endif  /* _PIDSTAT_H */