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