diff options
Diffstat (limited to 'src/plugins/stats/statistics.c')
-rw-r--r-- | src/plugins/stats/statistics.c | 725 |
1 files changed, 120 insertions, 605 deletions
diff --git a/src/plugins/stats/statistics.c b/src/plugins/stats/statistics.c index 9a4be685..09eec75b 100644 --- a/src/plugins/stats/statistics.c +++ b/src/plugins/stats/statistics.c | |||
@@ -19,491 +19,17 @@ | |||
19 | 19 | ||
20 | Portions of this code were adopted from the | 20 | Portions of this code were adopted from the |
21 | gnome-system-monitor v2.0.5, (C) 2001 Kevin Vandersloot | 21 | gnome-system-monitor v2.0.5, (C) 2001 Kevin Vandersloot |
22 | |||
23 | |||
24 | Todo: | ||
25 | - add any more StatEntries, update menu accordingly. | ||
26 | */ | 22 | */ |
27 | 23 | ||
28 | #include "platform.h" | 24 | #include "platform.h" |
29 | #include "gnunetgtk_common.h" | 25 | #include "gnunetgtk_common.h" |
30 | #include <GNUnet/gnunet_stats_lib.h> | 26 | #include <GNUnet/gnunet_stats_lib.h> |
27 | #include <GNUnet/gnunet_getoption_lib.h> | ||
28 | #include "functions.h" | ||
31 | 29 | ||
32 | #define UPDATE_INTERVAL (30 * cronSECONDS) | 30 | #define MAX_COLOR 4 |
33 | #define STAT_CONNECTIVITY 0 | 31 | #define GNOME_PAD_SMALL 2 |
34 | #define STAT_CPU_LOAD 1 | 32 | #define FRAME_WIDTH 0 |
35 | #define STAT_IN_TRAFFIC 2 | ||
36 | #define STAT_OUT_TRAFFIC 3 | ||
37 | |||
38 | |||
39 | typedef struct { | ||
40 | char * statName; | ||
41 | long long value; | ||
42 | long long lvalue; | ||
43 | cron_t delta; | ||
44 | } StatPair; | ||
45 | |||
46 | static StatPair * lastStatValues; | ||
47 | static unsigned int lsv_size; | ||
48 | static cron_t lastUpdate; | ||
49 | static Mutex lock; | ||
50 | |||
51 | static void updateStatValues(GNUNET_TCP_SOCKET * sock) { | ||
52 | STATS_CS_MESSAGE * statMsg; | ||
53 | CS_HEADER csHdr; | ||
54 | unsigned int count; | ||
55 | unsigned int i; | ||
56 | int j; | ||
57 | int mpos; | ||
58 | int found; | ||
59 | char * optName; | ||
60 | cron_t now; | ||
61 | cron_t prev; | ||
62 | |||
63 | cronTime(&now); | ||
64 | MUTEX_LOCK(&lock); | ||
65 | if (now - lastUpdate < UPDATE_INTERVAL) { | ||
66 | MUTEX_UNLOCK(&lock); | ||
67 | return; | ||
68 | } | ||
69 | prev = lastUpdate; | ||
70 | lastUpdate = now; | ||
71 | csHdr.size | ||
72 | = htons(sizeof(CS_HEADER)); | ||
73 | csHdr.tcpType | ||
74 | = htons(STATS_CS_PROTO_GET_STATISTICS); | ||
75 | if (SYSERR == writeToSocket(sock, | ||
76 | &csHdr)) { | ||
77 | MUTEX_UNLOCK(&lock); | ||
78 | return; | ||
79 | } | ||
80 | statMsg | ||
81 | = MALLOC(MAX_BUFFER_SIZE); | ||
82 | statMsg->totalCounters | ||
83 | = htonl(1); /* to ensure we enter the loop */ | ||
84 | count = 0; | ||
85 | while ( count < ntohl(statMsg->totalCounters) ) { | ||
86 | if (SYSERR == readFromSocket(sock, | ||
87 | (CS_HEADER**)&statMsg)) { | ||
88 | FREE(statMsg); | ||
89 | MUTEX_UNLOCK(&lock); | ||
90 | return; | ||
91 | } | ||
92 | if (ntohs(statMsg->header.size) < sizeof(STATS_CS_MESSAGE)) { | ||
93 | BREAK(); | ||
94 | break; | ||
95 | } | ||
96 | mpos = sizeof(unsigned long long) * ntohl(statMsg->statCounters); | ||
97 | if ( ((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values)) | ||
98 | [ntohs(statMsg->header.size) - sizeof(STATS_CS_MESSAGE) - 1] != '\0') { | ||
99 | BREAK(); | ||
100 | break; | ||
101 | } | ||
102 | for (i=0;i<ntohl(statMsg->statCounters);i++) { | ||
103 | optName = &((char*)(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values))[mpos]; | ||
104 | if ( (mpos > ntohs(statMsg->header.size) - sizeof(STATS_CS_MESSAGE)) || | ||
105 | (mpos + strlen(optName) + 1 > | ||
106 | ntohs(statMsg->header.size) - sizeof(STATS_CS_MESSAGE)) ) { | ||
107 | BREAK(); | ||
108 | break; /* out of bounds! */ | ||
109 | } | ||
110 | found = -1; | ||
111 | for (j=0;j<lsv_size;j++) | ||
112 | if (0 == strcmp(optName, | ||
113 | lastStatValues[j].statName)) | ||
114 | found = j; | ||
115 | if (found == -1) { | ||
116 | found = lsv_size; | ||
117 | GROW(lastStatValues, | ||
118 | lsv_size, | ||
119 | lsv_size+1); | ||
120 | lastStatValues[found].statName | ||
121 | = STRDUP(optName); | ||
122 | } | ||
123 | lastStatValues[found].lvalue | ||
124 | = lastStatValues[found].value; | ||
125 | lastStatValues[found].value | ||
126 | = ntohll(((STATS_CS_MESSAGE_GENERIC*)statMsg)->values[i]); | ||
127 | lastStatValues[found].delta | ||
128 | = now-prev; | ||
129 | mpos += strlen(optName)+1; | ||
130 | } | ||
131 | count += ntohl(statMsg->statCounters); | ||
132 | } /* end while */ | ||
133 | FREE(statMsg); | ||
134 | MUTEX_UNLOCK(&lock); | ||
135 | } | ||
136 | |||
137 | static int getStatValue(long long * value, | ||
138 | long long * lvalue, | ||
139 | cron_t * dtime, | ||
140 | GNUNET_TCP_SOCKET * sock, | ||
141 | const char * optName) { | ||
142 | unsigned int i; | ||
143 | |||
144 | *value = 0; | ||
145 | if (lvalue != NULL) | ||
146 | *lvalue = 0; | ||
147 | updateStatValues(sock); | ||
148 | MUTEX_LOCK(&lock); | ||
149 | for (i=0;i<lsv_size;i++) { | ||
150 | if (0 == strcmp(optName, | ||
151 | lastStatValues[i].statName)) { | ||
152 | *value = lastStatValues[i].value; | ||
153 | if (lvalue != NULL) | ||
154 | *lvalue = lastStatValues[i].lvalue; | ||
155 | if (dtime != NULL) | ||
156 | *dtime = lastStatValues[i].delta; | ||
157 | MUTEX_UNLOCK(&lock); | ||
158 | return OK; | ||
159 | } | ||
160 | } | ||
161 | MUTEX_UNLOCK(&lock); | ||
162 | return SYSERR; | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * Callback function to obtain the latest stats | ||
167 | * data for this stat display. | ||
168 | */ | ||
169 | typedef int (*UpdateData)(GNUNET_TCP_SOCKET * sock, | ||
170 | const void * closure, | ||
171 | gfloat ** data); | ||
172 | |||
173 | static int getConnectedNodesStat(GNUNET_TCP_SOCKET * sock, | ||
174 | const void * closure, | ||
175 | gfloat ** data) { | ||
176 | long long val; | ||
177 | char * cmh; | ||
178 | long cval; | ||
179 | |||
180 | cmh = getConfigurationOptionValue(sock, | ||
181 | "gnunetd", | ||
182 | "connection-max-hosts"); | ||
183 | if (cmh == NULL) | ||
184 | return SYSERR; | ||
185 | cval = atol(cmh); | ||
186 | FREE(cmh); | ||
187 | if (OK != getStatValue(&val, | ||
188 | NULL, | ||
189 | NULL, | ||
190 | sock, | ||
191 | _("# currently connected nodes"))) | ||
192 | return SYSERR; | ||
193 | data[0][0] = 0.8 * val / cval; | ||
194 | return OK; | ||
195 | } | ||
196 | |||
197 | static int getCPULoadStat(GNUNET_TCP_SOCKET * sock, | ||
198 | const void * closure, | ||
199 | gfloat ** data) { | ||
200 | long long val; | ||
201 | |||
202 | if (OK != getStatValue(&val, | ||
203 | NULL, | ||
204 | NULL, | ||
205 | sock, | ||
206 | _("% of allowed cpu load"))) | ||
207 | return SYSERR; | ||
208 | data[0][0] = val / 125.0; | ||
209 | return OK; | ||
210 | } | ||
211 | |||
212 | static const unsigned short afs_protocol_messages_queries[] = { | ||
213 | AFS_p2p_PROTO_QUERY, | ||
214 | AFS_p2p_PROTO_NSQUERY, | ||
215 | 0, | ||
216 | }; | ||
217 | |||
218 | static const unsigned short afs_protocol_messages_content[] = { | ||
219 | AFS_p2p_PROTO_3HASH_RESULT, | ||
220 | AFS_p2p_PROTO_CHK_RESULT, | ||
221 | AFS_p2p_PROTO_SBLOCK_RESULT, | ||
222 | 0, | ||
223 | }; | ||
224 | |||
225 | static int getTrafficRecvStats(GNUNET_TCP_SOCKET * sock, | ||
226 | const void * closure, | ||
227 | gfloat ** data) { | ||
228 | long long total; | ||
229 | long long noise; | ||
230 | long long content; | ||
231 | long long queries; | ||
232 | long long ltotal; | ||
233 | long long lnoise; | ||
234 | long long lcontent; | ||
235 | long long lqueries; | ||
236 | long long band; | ||
237 | long long tmp; | ||
238 | long long ltmp; | ||
239 | cron_t dtime; | ||
240 | char * available; | ||
241 | char * buffer; | ||
242 | int i; | ||
243 | |||
244 | MUTEX_LOCK(&lock); | ||
245 | if (OK != getStatValue(&total, | ||
246 | <otal, | ||
247 | &dtime, | ||
248 | sock, | ||
249 | _("# bytes decrypted"))) | ||
250 | return SYSERR; | ||
251 | if (OK != getStatValue(&noise, | ||
252 | &lnoise, | ||
253 | NULL, | ||
254 | sock, | ||
255 | _("# bytes of noise received"))) | ||
256 | return SYSERR; | ||
257 | i = 0; | ||
258 | content = lcontent = 0; | ||
259 | buffer = MALLOC(512); | ||
260 | while (afs_protocol_messages_content[i] != 0) { | ||
261 | SNPRINTF(buffer, | ||
262 | 512, | ||
263 | _("# bytes received of type %d"), | ||
264 | afs_protocol_messages_content[i++]); | ||
265 | if (OK == getStatValue(&tmp, | ||
266 | <mp, | ||
267 | NULL, | ||
268 | sock, | ||
269 | buffer)) { | ||
270 | content += tmp; | ||
271 | lcontent += ltmp; | ||
272 | } | ||
273 | } | ||
274 | i = 0; | ||
275 | while (afs_protocol_messages_queries[i] != 0) { | ||
276 | SNPRINTF(buffer, | ||
277 | 512, | ||
278 | _("# bytes received of type %d"), | ||
279 | afs_protocol_messages_queries[i++]); | ||
280 | if (OK == getStatValue(&tmp, | ||
281 | <mp, | ||
282 | NULL, | ||
283 | sock, | ||
284 | buffer)) { | ||
285 | queries += tmp; | ||
286 | lqueries += ltmp; | ||
287 | } | ||
288 | } | ||
289 | FREE(buffer); | ||
290 | MUTEX_UNLOCK(&lock); | ||
291 | available = getConfigurationOptionValue(sock, | ||
292 | "LOAD", | ||
293 | "MAXNETDOWNBPSTOTAL"); | ||
294 | if (available == NULL) | ||
295 | return SYSERR; | ||
296 | band = atol(available) * dtime / cronSECONDS; | ||
297 | FREE(available); | ||
298 | total -= ltotal; | ||
299 | noise -= lnoise; | ||
300 | queries -= lqueries; | ||
301 | content -= lcontent; | ||
302 | if (band <= 0) { | ||
303 | data[0][0] = 0.0; | ||
304 | data[0][1] = 0.0; | ||
305 | data[0][2] = 0.0; | ||
306 | data[0][3] = 0.0; | ||
307 | return OK; | ||
308 | } | ||
309 | data[0][0] = 0.8 * noise / band; /* red */ | ||
310 | data[0][1] = 0.8 * (content+noise) / band; /* green */ | ||
311 | data[0][2] = 0.8 * (queries+content+noise) / band; /* yellow */ | ||
312 | data[0][3] = 0.8 * total / band; /* blue */ | ||
313 | /*printf("I: %f %f %f\n", | ||
314 | data[0][0], | ||
315 | data[0][1], | ||
316 | data[0][2]);*/ | ||
317 | |||
318 | return OK; | ||
319 | } | ||
320 | |||
321 | |||
322 | static int getTrafficSendStats(GNUNET_TCP_SOCKET * sock, | ||
323 | const void * closure, | ||
324 | gfloat ** data) { | ||
325 | long long total; | ||
326 | long long noise; | ||
327 | long long content; | ||
328 | long long queries; | ||
329 | long long ltotal; | ||
330 | long long lnoise; | ||
331 | long long lcontent; | ||
332 | long long lqueries; | ||
333 | long long band; | ||
334 | long long tmp; | ||
335 | long long ltmp; | ||
336 | cron_t dtime; | ||
337 | char * available; | ||
338 | char * buffer; | ||
339 | int i; | ||
340 | |||
341 | MUTEX_LOCK(&lock); | ||
342 | if (OK != getStatValue(&total, | ||
343 | <otal, | ||
344 | &dtime, | ||
345 | sock, | ||
346 | _("# encrypted bytes sent"))) | ||
347 | return SYSERR; | ||
348 | if (OK != getStatValue(&noise, | ||
349 | &lnoise, | ||
350 | NULL, | ||
351 | sock, | ||
352 | _("# bytes noise sent"))) | ||
353 | return SYSERR; | ||
354 | i = 0; | ||
355 | content = lcontent = 0; | ||
356 | buffer = MALLOC(512); | ||
357 | while (afs_protocol_messages_content[i] != 0) { | ||
358 | SNPRINTF(buffer, | ||
359 | 512, | ||
360 | _("# bytes transmitted of type %d"), | ||
361 | afs_protocol_messages_content[i++]); | ||
362 | if (OK == getStatValue(&tmp, | ||
363 | <mp, | ||
364 | NULL, | ||
365 | sock, | ||
366 | buffer)) { | ||
367 | content += tmp; | ||
368 | lcontent += ltmp; | ||
369 | } | ||
370 | } | ||
371 | i = 0; | ||
372 | while (afs_protocol_messages_queries[i] != 0) { | ||
373 | SNPRINTF(buffer, | ||
374 | 512, | ||
375 | _("# bytes received of type %d"), | ||
376 | afs_protocol_messages_queries[i++]); | ||
377 | if (OK == getStatValue(&tmp, | ||
378 | <mp, | ||
379 | NULL, | ||
380 | sock, | ||
381 | buffer)) { | ||
382 | queries += tmp; | ||
383 | lqueries += ltmp; | ||
384 | } | ||
385 | } | ||
386 | FREE(buffer); | ||
387 | MUTEX_UNLOCK(&lock); | ||
388 | available = getConfigurationOptionValue(sock, | ||
389 | "LOAD", | ||
390 | "MAXNETUPBPSTOTAL"); | ||
391 | if (available == NULL) | ||
392 | return SYSERR; | ||
393 | band = atol(available) * dtime / cronSECONDS; | ||
394 | FREE(available); | ||
395 | total -= ltotal; | ||
396 | noise -= lnoise; | ||
397 | queries -= lqueries; | ||
398 | content -= lcontent; | ||
399 | if (band <= 0) { | ||
400 | data[0][0] = 0.0; | ||
401 | data[0][1] = 0.0; | ||
402 | data[0][2] = 0.0; | ||
403 | data[0][3] = 0.0; | ||
404 | return OK; | ||
405 | } | ||
406 | data[0][0] = 0.8 * noise / band; /* red */ | ||
407 | data[0][1] = 0.8 * (noise + content) / band; /* green */ | ||
408 | data[0][2] = 0.8 * (noise + content + queries) / band; /* yellow */ | ||
409 | data[0][3] = 0.8 * total / band; /* yellow */ | ||
410 | /* printf("O: %f %f %f\n", | ||
411 | data[0][0], | ||
412 | data[0][1], | ||
413 | data[0][2]);*/ | ||
414 | |||
415 | return OK; | ||
416 | } | ||
417 | |||
418 | |||
419 | |||
420 | typedef struct SE_ { | ||
421 | char * paneName; | ||
422 | char * frameName; | ||
423 | UpdateData getData; | ||
424 | void * get_closure; | ||
425 | unsigned int count; | ||
426 | int fill; /* YES / NO */ | ||
427 | } StatEntry; | ||
428 | |||
429 | #define STATS_COUNT 4 | ||
430 | |||
431 | static StatEntry stats[] = { | ||
432 | { | ||
433 | gettext_noop("Connectivity"), | ||
434 | gettext_noop("# connected nodes (100% = connection table size)"), | ||
435 | &getConnectedNodesStat, | ||
436 | NULL, | ||
437 | 1, | ||
438 | NO, | ||
439 | }, | ||
440 | { | ||
441 | gettext_noop("CPU load"), | ||
442 | gettext_noop("CPU load (in percent of allowed load)"), | ||
443 | &getCPULoadStat, | ||
444 | NULL, | ||
445 | 1, | ||
446 | NO, | ||
447 | }, | ||
448 | { | ||
449 | gettext_noop("Inbound Traffic"), | ||
450 | gettext_noop("Noise (red), Content (green), Queries (yellow), other (blue)"), | ||
451 | &getTrafficRecvStats, | ||
452 | NULL, | ||
453 | 4, | ||
454 | YES, | ||
455 | }, | ||
456 | { | ||
457 | gettext_noop("Outbound Traffic"), | ||
458 | gettext_noop("Noise (red), Content (green), Queries (yellow), other (blue)"), | ||
459 | &getTrafficSendStats, | ||
460 | NULL, | ||
461 | 4, | ||
462 | YES, | ||
463 | }, | ||
464 | { | ||
465 | NULL, | ||
466 | NULL, | ||
467 | NULL, | ||
468 | NULL, | ||
469 | 1, | ||
470 | NO, | ||
471 | }, | ||
472 | }; | ||
473 | |||
474 | |||
475 | /** | ||
476 | * Remove the active page from the notebook. | ||
477 | */ | ||
478 | static void statClose(void) { | ||
479 | gint pagenr; | ||
480 | |||
481 | pagenr = gtk_notebook_get_current_page(notebook); | ||
482 | gtk_notebook_remove_page(notebook, pagenr); | ||
483 | /* Need to refresh the widget -- | ||
484 | This forces the widget to redraw itself. */ | ||
485 | gtk_widget_draw(GTK_WIDGET(notebook), NULL); | ||
486 | } | ||
487 | |||
488 | |||
489 | /** | ||
490 | */ | ||
491 | static void addClosePopupMenu(GtkWidget * widget) { | ||
492 | GtkWidget * menu; | ||
493 | GtkItemFactory * popupFactory; | ||
494 | |||
495 | popupFactory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", | ||
496 | NULL); | ||
497 | gtk_item_factory_create_items(popupFactory, | ||
498 | statWindowMenuItems, | ||
499 | statWindowMenu, | ||
500 | NULL); | ||
501 | menu = gtk_item_factory_get_widget(popupFactory, "<main>"); | ||
502 | gtk_signal_connect(GTK_OBJECT(widget), | ||
503 | "button_press_event", | ||
504 | GTK_SIGNAL_FUNC(popupCallback), | ||
505 | menu); | ||
506 | } | ||
507 | 33 | ||
508 | 34 | ||
509 | typedef struct { | 35 | typedef struct { |
@@ -524,29 +50,15 @@ typedef struct { | |||
524 | GdkGC *gc; | 50 | GdkGC *gc; |
525 | int timer_index; | 51 | int timer_index; |
526 | gboolean draw; | 52 | gboolean draw; |
527 | GNUNET_TCP_SOCKET * sock; | ||
528 | int statIdx; | 53 | int statIdx; |
529 | } LoadGraph; | 54 | } LoadGraph; |
530 | 55 | ||
531 | #define MAX_COLOR 4 | ||
532 | |||
533 | typedef struct { | 56 | typedef struct { |
534 | gint graph_update_interval; | ||
535 | GdkColor bg_color; | 57 | GdkColor bg_color; |
536 | GdkColor frame_color; | 58 | GdkColor frame_color; |
537 | GdkColor mem_color[MAX_COLOR]; | 59 | GdkColor mem_color[MAX_COLOR]; |
538 | } ProcConfig; | 60 | } ProcConfig; |
539 | 61 | ||
540 | typedef struct ProcData { | ||
541 | ProcConfig config; | ||
542 | LoadGraph *mem_graph; | ||
543 | int statIdx; | ||
544 | } ProcData; | ||
545 | |||
546 | #define GNOME_PAD_SMALL 2 | ||
547 | #define FRAME_WIDTH 0 | ||
548 | |||
549 | |||
550 | /** | 62 | /** |
551 | * 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 |
552 | */ | 64 | */ |
@@ -606,7 +118,11 @@ static void load_graph_draw(LoadGraph *g) { | |||
606 | 0, y1, g->draw_width, y1); | 118 | 0, y1, g->draw_width, y1); |
607 | } | 119 | } |
608 | 120 | ||
609 | gdk_gc_set_line_attributes (g->gc, 2, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER ); | 121 | gdk_gc_set_line_attributes(g->gc, |
122 | 2, | ||
123 | GDK_LINE_SOLID, | ||
124 | GDK_CAP_ROUND, | ||
125 | GDK_JOIN_MITER); | ||
610 | delx = (float)g->draw_width / ( g->num_points - 1); | 126 | delx = (float)g->draw_width / ( g->num_points - 1); |
611 | 127 | ||
612 | for (j=0;j<g->count;j++) { | 128 | for (j=0;j<g->count;j++) { |
@@ -652,7 +168,10 @@ static void load_graph_draw(LoadGraph *g) { | |||
652 | } | 168 | } |
653 | } | 169 | } |
654 | 170 | ||
655 | gdk_gc_set_line_attributes (g->gc, 1, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER ); | 171 | gdk_gc_set_line_attributes (g->gc, 1, |
172 | GDK_LINE_SOLID, | ||
173 | GDK_CAP_ROUND, | ||
174 | GDK_JOIN_MITER ); | ||
656 | 175 | ||
657 | gdk_draw_pixmap (g->disp->window, | 176 | gdk_draw_pixmap (g->disp->window, |
658 | g->disp->style->fg_gc [GTK_WIDGET_STATE(g->disp)], | 177 | g->disp->style->fg_gc [GTK_WIDGET_STATE(g->disp)], |
@@ -665,7 +184,8 @@ static void load_graph_draw(LoadGraph *g) { | |||
665 | 184 | ||
666 | 185 | ||
667 | /* Updates the load graph when the timeout expires */ | 186 | /* Updates the load graph when the timeout expires */ |
668 | static int load_graph_update(LoadGraph *g) { | 187 | static gboolean load_graph_update(gpointer ptr) { |
188 | LoadGraph *g = ptr; | ||
669 | guint i; | 189 | guint i; |
670 | guint j; | 190 | guint j; |
671 | 191 | ||
@@ -673,8 +193,7 @@ static int load_graph_update(LoadGraph *g) { | |||
673 | memcpy(g->odata[i], | 193 | memcpy(g->odata[i], |
674 | g->data[i], | 194 | g->data[i], |
675 | g->data_size * g->count); | 195 | g->data_size * g->count); |
676 | stats[g->statIdx].getData(g->sock, | 196 | stats[g->statIdx].getData(stats[g->statIdx].get_closure, |
677 | stats[g->statIdx].get_closure, | ||
678 | g->data); | 197 | g->data); |
679 | for (i=0;i<g->num_points-1;i++) | 198 | for (i=0;i<g->num_points-1;i++) |
680 | for (j=0;j<g->count;j++) | 199 | for (j=0;j<g->count;j++) |
@@ -684,7 +203,7 @@ static int load_graph_update(LoadGraph *g) { | |||
684 | return TRUE; | 203 | return TRUE; |
685 | } | 204 | } |
686 | 205 | ||
687 | static void load_graph_unalloc (LoadGraph *g) { | 206 | static void load_graph_unalloc(LoadGraph *g) { |
688 | int i; | 207 | int i; |
689 | if (!g->allocated) | 208 | if (!g->allocated) |
690 | return; | 209 | return; |
@@ -733,24 +252,24 @@ static gint load_graph_configure(GtkWidget *widget, | |||
733 | } | 252 | } |
734 | 253 | ||
735 | if (!c->pixmap) | 254 | if (!c->pixmap) |
736 | c->pixmap = gdk_pixmap_new (widget->window, | 255 | c->pixmap = gdk_pixmap_new(widget->window, |
737 | widget->allocation.width, | 256 | widget->allocation.width, |
738 | widget->allocation.height, | 257 | widget->allocation.height, |
739 | gtk_widget_get_visual (c->disp)->depth); | 258 | gtk_widget_get_visual (c->disp)->depth); |
740 | gdk_draw_rectangle (c->pixmap, | 259 | gdk_draw_rectangle(c->pixmap, |
741 | widget->style->black_gc, | 260 | widget->style->black_gc, |
742 | TRUE, 0,0, | 261 | TRUE, 0,0, |
743 | widget->allocation.width, | 262 | widget->allocation.width, |
744 | widget->allocation.height); | 263 | widget->allocation.height); |
745 | gdk_draw_pixmap (widget->window, | 264 | gdk_draw_pixmap(widget->window, |
746 | c->disp->style->fg_gc [GTK_WIDGET_STATE(widget)], | 265 | c->disp->style->fg_gc[GTK_WIDGET_STATE(widget)], |
747 | c->pixmap, | 266 | c->pixmap, |
748 | 0, 0, | 267 | 0, 0, |
749 | 0, 0, | 268 | 0, 0, |
750 | c->disp->allocation.width, | 269 | c->disp->allocation.width, |
751 | c->disp->allocation.height); | 270 | c->disp->allocation.height); |
752 | 271 | ||
753 | load_graph_draw (c); | 272 | load_graph_draw(c); |
754 | return TRUE; | 273 | return TRUE; |
755 | } | 274 | } |
756 | 275 | ||
@@ -759,18 +278,18 @@ static gint load_graph_expose(GtkWidget *widget, | |||
759 | gpointer data_ptr) { | 278 | gpointer data_ptr) { |
760 | LoadGraph *g = (LoadGraph *) data_ptr; | 279 | LoadGraph *g = (LoadGraph *) data_ptr; |
761 | 280 | ||
762 | gdk_draw_pixmap (widget->window, | 281 | gdk_draw_pixmap(widget->window, |
763 | widget->style->fg_gc [GTK_WIDGET_STATE(widget)], | 282 | widget->style->fg_gc [GTK_WIDGET_STATE(widget)], |
764 | g->pixmap, | 283 | g->pixmap, |
765 | event->area.x, event->area.y, | 284 | event->area.x, event->area.y, |
766 | event->area.x, event->area.y, | 285 | event->area.x, event->area.y, |
767 | event->area.width, event->area.height); | 286 | event->area.width, event->area.height); |
768 | return FALSE; | 287 | return FALSE; |
769 | } | 288 | } |
770 | 289 | ||
771 | static void load_graph_stop (LoadGraph *g) { | 290 | static void load_graph_stop (LoadGraph *g) { |
772 | if (g->timer_index != -1) { | 291 | if (g->timer_index != -1) { |
773 | gtk_timeout_remove (g->timer_index); | 292 | gtk_timeout_remove(g->timer_index); |
774 | g->timer_index = -1; | 293 | g->timer_index = -1; |
775 | } | 294 | } |
776 | if (!g) | 295 | if (!g) |
@@ -784,139 +303,135 @@ static void load_graph_destroy(GtkWidget *widget, | |||
784 | load_graph_stop(g); | 303 | load_graph_stop(g); |
785 | if (g->timer_index != -1) | 304 | if (g->timer_index != -1) |
786 | gtk_timeout_remove (g->timer_index); | 305 | gtk_timeout_remove (g->timer_index); |
787 | if (g->sock != NULL) | ||
788 | releaseClientSocket(g->sock); | ||
789 | load_graph_unalloc(g); | 306 | load_graph_unalloc(g); |
790 | FREE(g->colors); | 307 | FREE(g->colors); |
791 | FREE(g); | 308 | FREE(g); |
792 | } | 309 | } |
793 | 310 | ||
794 | static LoadGraph * load_graph_new(ProcData *procdata) { | 311 | static LoadGraph * load_graph_new(int statIdx, |
312 | const ProcConfig * config) { | ||
795 | LoadGraph *g; | 313 | LoadGraph *g; |
796 | unsigned int i; | 314 | unsigned int i; |
797 | 315 | ||
798 | if ( (procdata->statIdx < 0) || | 316 | if (stats[statIdx].count > MAX_COLOR) { |
799 | (procdata->statIdx >= STATS_COUNT) ) { | ||
800 | BREAK(); | ||
801 | return NULL; | ||
802 | } | ||
803 | if (stats[procdata->statIdx].count > MAX_COLOR) { | ||
804 | BREAK(); | 317 | BREAK(); |
805 | return NULL; | 318 | return NULL; |
806 | } | 319 | } |
807 | 320 | ||
808 | g = MALLOC(sizeof(LoadGraph)); | 321 | g = MALLOC(sizeof(LoadGraph)); |
809 | g->sock = getClientSocket(); | 322 | g->statIdx = statIdx; |
810 | g->statIdx = procdata->statIdx; | 323 | g->count = stats[statIdx].count; |
811 | g->count = stats[g->statIdx].count; | 324 | g->speed = UPDATE_INTERVAL / cronMILLIS; |
812 | g->speed = procdata->config.graph_update_interval; | ||
813 | g->num_points = 600; | 325 | g->num_points = 600; |
814 | g->colors = MALLOC(sizeof(GdkColor) * (2+g->count)); | 326 | g->colors = MALLOC(sizeof(GdkColor) * (2+g->count)); |
815 | g->colors[0] = procdata->config.bg_color; | 327 | g->colors[0] = config->bg_color; |
816 | g->colors[1] = procdata->config.frame_color; | 328 | g->colors[1] = config->frame_color; |
817 | for (i=0;i<g->count;i++) | 329 | for (i=0;i<g->count;i++) |
818 | g->colors[2+i] = procdata->config.mem_color[i]; | 330 | g->colors[2+i] = config->mem_color[i]; |
819 | g->timer_index = -1; | 331 | g->timer_index = -1; |
820 | g->draw = FALSE; | 332 | g->draw = FALSE; |
821 | g->main_widget = gtk_vbox_new (FALSE, FALSE); | 333 | g->main_widget = gtk_vbox_new (FALSE, FALSE); |
822 | gtk_widget_show (g->main_widget); | 334 | gtk_widget_show(g->main_widget); |
823 | g->disp = gtk_drawing_area_new(); | 335 | g->disp = gtk_drawing_area_new(); |
824 | gtk_widget_show (g->disp); | 336 | gtk_widget_show (g->disp); |
825 | gtk_signal_connect (GTK_OBJECT (g->disp), | 337 | gtk_signal_connect(GTK_OBJECT (g->disp), |
826 | "expose_event", | 338 | "expose_event", |
827 | GTK_SIGNAL_FUNC (load_graph_expose), g); | 339 | GTK_SIGNAL_FUNC (load_graph_expose), g); |
828 | gtk_signal_connect (GTK_OBJECT(g->disp), | 340 | gtk_signal_connect(GTK_OBJECT(g->disp), |
829 | "configure_event", | 341 | "configure_event", |
830 | GTK_SIGNAL_FUNC (load_graph_configure), g); | 342 | GTK_SIGNAL_FUNC (load_graph_configure), g); |
831 | gtk_signal_connect (GTK_OBJECT(g->disp), | 343 | gtk_signal_connect(GTK_OBJECT(g->disp), |
832 | "destroy", | 344 | "destroy", |
833 | GTK_SIGNAL_FUNC (load_graph_destroy), g); | 345 | GTK_SIGNAL_FUNC (load_graph_destroy), g); |
834 | gtk_widget_add_events(g->disp, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); | 346 | gtk_widget_add_events(g->disp, |
835 | gtk_box_pack_start(GTK_BOX (g->main_widget), g->disp, TRUE, TRUE, 0); | 347 | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); |
348 | gtk_box_pack_start(GTK_BOX(g->main_widget), | ||
349 | g->disp, | ||
350 | TRUE, | ||
351 | TRUE, | ||
352 | 0); | ||
836 | load_graph_alloc(g); | 353 | load_graph_alloc(g); |
837 | gtk_widget_show_all (g->main_widget); | 354 | gtk_widget_show_all(g->main_widget); |
838 | g->timer_index = gtk_timeout_add(g->speed, | 355 | g->timer_index = gtk_timeout_add(g->speed, |
839 | (GtkFunction) load_graph_update, g); | 356 | &load_graph_update, g); |
840 | 357 | ||
841 | return g; | 358 | return g; |
842 | } | 359 | } |
843 | 360 | ||
844 | static void load_graph_start(LoadGraph *g) { | 361 | static GtkWidget * create_sys_view(int statIdx, |
845 | if (!g) | 362 | const ProcConfig * config) { |
846 | return; | ||
847 | |||
848 | if (g->timer_index == -1) | ||
849 | g->timer_index = gtk_timeout_add(g->speed, | ||
850 | (GtkFunction) load_graph_update, g); | ||
851 | |||
852 | g->draw = TRUE; | ||
853 | } | ||
854 | |||
855 | static GtkWidget * create_sys_view(ProcData * procdata) { | ||
856 | GtkWidget * mem_frame; | 363 | GtkWidget * mem_frame; |
857 | LoadGraph * mem_graph; | 364 | LoadGraph * mem_graph; |
858 | 365 | ||
859 | mem_graph = load_graph_new(procdata); | 366 | mem_graph = load_graph_new(statIdx, |
860 | procdata->mem_graph = mem_graph; | 367 | config); |
861 | if (mem_graph == NULL) | 368 | if (mem_graph == NULL) |
862 | return NULL; /* oops */ | 369 | return NULL; /* oops */ |
863 | mem_frame = gtk_frame_new(_(stats[procdata->statIdx].frameName)); | 370 | mem_frame = gtk_frame_new(_(stats[statIdx].frameName)); |
864 | gtk_container_add(GTK_CONTAINER(mem_frame), | 371 | gtk_container_add(GTK_CONTAINER(mem_frame), |
865 | mem_graph->main_widget); | 372 | mem_graph->main_widget); |
866 | gtk_container_set_border_width(GTK_CONTAINER(mem_graph->main_widget), | 373 | gtk_container_set_border_width(GTK_CONTAINER(mem_graph->main_widget), |
867 | GNOME_PAD_SMALL); | 374 | GNOME_PAD_SMALL); |
868 | gtk_container_set_border_width (GTK_CONTAINER(mem_frame), | 375 | gtk_container_set_border_width(GTK_CONTAINER(mem_frame), |
869 | GNOME_PAD_SMALL); | 376 | GNOME_PAD_SMALL); |
870 | gtk_widget_show(mem_frame); | 377 | gtk_widget_show(mem_frame); |
871 | addClosePopupMenu(mem_frame); | 378 | if (mem_graph->timer_index == -1) |
379 | mem_graph->timer_index | ||
380 | = gtk_timeout_add(mem_graph->speed, | ||
381 | &load_graph_update, | ||
382 | mem_graph); | ||
383 | mem_graph->draw = TRUE; | ||
872 | return mem_frame; | 384 | return mem_frame; |
873 | } | 385 | } |
874 | 386 | ||
875 | 387 | ||
876 | static GtkWidget * create_main_window(int stat) { | ||
877 | GtkWidget *sys_box; | ||
878 | ProcData procdata; | ||
879 | 388 | ||
880 | 389 | ||
881 | memset(&procdata, 0, sizeof(ProcData)); | 390 | |
882 | procdata.config.graph_update_interval | 391 | void init_stats() { |
883 | = UPDATE_INTERVAL / cronMILLIS; | 392 | GtkWidget * sys_box; |
884 | procdata.statIdx = stat; | 393 | GtkWidget * label; |
394 | GtkWidget * notebook; | ||
395 | ProcConfig config; | ||
396 | int i; | ||
397 | |||
398 | init_functions(); | ||
399 | notebook | ||
400 | = glade_xml_get_widget(getMainXML(), | ||
401 | "downloadNotebook"); | ||
402 | memset(&config, | ||
403 | 0, | ||
404 | sizeof(ProcConfig)); | ||
885 | gdk_color_parse("black", | 405 | gdk_color_parse("black", |
886 | &procdata.config.bg_color); | 406 | &config.bg_color); |
887 | gdk_color_parse("gray", | 407 | gdk_color_parse("gray", |
888 | &procdata.config.frame_color); | 408 | &config.frame_color); |
889 | gdk_color_parse("red", | 409 | gdk_color_parse("red", |
890 | &procdata.config.mem_color[0]); | 410 | &config.mem_color[0]); |
891 | gdk_color_parse("green", | 411 | gdk_color_parse("green", |
892 | &procdata.config.mem_color[1]); | 412 | &config.mem_color[1]); |
893 | gdk_color_parse("yellow", | 413 | gdk_color_parse("yellow", |
894 | &procdata.config.mem_color[2]); | 414 | &config.mem_color[2]); |
895 | gdk_color_parse("blue", | 415 | gdk_color_parse("blue", |
896 | &procdata.config.mem_color[3]); | 416 | &config.mem_color[3]); |
897 | GNUNET_ASSERT(MAX_COLOR == 4); | 417 | GNUNET_ASSERT(MAX_COLOR == 4); |
898 | sys_box = create_sys_view(&procdata); | 418 | i = -1; |
899 | if (sys_box == NULL) | 419 | while (stats[++i].paneName != NULL) { |
900 | return NULL; | 420 | sys_box = create_sys_view(i, |
901 | load_graph_start(procdata.mem_graph); | 421 | &config); |
902 | return sys_box; | 422 | if (sys_box == NULL) |
903 | } | 423 | continue; /* oops */ |
904 | 424 | ||
905 | 425 | label = gtk_label_new(gettext(stats[i].paneName)); | |
906 | 426 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), | |
907 | 427 | sys_box, | |
908 | 428 | label); | |
909 | void init_stats() { | 429 | } |
910 | MUTEX_CREATE_RECURSIVE(&lock); | 430 | gtk_widget_show(notebook); |
911 | wid = create_main_window(dptr); | ||
912 | if (wid != NULL) | ||
913 | addToNotebook(_(stats[dptr].paneName), | ||
914 | wid); | ||
915 | |||
916 | } | 431 | } |
917 | 432 | ||
918 | void done_stats() { | 433 | void done_stats() { |
919 | MUTEX_DESTROY(&lock); | 434 | done_functions(); |
920 | } | 435 | } |
921 | 436 | ||
922 | 437 | ||