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.c126
1 files changed, 63 insertions, 63 deletions
diff --git a/src/plugins/stats/statistics.c b/src/plugins/stats/statistics.c
index badbc303..db44f720 100644
--- a/src/plugins/stats/statistics.c
+++ b/src/plugins/stats/statistics.c
@@ -37,8 +37,8 @@ typedef struct {
37 guint count; 37 guint count;
38 guint speed; 38 guint speed;
39 guint draw_width, draw_height; 39 guint draw_width, draw_height;
40 guint num_points; 40 guint num_points;
41 guint allocated; 41 guint allocated;
42 GdkColor *colors; 42 GdkColor *colors;
43 gfloat **data, **odata; 43 gfloat **data, **odata;
44 guint data_size; 44 guint data_size;
@@ -48,7 +48,7 @@ typedef struct {
48 GtkWidget *label; 48 GtkWidget *label;
49 GdkPixmap *pixmap; 49 GdkPixmap *pixmap;
50 GdkGC *gc; 50 GdkGC *gc;
51 int timer_index; 51 int timer_index;
52 gboolean draw; 52 gboolean draw;
53 int statIdx; 53 int statIdx;
54} LoadGraph; 54} LoadGraph;
@@ -60,39 +60,39 @@ typedef struct {
60} ProcConfig; 60} ProcConfig;
61 61
62/** 62/**
63 * Redraws the backing pixmap for the load graph and updates the window 63 * Redraws the backing pixmap for the load graph and updates the window
64 */ 64 */
65static void load_graph_draw(LoadGraph *g) { 65static void load_graph_draw(LoadGraph *g) {
66 guint i; 66 guint i;
67 guint j; 67 guint j;
68 gint dely; 68 gint dely;
69 float delx; 69 float delx;
70 70
71 if (!g->disp->window) 71 if (!g->disp->window)
72 return; 72 return;
73 73
74 g->draw_width = g->disp->allocation.width; 74 g->draw_width = g->disp->allocation.width;
75 g->draw_height = g->disp->allocation.height; 75 g->draw_height = g->disp->allocation.height;
76 76
77 if (!g->pixmap) 77 if (!g->pixmap)
78 g->pixmap = gdk_pixmap_new (g->disp->window, 78 g->pixmap = gdk_pixmap_new (g->disp->window,
79 g->draw_width, g->draw_height, 79 g->draw_width, g->draw_height,
80 gtk_widget_get_visual (g->disp)->depth); 80 gtk_widget_get_visual (g->disp)->depth);
81 81
82 /* Create GC if necessary. */ 82 /* Create GC if necessary. */
83 if (!g->gc) { 83 if (!g->gc) {
84 g->gc = gdk_gc_new (g->disp->window); 84 g->gc = gdk_gc_new (g->disp->window);
85 gdk_gc_copy (g->gc, g->disp->style->white_gc); 85 gdk_gc_copy (g->gc, g->disp->style->white_gc);
86 } 86 }
87 87
88 /* Allocate colors. */ 88 /* Allocate colors. */
89 if (!g->colors_allocated) { 89 if (!g->colors_allocated) {
90 GdkColormap *colormap; 90 GdkColormap *colormap;
91 91
92 colormap = gdk_window_get_colormap (g->disp->window); 92 colormap = gdk_window_get_colormap (g->disp->window);
93 for (i=0;i<2+g->count;i++) 93 for (i=0;i<2+g->count;i++)
94 gdk_color_alloc (colormap, &(g->colors [i])); 94 gdk_color_alloc (colormap, &(g->colors [i]));
95 95
96 g->colors_allocated = 1; 96 g->colors_allocated = 1;
97 } 97 }
98 /* Erase Rectangle */ 98 /* Erase Rectangle */
@@ -102,7 +102,7 @@ static void load_graph_draw(LoadGraph *g) {
102 TRUE, 0, 0, 102 TRUE, 0, 0,
103 g->disp->allocation.width, 103 g->disp->allocation.width,
104 g->disp->allocation.height); 104 g->disp->allocation.height);
105 105
106 /* draw frame */ 106 /* draw frame */
107 gdk_gc_set_foreground (g->gc, &(g->colors [1])); 107 gdk_gc_set_foreground (g->gc, &(g->colors [1]));
108 gdk_draw_rectangle (g->pixmap, 108 gdk_draw_rectangle (g->pixmap,
@@ -110,39 +110,39 @@ static void load_graph_draw(LoadGraph *g) {
110 FALSE, 0, 0, 110 FALSE, 0, 0,
111 g->draw_width, 111 g->draw_width,
112 g->disp->allocation.height); 112 g->disp->allocation.height);
113 113
114 dely = g->draw_height / 5; 114 dely = g->draw_height / 5;
115 for (i = 1; i <5; i++) { 115 for (i = 1; i <5; i++) {
116 gint y1 = g->draw_height + 1 - i * dely; 116 gint y1 = g->draw_height + 1 - i * dely;
117 gdk_draw_line (g->pixmap, g->gc, 117 gdk_draw_line (g->pixmap, g->gc,
118 0, y1, g->draw_width, y1); 118 0, y1, g->draw_width, y1);
119 } 119 }
120 120
121 gdk_gc_set_line_attributes(g->gc, 121 gdk_gc_set_line_attributes(g->gc,
122 2, 122 2,
123 GDK_LINE_SOLID, 123 GDK_LINE_SOLID,
124 GDK_CAP_ROUND, 124 GDK_CAP_ROUND,
125 GDK_JOIN_MITER); 125 GDK_JOIN_MITER);
126 delx = (float)g->draw_width / ( g->num_points - 1); 126 delx = (float)g->draw_width / ( g->num_points - 1);
127 127
128 for (j=0;j<g->count;j++) { 128 for (j=0;j<g->count;j++) {
129 gdk_gc_set_foreground (g->gc, &(g->colors [j + 2])); 129 gdk_gc_set_foreground (g->gc, &(g->colors [j + 2]));
130 for (i = 0; i < g->num_points - 1; i++) { 130 for (i = 0; i < g->num_points - 1; i++) {
131 gint x1 = i * delx; 131 gint x1 = i * delx;
132 gint x2 = (i + 1) * delx; 132 gint x2 = (i + 1) * delx;
133 gint y1 = g->data[i][j] * g->draw_height - 1; 133 gint y1 = g->data[i][j] * g->draw_height - 1;
134 gint y2 = g->data[i+1][j] * g->draw_height - 1; 134 gint y2 = g->data[i+1][j] * g->draw_height - 1;
135 135
136 if ((g->data[i][j] != -1) && (g->data[i+1][j] != -1)) { 136 if ((g->data[i][j] != -1) && (g->data[i+1][j] != -1)) {
137 if (stats[g->statIdx].fill == NO) { 137 if (stats[g->statIdx].fill == NO) {
138 gdk_draw_line(g->pixmap, g->gc, 138 gdk_draw_line(g->pixmap, g->gc,
139 g->draw_width - x2, 139 g->draw_width - x2,
140 g->draw_height - y2, 140 g->draw_height - y2,
141 g->draw_width - x1, 141 g->draw_width - x1,
142 g->draw_height - y1); 142 g->draw_height - y1);
143 } else { 143 } else {
144 GdkPoint points[4]; 144 GdkPoint points[4];
145 145
146 points[0].x = g->draw_width - x2; 146 points[0].x = g->draw_width - x2;
147 points[0].y = g->draw_height - y2; 147 points[0].y = g->draw_height - y2;
148 points[1].x = g->draw_width - x1; 148 points[1].x = g->draw_width - x1;
@@ -162,17 +162,17 @@ static void load_graph_draw(LoadGraph *g) {
162 g->gc, 162 g->gc,
163 1, 163 1,
164 points, 164 points,
165 4); 165 4);
166 } 166 }
167 } 167 }
168 } 168 }
169 } 169 }
170 170
171 gdk_gc_set_line_attributes (g->gc, 1, 171 gdk_gc_set_line_attributes (g->gc, 1,
172 GDK_LINE_SOLID, 172 GDK_LINE_SOLID,
173 GDK_CAP_ROUND, 173 GDK_CAP_ROUND,
174 GDK_JOIN_MITER ); 174 GDK_JOIN_MITER );
175 175
176 gdk_draw_pixmap (g->disp->window, 176 gdk_draw_pixmap (g->disp->window,
177 g->disp->style->fg_gc [GTK_WIDGET_STATE(g->disp)], 177 g->disp->style->fg_gc [GTK_WIDGET_STATE(g->disp)],
178 g->pixmap, 178 g->pixmap,
@@ -186,20 +186,20 @@ static void load_graph_draw(LoadGraph *g) {
186/* Updates the load graph when the timeout expires */ 186/* Updates the load graph when the timeout expires */
187static gboolean load_graph_update(gpointer ptr) { 187static gboolean load_graph_update(gpointer ptr) {
188 LoadGraph *g = ptr; 188 LoadGraph *g = ptr;
189 guint i; 189 guint i;
190 guint j; 190 guint j;
191 191
192 for (i=0;i<g->num_points;i++) 192 for (i=0;i<g->num_points;i++)
193 memcpy(g->odata[i], 193 memcpy(g->odata[i],
194 g->data[i], 194 g->data[i],
195 g->data_size * g->count); 195 g->data_size * g->count);
196 stats[g->statIdx].getData(stats[g->statIdx].get_closure, 196 stats[g->statIdx].getData(stats[g->statIdx].get_closure,
197 g->data); 197 g->data);
198 for (i=0;i<g->num_points-1;i++) 198 for (i=0;i<g->num_points-1;i++)
199 for (j=0;j<g->count;j++) 199 for (j=0;j<g->count;j++)
200 g->data[i+1][j] = g->odata[i][j]; 200 g->data[i+1][j] = g->odata[i][j];
201 if (g->draw) 201 if (g->draw)
202 load_graph_draw (g); 202 load_graph_draw (g);
203 return TRUE; 203 return TRUE;
204} 204}
205 205
@@ -227,30 +227,30 @@ static void load_graph_alloc (LoadGraph *g) {
227 227
228 if (g->allocated) 228 if (g->allocated)
229 return; 229 return;
230 230
231 g->data = MALLOC(sizeof(gfloat *) * g->num_points); 231 g->data = MALLOC(sizeof(gfloat *) * g->num_points);
232 g->odata = MALLOC(sizeof(gfloat*) * g->num_points); 232 g->odata = MALLOC(sizeof(gfloat*) * g->num_points);
233 g->data_size = sizeof (gfloat); 233 g->data_size = sizeof (gfloat);
234 for (i = 0; i < g->num_points; i++) { 234 for (i = 0; i < g->num_points; i++) {
235 g->data[i] = MALLOC(g->data_size * g->count); 235 g->data[i] = MALLOC(g->data_size * g->count);
236 g->odata[i] = MALLOC(g->data_size * g->count); 236 g->odata[i] = MALLOC(g->data_size * g->count);
237 } 237 }
238 for (i=0;i<g->num_points;i++) 238 for (i=0;i<g->num_points;i++)
239 for (j=0;j<g->count;j++) 239 for (j=0;j<g->count;j++)
240 g->data[i][j] = -1; 240 g->data[i][j] = -1;
241 g->allocated = TRUE; 241 g->allocated = TRUE;
242} 242}
243 243
244static gint load_graph_configure(GtkWidget *widget, 244static gint load_graph_configure(GtkWidget *widget,
245 GdkEventConfigure *event, 245 GdkEventConfigure *event,
246 gpointer data_ptr) { 246 gpointer data_ptr) {
247 LoadGraph *c = (LoadGraph *) data_ptr; 247 LoadGraph *c = (LoadGraph *) data_ptr;
248 248
249 if (c->pixmap) { 249 if (c->pixmap) {
250 gdk_pixmap_unref (c->pixmap); 250 gdk_pixmap_unref (c->pixmap);
251 c->pixmap = NULL; 251 c->pixmap = NULL;
252 } 252 }
253 253
254 if (!c->pixmap) 254 if (!c->pixmap)
255 c->pixmap = gdk_pixmap_new(widget->window, 255 c->pixmap = gdk_pixmap_new(widget->window,
256 widget->allocation.width, 256 widget->allocation.width,
@@ -267,9 +267,9 @@ static gint load_graph_configure(GtkWidget *widget,
267 0, 0, 267 0, 0,
268 0, 0, 268 0, 0,
269 c->disp->allocation.width, 269 c->disp->allocation.width,
270 c->disp->allocation.height); 270 c->disp->allocation.height);
271 271
272 load_graph_draw(c); 272 load_graph_draw(c);
273 return TRUE; 273 return TRUE;
274} 274}
275 275
@@ -277,7 +277,7 @@ static gint load_graph_expose(GtkWidget *widget,
277 GdkEventExpose *event, 277 GdkEventExpose *event,
278 gpointer data_ptr) { 278 gpointer data_ptr) {
279 LoadGraph *g = (LoadGraph *) data_ptr; 279 LoadGraph *g = (LoadGraph *) data_ptr;
280 280
281 gdk_draw_pixmap(widget->window, 281 gdk_draw_pixmap(widget->window,
282 widget->style->fg_gc [GTK_WIDGET_STATE(widget)], 282 widget->style->fg_gc [GTK_WIDGET_STATE(widget)],
283 g->pixmap, 283 g->pixmap,
@@ -297,10 +297,10 @@ static void load_graph_stop (LoadGraph *g) {
297 g->draw = FALSE; 297 g->draw = FALSE;
298} 298}
299 299
300static void load_graph_destroy(GtkWidget *widget, 300static void load_graph_destroy(GtkWidget *widget,
301 gpointer data_ptr) { 301 gpointer data_ptr) {
302 LoadGraph *g = (LoadGraph *) data_ptr; 302 LoadGraph *g = (LoadGraph *) data_ptr;
303 load_graph_stop(g); 303 load_graph_stop(g);
304 if (g->timer_index != -1) 304 if (g->timer_index != -1)
305 gtk_timeout_remove (g->timer_index); 305 gtk_timeout_remove (g->timer_index);
306 load_graph_unalloc(g); 306 load_graph_unalloc(g);
@@ -317,7 +317,7 @@ static LoadGraph * load_graph_new(int statIdx,
317 BREAK(); 317 BREAK();
318 return NULL; 318 return NULL;
319 } 319 }
320 320
321 g = MALLOC(sizeof(LoadGraph)); 321 g = MALLOC(sizeof(LoadGraph));
322 g->statIdx = statIdx; 322 g->statIdx = statIdx;
323 g->count = stats[statIdx].count; 323 g->count = stats[statIdx].count;
@@ -325,8 +325,8 @@ static LoadGraph * load_graph_new(int statIdx,
325 g->num_points = 600; 325 g->num_points = 600;
326 g->colors = MALLOC(sizeof(GdkColor) * (2+g->count)); 326 g->colors = MALLOC(sizeof(GdkColor) * (2+g->count));
327 g->colors[0] = config->bg_color; 327 g->colors[0] = config->bg_color;
328 g->colors[1] = config->frame_color; 328 g->colors[1] = config->frame_color;
329 for (i=0;i<g->count;i++) 329 for (i=0;i<g->count;i++)
330 g->colors[2+i] = config->mem_color[i]; 330 g->colors[2+i] = config->mem_color[i];
331 g->timer_index = -1; 331 g->timer_index = -1;
332 g->draw = FALSE; 332 g->draw = FALSE;
@@ -337,24 +337,24 @@ static LoadGraph * load_graph_new(int statIdx,
337 gtk_signal_connect(GTK_OBJECT (g->disp), 337 gtk_signal_connect(GTK_OBJECT (g->disp),
338 "expose_event", 338 "expose_event",
339 GTK_SIGNAL_FUNC (load_graph_expose), g); 339 GTK_SIGNAL_FUNC (load_graph_expose), g);
340 gtk_signal_connect(GTK_OBJECT(g->disp), 340 gtk_signal_connect(GTK_OBJECT(g->disp),
341 "configure_event", 341 "configure_event",
342 GTK_SIGNAL_FUNC (load_graph_configure), g); 342 GTK_SIGNAL_FUNC (load_graph_configure), g);
343 gtk_signal_connect(GTK_OBJECT(g->disp), 343 gtk_signal_connect(GTK_OBJECT(g->disp),
344 "destroy", 344 "destroy",
345 GTK_SIGNAL_FUNC (load_graph_destroy), g); 345 GTK_SIGNAL_FUNC (load_graph_destroy), g);
346 gtk_widget_add_events(g->disp, 346 gtk_widget_add_events(g->disp,
347 GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); 347 GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
348 gtk_box_pack_start(GTK_BOX(g->main_widget), 348 gtk_box_pack_start(GTK_BOX(g->main_widget),
349 g->disp, 349 g->disp,
350 TRUE, 350 TRUE,
351 TRUE, 351 TRUE,
352 0); 352 0);
353 load_graph_alloc(g); 353 load_graph_alloc(g);
354 gtk_widget_show_all(g->main_widget); 354 gtk_widget_show_all(g->main_widget);
355 g->timer_index = gtk_timeout_add(g->speed, 355 g->timer_index = gtk_timeout_add(g->speed,
356 &load_graph_update, g); 356 &load_graph_update, g);
357 357
358 return g; 358 return g;
359} 359}
360 360
@@ -395,12 +395,12 @@ void init_stats() {
395 ProcConfig config; 395 ProcConfig config;
396 int i; 396 int i;
397 397
398 init_functions(); 398 init_functions();
399 notebook 399 notebook
400 = glade_xml_get_widget(getMainXML(), 400 = glade_xml_get_widget(getMainXML(),
401 "statsNotebook"); 401 "statsNotebook");
402 memset(&config, 402 memset(&config,
403 0, 403 0,
404 sizeof(ProcConfig)); 404 sizeof(ProcConfig));
405 gdk_color_parse("black", 405 gdk_color_parse("black",
406 &config.bg_color); 406 &config.bg_color);
@@ -419,14 +419,14 @@ void init_stats() {
419 while (stats[++i].paneName != NULL) { 419 while (stats[++i].paneName != NULL) {
420 sys_box = create_sys_view(i, 420 sys_box = create_sys_view(i,
421 &config); 421 &config);
422 if (sys_box == NULL) 422 if (sys_box == NULL)
423 continue; /* oops */ 423 continue; /* oops */
424 424
425 label = gtk_label_new(gettext(stats[i].paneName)); 425 label = gtk_label_new(gettext(stats[i].paneName));
426 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), 426 gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
427 sys_box, 427 sys_box,
428 label); 428 label);
429 } 429 }
430 gtk_widget_show(notebook); 430 gtk_widget_show(notebook);
431} 431}
432 432
@@ -434,5 +434,5 @@ void done_stats() {
434 done_functions(); 434 done_functions();
435} 435}
436 436
437 437
438/* end of statistics.c */ 438/* end of statistics.c */