1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
/* Procman
* Copyright (C) 2001 Kevin Vandersloot
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef _PROCMAN_PROCMAN_H_
#define _PROCMAN_PROCMAN_H_
#include <glibmm/refptr.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <glib.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <glibtop/cpu.h>
#include <time.h>
#include <sys/types.h>
#include <map>
#include <string>
struct ProcInfo;
struct ProcData;
struct LoadGraph;
#include "smooth_refresh.h"
#include "prettytable.h"
#define GSM_GSETTINGS_SCHEMA "org.mate.system-monitor"
enum
{
ALL_PROCESSES,
MY_PROCESSES,
ACTIVE_PROCESSES
};
enum
{
VERY_HIGH_PRIORITY,
HIGH_PRIORITY,
NORMAL_PRIORITY,
LOW_PRIORITY,
VERY_LOW_PRIORITY,
CUSTOM_PRIORITY
};
static const unsigned MIN_UPDATE_INTERVAL = 1 * 1000;
static const unsigned MAX_UPDATE_INTERVAL = 100 * 1000;
namespace procman
{
extern const std::string SHOW_SYSTEM_TAB_CMD;
extern const std::string SHOW_PROCESSES_TAB_CMD;
extern const std::string SHOW_RESOURCES_TAB_CMD;
extern const std::string SHOW_FILE_SYSTEMS_TAB_CMD;
}
enum ProcmanTab
{
PROCMAN_TAB_SYSINFO,
PROCMAN_TAB_PROCESSES,
PROCMAN_TAB_RESOURCES,
PROCMAN_TAB_DISKS
};
struct ProcConfig
{
gint width;
gint height;
gint xpos;
gint ypos;
gboolean maximized;
gboolean show_kill_warning;
gboolean show_tree;
gboolean show_all_fs;
int update_interval;
int graph_update_interval;
int disks_update_interval;
gint whose_process;
gint current_tab;
GdkRGBA cpu_color[GLIBTOP_NCPU];
GdkRGBA mem_color;
GdkRGBA swap_color;
GdkRGBA net_in_color;
GdkRGBA net_out_color;
GdkRGBA bg_color;
GdkRGBA frame_color;
gint num_cpus;
bool solaris_mode;
bool network_in_bits;
};
struct MutableProcInfo
{
MutableProcInfo()
: status(0)
{ }
std::string user;
gchar wchan[40];
// all these members are filled with libgtop which uses
// guint64 (to have fixed size data) but we don't need more
// than an unsigned long (even for 32bit apps on a 64bit
// kernel) as these data are amounts, not offsets.
gulong vmsize;
gulong memres;
gulong memshared;
gulong memwritable;
gulong mem;
// wnck gives an unsigned long
gulong memxserver;
gulong start_time;
guint64 cpu_time;
guint status;
guint pcpu;
gint nice;
gchar *cgroup_name;
gchar *unit;
gchar *session;
gchar *seat;
std::string owner;
};
class ProcInfo
: public MutableProcInfo
{
/* undefined */ ProcInfo& operator=(const ProcInfo&);
/* undefined */ ProcInfo(const ProcInfo&);
typedef std::map<guint, std::string> UserMap;
/* cached username */
static UserMap users;
public:
// TODO: use a set instead
// sorted by pid. The map has a nice property : it is sorted
// by pid so this helps a lot when looking for the parent node
// as ppid is nearly always < pid.
typedef std::map<pid_t, ProcInfo*> List;
typedef List::iterator Iterator;
static List all;
static ProcInfo* find(pid_t pid);
static Iterator begin() { return ProcInfo::all.begin(); }
static Iterator end() { return ProcInfo::all.end(); }
ProcInfo(pid_t pid);
~ProcInfo();
// adds one more ref to icon
void set_icon(Glib::RefPtr<Gdk::Pixbuf> icon);
void set_user(guint uid);
std::string lookup_user(guint uid);
GtkTreeIter node;
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
gchar *tooltip;
gchar *name;
gchar *arguments;
gchar *security_context;
const guint pid;
guint ppid;
guint uid;
// private:
// tracks cpu time per process keeps growing because if a
// ProcInfo is deleted this does not mean that the process is
// not going to be recreated on the next update. For example,
// if dependencies + (My or Active), the proclist is cleared
// on each update. This is a workaround
static std::map<pid_t, guint64> cpu_times;
};
struct ProcData
{
// lazy initialization
static ProcData* get_instance();
GtkUIManager *uimanager;
GtkActionGroup *action_group;
GtkWidget *statusbar;
gint tip_message_cid;
GtkWidget *tree;
GtkWidget *loadavg;
GtkWidget *endprocessbutton;
GtkWidget *popup_menu;
GtkWidget *disk_list;
GtkWidget *notebook;
ProcConfig config;
LoadGraph *cpu_graph;
LoadGraph *mem_graph;
LoadGraph *net_graph;
gint cpu_label_fixed_width;
gint net_label_fixed_width;
ProcInfo *selected_process;
GtkTreeSelection *selection;
guint timeout;
guint disk_timeout;
PrettyTable pretty_table;
GSettings *settings;
GtkWidget *app;
GtkUIManager *menu;
unsigned frequency;
SmoothRefresh *smooth_refresh;
guint64 cpu_total_time;
guint64 cpu_total_time_last;
private:
ProcData();
/* undefined */ ProcData(const ProcData &);
/* undefined */ ProcData& operator=(const ProcData &);
};
void procman_save_config (ProcData *data);
void procman_save_tree_state (GSettings *settings, GtkWidget *tree, const gchar *prefix);
gboolean procman_get_tree_state (GSettings *settings, GtkWidget *tree, const gchar *prefix);
struct ReniceArgs
{
ProcData *procdata;
int nice_value;
};
struct KillArgs
{
ProcData *procdata;
int signal;
};
#endif /* _PROCMAN_PROCMAN_H_ */
|