]> granicus.if.org Git - sysstat/blob - pidstat.h
sysstat 10.2.1
[sysstat] / pidstat.h
1 /*
2  * pidstat: Display per-process statistics.
3  * (C) 2007-2014 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 10
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
30 #define DISPLAY_CPU(m)          (((m) & P_A_CPU) == P_A_CPU)
31 #define DISPLAY_MEM(m)          (((m) & P_A_MEM) == P_A_MEM)
32 #define DISPLAY_IO(m)           (((m) & P_A_IO) == P_A_IO)
33 #define DISPLAY_CTXSW(m)        (((m) & P_A_CTXSW) == P_A_CTXSW)
34 #define DISPLAY_STACK(m)        (((m) & P_A_STACK) == P_A_STACK)
35 #define DISPLAY_KTAB(m)         (((m) & P_A_KTAB) == P_A_KTAB)
36
37 /* TASK/CHILD */
38 #define P_NULL          0x00
39 #define P_TASK          0x01
40 #define P_CHILD         0x02
41
42 #define DISPLAY_TASK_STATS(m)   (((m) & P_TASK) == P_TASK)
43 #define DISPLAY_CHILD_STATS(m)  (((m) & P_CHILD) == P_CHILD)
44
45 #define P_D_PID         0x001
46 #define P_D_ALL_PID     0x002
47 #define P_F_IRIX_MODE   0x004
48 #define P_F_COMMSTR     0x008
49 #define P_D_ACTIVE_PID  0x010
50 #define P_D_TID         0x020
51 #define P_D_ONELINE     0x040
52 #define P_D_CMDLINE     0x080
53 #define P_D_USERNAME    0x100
54 #define P_F_USERSTR     0x200
55
56 #define DISPLAY_PID(m)          (((m) & P_D_PID) == P_D_PID)
57 #define DISPLAY_ALL_PID(m)      (((m) & P_D_ALL_PID) == P_D_ALL_PID)
58 #define IRIX_MODE_OFF(m)        (((m) & P_F_IRIX_MODE) == P_F_IRIX_MODE)
59 #define COMMAND_STRING(m)       (((m) & P_F_COMMSTR) == P_F_COMMSTR)
60 #define DISPLAY_ACTIVE_PID(m)   (((m) & P_D_ACTIVE_PID) == P_D_ACTIVE_PID)
61 #define DISPLAY_TID(m)          (((m) & P_D_TID) == P_D_TID)
62 #define DISPLAY_ONELINE(m)      (((m) & P_D_ONELINE) == P_D_ONELINE)
63 #define DISPLAY_CMDLINE(m)      (((m) & P_D_CMDLINE) == P_D_CMDLINE)
64 #define DISPLAY_USERNAME(m)     (((m) & P_D_USERNAME) == P_D_USERNAME)
65 #define USER_STRING(m)          (((m) & P_F_USERSTR) == P_F_USERSTR)
66
67 /* Per-process flags */
68 #define F_NO_PID_IO     0x01
69 #define F_NO_PID_FD     0x02
70
71 #define NO_PID_IO(m)            (((m) & F_NO_PID_IO) == F_NO_PID_IO)
72 #define NO_PID_FD(m)            (((m) & F_NO_PID_FD) == F_NO_PID_FD)
73
74
75 #define PROC            "/proc"
76
77 #define PID_STAT        "/proc/%u/stat"
78 #define PID_STATUS      "/proc/%u/status"
79 #define PID_IO          "/proc/%u/io"
80 #define PID_CMDLINE     "/proc/%u/cmdline"
81 #define PID_SMAP        "/proc/%u/smaps"
82 #define PID_FD          "/proc/%u/fd"
83
84 #define PROC_TASK       "/proc/%u/task"
85 #define TASK_STAT       "/proc/%u/task/%u/stat"
86 #define TASK_STATUS     "/proc/%u/task/%u/status"
87 #define TASK_IO         "/proc/%u/task/%u/io"
88 #define TASK_CMDLINE    "/proc/%u/task/%u/cmdline"
89 #define TASK_SMAP       "/proc/%u/task/%u/smaps"
90 #define TASK_FD         "/proc/%u/task/%u/fd"
91
92 #define PRINT_ID_HDR(_timestamp_, _flag_)       do {                                            \
93                                                         printf("\n%-11s", _timestamp_); \
94                                                         if (DISPLAY_USERNAME(_flag_)) {         \
95                                                                 printf("     USER");            \
96                                                         }                                       \
97                                                         else {                                  \
98                                                                 printf("   UID");               \
99                                                         }                                       \
100                                                         if (DISPLAY_TID(_flag_)) {              \
101                                                                 printf("      TGID       TID"); \
102                                                         }                                       \
103                                                         else {                                  \
104                                                                 printf("       PID");           \
105                                                         }                                       \
106                                                 } while (0)
107
108 struct pid_stats {
109         unsigned long long read_bytes                   __attribute__ ((aligned (8)));
110         unsigned long long write_bytes                  __attribute__ ((packed));
111         unsigned long long cancelled_write_bytes        __attribute__ ((packed));
112         unsigned long long total_vsz                    __attribute__ ((packed));
113         unsigned long long total_rss                    __attribute__ ((packed));
114         unsigned long long total_stack_size             __attribute__ ((packed));
115         unsigned long long total_stack_ref              __attribute__ ((packed));
116         unsigned long long total_threads                __attribute__ ((packed));
117         unsigned long long total_fd_nr                  __attribute__ ((packed));
118         unsigned long long blkio_swapin_delays          __attribute__ ((packed));
119         unsigned long      minflt                       __attribute__ ((packed));
120         unsigned long      cminflt                      __attribute__ ((packed));
121         unsigned long      majflt                       __attribute__ ((packed));
122         unsigned long      cmajflt                      __attribute__ ((packed));
123         unsigned long      utime                        __attribute__ ((packed));
124         unsigned long      cutime                       __attribute__ ((packed));
125         unsigned long      stime                        __attribute__ ((packed));
126         unsigned long      cstime                       __attribute__ ((packed));
127         unsigned long      gtime                        __attribute__ ((packed));
128         unsigned long      cgtime                       __attribute__ ((packed));
129         unsigned long      vsz                          __attribute__ ((packed));
130         unsigned long      rss                          __attribute__ ((packed));
131         unsigned long      nvcsw                        __attribute__ ((packed));
132         unsigned long      nivcsw                       __attribute__ ((packed));
133         unsigned long      stack_size                   __attribute__ ((packed));
134         unsigned long      stack_ref                    __attribute__ ((packed));
135         /* If pid is null, the process has terminated */
136         unsigned int       pid                          __attribute__ ((packed));
137         /* If tgid is not null, then this PID is in fact a TID */
138         unsigned int       tgid                         __attribute__ ((packed));
139         unsigned int       rt_asum_count                __attribute__ ((packed));
140         unsigned int       rc_asum_count                __attribute__ ((packed));
141         unsigned int       uc_asum_count                __attribute__ ((packed));
142         unsigned int       tf_asum_count                __attribute__ ((packed));
143         unsigned int       sk_asum_count                __attribute__ ((packed));
144         unsigned int       delay_asum_count             __attribute__ ((packed));
145         unsigned int       processor                    __attribute__ ((packed));
146         unsigned int       flags                        __attribute__ ((packed));
147         unsigned int       uid                          __attribute__ ((packed));
148         unsigned int       threads                      __attribute__ ((packed));
149         unsigned int       fd_nr                        __attribute__ ((packed));
150         char               comm[MAX_COMM_LEN];
151         char               cmdline[MAX_CMDLINE_LEN];
152 };
153
154 #define PID_STATS_SIZE  (sizeof(struct pid_stats))
155
156 #endif  /* _PIDSTAT_H */