aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/statistics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/statistics.c')
-rw-r--r--src/statistics/statistics.c325
1 files changed, 154 insertions, 171 deletions
diff --git a/src/statistics/statistics.c b/src/statistics/statistics.c
index b8dd2cd3..af5f3a06 100644
--- a/src/statistics/statistics.c
+++ b/src/statistics/statistics.c
@@ -84,40 +84,37 @@ load_graph_draw (LoadGraph * g)
84 g->draw_height = g->disp->allocation.height; 84 g->draw_height = g->disp->allocation.height;
85 85
86 if (!g->pixmap) 86 if (!g->pixmap)
87 g->pixmap = gdk_pixmap_new (g->disp->window, 87 g->pixmap =
88 g->draw_width, g->draw_height, 88 gdk_pixmap_new (g->disp->window, g->draw_width, g->draw_height,
89 gtk_widget_get_visual (g->disp)->depth); 89 gtk_widget_get_visual (g->disp)->depth);
90 90
91 /* Create GC if necessary. */ 91 /* Create GC if necessary. */
92 if (!g->gc) 92 if (!g->gc)
93 { 93 {
94 g->gc = gdk_gc_new (g->disp->window); 94 g->gc = gdk_gc_new (g->disp->window);
95 gdk_gc_copy (g->gc, g->disp->style->white_gc); 95 gdk_gc_copy (g->gc, g->disp->style->white_gc);
96 } 96 }
97 97
98 /* Allocate colors. */ 98 /* Allocate colors. */
99 if (!g->colors_allocated) 99 if (!g->colors_allocated)
100 { 100 {
101 GdkColormap *colormap; 101 GdkColormap *colormap;
102 102
103 colormap = gdk_window_get_colormap (g->disp->window); 103 colormap = gdk_window_get_colormap (g->disp->window);
104 for (i = 0; i < 2 + g->count; i++) 104 for (i = 0; i < 2 + g->count; i++)
105 gdk_color_alloc (colormap, &(g->colors[i])); 105 gdk_color_alloc (colormap, &(g->colors[i]));
106 106
107 g->colors_allocated = 1; 107 g->colors_allocated = 1;
108 } 108 }
109 /* Erase Rectangle */ 109 /* Erase Rectangle */
110 gdk_gc_set_foreground (g->gc, &(g->colors[0])); 110 gdk_gc_set_foreground (g->gc, &(g->colors[0]));
111 gdk_draw_rectangle (g->pixmap, 111 gdk_draw_rectangle (g->pixmap, g->gc, TRUE, 0, 0, g->disp->allocation.width,
112 g->gc, 112 g->disp->allocation.height);
113 TRUE, 0, 0,
114 g->disp->allocation.width, g->disp->allocation.height);
115 113
116 /* draw frame */ 114 /* draw frame */
117 gdk_gc_set_foreground (g->gc, &(g->colors[1])); 115 gdk_gc_set_foreground (g->gc, &(g->colors[1]));
118 gdk_draw_rectangle (g->pixmap, 116 gdk_draw_rectangle (g->pixmap, g->gc, FALSE, 0, 0, g->draw_width,
119 g->gc, 117 g->disp->allocation.height);
120 FALSE, 0, 0, g->draw_width, g->disp->allocation.height);
121 118
122 max = 0.26; /* force showing at least the 25% line */ 119 max = 0.26; /* force showing at least the 25% line */
123 for (i = 0; i < g->num_points - 1; i++) 120 for (i = 0; i < g->num_points - 1; i++)
@@ -127,99 +124,94 @@ load_graph_draw (LoadGraph * g)
127 max = max * 1.01; /* leave top 1% free */ 124 max = max * 1.01; /* leave top 1% free */
128 125
129 font = gdk_font_load ("fixed"); /* deprecated, but pango is far more than 126 font = gdk_font_load ("fixed"); /* deprecated, but pango is far more than
130 what we need here -- fix later? */ 127 * what we need here -- fix later? */
131 /* draw lines at 25%, 50%, 75% and 100% of max */ 128 /* draw lines at 25%, 50%, 75% and 100% of max */
132 dely = g->draw_height / max / 4; 129 dely = g->draw_height / max / 4;
133 for (i = 1; i < 5; i++) 130 for (i = 1; i < 5; i++)
131 {
132 gint y1 = g->draw_height + 1 - i * dely;
133
134 if ((dely < 30) && (i != 4))
135 continue; /* only print additional
136 * lines if there is enough space! */
137 if (y1 > 0)
134 { 138 {
135 gint y1 = g->draw_height + 1 - i * dely; 139 const gchar *label[] = {
136 if ((dely < 30) && (i != 4)) 140 NULL,
137 continue; /* only print additional 141 " 25%",
138 lines if there is enough space! */ 142 " 50%",
139 if (y1 > 0) 143 " 75%",
140 { 144 "100%",
141 const gchar *label[] = { 145 };
142 NULL, 146 gdk_draw_string (g->pixmap, font, g->gc, 10, y1 - 8, label[i]);
143 " 25%", 147 gdk_draw_line (g->pixmap, g->gc, 0, y1, g->draw_width, y1);
144 " 50%", 148 if (i == 4)
145 " 75%", 149 {
146 "100%", 150 /* extra-thick line at 100% */
147 }; 151 gdk_draw_line (g->pixmap, g->gc, 0, y1 - 1, g->draw_width, y1 - 1);
148 gdk_draw_string (g->pixmap, font, g->gc, 10, y1 - 8, label[i]); 152 gdk_draw_line (g->pixmap, g->gc, 0, y1 + 1, g->draw_width, y1 + 1);
149 gdk_draw_line (g->pixmap, g->gc, 0, y1, g->draw_width, y1); 153
150 if (i == 4) 154 }
151 {
152 /* extra-thick line at 100% */
153 gdk_draw_line (g->pixmap, g->gc,
154 0, y1 - 1, g->draw_width, y1 - 1);
155 gdk_draw_line (g->pixmap, g->gc,
156 0, y1 + 1, g->draw_width, y1 + 1);
157
158 }
159 }
160 } 155 }
161 gdk_gc_set_line_attributes (g->gc, 156 }
162 2, 157 gdk_gc_set_line_attributes (g->gc, 2, GDK_LINE_SOLID, GDK_CAP_ROUND,
163 GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER); 158 GDK_JOIN_MITER);
164 delx = (float) g->draw_width / (g->num_points - 1); 159 delx = (float) g->draw_width / (g->num_points - 1);
165 160
166 for (j = 0; j < g->count; j++) 161 for (j = 0; j < g->count; j++)
162 {
163 gdk_gc_set_foreground (g->gc, &(g->colors[j + 2]));
164 for (i = 0; i < g->num_points - 1; i++)
167 { 165 {
168 gdk_gc_set_foreground (g->gc, &(g->colors[j + 2])); 166 gint x1 = i * delx;
169 for (i = 0; i < g->num_points - 1; i++) 167 gint x2 = (i + 1) * delx;
168 gint y1 = g->data[i][j] / max * g->draw_height - 1;
169 gint y2 = g->data[i + 1][j] / max * g->draw_height - 1;
170
171 if ((g->data[i][j] != -1) && (g->data[i + 1][j] != -1))
172 {
173 if (stats[g->statIdx].fill <= j)
170 { 174 {
171 gint x1 = i * delx; 175 gdk_draw_line (g->pixmap, g->gc, g->draw_width - x2,
172 gint x2 = (i + 1) * delx; 176 g->draw_height - y2, g->draw_width - x1,
173 gint y1 = g->data[i][j] / max * g->draw_height - 1; 177 g->draw_height - y1);
174 gint y2 = g->data[i + 1][j] / max * g->draw_height - 1;
175
176 if ((g->data[i][j] != -1) && (g->data[i + 1][j] != -1))
177 {
178 if (stats[g->statIdx].fill <= j)
179 {
180 gdk_draw_line (g->pixmap, g->gc,
181 g->draw_width - x2,
182 g->draw_height - y2,
183 g->draw_width - x1, g->draw_height - y1);
184 }
185 else
186 {
187 GdkPoint points[4];
188
189 points[0].x = g->draw_width - x2;
190 points[0].y = g->draw_height - y2;
191 points[1].x = g->draw_width - x1;
192 points[1].y = g->draw_height - y1;
193 points[2].x = g->draw_width - x1;
194 points[3].x = g->draw_width - x2;
195 if (j == 0)
196 {
197 points[2].y = g->draw_height;
198 points[3].y = g->draw_height;
199 }
200 else
201 {
202 gint ly1 = g->data[i][j - 1] / max * g->draw_height - 1;
203 gint ly2 =
204 g->data[i + 1][j - 1] / max * g->draw_height - 1;
205 points[2].y = g->draw_height - ly1;
206 points[3].y = g->draw_height - ly2;
207 }
208 gdk_draw_polygon (g->pixmap, g->gc, 1, points, 4);
209 }
210 }
211 } 178 }
179 else
180 {
181 GdkPoint points[4];
182
183 points[0].x = g->draw_width - x2;
184 points[0].y = g->draw_height - y2;
185 points[1].x = g->draw_width - x1;
186 points[1].y = g->draw_height - y1;
187 points[2].x = g->draw_width - x1;
188 points[3].x = g->draw_width - x2;
189 if (j == 0)
190 {
191 points[2].y = g->draw_height;
192 points[3].y = g->draw_height;
193 }
194 else
195 {
196 gint ly1 = g->data[i][j - 1] / max * g->draw_height - 1;
197 gint ly2 = g->data[i + 1][j - 1] / max * g->draw_height - 1;
198
199 points[2].y = g->draw_height - ly1;
200 points[3].y = g->draw_height - ly2;
201 }
202 gdk_draw_polygon (g->pixmap, g->gc, 1, points, 4);
203 }
204 }
212 } 205 }
206 }
213 207
214 gdk_gc_set_line_attributes (g->gc, 1, 208 gdk_gc_set_line_attributes (g->gc, 1, GDK_LINE_SOLID, GDK_CAP_ROUND,
215 GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER); 209 GDK_JOIN_MITER);
216 210
217 gdk_draw_pixmap (g->disp->window, 211 gdk_draw_pixmap (g->disp->window,
218 g->disp->style->fg_gc[GTK_WIDGET_STATE (g->disp)], 212 g->disp->style->fg_gc[GTK_WIDGET_STATE (g->disp)], g->pixmap,
219 g->pixmap, 213 0, 0, 0, 0, g->disp->allocation.width,
220 0, 0, 214 g->disp->allocation.height);
221 0, 0,
222 g->disp->allocation.width, g->disp->allocation.height);
223} 215}
224 216
225 217
@@ -246,21 +238,22 @@ static void
246load_graph_unalloc (LoadGraph * g) 238load_graph_unalloc (LoadGraph * g)
247{ 239{
248 unsigned int i; 240 unsigned int i;
241
249 if (!g->allocated) 242 if (!g->allocated)
250 return; 243 return;
251 for (i = 0; i < g->num_points; i++) 244 for (i = 0; i < g->num_points; i++)
252 { 245 {
253 GNUNET_free (g->data[i]); 246 GNUNET_free (g->data[i]);
254 GNUNET_free (g->odata[i]); 247 GNUNET_free (g->odata[i]);
255 } 248 }
256 GNUNET_free (g->data); 249 GNUNET_free (g->data);
257 GNUNET_free (g->odata); 250 GNUNET_free (g->odata);
258 g->data = g->odata = NULL; 251 g->data = g->odata = NULL;
259 if (g->pixmap) 252 if (g->pixmap)
260 { 253 {
261 gdk_pixmap_unref (g->pixmap); 254 gdk_pixmap_unref (g->pixmap);
262 g->pixmap = NULL; 255 g->pixmap = NULL;
263 } 256 }
264 g->allocated = FALSE; 257 g->allocated = FALSE;
265} 258}
266 259
@@ -277,10 +270,10 @@ load_graph_alloc (LoadGraph * g)
277 g->odata = GNUNET_malloc (sizeof (gfloat *) * g->num_points); 270 g->odata = GNUNET_malloc (sizeof (gfloat *) * g->num_points);
278 g->data_size = sizeof (gfloat); 271 g->data_size = sizeof (gfloat);
279 for (i = 0; i < g->num_points; i++) 272 for (i = 0; i < g->num_points; i++)
280 { 273 {
281 g->data[i] = GNUNET_malloc (g->data_size * g->count); 274 g->data[i] = GNUNET_malloc (g->data_size * g->count);
282 g->odata[i] = GNUNET_malloc (g->data_size * g->count); 275 g->odata[i] = GNUNET_malloc (g->data_size * g->count);
283 } 276 }
284 for (i = 0; i < g->num_points; i++) 277 for (i = 0; i < g->num_points; i++)
285 for (j = 0; j < g->count; j++) 278 for (j = 0; j < g->count; j++)
286 g->data[i][j] = -1; 279 g->data[i][j] = -1;
@@ -288,48 +281,42 @@ load_graph_alloc (LoadGraph * g)
288} 281}
289 282
290static gint 283static gint
291load_graph_configure (GtkWidget * widget, 284load_graph_configure (GtkWidget * widget, GdkEventConfigure * event,
292 GdkEventConfigure * event, gpointer data_ptr) 285 gpointer data_ptr)
293{ 286{
294 LoadGraph *c = (LoadGraph *) data_ptr; 287 LoadGraph *c = (LoadGraph *) data_ptr;
295 288
296 if (c->pixmap) 289 if (c->pixmap)
297 { 290 {
298 gdk_pixmap_unref (c->pixmap); 291 gdk_pixmap_unref (c->pixmap);
299 c->pixmap = NULL; 292 c->pixmap = NULL;
300 } 293 }
301 294
302 if (!c->pixmap) 295 if (!c->pixmap)
303 c->pixmap = gdk_pixmap_new (widget->window, 296 c->pixmap =
304 widget->allocation.width, 297 gdk_pixmap_new (widget->window, widget->allocation.width,
305 widget->allocation.height, 298 widget->allocation.height,
306 gtk_widget_get_visual (c->disp)->depth); 299 gtk_widget_get_visual (c->disp)->depth);
307 gdk_draw_rectangle (c->pixmap, 300 gdk_draw_rectangle (c->pixmap, widget->style->black_gc, TRUE, 0, 0,
308 widget->style->black_gc,
309 TRUE, 0, 0,
310 widget->allocation.width, widget->allocation.height); 301 widget->allocation.width, widget->allocation.height);
311 gdk_draw_pixmap (widget->window, 302 gdk_draw_pixmap (widget->window,
312 c->disp->style->fg_gc[GTK_WIDGET_STATE (widget)], 303 c->disp->style->fg_gc[GTK_WIDGET_STATE (widget)], c->pixmap,
313 c->pixmap, 304 0, 0, 0, 0, c->disp->allocation.width,
314 0, 0, 305 c->disp->allocation.height);
315 0, 0,
316 c->disp->allocation.width, c->disp->allocation.height);
317 306
318 load_graph_draw (c); 307 load_graph_draw (c);
319 return TRUE; 308 return TRUE;
320} 309}
321 310
322static gint 311static gint
323load_graph_expose (GtkWidget * widget, 312load_graph_expose (GtkWidget * widget, GdkEventExpose * event,
324 GdkEventExpose * event, gpointer data_ptr) 313 gpointer data_ptr)
325{ 314{
326 LoadGraph *g = (LoadGraph *) data_ptr; 315 LoadGraph *g = (LoadGraph *) data_ptr;
327 316
328 gdk_draw_pixmap (widget->window, 317 gdk_draw_pixmap (widget->window,
329 widget->style->fg_gc[GTK_WIDGET_STATE (widget)], 318 widget->style->fg_gc[GTK_WIDGET_STATE (widget)], g->pixmap,
330 g->pixmap, 319 event->area.x, event->area.y, event->area.x, event->area.y,
331 event->area.x, event->area.y,
332 event->area.x, event->area.y,
333 event->area.width, event->area.height); 320 event->area.width, event->area.height);
334 return FALSE; 321 return FALSE;
335} 322}
@@ -340,10 +327,10 @@ load_graph_stop (LoadGraph * g)
340 if (!g) 327 if (!g)
341 return; 328 return;
342 if (g->timer_index != -1) 329 if (g->timer_index != -1)
343 { 330 {
344 gtk_timeout_remove (g->timer_index); 331 gtk_timeout_remove (g->timer_index);
345 g->timer_index = -1; 332 g->timer_index = -1;
346 } 333 }
347 g->draw = FALSE; 334 g->draw = FALSE;
348} 335}
349 336
@@ -351,6 +338,7 @@ static void
351load_graph_destroy (GtkWidget * widget, gpointer data_ptr) 338load_graph_destroy (GtkWidget * widget, gpointer data_ptr)
352{ 339{
353 LoadGraph *g = (LoadGraph *) data_ptr; 340 LoadGraph *g = (LoadGraph *) data_ptr;
341
354 load_graph_stop (g); 342 load_graph_stop (g);
355 if (g->timer_index != -1) 343 if (g->timer_index != -1)
356 gtk_timeout_remove (g->timer_index); 344 gtk_timeout_remove (g->timer_index);
@@ -366,10 +354,10 @@ load_graph_new (int statIdx, const ProcConfig * config)
366 unsigned int i; 354 unsigned int i;
367 355
368 if (stats[statIdx].count > MAX_COLOR) 356 if (stats[statIdx].count > MAX_COLOR)
369 { 357 {
370 GNUNET_GE_BREAK (NULL, 0); 358 GNUNET_GE_BREAK (NULL, 0);
371 return NULL; 359 return NULL;
372 } 360 }
373 361
374 g = GNUNET_malloc (sizeof (LoadGraph)); 362 g = GNUNET_malloc (sizeof (LoadGraph));
375 g->statIdx = statIdx; 363 g->statIdx = statIdx;
@@ -387,13 +375,12 @@ load_graph_new (int statIdx, const ProcConfig * config)
387 gtk_widget_show (g->main_widget); 375 gtk_widget_show (g->main_widget);
388 g->disp = gtk_drawing_area_new (); 376 g->disp = gtk_drawing_area_new ();
389 gtk_widget_show (g->disp); 377 gtk_widget_show (g->disp);
390 gtk_signal_connect (GTK_OBJECT (g->disp), 378 gtk_signal_connect (GTK_OBJECT (g->disp), "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), "configure_event",
393 "configure_event",
394 GTK_SIGNAL_FUNC (load_graph_configure), g); 381 GTK_SIGNAL_FUNC (load_graph_configure), g);
395 gtk_signal_connect (GTK_OBJECT (g->disp), 382 gtk_signal_connect (GTK_OBJECT (g->disp), "destroy",
396 "destroy", GTK_SIGNAL_FUNC (load_graph_destroy), g); 383 GTK_SIGNAL_FUNC (load_graph_destroy), g);
397 gtk_widget_add_events (g->disp, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); 384 gtk_widget_add_events (g->disp, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
398 gtk_box_pack_start (GTK_BOX (g->main_widget), g->disp, TRUE, TRUE, 0); 385 gtk_box_pack_start (GTK_BOX (g->main_widget), g->disp, TRUE, TRUE, 0);
399 load_graph_alloc (g); 386 load_graph_alloc (g);
@@ -419,8 +406,8 @@ create_sys_view (int statIdx, const ProcConfig * config)
419 gtk_container_set_border_width (GTK_CONTAINER (mem_frame), GNOME_PAD_SMALL); 406 gtk_container_set_border_width (GTK_CONTAINER (mem_frame), GNOME_PAD_SMALL);
420 gtk_widget_show (mem_frame); 407 gtk_widget_show (mem_frame);
421 if (mem_graph->timer_index == -1) 408 if (mem_graph->timer_index == -1)
422 mem_graph->timer_index 409 mem_graph->timer_index =
423 = gtk_timeout_add (mem_graph->speed, &load_graph_update, mem_graph); 410 gtk_timeout_add (mem_graph->speed, &load_graph_update, mem_graph);
424 mem_graph->draw = TRUE; 411 mem_graph->draw = TRUE;
425 return mem_frame; 412 return mem_frame;
426} 413}
@@ -430,8 +417,7 @@ create_sys_view (int statIdx, const ProcConfig * config)
430 417
431 418
432void 419void
433init_stats (struct GNUNET_GE_Context *ectx, 420init_stats (struct GNUNET_GE_Context *ectx, struct GNUNET_GC_Configuration *cfg)
434 struct GNUNET_GC_Configuration *cfg)
435{ 421{
436 GtkWidget *statusConnexionsBox; 422 GtkWidget *statusConnexionsBox;
437 GtkWidget *statusConnexionsLabel; 423 GtkWidget *statusConnexionsLabel;
@@ -442,25 +428,22 @@ init_stats (struct GNUNET_GE_Context *ectx,
442 int i; 428 int i;
443 429
444 statusConnexionsLabel = 430 statusConnexionsLabel =
445 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), 431 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
446 "statusConnexionsLabel"); 432 "statusConnexionsLabel");
447 gtk_label_set_width_chars (GTK_LABEL (statusConnexionsLabel), 433 gtk_label_set_width_chars (GTK_LABEL (statusConnexionsLabel),
448 g_utf8_strlen (_("Connected to %Lu peers"), 434 g_utf8_strlen (_("Connected to %Lu peers"),
449 40) - 1); 435 40) - 1);
450 statusConnexionsBox = 436 statusConnexionsBox =
451 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), 437 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
452 "statusConnexionsBox"); 438 "statusConnexionsBox");
453 gtk_widget_set_sensitive (statusConnexionsBox, TRUE); 439 gtk_widget_set_sensitive (statusConnexionsBox, TRUE);
454 GNUNET_GC_get_configuration_value_number (cfg, 440 GNUNET_GC_get_configuration_value_number (cfg, "GNUNET-GTK", "STATS-INTERVAL",
455 "GNUNET-GTK", 441 1, 99 * GNUNET_CRON_YEARS,
456 "STATS-INTERVAL",
457 1,
458 99 * GNUNET_CRON_YEARS,
459 30 * GNUNET_CRON_SECONDS, 442 30 * GNUNET_CRON_SECONDS,
460 &UPDATE_INTERVAL); 443 &UPDATE_INTERVAL);
461 init_functions (ectx, cfg); 444 init_functions (ectx, cfg);
462 notebook = 445 notebook =
463 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "statsNotebook"); 446 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "statsNotebook");
464 memset (&config, 0, sizeof (ProcConfig)); 447 memset (&config, 0, sizeof (ProcConfig));
465 gdk_color_parse ("black", &config.bg_color); 448 gdk_color_parse ("black", &config.bg_color);
466 gdk_color_parse ("gray", &config.frame_color); 449 gdk_color_parse ("gray", &config.frame_color);
@@ -473,14 +456,14 @@ init_stats (struct GNUNET_GE_Context *ectx,
473 GNUNET_GE_ASSERT (ectx, MAX_COLOR == 6); 456 GNUNET_GE_ASSERT (ectx, MAX_COLOR == 6);
474 i = -1; 457 i = -1;
475 while (stats[++i].paneName != NULL) 458 while (stats[++i].paneName != NULL)
476 { 459 {
477 sys_box = create_sys_view (i, &config); 460 sys_box = create_sys_view (i, &config);
478 if (sys_box == NULL) 461 if (sys_box == NULL)
479 continue; /* oops */ 462 continue; /* oops */
480 463
481 label = gtk_label_new (gettext (stats[i].paneName)); 464 label = gtk_label_new (gettext (stats[i].paneName));
482 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, label); 465 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, label);
483 } 466 }
484 gtk_widget_show (notebook); 467 gtk_widget_show (notebook);
485} 468}
486 469