]> granicus.if.org Git - sysstat/blob - pidstat.h
Code cleaned.
[sysstat] / pidstat.h
1 /*
2  * pidstat: Display per-process statistics.
3  * (C) 2007-2010 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
21 /* Activities */
22 #define P_A_CPU         0x01
23 #define P_A_MEM         0x02
24 #define P_A_IO          0x04
25 #define P_A_CTXSW       0x08
26 #define P_A_STACK       0x10
27
28 #define DISPLAY_CPU(m)          (((m) & P_A_CPU) == P_A_CPU)
29 #define DISPLAY_MEM(m)          (((m) & P_A_MEM) == P_A_MEM)
30 #define DISPLAY_IO(m)           (((m) & P_A_IO) == P_A_IO)
31 #define DISPLAY_CTXSW(m)        (((m) & P_A_CTXSW) == P_A_CTXSW)
32 #define DISPLAY_STACK(m)        (((m) & P_A_STACK) == P_A_STACK)
33
34 /* TASK/CHILD */
35 #define P_NULL          0x00
36 #define P_TASK          0x01
37 #define P_CHILD         0x02
38
39 #define DISPLAY_TASK_STATS(m)   (((m) & P_TASK) == P_TASK)
40 #define DISPLAY_CHILD_STATS(m)  (((m) & P_CHILD) == P_CHILD)
41
42 #define P_D_PID         0x001
43 #define P_D_ALL_PID     0x002
44 #define P_F_IRIX_MODE   0x004
45 #define P_F_COMMSTR     0x008
46 #define P_D_ACTIVE_PID  0x010
47 #define P_D_TID         0x020
48 #define P_D_ONELINE     0x040
49 #define P_D_CMDLINE     0x080
50
51 #define DISPLAY_PID(m)          (((m) & P_D_PID) == P_D_PID)
52 #define DISPLAY_ALL_PID(m)      (((m) & P_D_ALL_PID) == P_D_ALL_PID)
53 #define IRIX_MODE_OFF(m)        (((m) & P_F_IRIX_MODE) == P_F_IRIX_MODE)
54 #define COMMAND_STRING(m)       (((m) & P_F_COMMSTR) == P_F_COMMSTR)
55 #define DISPLAY_ACTIVE_PID(m)   (((m) & P_D_ACTIVE_PID) == P_D_ACTIVE_PID)
56 #define DISPLAY_TID(m)          (((m) & P_D_TID) == P_D_TID)
57 #define DISPLAY_ONELINE(m)      (((m) & P_D_ONELINE) == P_D_ONELINE)
58 #define DISPLAY_CMDLINE(m)      (((m) & P_D_CMDLINE) == P_D_CMDLINE)
59
60 #define F_NO_PID_IO     0x01
61
62 #define NO_PID_IO(m)            (((m) & F_NO_PID_IO) == F_NO_PID_IO)
63
64 #define PROC            "/proc"
65
66 #define PROC_PID        "/proc/%u"
67 #define PID_STAT        "/proc/%u/stat"
68 #define PID_STATUS      "/proc/%u/status"
69 #define PID_IO          "/proc/%u/io"
70 #define PID_CMDLINE     "/proc/%u/cmdline"
71 #define PID_SMAP        "/proc/%u/smaps"
72
73 #define PROC_TASK       "/proc/%u/task"
74 #define TASK_STAT       "/proc/%u/task/%u/stat"
75 #define TASK_STATUS     "/proc/%u/task/%u/status"
76 #define TASK_IO         "/proc/%u/task/%u/io"
77 #define TASK_CMDLINE    "/proc/%u/task/%u/cmdline"
78 #define TASK_SMAP       "/proc/%u/task/%u/smaps"
79
80 #define PRINT_ID_HDR(_timestamp_, _flag_)       do {                                            \
81                                                         printf("\n%-11s", _timestamp_);         \
82                                                         if (DISPLAY_TID(_flag_)) {              \
83                                                                 printf("      TGID       TID"); \
84                                                         }                                       \
85                                                         else {                                  \
86                                                                 printf("       PID");           \
87                                                         }                                       \
88                                                 } while (0)
89
90 struct pid_stats {
91         unsigned long long read_bytes                   __attribute__ ((aligned (8)));
92         unsigned long long write_bytes                  __attribute__ ((packed));
93         unsigned long long cancelled_write_bytes        __attribute__ ((packed));
94         unsigned long long total_vsz                    __attribute__ ((packed));
95         unsigned long long total_rss                    __attribute__ ((packed));
96         unsigned long long total_stack_size             __attribute__ ((packed));
97         unsigned long long total_stack_ref              __attribute__ ((packed));
98         unsigned long      minflt                       __attribute__ ((packed));
99         unsigned long      cminflt                      __attribute__ ((packed));
100         unsigned long      majflt                       __attribute__ ((packed));
101         unsigned long      cmajflt                      __attribute__ ((packed));
102         unsigned long      utime                        __attribute__ ((packed));
103         unsigned long      cutime                       __attribute__ ((packed));
104         unsigned long      stime                        __attribute__ ((packed));
105         unsigned long      cstime                       __attribute__ ((packed));
106         unsigned long      gtime                        __attribute__ ((packed));
107         unsigned long      cgtime                       __attribute__ ((packed));
108         unsigned long      vsz                          __attribute__ ((packed));
109         unsigned long      rss                          __attribute__ ((packed));
110         unsigned long      nvcsw                        __attribute__ ((packed));
111         unsigned long      nivcsw                       __attribute__ ((packed));
112         unsigned long      stack_size                   __attribute__ ((packed));
113         unsigned long      stack_ref                    __attribute__ ((packed));
114         /* If pid is null, the process has terminated */
115         unsigned int       pid                          __attribute__ ((packed));
116         /* If tgid is not null, then this PID is in fact a TID */
117         unsigned int       tgid                         __attribute__ ((packed));
118         unsigned int       rt_asum_count                __attribute__ ((packed));
119         unsigned int       rc_asum_count                __attribute__ ((packed));
120         unsigned int       uc_asum_count                __attribute__ ((packed));
121         unsigned int       processor                    __attribute__ ((packed));
122         unsigned int       flags                        __attribute__ ((packed));
123         char               comm[MAX_COMM_LEN];
124         char               cmdline[MAX_CMDLINE_LEN];
125 };
126
127 #define PID_STATS_SIZE  (sizeof(struct pid_stats))
128
129 #endif  /* _PIDSTAT_H */