diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-04 09:19:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-04 09:19:32 +0000 |
commit | 334fa530a1475ac067e1d3f26bb588794b59baad (patch) | |
tree | dca98fcedd8b9cfa35919fac1775fe5808d2d3ca /src/dht/test_dht_multipeer.c | |
parent | 90e1bc31214319a78036c591228af5d0e23a71af (diff) | |
download | gnunet-334fa530a1475ac067e1d3f26bb588794b59baad.tar.gz gnunet-334fa530a1475ac067e1d3f26bb588794b59baad.zip |
adding stats
Diffstat (limited to 'src/dht/test_dht_multipeer.c')
-rw-r--r-- | src/dht/test_dht_multipeer.c | 119 |
1 files changed, 118 insertions, 1 deletions
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c index 8416577f0..2fc439ecb 100644 --- a/src/dht/test_dht_multipeer.c +++ b/src/dht/test_dht_multipeer.c | |||
@@ -237,6 +237,117 @@ do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
237 | 237 | ||
238 | 238 | ||
239 | /** | 239 | /** |
240 | * Master context for 'stat_run'. | ||
241 | */ | ||
242 | struct StatMaster | ||
243 | { | ||
244 | struct GNUNET_STATISTICS_Handle *stat; | ||
245 | unsigned int daemon; | ||
246 | unsigned int value; | ||
247 | }; | ||
248 | |||
249 | struct StatValues | ||
250 | { | ||
251 | const char *subsystem; | ||
252 | const char *name; | ||
253 | }; | ||
254 | |||
255 | /** | ||
256 | * Statistics we print out. | ||
257 | */ | ||
258 | static struct StatValues stats[] = { | ||
259 | {"core", "# bytes decrypted"}, | ||
260 | {"core", "# bytes encrypted"}, | ||
261 | {"core", "# discarded CORE_SEND requests"}, | ||
262 | {"core", "# discarded lower priority CORE_SEND requests"}, | ||
263 | {"transport", "# bytes received via TCP"}, | ||
264 | {"transport", "# bytes transmitted via TCP"}, | ||
265 | {"dht", "# FIXME"}, | ||
266 | {NULL, NULL} | ||
267 | }; | ||
268 | |||
269 | |||
270 | /** | ||
271 | * Callback function to process statistic values. | ||
272 | * | ||
273 | * @param cls closure | ||
274 | * @param subsystem name of subsystem that created the statistic | ||
275 | * @param name the name of the datum | ||
276 | * @param value the current value | ||
277 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not | ||
278 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | ||
279 | */ | ||
280 | static int | ||
281 | print_stat (void *cls, const char *subsystem, const char *name, uint64_t value, | ||
282 | int is_persistent) | ||
283 | { | ||
284 | struct StatMaster *sm = cls; | ||
285 | |||
286 | fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem, | ||
287 | name, (unsigned long long) value); | ||
288 | return GNUNET_OK; | ||
289 | } | ||
290 | |||
291 | |||
292 | /** | ||
293 | * Function that gathers stats from all daemons. | ||
294 | */ | ||
295 | static void | ||
296 | stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
297 | |||
298 | |||
299 | /** | ||
300 | * Function called when GET operation on stats is done. | ||
301 | */ | ||
302 | static void | ||
303 | get_done (void *cls, int success) | ||
304 | { | ||
305 | struct StatMaster *sm = cls; | ||
306 | |||
307 | GNUNET_break (GNUNET_OK == success); | ||
308 | sm->value++; | ||
309 | GNUNET_SCHEDULER_add_now (&stat_run, sm); | ||
310 | } | ||
311 | |||
312 | |||
313 | /** | ||
314 | * Function that gathers stats from all daemons. | ||
315 | */ | ||
316 | static void | ||
317 | stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
318 | { | ||
319 | struct StatMaster *sm = cls; | ||
320 | |||
321 | if (stats[sm->value].name != NULL) | ||
322 | { | ||
323 | GNUNET_STATISTICS_get (sm->stat, | ||
324 | #if 0 | ||
325 | NULL, NULL, | ||
326 | #else | ||
327 | stats[sm->value].subsystem, stats[sm->value].name, | ||
328 | #endif | ||
329 | GNUNET_TIME_UNIT_FOREVER_REL, &get_done, &print_stat, | ||
330 | sm); | ||
331 | return; | ||
332 | } | ||
333 | GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO); | ||
334 | sm->value = 0; | ||
335 | sm->daemon++; | ||
336 | if (sm->daemon == num_peers) | ||
337 | { | ||
338 | GNUNET_free (sm); | ||
339 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | ||
340 | return; | ||
341 | } | ||
342 | sm->stat = | ||
343 | GNUNET_STATISTICS_create ("<driver>", | ||
344 | GNUNET_TESTING_daemon_get (pg, | ||
345 | sm->daemon)->cfg); | ||
346 | GNUNET_SCHEDULER_add_now (&stat_run, sm); | ||
347 | } | ||
348 | |||
349 | |||
350 | /** | ||
240 | * Function scheduled to be run on the successful completion of this | 351 | * Function scheduled to be run on the successful completion of this |
241 | * testcase. | 352 | * testcase. |
242 | */ | 353 | */ |
@@ -245,6 +356,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
245 | { | 356 | { |
246 | struct TestPutContext *test_put; | 357 | struct TestPutContext *test_put; |
247 | struct TestGetContext *test_get; | 358 | struct TestGetContext *test_get; |
359 | struct StatMaster *sm; | ||
248 | 360 | ||
249 | die_task = GNUNET_SCHEDULER_NO_TASK; | 361 | die_task = GNUNET_SCHEDULER_NO_TASK; |
250 | while (NULL != (test_put = all_puts_head)) | 362 | while (NULL != (test_put = all_puts_head)) |
@@ -273,7 +385,12 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
273 | GNUNET_free (test_get); | 385 | GNUNET_free (test_get); |
274 | } | 386 | } |
275 | ok = 0; | 387 | ok = 0; |
276 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | 388 | sm = GNUNET_malloc (sizeof (struct StatMaster)); |
389 | sm->stat = | ||
390 | GNUNET_STATISTICS_create ("<driver>", | ||
391 | GNUNET_TESTING_daemon_get (pg, | ||
392 | sm->daemon)->cfg); | ||
393 | GNUNET_SCHEDULER_add_now (&stat_run, sm); | ||
277 | } | 394 | } |
278 | 395 | ||
279 | 396 | ||