Support for per-task I/O statistics - $top_io
[monky] / src / top.h
1 /* Conky, a system monitor, based on torsmo
2  *
3  * Any original torsmo code is licensed under the BSD license
4  *
5  * All code written since the fork of torsmo is licensed under the GPL
6  *
7  * Please see COPYING for details
8  *
9  * Copyright (c) 2005 Adi Zaimi, Dan Piponi <dan@tanelorn.demon.co.uk>,
10  *                                        Dave Clark <clarkd@skynet.ca>
11  * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
12  *      (see AUTHORS)
13  * All rights reserved.
14  *
15  * This program is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  * You should have received a copy of the GNU General Public License
25  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26  *
27  */
28
29 #ifndef _top_h_
30 #define _top_h_
31
32 /* Ensure there's an operating system defined.
33  * compile with gcc -DOS ...
34  * There is *no* default because every OS has it's own way of revealing
35  * CPU/memory usage. */
36
37 /******************************************
38  * Includes                                                               *
39  ******************************************/
40
41 #include "conky.h"
42 #define CPU_THRESHHOLD  0       /* threshhold for the cpu diff to appear */
43 #include <time.h>
44 #include <dirent.h>
45 #include <string.h>
46 #include <fcntl.h>
47 #include <unistd.h>
48 #include <ctype.h>
49 #include <math.h>
50 #include <assert.h>
51 #include <limits.h>
52 #include <errno.h>
53 #include <signal.h>
54
55 #include <sys/wait.h>
56 #include <sys/stat.h>
57 #include <sys/types.h>
58 #include <sys/ioctl.h>
59 #include <sys/time.h>
60
61 #include <regex.h>
62
63 /******************************************
64  * Defines                                                                *
65  ******************************************/
66
67 /* XXX: I shouldn't really use this BUFFER_LEN variable but scanf is so lame
68  * and it'll take me a while to write a replacement. */
69 #define BUFFER_LEN 1024
70
71 #define PROCFS_TEMPLATE "/proc/%d/stat"
72 #define PROCFS_TEMPLATE_MEM "/proc/%d/statm"
73 #define PROCFS_TEMPLATE_IO "/proc/%d/io"
74 #define PROCFS_CMDLINE_TEMPLATE "/proc/%d/cmdline"
75 #define MAX_SP 10       // number of elements to sort
76
77 enum top_field {
78         TOP_CPU,
79         TOP_NAME,
80         TOP_PID,
81         TOP_MEM,
82         TOP_TIME,
83         TOP_MEM_RES,
84         TOP_MEM_VSIZE,
85 #ifdef IOSTATS
86         TOP_READ_BYTES,
87         TOP_WRITE_BYTES,
88         TOP_IO_PERC
89 #endif
90 };
91
92 /******************************************
93  * Process class                                                  *
94  ******************************************/
95
96 struct process {
97         struct process *next;
98         struct process *previous;
99
100         pid_t pid;
101         char *name;
102         float amount;
103         // User and kernel times are in hundredths of seconds
104         unsigned long user_time;
105         unsigned long total;
106         unsigned long kernel_time;
107         unsigned long previous_user_time;
108         unsigned long previous_kernel_time;
109         unsigned long total_cpu_time;
110         unsigned int vsize;
111         unsigned int rss;
112 #ifdef IOSTATS
113         unsigned long long read_bytes;
114         unsigned long long previous_read_bytes;
115         unsigned long long write_bytes;
116         unsigned long long previous_write_bytes;
117         float io_perc;
118 #endif
119         unsigned int time_stamp;
120         unsigned int counted;
121         unsigned int changed;
122         float totalmem;
123 };
124
125 struct sorted_process {
126         struct sorted_process *greater;
127         struct sorted_process *less;
128         struct process *proc;
129 };
130
131 /* Pointer to head of process list */
132 void process_find_top(struct process **, struct process **, struct process **
133 #ifdef IOSTATS
134                 , struct process **
135 #endif
136                 );
137
138 #endif /* _top_h_ */