aboutsummaryrefslogtreecommitdiff
path: root/src/statistics
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-05-15 15:51:29 +0000
committerng0 <ng0@n0.is>2019-05-15 15:51:29 +0000
commit51cf7682ce12732f75365e2766f481132b3baaee (patch)
treea3f0a8e08c6e93a17216dc66236ad3e157878cd9 /src/statistics
parentf85786c61f2f03c6e3d2d7f00a6b1446bab3c41e (diff)
downloadgnunet-gtk-51cf7682ce12732f75365e2766f481132b3baaee.tar.gz
gnunet-gtk-51cf7682ce12732f75365e2766f481132b3baaee.zip
clang-format all C code. Add symlink of clang-format to bootstrap.
Diffstat (limited to 'src/statistics')
-rw-r--r--src/statistics/functions.c341
-rw-r--r--src/statistics/functions.h4
-rw-r--r--src/statistics/gnunet-statistics-gtk-about.c2
-rw-r--r--src/statistics/gnunet-statistics-gtk.c129
-rw-r--r--src/statistics/gtk_statistics.c173
-rw-r--r--src/statistics/gtk_statistics.h37
-rw-r--r--src/statistics/gtk_statistics_demo.c28
-rw-r--r--src/statistics/statistics.c178
8 files changed, 501 insertions, 391 deletions
diff --git a/src/statistics/functions.c b/src/statistics/functions.c
index 5d205589..f5149dd9 100644
--- a/src/statistics/functions.c
+++ b/src/statistics/functions.c
@@ -50,8 +50,11 @@ static struct GNUNET_GC_Configuration *cfg;
50static struct GNUNET_CronManager *cron; 50static struct GNUNET_CronManager *cron;
51 51
52static int 52static int
53getStatValue (unsigned long long *value, unsigned long long *lvalue, 53getStatValue (unsigned long long *value,
54 GNUNET_CronTime * dtime, const char *optName, int monotone) 54 unsigned long long *lvalue,
55 GNUNET_CronTime *dtime,
56 const char *optName,
57 int monotone)
55{ 58{
56 unsigned int i; 59 unsigned int i;
57 60
@@ -68,14 +71,15 @@ getStatValue (unsigned long long *value, unsigned long long *lvalue,
68 if (dtime != NULL) 71 if (dtime != NULL)
69 *dtime = lastStatValues[i].delta; 72 *dtime = lastStatValues[i].delta;
70 if ((monotone == GNUNET_YES) && (lvalue != NULL) && (*lvalue > *value)) 73 if ((monotone == GNUNET_YES) && (lvalue != NULL) && (*lvalue > *value))
71 return GNUNET_SYSERR; /* gnunetd restart? */ 74 return GNUNET_SYSERR; /* gnunetd restart? */
72 return GNUNET_OK; 75 return GNUNET_OK;
73 } 76 }
74 } 77 }
75#if FUNCTIONS_DEBUG 78#if FUNCTIONS_DEBUG
76 GNUNET_GE_LOG (ectx, 79 GNUNET_GE_LOG (ectx,
77 GNUNET_GE_ERROR | GNUNET_GE_DEVELOPER | GNUNET_GE_ADMIN | 80 GNUNET_GE_ERROR | GNUNET_GE_DEVELOPER | GNUNET_GE_ADMIN |
78 GNUNET_GE_USER | GNUNET_GE_BULK, "Statistic not found: `%s'\n", 81 GNUNET_GE_USER | GNUNET_GE_BULK,
82 "Statistic not found: `%s'\n",
79 optName); 83 optName);
80#endif 84#endif
81 return GNUNET_SYSERR; 85 return GNUNET_SYSERR;
@@ -89,14 +93,13 @@ updateConnectionGoal (void *unused)
89 char *availableUp; 93 char *availableUp;
90 94
91 GNUNET_mutex_lock (lock); 95 GNUNET_mutex_lock (lock);
92 cmh = 96 cmh = GNUNET_get_daemon_configuration_value (sock,
93 GNUNET_get_daemon_configuration_value (sock, "gnunetd", 97 "gnunetd",
94 "connection-max-hosts"); 98 "connection-max-hosts");
95 availableDown = 99 availableDown =
96 GNUNET_get_daemon_configuration_value (sock, "LOAD", 100 GNUNET_get_daemon_configuration_value (sock, "LOAD", "MAXNETDOWNBPSTOTAL");
97 "MAXNETDOWNBPSTOTAL");
98 availableUp = 101 availableUp =
99 GNUNET_get_daemon_configuration_value (sock, "LOAD", "MAXNETUPBPSTOTAL"); 102 GNUNET_get_daemon_configuration_value (sock, "LOAD", "MAXNETUPBPSTOTAL");
100 GNUNET_mutex_unlock (lock); 103 GNUNET_mutex_unlock (lock);
101 if (cmh == NULL) 104 if (cmh == NULL)
102 connectionGoal = 0; 105 connectionGoal = 0;
@@ -117,7 +120,7 @@ updateConnectionGoal (void *unused)
117} 120}
118 121
119static int 122static int
120getConnectedNodesStat (const void *closure, gfloat ** data) 123getConnectedNodesStat (const void *closure, gfloat **data)
121{ 124{
122 unsigned long long val; 125 unsigned long long val;
123 126
@@ -131,7 +134,7 @@ getConnectedNodesStat (const void *closure, gfloat ** data)
131} 134}
132 135
133static int 136static int
134getLoadStat (const void *closure, gfloat ** data) 137getLoadStat (const void *closure, gfloat **data)
135{ 138{
136 unsigned long long valc; 139 unsigned long long valc;
137 unsigned long long vali; 140 unsigned long long vali;
@@ -144,13 +147,17 @@ getLoadStat (const void *closure, gfloat ** data)
144 if (GNUNET_OK != 147 if (GNUNET_OK !=
145 getStatValue (&vali, NULL, NULL, "% of allowed io load", GNUNET_NO)) 148 getStatValue (&vali, NULL, NULL, "% of allowed io load", GNUNET_NO))
146 return GNUNET_SYSERR; 149 return GNUNET_SYSERR;
147 if (GNUNET_OK != 150 if (GNUNET_OK != getStatValue (&valu,
148 getStatValue (&valu, NULL, NULL, "% of allowed network load (up)", 151 NULL,
149 GNUNET_NO)) 152 NULL,
153 "% of allowed network load (up)",
154 GNUNET_NO))
150 return GNUNET_SYSERR; 155 return GNUNET_SYSERR;
151 if (GNUNET_OK != 156 if (GNUNET_OK != getStatValue (&vald,
152 getStatValue (&vald, NULL, NULL, "% of allowed network load (down)", 157 NULL,
153 GNUNET_NO)) 158 NULL,
159 "% of allowed network load (down)",
160 GNUNET_NO))
154 return GNUNET_SYSERR; 161 return GNUNET_SYSERR;
155 data[0][0] = (gfloat) valc / 100.0; 162 data[0][0] = (gfloat) valc / 100.0;
156 data[0][1] = (gfloat) vali / 100.0; 163 data[0][1] = (gfloat) vali / 100.0;
@@ -160,22 +167,28 @@ getLoadStat (const void *closure, gfloat ** data)
160} 167}
161 168
162static int 169static int
163getQuotaStat (const void *closure, gfloat ** data) 170getQuotaStat (const void *closure, gfloat **data)
164{ 171{
165 unsigned long long allowed; 172 unsigned long long allowed;
166 unsigned long long have; 173 unsigned long long have;
167 174
168 data[0][0] = 0; 175 data[0][0] = 0;
169 data[0][1] = 0; 176 data[0][1] = 0;
170 if ((GNUNET_OK == 177 if ((GNUNET_OK == getStatValue (&allowed,
171 getStatValue (&allowed, NULL, NULL, "# bytes allowed in datastore", 178 NULL,
172 GNUNET_NO)) && (allowed != 0) && 179 NULL,
180 "# bytes allowed in datastore",
181 GNUNET_NO)) &&
182 (allowed != 0) &&
173 (GNUNET_OK == 183 (GNUNET_OK ==
174 getStatValue (&have, NULL, NULL, "# bytes in datastore", GNUNET_NO))) 184 getStatValue (&have, NULL, NULL, "# bytes in datastore", GNUNET_NO)))
175 data[0][0] = ((gfloat) have) / allowed; 185 data[0][0] = ((gfloat) have) / allowed;
176 if ((GNUNET_OK == 186 if ((GNUNET_OK == getStatValue (&allowed,
177 getStatValue (&allowed, NULL, NULL, "# max bytes allowed in dstore", 187 NULL,
178 GNUNET_NO)) && (allowed != 0) && 188 NULL,
189 "# max bytes allowed in dstore",
190 GNUNET_NO)) &&
191 (allowed != 0) &&
179 (GNUNET_OK == 192 (GNUNET_OK ==
180 getStatValue (&have, NULL, NULL, "# bytes in dstore", GNUNET_NO))) 193 getStatValue (&have, NULL, NULL, "# bytes in dstore", GNUNET_NO)))
181 data[0][1] = ((gfloat) have) / allowed; 194 data[0][1] = ((gfloat) have) / allowed;
@@ -183,7 +196,7 @@ getQuotaStat (const void *closure, gfloat ** data)
183} 196}
184 197
185static int 198static int
186getTrafficRecvStats (const void *closure, gfloat ** data) 199getTrafficRecvStats (const void *closure, gfloat **data)
187{ 200{
188 unsigned long long total; 201 unsigned long long total;
189 unsigned long long noise; 202 unsigned long long noise;
@@ -203,35 +216,45 @@ getTrafficRecvStats (const void *closure, gfloat ** data)
203 if (GNUNET_OK != 216 if (GNUNET_OK !=
204 getStatValue (&total, &ltotal, &dtime, "# bytes received", GNUNET_YES)) 217 getStatValue (&total, &ltotal, &dtime, "# bytes received", GNUNET_YES))
205 return GNUNET_SYSERR; 218 return GNUNET_SYSERR;
206 if (GNUNET_OK != 219 if (GNUNET_OK != getStatValue (&noise,
207 getStatValue (&noise, &lnoise, NULL, "# bytes of noise received", 220 &lnoise,
208 GNUNET_YES)) 221 NULL,
222 "# bytes of noise received",
223 GNUNET_YES))
209 return GNUNET_SYSERR; 224 return GNUNET_SYSERR;
210 buffer = GNUNET_malloc (512); 225 buffer = GNUNET_malloc (512);
211 GNUNET_snprintf (buffer, 512, "# bytes received of type %d", 226 GNUNET_snprintf (buffer,
227 512,
228 "# bytes received of type %d",
212 GNUNET_P2P_PROTO_GAP_RESULT); 229 GNUNET_P2P_PROTO_GAP_RESULT);
213 if (GNUNET_OK != getStatValue (&content, &lcontent, NULL, buffer, GNUNET_YES)) 230 if (GNUNET_OK != getStatValue (&content, &lcontent, NULL, buffer, GNUNET_YES))
214 { 231 {
215 content = 0; 232 content = 0;
216 lcontent = 0; 233 lcontent = 0;
217 } 234 }
218 GNUNET_snprintf (buffer, 512, "# bytes received of type %d", 235 GNUNET_snprintf (buffer,
236 512,
237 "# bytes received of type %d",
219 GNUNET_P2P_PROTO_HELLO); 238 GNUNET_P2P_PROTO_HELLO);
220 if (GNUNET_OK != getStatValue (&hellos, &lhellos, NULL, buffer, GNUNET_YES)) 239 if (GNUNET_OK != getStatValue (&hellos, &lhellos, NULL, buffer, GNUNET_YES))
221 { 240 {
222 hellos = 0; 241 hellos = 0;
223 lhellos = 0; 242 lhellos = 0;
224 } 243 }
225 GNUNET_snprintf (buffer, 512, "# bytes received of type %d", 244 GNUNET_snprintf (buffer,
245 512,
246 "# bytes received of type %d",
226 GNUNET_P2P_PROTO_GAP_QUERY); 247 GNUNET_P2P_PROTO_GAP_QUERY);
227 if (GNUNET_OK != getStatValue (&queries, &lqueries, NULL, buffer, GNUNET_YES)) 248 if (GNUNET_OK != getStatValue (&queries, &lqueries, NULL, buffer, GNUNET_YES))
228 { 249 {
229 queries = 0; 250 queries = 0;
230 lqueries = 0; 251 lqueries = 0;
231 } 252 }
232 if (GNUNET_OK != 253 if (GNUNET_OK != getStatValue (&rlimit,
233 getStatValue (&rlimit, &lrlimit, NULL, 254 &lrlimit,
234 "# total bytes per second receive limit", GNUNET_NO)) 255 NULL,
256 "# total bytes per second receive limit",
257 GNUNET_NO))
235 { 258 {
236 rlimit = 0; 259 rlimit = 0;
237 lrlimit = 0; 260 lrlimit = 0;
@@ -255,12 +278,17 @@ getTrafficRecvStats (const void *closure, gfloat ** data)
255 data[0][5] = 0.0; 278 data[0][5] = 0.0;
256 return GNUNET_OK; 279 return GNUNET_OK;
257 } 280 }
258 data[0][0] = ((gfloat) noise) / (banddown * dtime / GNUNET_CRON_SECONDS); /* red */ 281 data[0][0] =
259 data[0][1] = ((gfloat) (content + noise)) / (banddown * dtime / GNUNET_CRON_SECONDS); /* green */ 282 ((gfloat) noise) / (banddown * dtime / GNUNET_CRON_SECONDS); /* red */
260 data[0][2] = ((gfloat) (queries + content + noise)) / (banddown * dtime / GNUNET_CRON_SECONDS); /* yellow */ 283 data[0][1] = ((gfloat) (content + noise)) /
261 data[0][3] = ((gfloat) (queries + content + noise + hellos)) / (banddown * dtime / GNUNET_CRON_SECONDS); /* blue */ 284 (banddown * dtime / GNUNET_CRON_SECONDS); /* green */
262 data[0][4] = ((gfloat) total) / (banddown * dtime / GNUNET_CRON_SECONDS); /* gray */ 285 data[0][2] = ((gfloat) (queries + content + noise)) /
263 data[0][5] = (gfloat) rlimit / banddown; /* magenta */ 286 (banddown * dtime / GNUNET_CRON_SECONDS); /* yellow */
287 data[0][3] = ((gfloat) (queries + content + noise + hellos)) /
288 (banddown * dtime / GNUNET_CRON_SECONDS); /* blue */
289 data[0][4] =
290 ((gfloat) total) / (banddown * dtime / GNUNET_CRON_SECONDS); /* gray */
291 data[0][5] = (gfloat) rlimit / banddown; /* magenta */
264#if 0 292#if 0
265 printf ("I: %f %f %f %f\n", data[0][0], data[0][1], data[0][2]); 293 printf ("I: %f %f %f %f\n", data[0][0], data[0][1], data[0][2]);
266#endif 294#endif
@@ -268,7 +296,7 @@ getTrafficRecvStats (const void *closure, gfloat ** data)
268} 296}
269 297
270static int 298static int
271getTrafficSendStats (const void *closure, gfloat ** data) 299getTrafficSendStats (const void *closure, gfloat **data)
272{ 300{
273 unsigned long long total; 301 unsigned long long total;
274 unsigned long long noise; 302 unsigned long long noise;
@@ -292,30 +320,38 @@ getTrafficSendStats (const void *closure, gfloat ** data)
292 getStatValue (&noise, &lnoise, NULL, "# bytes noise sent", GNUNET_YES)) 320 getStatValue (&noise, &lnoise, NULL, "# bytes noise sent", GNUNET_YES))
293 return GNUNET_SYSERR; 321 return GNUNET_SYSERR;
294 buffer = GNUNET_malloc (512); 322 buffer = GNUNET_malloc (512);
295 GNUNET_snprintf (buffer, 512, "# bytes transmitted of type %d", 323 GNUNET_snprintf (buffer,
324 512,
325 "# bytes transmitted of type %d",
296 GNUNET_P2P_PROTO_GAP_RESULT); 326 GNUNET_P2P_PROTO_GAP_RESULT);
297 if (GNUNET_OK != getStatValue (&content, &lcontent, NULL, buffer, GNUNET_YES)) 327 if (GNUNET_OK != getStatValue (&content, &lcontent, NULL, buffer, GNUNET_YES))
298 { 328 {
299 content = 0; 329 content = 0;
300 lcontent = 0; 330 lcontent = 0;
301 } 331 }
302 GNUNET_snprintf (buffer, 512, "# bytes transmitted of type %d", 332 GNUNET_snprintf (buffer,
333 512,
334 "# bytes transmitted of type %d",
303 GNUNET_P2P_PROTO_GAP_QUERY); 335 GNUNET_P2P_PROTO_GAP_QUERY);
304 if (GNUNET_OK != getStatValue (&queries, &lqueries, NULL, buffer, GNUNET_YES)) 336 if (GNUNET_OK != getStatValue (&queries, &lqueries, NULL, buffer, GNUNET_YES))
305 { 337 {
306 queries = 0; 338 queries = 0;
307 lqueries = 0; 339 lqueries = 0;
308 } 340 }
309 GNUNET_snprintf (buffer, 512, "# bytes transmitted of type %d", 341 GNUNET_snprintf (buffer,
342 512,
343 "# bytes transmitted of type %d",
310 GNUNET_P2P_PROTO_HELLO); 344 GNUNET_P2P_PROTO_HELLO);
311 if (GNUNET_OK != getStatValue (&hellos, &lhellos, NULL, buffer, GNUNET_YES)) 345 if (GNUNET_OK != getStatValue (&hellos, &lhellos, NULL, buffer, GNUNET_YES))
312 { 346 {
313 queries = 0; 347 queries = 0;
314 lqueries = 0; 348 lqueries = 0;
315 } 349 }
316 if (GNUNET_OK != 350 if (GNUNET_OK != getStatValue (&slimit,
317 getStatValue (&slimit, &lslimit, NULL, 351 &lslimit,
318 "# total bytes per second send limit", GNUNET_NO)) 352 NULL,
353 "# total bytes per second send limit",
354 GNUNET_NO))
319 { 355 {
320 slimit = 0; 356 slimit = 0;
321 lslimit = 0; 357 lslimit = 0;
@@ -338,12 +374,17 @@ getTrafficSendStats (const void *closure, gfloat ** data)
338 data[0][5] = 0.0; 374 data[0][5] = 0.0;
339 return GNUNET_OK; 375 return GNUNET_OK;
340 } 376 }
341 data[0][0] = ((gfloat) noise) / (bandup * dtime / GNUNET_CRON_SECONDS); /* red */ 377 data[0][0] =
342 data[0][1] = ((gfloat) (noise + content)) / (bandup * dtime / GNUNET_CRON_SECONDS); /* green */ 378 ((gfloat) noise) / (bandup * dtime / GNUNET_CRON_SECONDS); /* red */
343 data[0][2] = ((gfloat) (noise + content + queries)) / (bandup * dtime / GNUNET_CRON_SECONDS); /* yellow */ 379 data[0][1] = ((gfloat) (noise + content)) /
344 data[0][3] = ((gfloat) (noise + content + queries + hellos)) / (bandup * dtime / GNUNET_CRON_SECONDS); /* blue */ 380 (bandup * dtime / GNUNET_CRON_SECONDS); /* green */
345 data[0][4] = ((gfloat) total) / (bandup * dtime / GNUNET_CRON_SECONDS); /* grey */ 381 data[0][2] = ((gfloat) (noise + content + queries)) /
346 data[0][5] = ((gfloat) slimit) / bandup; /* magenta */ 382 (bandup * dtime / GNUNET_CRON_SECONDS); /* yellow */
383 data[0][3] = ((gfloat) (noise + content + queries + hellos)) /
384 (bandup * dtime / GNUNET_CRON_SECONDS); /* blue */
385 data[0][4] =
386 ((gfloat) total) / (bandup * dtime / GNUNET_CRON_SECONDS); /* grey */
387 data[0][5] = ((gfloat) slimit) / bandup; /* magenta */
347#if 0 388#if 0
348 printf ("O: %f %f %f %f\n", data[0][0], data[0][1], data[0][2], data[0][3]); 389 printf ("O: %f %f %f %f\n", data[0][0], data[0][1], data[0][2], data[0][3]);
349#endif 390#endif
@@ -351,7 +392,7 @@ getTrafficSendStats (const void *closure, gfloat ** data)
351} 392}
352 393
353static int 394static int
354getTrustStats (const void *closure, gfloat ** data) 395getTrustStats (const void *closure, gfloat **data)
355{ 396{
356 unsigned long long spent; 397 unsigned long long spent;
357 unsigned long long earned; 398 unsigned long long earned;
@@ -367,9 +408,11 @@ getTrustStats (const void *closure, gfloat ** data)
367 if (GNUNET_OK != 408 if (GNUNET_OK !=
368 getStatValue (&earned, &learned, NULL, "# trust earned", GNUNET_YES)) 409 getStatValue (&earned, &learned, NULL, "# trust earned", GNUNET_YES))
369 return GNUNET_SYSERR; 410 return GNUNET_SYSERR;
370 if (GNUNET_OK != 411 if (GNUNET_OK != getStatValue (&awarded,
371 getStatValue (&awarded, &lawarded, NULL, "# gap total trust awarded", 412 &lawarded,
372 GNUNET_YES)) 413 NULL,
414 "# gap total trust awarded",
415 GNUNET_YES))
373 return GNUNET_SYSERR; 416 return GNUNET_SYSERR;
374 max = spent; 417 max = spent;
375 if (earned > max) 418 if (earned > max)
@@ -393,20 +436,25 @@ getTrustStats (const void *closure, gfloat ** data)
393} 436}
394 437
395static int 438static int
396getEffectivenessStats (const void *closure, gfloat ** data) 439getEffectivenessStats (const void *closure, gfloat **data)
397{ 440{
398 unsigned long long total; /* total number of queries passed on to remote */ 441 unsigned long long total; /* total number of queries passed on to remote */
399 unsigned long long success; /* responses forwarded (including local and remote) */ 442 unsigned long long
443 success; /* responses forwarded (including local and remote) */
400 unsigned long long ltotal; 444 unsigned long long ltotal;
401 unsigned long long lsuccess; 445 unsigned long long lsuccess;
402 446
403 if (GNUNET_OK != 447 if (GNUNET_OK != getStatValue (&total,
404 getStatValue (&total, &ltotal, NULL, "# gap requests total sent", 448 &ltotal,
405 GNUNET_YES)) 449 NULL,
450 "# gap requests total sent",
451 GNUNET_YES))
406 return GNUNET_SYSERR; 452 return GNUNET_SYSERR;
407 if (GNUNET_OK != 453 if (GNUNET_OK != getStatValue (&success,
408 getStatValue (&success, &lsuccess, NULL, "# gap routes succeeded", 454 &lsuccess,
409 GNUNET_YES)) 455 NULL,
456 "# gap routes succeeded",
457 GNUNET_YES))
410 return GNUNET_SYSERR; 458 return GNUNET_SYSERR;
411 if (total > 0) 459 if (total > 0)
412 data[0][0] = 1.0 * success / total; 460 data[0][0] = 1.0 * success / total;
@@ -477,9 +525,11 @@ updateDaemonStatus (void *cls)
477 525
478 if (uc->is_running) 526 if (uc->is_running)
479 { 527 {
480 if (GNUNET_OK != 528 if (GNUNET_OK != getStatValue (&connected_peers,
481 getStatValue (&connected_peers, NULL, NULL, "# of connected peers", 529 NULL,
482 GNUNET_NO)) 530 NULL,
531 "# of connected peers",
532 GNUNET_NO))
483 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_UNKNOWN, 0); 533 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_UNKNOWN, 0);
484 else if (connected_peers > 0) 534 else if (connected_peers > 0)
485 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_CONNECTED, 535 GNUNET_GTK_display_daemon_status (GNUNET_GTK_STATUS_CONNECTED,
@@ -516,80 +566,72 @@ updateStatValues (void *unused)
516 566
517StatEntry stats[] = { 567StatEntry stats[] = {
518 { 568 {
519 gettext_noop ("Connectivity"), 569 gettext_noop ("Connectivity"),
520 gettext_noop ("# connected nodes (100% = connection table size)"), 570 gettext_noop ("# connected nodes (100% = connection table size)"),
521 &getConnectedNodesStat, 571 &getConnectedNodesStat,
522 NULL, 572 NULL,
523 1, 573 1,
524 GNUNET_NO, 574 GNUNET_NO,
525 } 575 },
526 ,
527 { 576 {
528 gettext_noop ("System load"), 577 gettext_noop ("System load"),
529 gettext_noop 578 gettext_noop (
530 ("CPU load (red), IO load (green), Network upload (yellow), Network download (blue)"), 579 "CPU load (red), IO load (green), Network upload (yellow), Network download (blue)"),
531 &getLoadStat, 580 &getLoadStat,
532 NULL, 581 NULL,
533 4, 582 4,
534 GNUNET_NO, 583 GNUNET_NO,
535 } 584 },
536 ,
537 { 585 {
538 gettext_noop ("Datastore capacity"), 586 gettext_noop ("Datastore capacity"),
539 gettext_noop ("Persistent file-sharing data (red) and DHT cache (green)"), 587 gettext_noop ("Persistent file-sharing data (red) and DHT cache (green)"),
540 &getQuotaStat, 588 &getQuotaStat,
541 NULL, 589 NULL,
542 2, 590 2,
543 GNUNET_NO, 591 GNUNET_NO,
544 } 592 },
545 ,
546 { 593 {
547 gettext_noop ("Inbound Traffic"), 594 gettext_noop ("Inbound Traffic"),
548 gettext_noop 595 gettext_noop (
549 ("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"), 596 "Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"),
550 &getTrafficRecvStats, 597 &getTrafficRecvStats,
551 NULL, 598 NULL,
552 6, 599 6,
553 5, 600 5,
554 } 601 },
555 ,
556 { 602 {
557 gettext_noop ("Outbound Traffic"), 603 gettext_noop ("Outbound Traffic"),
558 gettext_noop 604 gettext_noop (
559 ("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"), 605 "Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"),
560 &getTrafficSendStats, 606 &getTrafficSendStats,
561 NULL, 607 NULL,
562 6, 608 6,
563 5, 609 5,
564 } 610 },
565 ,
566 { 611 {
567 gettext_noop ("Trust"), 612 gettext_noop ("Trust"),
568 gettext_noop ("Spent (red), Earned (green) and Awarded (yellow)"), 613 gettext_noop ("Spent (red), Earned (green) and Awarded (yellow)"),
569 &getTrustStats, 614 &getTrustStats,
570 NULL, 615 NULL,
571 3, 616 3,
572 GNUNET_NO, 617 GNUNET_NO,
573 } 618 },
574 ,
575 { 619 {
576 gettext_noop ("Routing Effectiveness"), 620 gettext_noop ("Routing Effectiveness"),
577 gettext_noop ("Average (red) effectiveness (100% = perfect)"), 621 gettext_noop ("Average (red) effectiveness (100% = perfect)"),
578 &getEffectivenessStats, 622 &getEffectivenessStats,
579 NULL, 623 NULL,
580 1, 624 1,
581 GNUNET_NO, 625 GNUNET_NO,
582 } 626 },
583 ,
584 { 627 {
585 NULL, 628 NULL,
586 NULL, 629 NULL,
587 NULL, 630 NULL,
588 NULL, 631 NULL,
589 0, 632 0,
590 GNUNET_NO, 633 GNUNET_NO,
591 } 634 },
592 ,
593}; 635};
594 636
595static unsigned long long UPDATE_INTERVAL; 637static unsigned long long UPDATE_INTERVAL;
@@ -599,17 +641,26 @@ init_functions (struct GNUNET_GE_Context *e, struct GNUNET_GC_Configuration *c)
599{ 641{
600 ectx = e; 642 ectx = e;
601 cfg = c; 643 cfg = c;
602 GNUNET_GC_get_configuration_value_number (cfg, "GNUNET-GTK", "STATS-INTERVAL", 644 GNUNET_GC_get_configuration_value_number (cfg,
603 1, 99 * GNUNET_CRON_YEARS, 645 "GNUNET-GTK",
646 "STATS-INTERVAL",
647 1,
648 99 * GNUNET_CRON_YEARS,
604 30 * GNUNET_CRON_SECONDS, 649 30 * GNUNET_CRON_SECONDS,
605 &UPDATE_INTERVAL); 650 &UPDATE_INTERVAL);
606 sock = GNUNET_client_connection_create (ectx, cfg); 651 sock = GNUNET_client_connection_create (ectx, cfg);
607 lock = GNUNET_mutex_create (GNUNET_NO); 652 lock = GNUNET_mutex_create (GNUNET_NO);
608 cron = GNUNET_GTK_get_cron_manager (); 653 cron = GNUNET_GTK_get_cron_manager ();
609 GNUNET_cron_add_job (cron, &updateStatValues, UPDATE_INTERVAL, 654 GNUNET_cron_add_job (cron,
610 UPDATE_INTERVAL, NULL); 655 &updateStatValues,
611 GNUNET_cron_add_job (cron, &updateConnectionGoal, 5 * GNUNET_CRON_SECONDS, 656 UPDATE_INTERVAL,
612 5 * GNUNET_CRON_MINUTES, NULL); 657 UPDATE_INTERVAL,
658 NULL);
659 GNUNET_cron_add_job (cron,
660 &updateConnectionGoal,
661 5 * GNUNET_CRON_SECONDS,
662 5 * GNUNET_CRON_MINUTES,
663 NULL);
613 updateStatValues (NULL); 664 updateStatValues (NULL);
614} 665}
615 666
@@ -618,7 +669,9 @@ done_functions ()
618{ 669{
619 unsigned int i; 670 unsigned int i;
620 671
621 GNUNET_cron_del_job (cron, &updateConnectionGoal, 5 * GNUNET_CRON_MINUTES, 672 GNUNET_cron_del_job (cron,
673 &updateConnectionGoal,
674 5 * GNUNET_CRON_MINUTES,
622 NULL); 675 NULL);
623 GNUNET_cron_del_job (cron, &updateStatValues, UPDATE_INTERVAL, NULL); 676 GNUNET_cron_del_job (cron, &updateStatValues, UPDATE_INTERVAL, NULL);
624 GNUNET_mutex_destroy (lock); 677 GNUNET_mutex_destroy (lock);
diff --git a/src/statistics/functions.h b/src/statistics/functions.h
index 079f2f28..56919f5f 100644
--- a/src/statistics/functions.h
+++ b/src/statistics/functions.h
@@ -36,7 +36,7 @@ typedef struct
36 * Callback function to obtain the latest stats 36 * Callback function to obtain the latest stats
37 * data for this stat display. 37 * data for this stat display.
38 */ 38 */
39typedef int (*UpdateData) (const void *closure, gfloat ** data); 39typedef int (*UpdateData) (const void *closure, gfloat **data);
40 40
41 41
42typedef struct SE_ 42typedef struct SE_
@@ -46,7 +46,7 @@ typedef struct SE_
46 UpdateData getData; 46 UpdateData getData;
47 void *get_closure; 47 void *get_closure;
48 unsigned int count; 48 unsigned int count;
49 unsigned int fill; /* fill first "fill" entries */ 49 unsigned int fill; /* fill first "fill" entries */
50} StatEntry; 50} StatEntry;
51 51
52extern StatEntry stats[]; 52extern StatEntry stats[];
diff --git a/src/statistics/gnunet-statistics-gtk-about.c b/src/statistics/gnunet-statistics-gtk-about.c
index 78954035..113e7f87 100644
--- a/src/statistics/gnunet-statistics-gtk-about.c
+++ b/src/statistics/gnunet-statistics-gtk-about.c
@@ -32,7 +32,7 @@
32 * This displays an about window 32 * This displays an about window
33 */ 33 */
34void 34void
35GNUNET_STATISTICS_GTK_main_menu_help_about_activate_cb (GtkWidget * dummy, 35GNUNET_STATISTICS_GTK_main_menu_help_about_activate_cb (GtkWidget *dummy,
36 gpointer data) 36 gpointer data)
37{ 37{
38 GNUNET_GTK_display_about ("gnunet_statistics_gtk_about_window.glade"); 38 GNUNET_GTK_display_about ("gnunet_statistics_gtk_about_window.glade");
diff --git a/src/statistics/gnunet-statistics-gtk.c b/src/statistics/gnunet-statistics-gtk.c
index a2b3a71c..303b53f1 100644
--- a/src/statistics/gnunet-statistics-gtk.c
+++ b/src/statistics/gnunet-statistics-gtk.c
@@ -57,50 +57,55 @@ struct PlotInfo
57 * Name of color to use when plotting. 57 * Name of color to use when plotting.
58 */ 58 */
59 const char *color_name; 59 const char *color_name;
60
61}; 60};
62 61
63 62
64/** 63/**
65 * Selected statistics for the connection tab. 64 * Selected statistics for the connection tab.
66 */ 65 */
67static const struct PlotInfo connection_data[] = { 66static const struct PlotInfo connection_data[] =
68 {"fs", "# peers connected", "file-sharing connections", "blue"}, 67 {{"fs", "# peers connected", "file-sharing connections", "blue"},
69 {"core", "# peers connected", "encrypted connections (core)", "green"}, 68 {"core", "# peers connected", "encrypted connections (core)", "green"},
70 {"core", "# neighbour entries allocated", "transport connections (core)", 69 {"core",
71 "yellow"}, 70 "# neighbour entries allocated",
72 {"transport", "# peers connected", "total connections (transport)", "orange"}, 71 "transport connections (core)",
73 {"transport", "# TCP sessions active", "tcp connections", "red"}, 72 "yellow"},
74 {"transport", "# UDP sessions active", "udp connections", "gray"}, 73 {"transport",
75 {"dht", "# peers connected", "DHT connections", "brown"}, 74 "# peers connected",
76 {"nse", "# nodes in the network (estimate)", "network size (estimate)", 75 "total connections (transport)",
77 "purple"}, 76 "orange"},
78 {NULL, NULL, NULL} 77 {"transport", "# TCP sessions active", "tcp connections", "red"},
79}; 78 {"transport", "# UDP sessions active", "udp connections", "gray"},
79 {"dht", "# peers connected", "DHT connections", "brown"},
80 {"nse",
81 "# nodes in the network (estimate)",
82 "network size (estimate)",
83 "purple"},
84 {NULL, NULL, NULL}};
80 85
81 86
82/** 87/**
83 * Selected statistics for the traffic tab. 88 * Selected statistics for the traffic tab.
84 */ 89 */
85static const struct PlotInfo traffic_data[] = { 90static const struct PlotInfo traffic_data[] =
86 {"core", "# bytes encrypted", "bytes encrypted", "blue"}, 91 {{"core", "# bytes encrypted", "bytes encrypted", "blue"},
87 {"core", "# bytes decrypted", "bytes decrypted", "green"}, 92 {"core", "# bytes decrypted", "bytes decrypted", "green"},
88 {"transport", "# bytes received via TCP", "received via tcp", "yellow"}, 93 {"transport", "# bytes received via TCP", "received via tcp", "yellow"},
89 {"transport", "# bytes transmitted via TCP", "sent via tcp", "brown"}, 94 {"transport", "# bytes transmitted via TCP", "sent via tcp", "brown"},
90 {NULL, NULL, NULL} 95 {NULL, NULL, NULL}};
91};
92 96
93 97
94/** 98/**
95 * Selected statistics for the storage tab. 99 * Selected statistics for the storage tab.
96 */ 100 */
97static const struct PlotInfo storage_data[] = { 101static const struct PlotInfo storage_data[] =
98 {"datastore", "# quota", "datastore capacity", "blue"}, 102 {{"datastore", "# quota", "datastore capacity", "blue"},
99 {"datastore", "# utilization by current datastore", "datastore utilization", 103 {"datastore",
100 "yellow"}, 104 "# utilization by current datastore",
101 {"datastore", "# cache size", "reservation for datastore cache", "green"}, 105 "datastore utilization",
102 {NULL, NULL, NULL} 106 "yellow"},
103}; 107 {"datastore", "# cache size", "reservation for datastore cache", "green"},
108 {NULL, NULL, NULL}};
104 109
105 110
106/** 111/**
@@ -139,14 +144,12 @@ process_value_update (void *cls,
139 GtkStatistics *stats = cls; 144 GtkStatistics *stats = cls;
140 char *id; 145 char *id;
141 146
142 GNUNET_asprintf (&id, 147 GNUNET_asprintf (&id, "%s: %s", subsystem, name);
143 "%s: %s",
144 subsystem,
145 name);
146 gtk_statistics_update_value (stats, 148 gtk_statistics_update_value (stats,
147 id, 149 id,
148 GNUNET_TIME_absolute_get_duration 150 GNUNET_TIME_absolute_get_duration (start_time)
149 (start_time).rel_value_us / 1000000LL, 151 .rel_value_us /
152 1000000LL,
150 value); 153 value);
151 GNUNET_free (id); 154 GNUNET_free (id);
152 return GNUNET_OK; 155 return GNUNET_OK;
@@ -173,8 +176,7 @@ get_object (const char *name)
173 * @param info what to draw 176 * @param info what to draw
174 */ 177 */
175static void 178static void
176create_plot (const char *box_name, 179create_plot (const char *box_name, const struct PlotInfo *info)
177 const struct PlotInfo *info)
178{ 180{
179 GtkBox *box; 181 GtkBox *box;
180 GtkStatistics *ret; 182 GtkStatistics *ret;
@@ -185,14 +187,8 @@ create_plot (const char *box_name,
185 187
186 for (unsigned int i = 0; NULL != info[i].subsystem; i++) 188 for (unsigned int i = 0; NULL != info[i].subsystem; i++)
187 { 189 {
188 GNUNET_asprintf (&id, 190 GNUNET_asprintf (&id, "%s: %s", info[i].subsystem, info[i].name);
189 "%s: %s", 191 gtk_statistics_add_line (ret, id, info[i].label, info[i].color_name);
190 info[i].subsystem,
191 info[i].name);
192 gtk_statistics_add_line (ret,
193 id,
194 info[i].label,
195 info[i].color_name);
196 GNUNET_free (id); 192 GNUNET_free (id);
197 GNUNET_STATISTICS_watch (statistics, 193 GNUNET_STATISTICS_watch (statistics,
198 info[i].subsystem, 194 info[i].subsystem,
@@ -201,11 +197,7 @@ create_plot (const char *box_name,
201 ret); 197 ret);
202 } 198 }
203 gtk_widget_show (GTK_WIDGET (ret)); 199 gtk_widget_show (GTK_WIDGET (ret));
204 gtk_box_pack_start (box, 200 gtk_box_pack_start (box, GTK_WIDGET (ret), TRUE, TRUE, 0);
205 GTK_WIDGET (ret),
206 TRUE,
207 TRUE,
208 0);
209} 201}
210 202
211 203
@@ -219,8 +211,7 @@ shutdown_task (void *cls)
219{ 211{
220 GNUNET_GTK_main_loop_quit (ml); 212 GNUNET_GTK_main_loop_quit (ml);
221 ml = NULL; 213 ml = NULL;
222 GNUNET_STATISTICS_destroy (statistics, 214 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
223 GNUNET_NO);
224 statistics = NULL; 215 statistics = NULL;
225} 216}
226 217
@@ -229,8 +220,7 @@ shutdown_task (void *cls)
229 * Callback invoked if the application is supposed to exit. 220 * Callback invoked if the application is supposed to exit.
230 */ 221 */
231void 222void
232GNUNET_STATISTICS_GTK_quit_cb (GObject *object, 223GNUNET_STATISTICS_GTK_quit_cb (GObject *object, gpointer user_data)
233 gpointer user_data)
234{ 224{
235 GNUNET_SCHEDULER_shutdown (); 225 GNUNET_SCHEDULER_shutdown ();
236} 226}
@@ -247,20 +237,18 @@ run (void *cls)
247 237
248 ml = cls; 238 ml = cls;
249 239
250 if (GNUNET_OK != 240 if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL))
251 GNUNET_GTK_main_loop_build_window (ml,
252 NULL))
253 { 241 {
254 return; 242 return;
255 } 243 }
256 244
257 statistics 245 statistics =
258 = GNUNET_STATISTICS_create ("gnunet-statistics-gtk", 246 GNUNET_STATISTICS_create ("gnunet-statistics-gtk",
259 GNUNET_GTK_main_loop_get_configuration (ml)); 247 GNUNET_GTK_main_loop_get_configuration (ml));
260 if (NULL == statistics) 248 if (NULL == statistics)
261 { 249 {
262 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
263 _("Failed to initiate connection with statistics service\n")); 251 _ ("Failed to initiate connection with statistics service\n"));
264 return; 252 return;
265 } 253 }
266 GNUNET_GTK_set_icon_search_path (); 254 GNUNET_GTK_set_icon_search_path ();
@@ -268,31 +256,24 @@ run (void *cls)
268 256
269 /* setup main window */ 257 /* setup main window */
270 main_window = GTK_WIDGET (get_object ("GNUNET_STATISTICS_GTK_main_window")); 258 main_window = GTK_WIDGET (get_object ("GNUNET_STATISTICS_GTK_main_window"));
271 main_window = GNUNET_GTK_plug_me ("GNUNET_STATISTICS_GTK_PLUG", 259 main_window = GNUNET_GTK_plug_me ("GNUNET_STATISTICS_GTK_PLUG", main_window);
272 main_window);
273 gtk_window_maximize (GTK_WINDOW (main_window)); 260 gtk_window_maximize (GTK_WINDOW (main_window));
274 create_plot ("GNUNET_STATISTICS_GTK_connectivity_box", 261 create_plot ("GNUNET_STATISTICS_GTK_connectivity_box", connection_data);
275 connection_data); 262 create_plot ("GNUNET_STATISTICS_GTK_traffic_box", traffic_data);
276 create_plot ("GNUNET_STATISTICS_GTK_traffic_box", 263 create_plot ("GNUNET_STATISTICS_GTK_storage_box", storage_data);
277 traffic_data);
278 create_plot ("GNUNET_STATISTICS_GTK_storage_box",
279 storage_data);
280 264
281 /* make GUI visible */ 265 /* make GUI visible */
282 gtk_widget_show (main_window); 266 gtk_widget_show (main_window);
283 gtk_window_present (GTK_WINDOW (main_window)); 267 gtk_window_present (GTK_WINDOW (main_window));
284 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 268 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
285 NULL);
286} 269}
287 270
288 271
289int 272int
290main (int argc, 273main (int argc, char *const *argv)
291 char *const *argv)
292{ 274{
293 static struct GNUNET_GETOPT_CommandLineOption options[] = { 275 static struct GNUNET_GETOPT_CommandLineOption options[] = {
294 GNUNET_GETOPT_OPTION_END 276 GNUNET_GETOPT_OPTION_END};
295 };
296 277
297 start_time = GNUNET_TIME_absolute_get (); 278 start_time = GNUNET_TIME_absolute_get ();
298 if (GNUNET_OK != 279 if (GNUNET_OK !=
diff --git a/src/statistics/gtk_statistics.c b/src/statistics/gtk_statistics.c
index d7259bfc..3a7aba8e 100644
--- a/src/statistics/gtk_statistics.c
+++ b/src/statistics/gtk_statistics.c
@@ -59,7 +59,6 @@ struct HistoricValue
59 * A value we recorded. 59 * A value we recorded.
60 */ 60 */
61 uint64_t y; 61 uint64_t y;
62
63}; 62};
64 63
65/** 64/**
@@ -116,20 +115,22 @@ struct _GtkStatisticsPrivate
116 115
117 116
118static gboolean 117static gboolean
119gtk_statistics_draw (GtkWidget * widget, cairo_t * cr); 118gtk_statistics_draw (GtkWidget *widget, cairo_t *cr);
120 119
121static void 120static void
122gtk_statistics_finalize (GObject * object); 121gtk_statistics_finalize (GObject *object);
123 122
124 123
125G_DEFINE_TYPE_EXTENDED (GtkStatistics, gtk_statistics, GTK_TYPE_WIDGET, 0, 124G_DEFINE_TYPE_EXTENDED (GtkStatistics,
125 gtk_statistics,
126 GTK_TYPE_WIDGET,
127 0,
126 G_ADD_PRIVATE (GtkStatistics)) 128 G_ADD_PRIVATE (GtkStatistics))
127 129
128 130
129#if GTK_MAJOR_VERSION < 3 131#if GTK_MAJOR_VERSION < 3
130static gboolean 132static gboolean
131statistics_expose (GtkWidget * statistics, 133statistics_expose (GtkWidget *statistics, GdkEventExpose *event)
132 GdkEventExpose * event)
133{ 134{
134 GtkAllocation alloc; 135 GtkAllocation alloc;
135 cairo_t *cr; 136 cairo_t *cr;
@@ -137,8 +138,12 @@ statistics_expose (GtkWidget * statistics,
137 gint y; 138 gint y;
138 139
139 gtk_widget_translate_coordinates (statistics, 140 gtk_widget_translate_coordinates (statistics,
140 GTK_WIDGET (gtk_widget_get_toplevel 141 GTK_WIDGET (
141 (statistics)), 0, 0, &x, &y); 142 gtk_widget_get_toplevel (statistics)),
143 0,
144 0,
145 &x,
146 &y);
142 gtk_widget_get_allocation (statistics, &alloc); 147 gtk_widget_get_allocation (statistics, &alloc);
143 cr = gdk_cairo_create (statistics->window); 148 cr = gdk_cairo_create (statistics->window);
144 cairo_translate (cr, x, y); 149 cairo_translate (cr, x, y);
@@ -153,7 +158,7 @@ statistics_expose (GtkWidget * statistics,
153 158
154 159
155static void 160static void
156gtk_statistics_class_init (GtkStatisticsClass * class) 161gtk_statistics_class_init (GtkStatisticsClass *class)
157{ 162{
158 GObjectClass *gobject_class; 163 GObjectClass *gobject_class;
159 GtkWidgetClass *widget_class; 164 GtkWidgetClass *widget_class;
@@ -169,16 +174,18 @@ gtk_statistics_class_init (GtkStatisticsClass * class)
169 174
170 175
171static void 176static void
172gtk_statistics_init (GtkStatistics * statistics) 177gtk_statistics_init (GtkStatistics *statistics)
173{ 178{
174 GtkStatisticsPrivate *priv; 179 GtkStatisticsPrivate *priv;
175 180
176 statistics->priv = 181 statistics->priv = G_TYPE_INSTANCE_GET_PRIVATE (statistics,
177 G_TYPE_INSTANCE_GET_PRIVATE (statistics, GTK_TYPE_STATISTICS, 182 GTK_TYPE_STATISTICS,
178 GtkStatisticsPrivate); 183 GtkStatisticsPrivate);
179 priv = statistics->priv; 184 priv = statistics->priv;
180#if GTK_MAJOR_VERSION < 3 185#if GTK_MAJOR_VERSION < 3
181 g_signal_connect (statistics, "expose-event", G_CALLBACK (statistics_expose), 186 g_signal_connect (statistics,
187 "expose-event",
188 G_CALLBACK (statistics_expose),
182 statistics); 189 statistics);
183#endif 190#endif
184 gtk_widget_set_has_window (GTK_WIDGET (statistics), FALSE); 191 gtk_widget_set_has_window (GTK_WIDGET (statistics), FALSE);
@@ -219,10 +226,10 @@ gtk_statistics_new ()
219 * @param color_name name of the color to use 226 * @param color_name name of the color to use
220 */ 227 */
221void 228void
222gtk_statistics_add_line (GtkStatistics * statistics, 229gtk_statistics_add_line (GtkStatistics *statistics,
223 const char *id, 230 const char *id,
224 const char *label, 231 const char *label,
225 const char *color_name) 232 const char *color_name)
226{ 233{
227 GtkStatisticsPrivate *priv; 234 GtkStatisticsPrivate *priv;
228 struct ValueHistory *vh; 235 struct ValueHistory *vh;
@@ -232,10 +239,10 @@ gtk_statistics_add_line (GtkStatistics * statistics,
232 g_return_if_fail (gdk_rgba_parse (&c, color_name)); 239 g_return_if_fail (gdk_rgba_parse (&c, color_name));
233 priv = statistics->priv; 240 priv = statistics->priv;
234 priv->values = 241 priv->values =
235 g_realloc (priv->values, 242 g_realloc (priv->values,
236 sizeof (struct ValueHistory *) * (1 + priv->num_values)); 243 sizeof (struct ValueHistory *) * (1 + priv->num_values));
237 priv->values[priv->num_values++] = vh = 244 priv->values[priv->num_values++] = vh =
238 g_malloc (sizeof (struct ValueHistory)); 245 g_malloc (sizeof (struct ValueHistory));
239 vh->id = strdup (id); 246 vh->id = strdup (id);
240 vh->label = strdup (label); 247 vh->label = strdup (label);
241 vh->red = c.red; 248 vh->red = c.red;
@@ -255,8 +262,10 @@ gtk_statistics_add_line (GtkStatistics * statistics,
255 * @param y new y-value 262 * @param y new y-value
256 */ 263 */
257void 264void
258gtk_statistics_update_value (GtkStatistics * statistics, const char *id, 265gtk_statistics_update_value (GtkStatistics *statistics,
259 uint64_t x, uint64_t y) 266 const char *id,
267 uint64_t x,
268 uint64_t y)
260{ 269{
261 GtkStatisticsPrivate *priv; 270 GtkStatisticsPrivate *priv;
262 GtkWidget *widget; 271 GtkWidget *widget;
@@ -313,7 +322,7 @@ num_to_label (unsigned long long num, char *label)
313 * @param cr drawing context 322 * @param cr drawing context
314 */ 323 */
315static gboolean 324static gboolean
316gtk_statistics_draw (GtkWidget * widget, cairo_t * cr) 325gtk_statistics_draw (GtkWidget *widget, cairo_t *cr)
317{ 326{
318 GtkStatistics *statistics = GTK_STATISTICS (widget); 327 GtkStatistics *statistics = GTK_STATISTICS (widget);
319 GtkStatisticsPrivate *priv = statistics->priv; 328 GtkStatisticsPrivate *priv = statistics->priv;
@@ -344,8 +353,8 @@ gtk_statistics_draw (GtkWidget * widget, cairo_t * cr)
344 vh = priv->values[i]; 353 vh = priv->values[i];
345 for (j = 0; j < vh->history_size; j++) 354 for (j = 0; j < vh->history_size; j++)
346 { 355 {
347 hv = &vh->history[(vh->last_history_offset - j + MAX_HISTORY) % 356 hv =
348 MAX_HISTORY]; 357 &vh->history[(vh->last_history_offset - j + MAX_HISTORY) % MAX_HISTORY];
349 xmin = GNUNET_MIN (hv->x, xmin); 358 xmin = GNUNET_MIN (hv->x, xmin);
350 xmax = GNUNET_MAX (hv->x, xmax); 359 xmax = GNUNET_MAX (hv->x, xmax);
351 ymax = GNUNET_MAX (hv->y, ymax); 360 ymax = GNUNET_MAX (hv->y, ymax);
@@ -368,10 +377,12 @@ gtk_statistics_draw (GtkWidget * widget, cairo_t * cr)
368 cairo_paint (cr); 377 cairo_paint (cr);
369 378
370 if ((0 == priv->num_values) || (ymax == 0)) 379 if ((0 == priv->num_values) || (ymax == 0))
371 return FALSE; /* done */ 380 return FALSE; /* done */
372 /* select font */ 381 /* select font */
373 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); 382 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
374 cairo_select_font_face (cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, 383 cairo_select_font_face (cr,
384 "Georgia",
385 CAIRO_FONT_SLANT_NORMAL,
375 CAIRO_FONT_WEIGHT_BOLD); 386 CAIRO_FONT_WEIGHT_BOLD);
376 cairo_set_font_size (cr, GNUNET_MIN (20, height / (2 * XTICKS))); 387 cairo_set_font_size (cr, GNUNET_MIN (20, height / (2 * XTICKS)));
377 388
@@ -380,9 +391,8 @@ gtk_statistics_draw (GtkWidget * widget, cairo_t * cr)
380 tex_max.height = 0; 391 tex_max.height = 0;
381 for (i = 0; i < XTICKS; i++) 392 for (i = 0; i < XTICKS; i++)
382 { 393 {
383 num_to_label ((unsigned long long) (xmin + 394 num_to_label ((unsigned long long) (xmin + (xmax - xmin) * ((uint64_t) i) /
384 (xmax - 395 (XTICKS - 1)),
385 xmin) * ((uint64_t) i) / (XTICKS - 1)),
386 label); 396 label);
387 cairo_text_extents (cr, label, &te); 397 cairo_text_extents (cr, label, &te);
388 tex_max.width = GNUNET_MAX (te.width, tex_max.width); 398 tex_max.width = GNUNET_MAX (te.width, tex_max.width);
@@ -405,32 +415,30 @@ gtk_statistics_draw (GtkWidget * widget, cairo_t * cr)
405 num_to_label ((unsigned long long) ymax * ((uint64_t) i) / (YTICKS - 1), 415 num_to_label ((unsigned long long) ymax * ((uint64_t) i) / (YTICKS - 1),
406 label); 416 label);
407 cairo_text_extents (cr, label, &te); 417 cairo_text_extents (cr, label, &te);
408 cairo_move_to (cr, BORDER + tey_max.width - te.width, 418 cairo_move_to (cr,
409 BORDER + tey_max.height + (YTICKS - i - 1) * (height - 419 BORDER + tey_max.width - te.width,
410 2.0 * BORDER - 420 BORDER + tey_max.height +
411 tey_max.height 421 (YTICKS - i - 1) *
412 - 422 (height - 2.0 * BORDER - tey_max.height -
413 tex_max.height) 423 tex_max.height) /
414 / (double) (YTICKS - 1)); 424 (double) (YTICKS - 1));
415 cairo_show_text (cr, label); 425 cairo_show_text (cr, label);
416 426
417 427
418 cairo_move_to (cr, 2.0 * BORDER + tey_max.width, 428 cairo_move_to (cr,
419 BORDER + tey_max.height / 2.0 + (YTICKS - i - 1) * (height - 429 2.0 * BORDER + tey_max.width,
420 2.0 * 430 BORDER + tey_max.height / 2.0 +
421 BORDER - 431 (YTICKS - i - 1) *
422 tex_max.height 432 (height - 2.0 * BORDER - tex_max.height -
423 - 433 tey_max.height) /
424 tey_max.height) 434 (double) (YTICKS - 1));
425 / (double) (YTICKS - 1)); 435 cairo_line_to (cr,
426 cairo_line_to (cr, 2.0 * BORDER + tey_max.width + BORDER / 2.0, 436 2.0 * BORDER + tey_max.width + BORDER / 2.0,
427 BORDER + tey_max.height / 2.0 + (YTICKS - i - 1) * (height - 437 BORDER + tey_max.height / 2.0 +
428 2.0 * 438 (YTICKS - i - 1) *
429 BORDER - 439 (height - 2.0 * BORDER - tex_max.height -
430 tex_max.height 440 tey_max.height) /
431 - 441 (double) (YTICKS - 1));
432 tey_max.height)
433 / (double) (YTICKS - 1));
434 442
435 cairo_stroke (cr); 443 cairo_stroke (cr);
436 } 444 }
@@ -438,41 +446,42 @@ gtk_statistics_draw (GtkWidget * widget, cairo_t * cr)
438 /* draw x-axis labels */ 446 /* draw x-axis labels */
439 for (i = 0; i < XTICKS; i++) 447 for (i = 0; i < XTICKS; i++)
440 { 448 {
441 num_to_label ((unsigned long long) (xmin + 449 num_to_label ((unsigned long long) (xmin + (xmax - xmin) * ((uint64_t) i) /
442 (xmax - 450 (XTICKS - 1)),
443 xmin) * ((uint64_t) i) / (XTICKS - 1)),
444 label); 451 label);
445 cairo_text_extents (cr, label, &te); 452 cairo_text_extents (cr, label, &te);
446 if (i != 0) 453 if (i != 0)
447 { 454 {
448 cairo_move_to (cr, 455 cairo_move_to (cr,
449 2.0 * BORDER + tey_max.width + (width - tey_max.width - 456 2.0 * BORDER + tey_max.width +
450 tex_max.width / 2.0 - 457 (width - tey_max.width - tex_max.width / 2.0 -
451 3.0 * BORDER) * i / 458 3.0 * BORDER) *
452 (XTICKS - 1.0) - te.width / 2.0, 459 i / (XTICKS - 1.0) -
460 te.width / 2.0,
453 height - BORDER / 2.0 - tex_max.height / 2.0); 461 height - BORDER / 2.0 - tex_max.height / 2.0);
454 cairo_show_text (cr, label); 462 cairo_show_text (cr, label);
455 } 463 }
456 cairo_move_to (cr, 464 cairo_move_to (cr,
457 2.0 * BORDER + tey_max.width + (width - tey_max.width - 465 2.0 * BORDER + tey_max.width +
458 tex_max.width / 2.0 - 466 (width - tey_max.width - tex_max.width / 2.0 -
459 3.0 * BORDER) * i / (XTICKS - 467 3.0 * BORDER) *
460 1.0), 468 i / (XTICKS - 1.0),
461 height - BORDER - tey_max.height / 2.0 - tex_max.height); 469 height - BORDER - tey_max.height / 2.0 - tex_max.height);
462 cairo_line_to (cr, 470 cairo_line_to (cr,
463 2.0 * BORDER + tey_max.width + (width - tey_max.width - 471 2.0 * BORDER + tey_max.width +
464 tex_max.width / 2.0 - 472 (width - tey_max.width - tex_max.width / 2.0 -
465 3.0 * BORDER) * i / (XTICKS - 473 3.0 * BORDER) *
466 1.0), 474 i / (XTICKS - 1.0),
467 height - BORDER - tey_max.height / 2.0 - tex_max.height - 475 height - BORDER - tey_max.height / 2.0 - tex_max.height -
468 BORDER / 2.0); 476 BORDER / 2.0);
469 477
470 cairo_stroke (cr); 478 cairo_stroke (cr);
471 } 479 }
472 480
473 /* plot border */ 481 /* plot border */
474 cairo_set_line_width (cr, 1.0); 482 cairo_set_line_width (cr, 1.0);
475 cairo_rectangle (cr, tey_max.width + BORDER * 2.0, 483 cairo_rectangle (cr,
484 tey_max.width + BORDER * 2.0,
476 BORDER + tey_max.height / 2.0, 485 BORDER + tey_max.height / 2.0,
477 width - BORDER * 3.0 - tey_max.width - tex_max.width / 2.0, 486 width - BORDER * 3.0 - tey_max.width - tex_max.width / 2.0,
478 height - BORDER * 2.0 - tey_max.height - tex_max.height); 487 height - BORDER * 2.0 - tey_max.height - tex_max.height);
@@ -484,8 +493,8 @@ gtk_statistics_draw (GtkWidget * widget, cairo_t * cr)
484 cairo_set_font_size (cr, 493 cairo_set_font_size (cr,
485 GNUNET_MIN (20, 494 GNUNET_MIN (20,
486 (height - 3.0 * BORDER - tex_max.height - 495 (height - 3.0 * BORDER - tex_max.height -
487 tey_max.height / 2) / (priv->num_values + 496 tey_max.height / 2) /
488 1))); 497 (priv->num_values + 1)));
489 498
490 h = 2.0 * BORDER + tey_max.height / 2; 499 h = 2.0 * BORDER + tey_max.height / 2;
491 500
@@ -502,9 +511,9 @@ gtk_statistics_draw (GtkWidget * widget, cairo_t * cr)
502 { 511 {
503 hv = &vh->history[vh->last_history_offset % MAX_HISTORY]; 512 hv = &vh->history[vh->last_history_offset % MAX_HISTORY];
504 ry = hv->y / (double) ymax; 513 ry = hv->y / (double) ymax;
505 ry = BORDER + tex_max.height / 2.0 + (1.0 - ry) * (height - BORDER * 2.0 - 514 ry =
506 tey_max.height - 515 BORDER + tex_max.height / 2.0 +
507 tex_max.height); 516 (1.0 - ry) * (height - BORDER * 2.0 - tey_max.height - tex_max.height);
508 /* if y-values are small, offset y-values a bit to allow overlapping curves to still show up */ 517 /* if y-values are small, offset y-values a bit to allow overlapping curves to still show up */
509 if (ymax < height / (priv->num_values * 4)) 518 if (ymax < height / (priv->num_values * 4))
510 ry += priv->num_values * 2 - (4 * i); 519 ry += priv->num_values * 2 - (4 * i);
@@ -516,16 +525,16 @@ gtk_statistics_draw (GtkWidget * widget, cairo_t * cr)
516 525
517 for (j = 0; j < vh->history_size; j++) 526 for (j = 0; j < vh->history_size; j++)
518 { 527 {
519 hv = &vh->history[(vh->last_history_offset - j + MAX_HISTORY) % 528 hv =
520 MAX_HISTORY]; 529 &vh->history[(vh->last_history_offset - j + MAX_HISTORY) % MAX_HISTORY];
521 rx = (hv->x - xmin) / (double) (xmax - xmin); 530 rx = (hv->x - xmin) / (double) (xmax - xmin);
522 ry = hv->y / (double) ymax; 531 ry = hv->y / (double) ymax;
523 532
524 rx = tey_max.width + BORDER * 2.0 + 533 rx = tey_max.width + BORDER * 2.0 +
525 (rx * (width - BORDER * 3.0 - tey_max.width - tex_max.width / 2.0)); 534 (rx * (width - BORDER * 3.0 - tey_max.width - tex_max.width / 2.0));
526 ry = BORDER + tex_max.height / 2.0 + (1.0 - ry) * (height - BORDER * 2.0 - 535 ry =
527 tey_max.height - 536 BORDER + tex_max.height / 2.0 +
528 tex_max.height); 537 (1.0 - ry) * (height - BORDER * 2.0 - tey_max.height - tex_max.height);
529 538
530 /* if y-values are small, offset y-values a bit to allow overlapping curves to still show up */ 539 /* if y-values are small, offset y-values a bit to allow overlapping curves to still show up */
531 if (ymax < height / (priv->num_values * 4)) 540 if (ymax < height / (priv->num_values * 4))
@@ -546,7 +555,7 @@ gtk_statistics_draw (GtkWidget * widget, cairo_t * cr)
546 * @param object object to release 555 * @param object object to release
547 */ 556 */
548static void 557static void
549gtk_statistics_finalize (GObject * object) 558gtk_statistics_finalize (GObject *object)
550{ 559{
551 GtkStatistics *label = GTK_STATISTICS (object); 560 GtkStatistics *label = GTK_STATISTICS (object);
552 GtkStatisticsPrivate *priv = label->priv; 561 GtkStatisticsPrivate *priv = label->priv;
diff --git a/src/statistics/gtk_statistics.h b/src/statistics/gtk_statistics.h
index 7d56175e..99d5c88a 100644
--- a/src/statistics/gtk_statistics.h
+++ b/src/statistics/gtk_statistics.h
@@ -31,12 +31,17 @@
31#include <cairo.h> 31#include <cairo.h>
32 32
33G_BEGIN_DECLS 33G_BEGIN_DECLS
34#define GTK_TYPE_STATISTICS (gtk_statistics_get_type ()) 34#define GTK_TYPE_STATISTICS (gtk_statistics_get_type ())
35#define GTK_STATISTICS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_STATISTICS, GtkStatistics)) 35#define GTK_STATISTICS(obj) \
36#define GTK_STATISTICS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_STATISTICS, GtkStatisticsClass)) 36 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_STATISTICS, GtkStatistics))
37#define GTK_IS_STATISTICS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_STATISTICS)) 37#define GTK_STATISTICS_CLASS(klass) \
38#define GTK_IS_STATISTICS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_STATISTICS)) 38 (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_STATISTICS, GtkStatisticsClass))
39#define GTK_STATISTICS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_STATISTICS, GtkStatisticsClass)) 39#define GTK_IS_STATISTICS(obj) \
40 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_STATISTICS))
41#define GTK_IS_STATISTICS_CLASS(klass) \
42 (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_STATISTICS))
43#define GTK_STATISTICS_GET_CLASS(obj) \
44 (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_STATISTICS, GtkStatisticsClass))
40typedef struct _GtkStatistics GtkStatistics; 45typedef struct _GtkStatistics GtkStatistics;
41typedef struct _GtkStatisticsPrivate GtkStatisticsPrivate; 46typedef struct _GtkStatisticsPrivate GtkStatisticsPrivate;
42typedef struct _GtkStatisticsClass GtkStatisticsClass; 47typedef struct _GtkStatisticsClass GtkStatisticsClass;
@@ -62,13 +67,19 @@ struct _GtkStatisticsClass
62 67
63 68
64GType 69GType
65gtk_statistics_get_type (void) 70gtk_statistics_get_type (void) G_GNUC_CONST;
66 G_GNUC_CONST; 71GtkWidget *
67 GtkWidget *gtk_statistics_new (void); 72gtk_statistics_new (void);
68 void gtk_statistics_add_line (GtkStatistics * statistics, const char *id, 73void
69 const char *label, const char *color_name); 74gtk_statistics_add_line (GtkStatistics *statistics,
70 void gtk_statistics_update_value (GtkStatistics * statistics, const char *id, 75 const char *id,
71 uint64_t x, uint64_t y); 76 const char *label,
77 const char *color_name);
78void
79gtk_statistics_update_value (GtkStatistics *statistics,
80 const char *id,
81 uint64_t x,
82 uint64_t y);
72 83
73 84
74G_END_DECLS 85G_END_DECLS
diff --git a/src/statistics/gtk_statistics_demo.c b/src/statistics/gtk_statistics_demo.c
index efd98e07..58f017cb 100644
--- a/src/statistics/gtk_statistics_demo.c
+++ b/src/statistics/gtk_statistics_demo.c
@@ -7,14 +7,18 @@
7 * Update view (add more points). 7 * Update view (add more points).
8 */ 8 */
9static gboolean 9static gboolean
10update (GtkWidget * widget, GdkEvent * event, gpointer user_data) 10update (GtkWidget *widget, GdkEvent *event, gpointer user_data)
11{ 11{
12 static unsigned int i = 600; 12 static unsigned int i = 600;
13 struct GtkStatistics *statistics = user_data; 13 struct GtkStatistics *statistics = user_data;
14 14
15 gtk_statistics_update_value (GTK_STATISTICS (statistics), "sin", i, 15 gtk_statistics_update_value (GTK_STATISTICS (statistics),
16 "sin",
17 i,
16 (uint64_t) (500 * (1.0 + sin (i / 100.0)))); 18 (uint64_t) (500 * (1.0 + sin (i / 100.0))));
17 gtk_statistics_update_value (GTK_STATISTICS (statistics), "cos", i * 2, 19 gtk_statistics_update_value (GTK_STATISTICS (statistics),
20 "cos",
21 i * 2,
18 (uint64_t) (i * (1.0 + cos (i / 100.0)))); 22 (uint64_t) (i * (1.0 + cos (i / 100.0))));
19 i++; 23 i++;
20 return FALSE; 24 return FALSE;
@@ -33,19 +37,27 @@ main (int argc, char **argv)
33 gtk_window_set_title (GTK_WINDOW (window), "STATISTICS widget"); 37 gtk_window_set_title (GTK_WINDOW (window), "STATISTICS widget");
34 gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER); 38 gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
35 gtk_window_set_default_size (GTK_WINDOW (window), 400, 200); 39 gtk_window_set_default_size (GTK_WINDOW (window), 400, 200);
36 g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), 40 g_signal_connect (G_OBJECT (window),
41 "destroy",
42 G_CALLBACK (gtk_main_quit),
37 NULL); 43 NULL);
38 statistics = gtk_statistics_new (); 44 statistics = gtk_statistics_new ();
39 gtk_statistics_add_line (GTK_STATISTICS (statistics), "sin", "sin", "red"); 45 gtk_statistics_add_line (GTK_STATISTICS (statistics), "sin", "sin", "red");
40 for (i = 0; i < 600; i++) 46 for (i = 0; i < 600; i++)
41 gtk_statistics_update_value (GTK_STATISTICS (statistics), "sin", i, 47 gtk_statistics_update_value (GTK_STATISTICS (statistics),
48 "sin",
49 i,
42 (uint64_t) (500 * (1.0 + sin (i / 100.0)))); 50 (uint64_t) (500 * (1.0 + sin (i / 100.0))));
43 gtk_statistics_add_line (GTK_STATISTICS (statistics), "cos", "cos", "blue"); 51 gtk_statistics_add_line (GTK_STATISTICS (statistics), "cos", "cos", "blue");
44 for (i = 0; i < 600; i++) 52 for (i = 0; i < 600; i++)
45 gtk_statistics_update_value (GTK_STATISTICS (statistics), "cos", i * 2, 53 gtk_statistics_update_value (GTK_STATISTICS (statistics),
54 "cos",
55 i * 2,
46 (uint64_t) (i * (1.0 + cos (i / 100.0)))); 56 (uint64_t) (i * (1.0 + cos (i / 100.0))));
47 g_signal_connect (G_OBJECT (window), "motion-notify-event", 57 g_signal_connect (G_OBJECT (window),
48 G_CALLBACK (update), statistics); 58 "motion-notify-event",
59 G_CALLBACK (update),
60 statistics);
49 gtk_container_add (GTK_CONTAINER (window), statistics); 61 gtk_container_add (GTK_CONTAINER (window), statistics);
50 gtk_widget_add_events (GTK_WIDGET (window), GDK_POINTER_MOTION_MASK); 62 gtk_widget_add_events (GTK_WIDGET (window), GDK_POINTER_MOTION_MASK);
51 63
diff --git a/src/statistics/statistics.c b/src/statistics/statistics.c
index 63366fd5..ddab959f 100644
--- a/src/statistics/statistics.c
+++ b/src/statistics/statistics.c
@@ -68,7 +68,7 @@ static unsigned long long UPDATE_INTERVAL;
68 * 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
69 */ 69 */
70static void 70static void
71load_graph_draw (LoadGraph * g) 71load_graph_draw (LoadGraph *g)
72{ 72{
73 guint i; 73 guint i;
74 guint j; 74 guint j;
@@ -77,26 +77,27 @@ load_graph_draw (LoadGraph * g)
77 float max; 77 float max;
78 GdkFont *font; 78 GdkFont *font;
79 79
80 if (!g->disp->window) 80 if (! g->disp->window)
81 return; 81 return;
82 82
83 g->draw_width = g->disp->allocation.width; 83 g->draw_width = g->disp->allocation.width;
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 = 87 g->pixmap = gdk_pixmap_new (g->disp->window,
88 gdk_pixmap_new (g->disp->window, g->draw_width, g->draw_height, 88 g->draw_width,
89 gtk_widget_get_visual (g->disp)->depth); 89 g->draw_height,
90 gtk_widget_get_visual (g->disp)->depth);
90 91
91 /* Create GC if necessary. */ 92 /* Create GC if necessary. */
92 if (!g->gc) 93 if (! g->gc)
93 { 94 {
94 g->gc = gdk_gc_new (g->disp->window); 95 g->gc = gdk_gc_new (g->disp->window);
95 gdk_gc_copy (g->gc, g->disp->style->white_gc); 96 gdk_gc_copy (g->gc, g->disp->style->white_gc);
96 } 97 }
97 98
98 /* Allocate colors. */ 99 /* Allocate colors. */
99 if (!g->colors_allocated) 100 if (! g->colors_allocated)
100 { 101 {
101 GdkColormap *colormap; 102 GdkColormap *colormap;
102 103
@@ -108,22 +109,32 @@ load_graph_draw (LoadGraph * g)
108 } 109 }
109 /* Erase Rectangle */ 110 /* Erase Rectangle */
110 gdk_gc_set_foreground (g->gc, &(g->colors[0])); 111 gdk_gc_set_foreground (g->gc, &(g->colors[0]));
111 gdk_draw_rectangle (g->pixmap, g->gc, TRUE, 0, 0, g->disp->allocation.width, 112 gdk_draw_rectangle (g->pixmap,
113 g->gc,
114 TRUE,
115 0,
116 0,
117 g->disp->allocation.width,
112 g->disp->allocation.height); 118 g->disp->allocation.height);
113 119
114 /* draw frame */ 120 /* draw frame */
115 gdk_gc_set_foreground (g->gc, &(g->colors[1])); 121 gdk_gc_set_foreground (g->gc, &(g->colors[1]));
116 gdk_draw_rectangle (g->pixmap, g->gc, FALSE, 0, 0, g->draw_width, 122 gdk_draw_rectangle (g->pixmap,
123 g->gc,
124 FALSE,
125 0,
126 0,
127 g->draw_width,
117 g->disp->allocation.height); 128 g->disp->allocation.height);
118 129
119 max = 0.26; /* force showing at least the 25% line */ 130 max = 0.26; /* force showing at least the 25% line */
120 for (i = 0; i < g->num_points - 1; i++) 131 for (i = 0; i < g->num_points - 1; i++)
121 for (j = 0; j < g->count; j++) 132 for (j = 0; j < g->count; j++)
122 if (g->data[i][j] > max) 133 if (g->data[i][j] > max)
123 max = g->data[i][j]; 134 max = g->data[i][j];
124 max = max * 1.01; /* leave top 1% free */ 135 max = max * 1.01; /* leave top 1% free */
125 136
126 font = gdk_font_load ("fixed"); /* deprecated, but pango is far more than 137 font = gdk_font_load ("fixed"); /* deprecated, but pango is far more than
127 * what we need here -- fix later? */ 138 * what we need here -- fix later? */
128 /* draw lines at 25%, 50%, 75% and 100% of max */ 139 /* draw lines at 25%, 50%, 75% and 100% of max */
129 dely = g->draw_height / max / 4; 140 dely = g->draw_height / max / 4;
@@ -132,7 +143,7 @@ load_graph_draw (LoadGraph * g)
132 gint y1 = g->draw_height + 1 - i * dely; 143 gint y1 = g->draw_height + 1 - i * dely;
133 144
134 if ((dely < 30) && (i != 4)) 145 if ((dely < 30) && (i != 4))
135 continue; /* only print additional 146 continue; /* only print additional
136 * lines if there is enough space! */ 147 * lines if there is enough space! */
137 if (y1 > 0) 148 if (y1 > 0)
138 { 149 {
@@ -150,11 +161,13 @@ load_graph_draw (LoadGraph * g)
150 /* extra-thick line at 100% */ 161 /* extra-thick line at 100% */
151 gdk_draw_line (g->pixmap, g->gc, 0, y1 - 1, g->draw_width, y1 - 1); 162 gdk_draw_line (g->pixmap, g->gc, 0, y1 - 1, g->draw_width, y1 - 1);
152 gdk_draw_line (g->pixmap, g->gc, 0, y1 + 1, g->draw_width, y1 + 1); 163 gdk_draw_line (g->pixmap, g->gc, 0, y1 + 1, g->draw_width, y1 + 1);
153
154 } 164 }
155 } 165 }
156 } 166 }
157 gdk_gc_set_line_attributes (g->gc, 2, GDK_LINE_SOLID, GDK_CAP_ROUND, 167 gdk_gc_set_line_attributes (g->gc,
168 2,
169 GDK_LINE_SOLID,
170 GDK_CAP_ROUND,
158 GDK_JOIN_MITER); 171 GDK_JOIN_MITER);
159 delx = (float) g->draw_width / (g->num_points - 1); 172 delx = (float) g->draw_width / (g->num_points - 1);
160 173
@@ -172,8 +185,11 @@ load_graph_draw (LoadGraph * g)
172 { 185 {
173 if (stats[g->statIdx].fill <= j) 186 if (stats[g->statIdx].fill <= j)
174 { 187 {
175 gdk_draw_line (g->pixmap, g->gc, g->draw_width - x2, 188 gdk_draw_line (g->pixmap,
176 g->draw_height - y2, g->draw_width - x1, 189 g->gc,
190 g->draw_width - x2,
191 g->draw_height - y2,
192 g->draw_width - x1,
177 g->draw_height - y1); 193 g->draw_height - y1);
178 } 194 }
179 else 195 else
@@ -205,12 +221,20 @@ load_graph_draw (LoadGraph * g)
205 } 221 }
206 } 222 }
207 223
208 gdk_gc_set_line_attributes (g->gc, 1, GDK_LINE_SOLID, GDK_CAP_ROUND, 224 gdk_gc_set_line_attributes (g->gc,
225 1,
226 GDK_LINE_SOLID,
227 GDK_CAP_ROUND,
209 GDK_JOIN_MITER); 228 GDK_JOIN_MITER);
210 229
211 gdk_draw_pixmap (g->disp->window, 230 gdk_draw_pixmap (g->disp->window,
212 g->disp->style->fg_gc[GTK_WIDGET_STATE (g->disp)], g->pixmap, 231 g->disp->style->fg_gc[GTK_WIDGET_STATE (g->disp)],
213 0, 0, 0, 0, g->disp->allocation.width, 232 g->pixmap,
233 0,
234 0,
235 0,
236 0,
237 g->disp->allocation.width,
214 g->disp->allocation.height); 238 g->disp->allocation.height);
215} 239}
216 240
@@ -235,11 +259,11 @@ load_graph_update (gpointer ptr)
235} 259}
236 260
237static void 261static void
238load_graph_unalloc (LoadGraph * g) 262load_graph_unalloc (LoadGraph *g)
239{ 263{
240 unsigned int i; 264 unsigned int i;
241 265
242 if (!g->allocated) 266 if (! g->allocated)
243 return; 267 return;
244 for (i = 0; i < g->num_points; i++) 268 for (i = 0; i < g->num_points; i++)
245 { 269 {
@@ -258,7 +282,7 @@ load_graph_unalloc (LoadGraph * g)
258} 282}
259 283
260static void 284static void
261load_graph_alloc (LoadGraph * g) 285load_graph_alloc (LoadGraph *g)
262{ 286{
263 unsigned int i; 287 unsigned int i;
264 unsigned int j; 288 unsigned int j;
@@ -281,7 +305,8 @@ load_graph_alloc (LoadGraph * g)
281} 305}
282 306
283static gint 307static gint
284load_graph_configure (GtkWidget * widget, GdkEventConfigure * event, 308load_graph_configure (GtkWidget *widget,
309 GdkEventConfigure *event,
285 gpointer data_ptr) 310 gpointer data_ptr)
286{ 311{
287 LoadGraph *c = (LoadGraph *) data_ptr; 312 LoadGraph *c = (LoadGraph *) data_ptr;
@@ -292,16 +317,26 @@ load_graph_configure (GtkWidget * widget, GdkEventConfigure * event,
292 c->pixmap = NULL; 317 c->pixmap = NULL;
293 } 318 }
294 319
295 if (!c->pixmap) 320 if (! c->pixmap)
296 c->pixmap = 321 c->pixmap = gdk_pixmap_new (widget->window,
297 gdk_pixmap_new (widget->window, widget->allocation.width, 322 widget->allocation.width,
298 widget->allocation.height, 323 widget->allocation.height,
299 gtk_widget_get_visual (c->disp)->depth); 324 gtk_widget_get_visual (c->disp)->depth);
300 gdk_draw_rectangle (c->pixmap, widget->style->black_gc, TRUE, 0, 0, 325 gdk_draw_rectangle (c->pixmap,
301 widget->allocation.width, widget->allocation.height); 326 widget->style->black_gc,
327 TRUE,
328 0,
329 0,
330 widget->allocation.width,
331 widget->allocation.height);
302 gdk_draw_pixmap (widget->window, 332 gdk_draw_pixmap (widget->window,
303 c->disp->style->fg_gc[GTK_WIDGET_STATE (widget)], c->pixmap, 333 c->disp->style->fg_gc[GTK_WIDGET_STATE (widget)],
304 0, 0, 0, 0, c->disp->allocation.width, 334 c->pixmap,
335 0,
336 0,
337 0,
338 0,
339 c->disp->allocation.width,
305 c->disp->allocation.height); 340 c->disp->allocation.height);
306 341
307 load_graph_draw (c); 342 load_graph_draw (c);
@@ -309,22 +344,26 @@ load_graph_configure (GtkWidget * widget, GdkEventConfigure * event,
309} 344}
310 345
311static gint 346static gint
312load_graph_expose (GtkWidget * widget, GdkEventExpose * event, 347load_graph_expose (GtkWidget *widget, GdkEventExpose *event, gpointer data_ptr)
313 gpointer data_ptr)
314{ 348{
315 LoadGraph *g = (LoadGraph *) data_ptr; 349 LoadGraph *g = (LoadGraph *) data_ptr;
316 350
317 gdk_draw_pixmap (widget->window, 351 gdk_draw_pixmap (widget->window,
318 widget->style->fg_gc[GTK_WIDGET_STATE (widget)], g->pixmap, 352 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
319 event->area.x, event->area.y, event->area.x, event->area.y, 353 g->pixmap,
320 event->area.width, event->area.height); 354 event->area.x,
355 event->area.y,
356 event->area.x,
357 event->area.y,
358 event->area.width,
359 event->area.height);
321 return FALSE; 360 return FALSE;
322} 361}
323 362
324static void 363static void
325load_graph_stop (LoadGraph * g) 364load_graph_stop (LoadGraph *g)
326{ 365{
327 if (!g) 366 if (! g)
328 return; 367 return;
329 if (g->timer_index != -1) 368 if (g->timer_index != -1)
330 { 369 {
@@ -335,7 +374,7 @@ load_graph_stop (LoadGraph * g)
335} 374}
336 375
337static void 376static void
338load_graph_destroy (GtkWidget * widget, gpointer data_ptr) 377load_graph_destroy (GtkWidget *widget, gpointer data_ptr)
339{ 378{
340 LoadGraph *g = (LoadGraph *) data_ptr; 379 LoadGraph *g = (LoadGraph *) data_ptr;
341 380
@@ -348,7 +387,7 @@ load_graph_destroy (GtkWidget * widget, gpointer data_ptr)
348} 387}
349 388
350static LoadGraph * 389static LoadGraph *
351load_graph_new (int statIdx, const ProcConfig * config) 390load_graph_new (int statIdx, const ProcConfig *config)
352{ 391{
353 LoadGraph *g; 392 LoadGraph *g;
354 unsigned int i; 393 unsigned int i;
@@ -375,12 +414,18 @@ load_graph_new (int statIdx, const ProcConfig * config)
375 gtk_widget_show (g->main_widget); 414 gtk_widget_show (g->main_widget);
376 g->disp = gtk_drawing_area_new (); 415 g->disp = gtk_drawing_area_new ();
377 gtk_widget_show (g->disp); 416 gtk_widget_show (g->disp);
378 gtk_signal_connect (GTK_OBJECT (g->disp), "expose_event", 417 gtk_signal_connect (GTK_OBJECT (g->disp),
379 GTK_SIGNAL_FUNC (load_graph_expose), g); 418 "expose_event",
380 gtk_signal_connect (GTK_OBJECT (g->disp), "configure_event", 419 GTK_SIGNAL_FUNC (load_graph_expose),
381 GTK_SIGNAL_FUNC (load_graph_configure), g); 420 g);
382 gtk_signal_connect (GTK_OBJECT (g->disp), "destroy", 421 gtk_signal_connect (GTK_OBJECT (g->disp),
383 GTK_SIGNAL_FUNC (load_graph_destroy), g); 422 "configure_event",
423 GTK_SIGNAL_FUNC (load_graph_configure),
424 g);
425 gtk_signal_connect (GTK_OBJECT (g->disp),
426 "destroy",
427 GTK_SIGNAL_FUNC (load_graph_destroy),
428 g);
384 gtk_widget_add_events (g->disp, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); 429 gtk_widget_add_events (g->disp, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
385 gtk_box_pack_start (GTK_BOX (g->main_widget), g->disp, TRUE, TRUE, 0); 430 gtk_box_pack_start (GTK_BOX (g->main_widget), g->disp, TRUE, TRUE, 0);
386 load_graph_alloc (g); 431 load_graph_alloc (g);
@@ -391,15 +436,15 @@ load_graph_new (int statIdx, const ProcConfig * config)
391} 436}
392 437
393static GtkWidget * 438static GtkWidget *
394create_sys_view (int statIdx, const ProcConfig * config) 439create_sys_view (int statIdx, const ProcConfig *config)
395{ 440{
396 GtkWidget *mem_frame; 441 GtkWidget *mem_frame;
397 LoadGraph *mem_graph; 442 LoadGraph *mem_graph;
398 443
399 mem_graph = load_graph_new (statIdx, config); 444 mem_graph = load_graph_new (statIdx, config);
400 if (mem_graph == NULL) 445 if (mem_graph == NULL)
401 return NULL; /* oops */ 446 return NULL; /* oops */
402 mem_frame = gtk_frame_new (_(stats[statIdx].frameName)); 447 mem_frame = gtk_frame_new (_ (stats[statIdx].frameName));
403 gtk_container_add (GTK_CONTAINER (mem_frame), mem_graph->main_widget); 448 gtk_container_add (GTK_CONTAINER (mem_frame), mem_graph->main_widget);
404 gtk_container_set_border_width (GTK_CONTAINER (mem_graph->main_widget), 449 gtk_container_set_border_width (GTK_CONTAINER (mem_graph->main_widget),
405 GNOME_PAD_SMALL); 450 GNOME_PAD_SMALL);
@@ -407,15 +452,12 @@ create_sys_view (int statIdx, const ProcConfig * config)
407 gtk_widget_show (mem_frame); 452 gtk_widget_show (mem_frame);
408 if (mem_graph->timer_index == -1) 453 if (mem_graph->timer_index == -1)
409 mem_graph->timer_index = 454 mem_graph->timer_index =
410 gtk_timeout_add (mem_graph->speed, &load_graph_update, mem_graph); 455 gtk_timeout_add (mem_graph->speed, &load_graph_update, mem_graph);
411 mem_graph->draw = TRUE; 456 mem_graph->draw = TRUE;
412 return mem_frame; 457 return mem_frame;
413} 458}
414 459
415 460
416
417
418
419void 461void
420init_stats (struct GNUNET_GE_Context *ectx, struct GNUNET_GC_Configuration *cfg) 462init_stats (struct GNUNET_GE_Context *ectx, struct GNUNET_GC_Configuration *cfg)
421{ 463{
@@ -428,22 +470,24 @@ init_stats (struct GNUNET_GE_Context *ectx, struct GNUNET_GC_Configuration *cfg)
428 int i; 470 int i;
429 471
430 statusConnexionsLabel = 472 statusConnexionsLabel =
431 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), 473 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
432 "statusConnexionsLabel"); 474 "statusConnexionsLabel");
433 gtk_label_set_width_chars (GTK_LABEL (statusConnexionsLabel), 475 gtk_label_set_width_chars (GTK_LABEL (statusConnexionsLabel),
434 g_utf8_strlen (_("Connected to %Lu peers"), 476 g_utf8_strlen (_ ("Connected to %Lu peers"), 40) -
435 40) - 1); 477 1);
436 statusConnexionsBox = 478 statusConnexionsBox = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (),
437 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), 479 "statusConnexionsBox");
438 "statusConnexionsBox");
439 gtk_widget_set_sensitive (statusConnexionsBox, TRUE); 480 gtk_widget_set_sensitive (statusConnexionsBox, TRUE);
440 GNUNET_GC_get_configuration_value_number (cfg, "GNUNET-GTK", "STATS-INTERVAL", 481 GNUNET_GC_get_configuration_value_number (cfg,
441 1, 99 * GNUNET_CRON_YEARS, 482 "GNUNET-GTK",
483 "STATS-INTERVAL",
484 1,
485 99 * GNUNET_CRON_YEARS,
442 30 * GNUNET_CRON_SECONDS, 486 30 * GNUNET_CRON_SECONDS,
443 &UPDATE_INTERVAL); 487 &UPDATE_INTERVAL);
444 init_functions (ectx, cfg); 488 init_functions (ectx, cfg);
445 notebook = 489 notebook =
446 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "statsNotebook"); 490 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "statsNotebook");
447 memset (&config, 0, sizeof (ProcConfig)); 491 memset (&config, 0, sizeof (ProcConfig));
448 gdk_color_parse ("black", &config.bg_color); 492 gdk_color_parse ("black", &config.bg_color);
449 gdk_color_parse ("gray", &config.frame_color); 493 gdk_color_parse ("gray", &config.frame_color);
@@ -459,7 +503,7 @@ init_stats (struct GNUNET_GE_Context *ectx, struct GNUNET_GC_Configuration *cfg)
459 { 503 {
460 sys_box = create_sys_view (i, &config); 504 sys_box = create_sys_view (i, &config);
461 if (sys_box == NULL) 505 if (sys_box == NULL)
462 continue; /* oops */ 506 continue; /* oops */
463 507
464 label = gtk_label_new (gettext (stats[i].paneName)); 508 label = gtk_label_new (gettext (stats[i].paneName));
465 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, label); 509 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, label);