aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/stats/statistics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/stats/statistics.c')
-rw-r--r--src/plugins/stats/statistics.c587
1 files changed, 287 insertions, 300 deletions
diff --git a/src/plugins/stats/statistics.c b/src/plugins/stats/statistics.c
index d1da9422..4f8c34b1 100644
--- a/src/plugins/stats/statistics.c
+++ b/src/plugins/stats/statistics.c
@@ -32,7 +32,8 @@
32#define FRAME_WIDTH 0 32#define FRAME_WIDTH 0
33 33
34 34
35typedef struct { 35typedef struct
36{
36 gint type; 37 gint type;
37 guint count; 38 guint count;
38 guint speed; 39 guint speed;
@@ -54,10 +55,11 @@ typedef struct {
54 int statIdx; 55 int statIdx;
55} LoadGraph; 56} LoadGraph;
56 57
57typedef struct { 58typedef struct
58 GdkColor bg_color; 59{
59 GdkColor frame_color; 60 GdkColor bg_color;
60 GdkColor mem_color[MAX_COLOR]; 61 GdkColor frame_color;
62 GdkColor mem_color[MAX_COLOR];
61} ProcConfig; 63} ProcConfig;
62 64
63static unsigned long long UPDATE_INTERVAL; 65static unsigned long long UPDATE_INTERVAL;
@@ -65,13 +67,15 @@ static unsigned long long UPDATE_INTERVAL;
65/** 67/**
66 * Redraws the backing pixmap for the load graph and updates the window 68 * Redraws the backing pixmap for the load graph and updates the window
67 */ 69 */
68static void load_graph_draw(LoadGraph *g) { 70static void
71load_graph_draw (LoadGraph * g)
72{
69 guint i; 73 guint i;
70 guint j; 74 guint j;
71 gint dely; 75 gint dely;
72 float delx; 76 float delx;
73 float max; 77 float max;
74 GdkFont * font; 78 GdkFont *font;
75 79
76 if (!g->disp->window) 80 if (!g->disp->window)
77 return; 81 return;
@@ -81,345 +85,342 @@ static void load_graph_draw(LoadGraph *g) {
81 85
82 if (!g->pixmap) 86 if (!g->pixmap)
83 g->pixmap = gdk_pixmap_new (g->disp->window, 87 g->pixmap = gdk_pixmap_new (g->disp->window,
84 g->draw_width, g->draw_height, 88 g->draw_width, g->draw_height,
85 gtk_widget_get_visual (g->disp)->depth); 89 gtk_widget_get_visual (g->disp)->depth);
86 90
87 /* Create GC if necessary. */ 91 /* Create GC if necessary. */
88 if (!g->gc) { 92 if (!g->gc)
89 g->gc = gdk_gc_new (g->disp->window); 93 {
90 gdk_gc_copy (g->gc, g->disp->style->white_gc); 94 g->gc = gdk_gc_new (g->disp->window);
91 } 95 gdk_gc_copy (g->gc, g->disp->style->white_gc);
96 }
92 97
93 /* Allocate colors. */ 98 /* Allocate colors. */
94 if (!g->colors_allocated) { 99 if (!g->colors_allocated)
95 GdkColormap *colormap; 100 {
101 GdkColormap *colormap;
96 102
97 colormap = gdk_window_get_colormap (g->disp->window); 103 colormap = gdk_window_get_colormap (g->disp->window);
98 for (i=0;i<2+g->count;i++) 104 for (i = 0; i < 2 + g->count; i++)
99 gdk_color_alloc (colormap, &(g->colors [i])); 105 gdk_color_alloc (colormap, &(g->colors[i]));
100 106
101 g->colors_allocated = 1; 107 g->colors_allocated = 1;
102 } 108 }
103 /* Erase Rectangle */ 109 /* Erase Rectangle */
104 gdk_gc_set_foreground (g->gc, &(g->colors [0])); 110 gdk_gc_set_foreground (g->gc, &(g->colors[0]));
105 gdk_draw_rectangle (g->pixmap, 111 gdk_draw_rectangle (g->pixmap,
106 g->gc, 112 g->gc,
107 TRUE, 0, 0, 113 TRUE, 0, 0,
108 g->disp->allocation.width, 114 g->disp->allocation.width, g->disp->allocation.height);
109 g->disp->allocation.height);
110 115
111 /* draw frame */ 116 /* draw frame */
112 gdk_gc_set_foreground (g->gc, &(g->colors [1])); 117 gdk_gc_set_foreground (g->gc, &(g->colors[1]));
113 gdk_draw_rectangle (g->pixmap, 118 gdk_draw_rectangle (g->pixmap,
114 g->gc, 119 g->gc,
115 FALSE, 0, 0, 120 FALSE, 0, 0, g->draw_width, g->disp->allocation.height);
116 g->draw_width,
117 g->disp->allocation.height);
118 121
119 max = 0.26; /* force showing at least the 25% line */ 122 max = 0.26; /* force showing at least the 25% line */
120 for (i = 0; i < g->num_points - 1; i++) 123 for (i = 0; i < g->num_points - 1; i++)
121 for (j=0;j<g->count;j++) 124 for (j = 0; j < g->count; j++)
122 if (g->data[i][j] > max) 125 if (g->data[i][j] > max)
123 max = g->data[i][j]; 126 max = g->data[i][j];
124 max = max * 1.01; /* leave top 1% free */ 127 max = max * 1.01; /* leave top 1% free */
125 128
126 font = gdk_font_load("fixed"); /* deprecated, but pango is far more than 129 font = gdk_font_load ("fixed"); /* deprecated, but pango is far more than
127 what we need here -- fix later? */ 130 what we need here -- fix later? */
128 /* draw lines at 25%, 50%, 75% and 100% of max */ 131 /* draw lines at 25%, 50%, 75% and 100% of max */
129 dely = g->draw_height / max / 4; 132 dely = g->draw_height / max / 4;
130 for (i = 1; i < 5; i++) { 133 for (i = 1; i < 5; i++)
131 gint y1 = g->draw_height + 1 - i * dely; 134 {
132 if ( (dely < 30) && (i != 4) ) 135 gint y1 = g->draw_height + 1 - i * dely;
133 continue; /* only print additional 136 if ((dely < 30) && (i != 4))
134 lines if there is enough space! */ 137 continue; /* only print additional
135 if (y1 > 0) { 138 lines if there is enough space! */
136 const gchar * label[] = { 139 if (y1 > 0)
137 NULL, 140 {
138 " 25%", 141 const gchar *label[] = {
139 " 50%", 142 NULL,
140 " 75%", 143 " 25%",
141 "100%", 144 " 50%",
142 }; 145 " 75%",
143 gdk_draw_string(g->pixmap, 146 "100%",
144 font, 147 };
145 g->gc, 148 gdk_draw_string (g->pixmap, font, g->gc, 10, y1 - 8, label[i]);
146 10, 149 gdk_draw_line (g->pixmap, g->gc, 0, y1, g->draw_width, y1);
147 y1 - 8, 150 if (i == 4)
148 label[i]); 151 {
149 gdk_draw_line (g->pixmap, g->gc, 152 /* extra-thick line at 100% */
150 0, y1, g->draw_width, y1); 153 gdk_draw_line (g->pixmap, g->gc,
151 if (i == 4) { 154 0, y1 - 1, g->draw_width, y1 - 1);
152 /* extra-thick line at 100% */ 155 gdk_draw_line (g->pixmap, g->gc,
153 gdk_draw_line (g->pixmap, g->gc, 156 0, y1 + 1, g->draw_width, y1 + 1);
154 0, y1 - 1, g->draw_width, y1 - 1); 157
155 gdk_draw_line (g->pixmap, g->gc, 158 }
156 0, y1 + 1, g->draw_width, y1 + 1); 159 }
157
158 }
159 } 160 }
160 } 161 gdk_gc_set_line_attributes (g->gc,
161 gdk_gc_set_line_attributes(g->gc, 162 2,
162 2, 163 GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER);
163 GDK_LINE_SOLID, 164 delx = (float) g->draw_width / (g->num_points - 1);
164 GDK_CAP_ROUND, 165
165 GDK_JOIN_MITER); 166 for (j = 0; j < g->count; j++)
166 delx = (float)g->draw_width / ( g->num_points - 1); 167 {
167 168 gdk_gc_set_foreground (g->gc, &(g->colors[j + 2]));
168 for (j=0;j<g->count;j++) { 169 for (i = 0; i < g->num_points - 1; i++)
169 gdk_gc_set_foreground (g->gc, &(g->colors [j + 2])); 170 {
170 for (i = 0; i < g->num_points - 1; i++) { 171 gint x1 = i * delx;
171 gint x1 = i * delx; 172 gint x2 = (i + 1) * delx;
172 gint x2 = (i + 1) * delx; 173 gint y1 = g->data[i][j] / max * g->draw_height - 1;
173 gint y1 = g->data[i][j] / max * g->draw_height - 1; 174 gint y2 = g->data[i + 1][j] / max * g->draw_height - 1;
174 gint y2 = g->data[i+1][j] / max * g->draw_height - 1; 175
175 176 if ((g->data[i][j] != -1) && (g->data[i + 1][j] != -1))
176 if ((g->data[i][j] != -1) && (g->data[i+1][j] != -1)) { 177 {
177 if (stats[g->statIdx].fill <= j) { 178 if (stats[g->statIdx].fill <= j)
178 gdk_draw_line(g->pixmap, g->gc, 179 {
179 g->draw_width - x2, 180 gdk_draw_line (g->pixmap, g->gc,
180 g->draw_height - y2, 181 g->draw_width - x2,
181 g->draw_width - x1, 182 g->draw_height - y2,
182 g->draw_height - y1); 183 g->draw_width - x1, g->draw_height - y1);
183 } else { 184 }
184 GdkPoint points[4]; 185 else
185 186 {
186 points[0].x = g->draw_width - x2; 187 GdkPoint points[4];
187 points[0].y = g->draw_height - y2; 188
188 points[1].x = g->draw_width - x1; 189 points[0].x = g->draw_width - x2;
189 points[1].y = g->draw_height - y1; 190 points[0].y = g->draw_height - y2;
190 points[2].x = g->draw_width - x1; 191 points[1].x = g->draw_width - x1;
191 points[3].x = g->draw_width - x2; 192 points[1].y = g->draw_height - y1;
192 if (j == 0) { 193 points[2].x = g->draw_width - x1;
193 points[2].y = g->draw_height; 194 points[3].x = g->draw_width - x2;
194 points[3].y = g->draw_height; 195 if (j == 0)
195 } else { 196 {
196 gint ly1 = g->data[i][j-1] / max * g->draw_height - 1; 197 points[2].y = g->draw_height;
197 gint ly2 = g->data[i+1][j-1] / max * g->draw_height - 1; 198 points[3].y = g->draw_height;
198 points[2].y = g->draw_height - ly1; 199 }
199 points[3].y = g->draw_height - ly2; 200 else
200 } 201 {
201 gdk_draw_polygon(g->pixmap, 202 gint ly1 = g->data[i][j - 1] / max * g->draw_height - 1;
202 g->gc, 203 gint ly2 =
203 1, 204 g->data[i + 1][j - 1] / max * g->draw_height - 1;
204 points, 205 points[2].y = g->draw_height - ly1;
205 4); 206 points[3].y = g->draw_height - ly2;
206 } 207 }
207 } 208 gdk_draw_polygon (g->pixmap, g->gc, 1, points, 4);
209 }
210 }
211 }
208 } 212 }
209 }
210 213
211 gdk_gc_set_line_attributes (g->gc, 1, 214 gdk_gc_set_line_attributes (g->gc, 1,
212 GDK_LINE_SOLID, 215 GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER);
213 GDK_CAP_ROUND,
214 GDK_JOIN_MITER );
215 216
216 gdk_draw_pixmap (g->disp->window, 217 gdk_draw_pixmap (g->disp->window,
217 g->disp->style->fg_gc [GTK_WIDGET_STATE(g->disp)], 218 g->disp->style->fg_gc[GTK_WIDGET_STATE (g->disp)],
218 g->pixmap, 219 g->pixmap,
219 0, 0, 220 0, 0,
220 0, 0, 221 0, 0,
221 g->disp->allocation.width, 222 g->disp->allocation.width, g->disp->allocation.height);
222 g->disp->allocation.height);
223} 223}
224 224
225 225
226/* Updates the load graph when the timeout expires */ 226/* Updates the load graph when the timeout expires */
227static gboolean load_graph_update(gpointer ptr) { 227static gboolean
228load_graph_update (gpointer ptr)
229{
228 LoadGraph *g = ptr; 230 LoadGraph *g = ptr;
229 guint i; 231 guint i;
230 guint j; 232 guint j;
231 233
232 for (i=0;i<g->num_points;i++) 234 for (i = 0; i < g->num_points; i++)
233 memcpy(g->odata[i], 235 memcpy (g->odata[i], g->data[i], g->data_size * g->count);
234 g->data[i], 236 stats[g->statIdx].getData (stats[g->statIdx].get_closure, g->data);
235 g->data_size * g->count); 237 for (i = 0; i < g->num_points - 1; i++)
236 stats[g->statIdx].getData(stats[g->statIdx].get_closure, 238 for (j = 0; j < g->count; j++)
237 g->data); 239 g->data[i + 1][j] = g->odata[i][j];
238 for (i=0;i<g->num_points-1;i++)
239 for (j=0;j<g->count;j++)
240 g->data[i+1][j] = g->odata[i][j];
241 if (g->draw) 240 if (g->draw)
242 load_graph_draw (g); 241 load_graph_draw (g);
243 return TRUE; 242 return TRUE;
244} 243}
245 244
246static void load_graph_unalloc(LoadGraph *g) { 245static void
246load_graph_unalloc (LoadGraph * g)
247{
247 int i; 248 int i;
248 if (!g->allocated) 249 if (!g->allocated)
249 return; 250 return;
250 for (i = 0; i < g->num_points; i++) { 251 for (i = 0; i < g->num_points; i++)
251 FREE(g->data[i]); 252 {
252 FREE(g->odata[i]); 253 FREE (g->data[i]);
253 } 254 FREE (g->odata[i]);
254 FREE(g->data); 255 }
255 FREE(g->odata); 256 FREE (g->data);
257 FREE (g->odata);
256 g->data = g->odata = NULL; 258 g->data = g->odata = NULL;
257 if (g->pixmap) { 259 if (g->pixmap)
258 gdk_pixmap_unref(g->pixmap); 260 {
259 g->pixmap = NULL; 261 gdk_pixmap_unref (g->pixmap);
260 } 262 g->pixmap = NULL;
263 }
261 g->allocated = FALSE; 264 g->allocated = FALSE;
262} 265}
263 266
264static void load_graph_alloc (LoadGraph *g) { 267static void
268load_graph_alloc (LoadGraph * g)
269{
265 int i; 270 int i;
266 int j; 271 int j;
267 272
268 if (g->allocated) 273 if (g->allocated)
269 return; 274 return;
270 275
271 g->data = MALLOC(sizeof(gfloat *) * g->num_points); 276 g->data = MALLOC (sizeof (gfloat *) * g->num_points);
272 g->odata = MALLOC(sizeof(gfloat*) * g->num_points); 277 g->odata = MALLOC (sizeof (gfloat *) * g->num_points);
273 g->data_size = sizeof (gfloat); 278 g->data_size = sizeof (gfloat);
274 for (i = 0; i < g->num_points; i++) { 279 for (i = 0; i < g->num_points; i++)
275 g->data[i] = MALLOC(g->data_size * g->count); 280 {
276 g->odata[i] = MALLOC(g->data_size * g->count); 281 g->data[i] = MALLOC (g->data_size * g->count);
277 } 282 g->odata[i] = MALLOC (g->data_size * g->count);
278 for (i=0;i<g->num_points;i++) 283 }
279 for (j=0;j<g->count;j++) 284 for (i = 0; i < g->num_points; i++)
285 for (j = 0; j < g->count; j++)
280 g->data[i][j] = -1; 286 g->data[i][j] = -1;
281 g->allocated = TRUE; 287 g->allocated = TRUE;
282} 288}
283 289
284static gint load_graph_configure(GtkWidget *widget, 290static gint
285 GdkEventConfigure *event, 291load_graph_configure (GtkWidget * widget,
286 gpointer data_ptr) { 292 GdkEventConfigure * event, gpointer data_ptr)
293{
287 LoadGraph *c = (LoadGraph *) data_ptr; 294 LoadGraph *c = (LoadGraph *) data_ptr;
288 295
289 if (c->pixmap) { 296 if (c->pixmap)
290 gdk_pixmap_unref (c->pixmap); 297 {
291 c->pixmap = NULL; 298 gdk_pixmap_unref (c->pixmap);
292 } 299 c->pixmap = NULL;
300 }
293 301
294 if (!c->pixmap) 302 if (!c->pixmap)
295 c->pixmap = gdk_pixmap_new(widget->window, 303 c->pixmap = gdk_pixmap_new (widget->window,
296 widget->allocation.width, 304 widget->allocation.width,
297 widget->allocation.height, 305 widget->allocation.height,
298 gtk_widget_get_visual (c->disp)->depth); 306 gtk_widget_get_visual (c->disp)->depth);
299 gdk_draw_rectangle(c->pixmap, 307 gdk_draw_rectangle (c->pixmap,
300 widget->style->black_gc, 308 widget->style->black_gc,
301 TRUE, 0,0, 309 TRUE, 0, 0,
302 widget->allocation.width, 310 widget->allocation.width, widget->allocation.height);
303 widget->allocation.height); 311 gdk_draw_pixmap (widget->window,
304 gdk_draw_pixmap(widget->window, 312 c->disp->style->fg_gc[GTK_WIDGET_STATE (widget)],
305 c->disp->style->fg_gc[GTK_WIDGET_STATE(widget)], 313 c->pixmap,
306 c->pixmap, 314 0, 0,
307 0, 0, 315 0, 0,
308 0, 0, 316 c->disp->allocation.width, c->disp->allocation.height);
309 c->disp->allocation.width, 317
310 c->disp->allocation.height); 318 load_graph_draw (c);
311
312 load_graph_draw(c);
313 return TRUE; 319 return TRUE;
314} 320}
315 321
316static gint load_graph_expose(GtkWidget *widget, 322static gint
317 GdkEventExpose *event, 323load_graph_expose (GtkWidget * widget,
318 gpointer data_ptr) { 324 GdkEventExpose * event, gpointer data_ptr)
325{
319 LoadGraph *g = (LoadGraph *) data_ptr; 326 LoadGraph *g = (LoadGraph *) data_ptr;
320 327
321 gdk_draw_pixmap(widget->window, 328 gdk_draw_pixmap (widget->window,
322 widget->style->fg_gc [GTK_WIDGET_STATE(widget)], 329 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
323 g->pixmap, 330 g->pixmap,
324 event->area.x, event->area.y, 331 event->area.x, event->area.y,
325 event->area.x, event->area.y, 332 event->area.x, event->area.y,
326 event->area.width, event->area.height); 333 event->area.width, event->area.height);
327 return FALSE; 334 return FALSE;
328} 335}
329 336
330static void load_graph_stop (LoadGraph *g) { 337static void
338load_graph_stop (LoadGraph * g)
339{
331 if (!g) 340 if (!g)
332 return; 341 return;
333 if (g->timer_index != -1) { 342 if (g->timer_index != -1)
334 gtk_timeout_remove(g->timer_index); 343 {
335 g->timer_index = -1; 344 gtk_timeout_remove (g->timer_index);
336 } 345 g->timer_index = -1;
346 }
337 g->draw = FALSE; 347 g->draw = FALSE;
338} 348}
339 349
340static void load_graph_destroy(GtkWidget *widget, 350static void
341 gpointer data_ptr) { 351load_graph_destroy (GtkWidget * widget, gpointer data_ptr)
352{
342 LoadGraph *g = (LoadGraph *) data_ptr; 353 LoadGraph *g = (LoadGraph *) data_ptr;
343 load_graph_stop(g); 354 load_graph_stop (g);
344 if (g->timer_index != -1) 355 if (g->timer_index != -1)
345 gtk_timeout_remove (g->timer_index); 356 gtk_timeout_remove (g->timer_index);
346 load_graph_unalloc(g); 357 load_graph_unalloc (g);
347 FREE(g->colors); 358 FREE (g->colors);
348 FREE(g); 359 FREE (g);
349} 360}
350 361
351static LoadGraph * load_graph_new(int statIdx, 362static LoadGraph *
352 const ProcConfig * config) { 363load_graph_new (int statIdx, const ProcConfig * config)
364{
353 LoadGraph *g; 365 LoadGraph *g;
354 unsigned int i; 366 unsigned int i;
355 367
356 if (stats[statIdx].count > MAX_COLOR) { 368 if (stats[statIdx].count > MAX_COLOR)
357 GE_BREAK(NULL, 0); 369 {
358 return NULL; 370 GE_BREAK (NULL, 0);
359 } 371 return NULL;
372 }
360 373
361 g = MALLOC(sizeof(LoadGraph)); 374 g = MALLOC (sizeof (LoadGraph));
362 g->statIdx = statIdx; 375 g->statIdx = statIdx;
363 g->count = stats[statIdx].count; 376 g->count = stats[statIdx].count;
364 g->speed = UPDATE_INTERVAL / cronMILLIS; 377 g->speed = UPDATE_INTERVAL / cronMILLIS;
365 g->num_points = 600; 378 g->num_points = 600;
366 g->colors = MALLOC(sizeof(GdkColor) * (2+g->count)); 379 g->colors = MALLOC (sizeof (GdkColor) * (2 + g->count));
367 g->colors[0] = config->bg_color; 380 g->colors[0] = config->bg_color;
368 g->colors[1] = config->frame_color; 381 g->colors[1] = config->frame_color;
369 for (i=0;i<g->count;i++) 382 for (i = 0; i < g->count; i++)
370 g->colors[2+i] = config->mem_color[i]; 383 g->colors[2 + i] = config->mem_color[i];
371 g->timer_index = -1; 384 g->timer_index = -1;
372 g->draw = FALSE; 385 g->draw = FALSE;
373 g->main_widget = gtk_vbox_new (FALSE, FALSE); 386 g->main_widget = gtk_vbox_new (FALSE, FALSE);
374 gtk_widget_show(g->main_widget); 387 gtk_widget_show (g->main_widget);
375 g->disp = gtk_drawing_area_new(); 388 g->disp = gtk_drawing_area_new ();
376 gtk_widget_show (g->disp); 389 gtk_widget_show (g->disp);
377 gtk_signal_connect(GTK_OBJECT (g->disp), 390 gtk_signal_connect (GTK_OBJECT (g->disp),
378 "expose_event", 391 "expose_event", GTK_SIGNAL_FUNC (load_graph_expose), g);
379 GTK_SIGNAL_FUNC (load_graph_expose), g); 392 gtk_signal_connect (GTK_OBJECT (g->disp),
380 gtk_signal_connect(GTK_OBJECT(g->disp), 393 "configure_event",
381 "configure_event", 394 GTK_SIGNAL_FUNC (load_graph_configure), g);
382 GTK_SIGNAL_FUNC (load_graph_configure), g); 395 gtk_signal_connect (GTK_OBJECT (g->disp),
383 gtk_signal_connect(GTK_OBJECT(g->disp), 396 "destroy", GTK_SIGNAL_FUNC (load_graph_destroy), g);
384 "destroy", 397 gtk_widget_add_events (g->disp, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
385 GTK_SIGNAL_FUNC (load_graph_destroy), g); 398 gtk_box_pack_start (GTK_BOX (g->main_widget), g->disp, TRUE, TRUE, 0);
386 gtk_widget_add_events(g->disp, 399 load_graph_alloc (g);
387 GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); 400 gtk_widget_show_all (g->main_widget);
388 gtk_box_pack_start(GTK_BOX(g->main_widget), 401 g->timer_index = gtk_timeout_add (g->speed, &load_graph_update, g);
389 g->disp,
390 TRUE,
391 TRUE,
392 0);
393 load_graph_alloc(g);
394 gtk_widget_show_all(g->main_widget);
395 g->timer_index = gtk_timeout_add(g->speed,
396 &load_graph_update, g);
397 402
398 return g; 403 return g;
399} 404}
400 405
401static GtkWidget * create_sys_view(int statIdx, 406static GtkWidget *
402 const ProcConfig * config) { 407create_sys_view (int statIdx, const ProcConfig * config)
403 GtkWidget * mem_frame; 408{
404 LoadGraph * mem_graph; 409 GtkWidget *mem_frame;
410 LoadGraph *mem_graph;
405 411
406 mem_graph = load_graph_new(statIdx, 412 mem_graph = load_graph_new (statIdx, config);
407 config);
408 if (mem_graph == NULL) 413 if (mem_graph == NULL)
409 return NULL; /* oops */ 414 return NULL; /* oops */
410 mem_frame = gtk_frame_new(_(stats[statIdx].frameName)); 415 mem_frame = gtk_frame_new (_(stats[statIdx].frameName));
411 gtk_container_add(GTK_CONTAINER(mem_frame), 416 gtk_container_add (GTK_CONTAINER (mem_frame), mem_graph->main_widget);
412 mem_graph->main_widget); 417 gtk_container_set_border_width (GTK_CONTAINER (mem_graph->main_widget),
413 gtk_container_set_border_width(GTK_CONTAINER(mem_graph->main_widget), 418 GNOME_PAD_SMALL);
414 GNOME_PAD_SMALL); 419 gtk_container_set_border_width (GTK_CONTAINER (mem_frame), GNOME_PAD_SMALL);
415 gtk_container_set_border_width(GTK_CONTAINER(mem_frame), 420 gtk_widget_show (mem_frame);
416 GNOME_PAD_SMALL);
417 gtk_widget_show(mem_frame);
418 if (mem_graph->timer_index == -1) 421 if (mem_graph->timer_index == -1)
419 mem_graph->timer_index 422 mem_graph->timer_index
420 = gtk_timeout_add(mem_graph->speed, 423 = gtk_timeout_add (mem_graph->speed, &load_graph_update, mem_graph);
421 &load_graph_update,
422 mem_graph);
423 mem_graph->draw = TRUE; 424 mem_graph->draw = TRUE;
424 return mem_frame; 425 return mem_frame;
425} 426}
@@ -428,64 +429,50 @@ static GtkWidget * create_sys_view(int statIdx,
428 429
429 430
430 431
431void init_stats(struct GE_Context * ectx, 432void
432 struct GC_Configuration * cfg) { 433init_stats (struct GE_Context *ectx, struct GC_Configuration *cfg)
433 GtkWidget * sys_box; 434{
434 GtkWidget * label; 435 GtkWidget *sys_box;
435 GtkWidget * notebook; 436 GtkWidget *label;
437 GtkWidget *notebook;
436 ProcConfig config; 438 ProcConfig config;
437 int i; 439 int i;
438 440
439 GC_get_configuration_value_number(cfg, 441 GC_get_configuration_value_number (cfg,
440 "GNUNET-GTK", 442 "GNUNET-GTK",
441 "STATS-INTERVAL", 443 "STATS-INTERVAL",
442 1, 444 1,
443 99 * cronYEARS, 445 99 * cronYEARS,
444 30 * cronSECONDS, 446 30 * cronSECONDS, &UPDATE_INTERVAL);
445 &UPDATE_INTERVAL); 447 init_functions (ectx, cfg);
446 init_functions(ectx, 448 notebook = glade_xml_get_widget (getMainXML (), "statsNotebook");
447 cfg); 449 memset (&config, 0, sizeof (ProcConfig));
448 notebook 450 gdk_color_parse ("black", &config.bg_color);
449 = glade_xml_get_widget(getMainXML(), 451 gdk_color_parse ("gray", &config.frame_color);
450 "statsNotebook"); 452 gdk_color_parse ("red", &config.mem_color[0]);
451 memset(&config, 453 gdk_color_parse ("green", &config.mem_color[1]);
452 0, 454 gdk_color_parse ("yellow", &config.mem_color[2]);
453 sizeof(ProcConfig)); 455 gdk_color_parse ("blue", &config.mem_color[3]);
454 gdk_color_parse("black", 456 gdk_color_parse ("gray", &config.mem_color[4]);
455 &config.bg_color); 457 gdk_color_parse ("magenta", &config.mem_color[5]);
456 gdk_color_parse("gray", 458 GE_ASSERT (ectx, MAX_COLOR == 6);
457 &config.frame_color);
458 gdk_color_parse("red",
459 &config.mem_color[0]);
460 gdk_color_parse("green",
461 &config.mem_color[1]);
462 gdk_color_parse("yellow",
463 &config.mem_color[2]);
464 gdk_color_parse("blue",
465 &config.mem_color[3]);
466 gdk_color_parse("gray",
467 &config.mem_color[4]);
468 gdk_color_parse("magenta",
469 &config.mem_color[5]);
470 GE_ASSERT(ectx,
471 MAX_COLOR == 6);
472 i = -1; 459 i = -1;
473 while (stats[++i].paneName != NULL) { 460 while (stats[++i].paneName != NULL)
474 sys_box = create_sys_view(i, 461 {
475 &config); 462 sys_box = create_sys_view (i, &config);
476 if (sys_box == NULL) 463 if (sys_box == NULL)
477 continue; /* oops */ 464 continue; /* oops */
478 465
479 label = gtk_label_new(gettext(stats[i].paneName)); 466 label = gtk_label_new (gettext (stats[i].paneName));
480 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), 467 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, label);
481 sys_box, 468 }
482 label); 469 gtk_widget_show (notebook);
483 }
484 gtk_widget_show(notebook);
485} 470}
486 471
487void done_stats() { 472void
488 done_functions(); 473done_stats ()
474{
475 done_functions ();
489} 476}
490 477
491 478