1 /*
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-2021 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 /* threshold for the cpu diff to appear */
46 #include <assert.h>
47 #include <ctype.h>
48 #include <dirent.h>
49 #include <errno.h>
50 #include <fcntl.h>
51 #include <limits.h>
52 #include <math.h>
53 #include <signal.h>
54 #include <string.h>
55 #include <time.h>
56 #include <unistd.h>
57 
58 #include <sys/ioctl.h>
59 #include <sys/param.h>
60 #include <sys/stat.h>
61 #include <sys/time.h>
62 #include <sys/types.h>
63 #include <sys/wait.h>
64 
65 #include <pwd.h>
66 #include <regex.h>
67 
68 /******************************************
69  * Defines								  *
70  ******************************************/
71 
72 /* XXX: I shouldn't really use this BUFFER_LEN variable but scanf is so lame
73  * and it'll take me a while to write a replacement. */
74 #define BUFFER_LEN 1024
75 
76 #define MAX_SP 10  // number of elements to sort
77 
78 /******************************************
79  * Process class						  *
80  ******************************************/
81 
82 struct process {
83   struct process *next;
84   struct process *previous;
85 
86   pid_t pid;
87   char *name;
88   char *basename;
89   uid_t uid;
90   float amount;
91   // User and kernel times are in hundredths of seconds
92   unsigned long user_time;
93   unsigned long total;
94   unsigned long kernel_time;
95   unsigned long previous_user_time;
96   unsigned long previous_kernel_time;
97   unsigned long total_cpu_time;
98   unsigned long previous_total_cpu_time;
99   unsigned long long vsize;
100   unsigned long long rss;
101 #ifdef BUILD_IOSTATS
102   unsigned long long read_bytes;
103   unsigned long long previous_read_bytes;
104   unsigned long long write_bytes;
105   unsigned long long previous_write_bytes;
106   float io_perc;
107 #endif
108   unsigned int time_stamp;
109   unsigned int counted;
110   unsigned int changed;
111 };
112 
113 struct sorted_process {
114   struct sorted_process *greater;
115   struct sorted_process *less;
116   struct process *proc;
117 };
118 
119 /* lookup a program by it's name */
120 struct process *get_process_by_name(const char *);
121 
122 int parse_top_args(const char *s, const char *arg, struct text_object *obj);
123 
124 int update_top(void);
125 
126 void get_top_info(void);
127 
128 extern struct process *first_process;
129 extern unsigned long g_time;
130 
131 struct process *get_process(pid_t pid);
132 
133 #endif /* _top_h_ */
134