aboutsummaryrefslogtreecommitdiff
path: root/src/nse
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-01 08:09:45 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-01 08:09:45 +0000
commit6eca06b41b3f4153926b95ef5050b008115ac69a (patch)
tree5b6064f91ba96f13c671ceb24b8b76fbce78e9d7 /src/nse
parentc206e5229ac556989351d207b8f782610bbee730 (diff)
downloadgnunet-6eca06b41b3f4153926b95ef5050b008115ac69a.tar.gz
gnunet-6eca06b41b3f4153926b95ef5050b008115ac69a.zip
fixes
Diffstat (limited to 'src/nse')
-rw-r--r--src/nse/nse-profiler.c133
1 files changed, 58 insertions, 75 deletions
diff --git a/src/nse/nse-profiler.c b/src/nse/nse-profiler.c
index 91b260f4c..d32456a1c 100644
--- a/src/nse/nse-profiler.c
+++ b/src/nse/nse-profiler.c
@@ -42,14 +42,13 @@ struct NSEPeer
42 struct GNUNET_NSE_Handle *nse_handle; 42 struct GNUNET_NSE_Handle *nse_handle;
43}; 43};
44 44
45
45struct StatsContext 46struct StatsContext
46{ 47{
47 GNUNET_SCHEDULER_Task task;
48 GNUNET_SCHEDULER_TaskIdentifier *task_id;
49 void *task_cls;
50 unsigned long long total_nse_bytes; 48 unsigned long long total_nse_bytes;
51}; 49};
52 50
51
53static struct NSEPeer *peer_head; 52static struct NSEPeer *peer_head;
54 53
55static struct NSEPeer *peer_tail; 54static struct NSEPeer *peer_tail;
@@ -166,6 +165,7 @@ shutdown_callback (void *cls, const char *emsg)
166 } 165 }
167} 166}
168 167
168
169static void 169static void
170shutdown_task (void *cls, 170shutdown_task (void *cls,
171 const struct GNUNET_SCHEDULER_TaskContext *tc) 171 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -193,6 +193,7 @@ shutdown_task (void *cls,
193 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 193 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
194} 194}
195 195
196
196/** 197/**
197 * Callback to call when network size estimate is updated. 198 * Callback to call when network size estimate is updated.
198 * 199 *
@@ -213,11 +214,11 @@ handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, double estima
213 if (output_file != NULL) 214 if (output_file != NULL)
214 { 215 {
215 size = GNUNET_asprintf(&output_buffer, 216 size = GNUNET_asprintf(&output_buffer,
216 "%s %u %llu %f %f %f\n", 217 "%s %llu %llu %f %f %f\n",
217 GNUNET_i2s(&peer->daemon->id), 218 GNUNET_i2s(&peer->daemon->id),
218 peers_running, 219 peers_running,
219 timestamp.abs_value, 220 timestamp.abs_value,
220 pow(2, estimate), 221 GNUNET_NSE_log_estimate_to_n(estimate),
221 estimate, 222 estimate,
222 std_dev); 223 std_dev);
223 if (size != GNUNET_DISK_file_write(output_file, output_buffer, size)) 224 if (size != GNUNET_DISK_file_write(output_file, output_buffer, size))
@@ -234,6 +235,7 @@ handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp, double estima
234 235
235} 236}
236 237
238
237static void 239static void
238connect_nse_service (void *cls, 240connect_nse_service (void *cls,
239 const struct GNUNET_SCHEDULER_TaskContext *tc) 241 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -281,12 +283,14 @@ churn_peers (void *cls,
281static void 283static void
282stats_finished_callback (void *cls, int success) 284stats_finished_callback (void *cls, int success)
283{ 285{
284 struct StatsContext *stats_context = (struct StatsContext *)cls; 286 struct StatsContext *stats_context = cls;
285 char *buf; 287 char *buf;
286 int buf_len; 288 int buf_len;
287 289
288 if ((GNUNET_OK == success) && (data_file != NULL)) /* Stats lookup successful, write out data */ 290 if ( (GNUNET_OK == success) &&
291 (data_file != NULL) )
289 { 292 {
293 /* Stats lookup successful, write out data */
290 buf = NULL; 294 buf = NULL;
291 buf_len = GNUNET_asprintf(&buf, 295 buf_len = GNUNET_asprintf(&buf,
292 "TOTAL_NSE_BYTES: %u\n", 296 "TOTAL_NSE_BYTES: %u\n",
@@ -298,9 +302,8 @@ stats_finished_callback (void *cls, int success)
298 GNUNET_free_non_null(buf); 302 GNUNET_free_non_null(buf);
299 } 303 }
300 304
301 if (stats_context->task != NULL) 305 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == shutdown_handle);
302 *stats_context->task_id = GNUNET_SCHEDULER_add_now(stats_context->task, 306 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
303 stats_context->task_cls);
304 GNUNET_free(stats_context); 307 GNUNET_free(stats_context);
305} 308}
306 309
@@ -326,32 +329,13 @@ statistics_iterator (void *cls,
326{ 329{
327 struct StatsContext *stats_context = cls; 330 struct StatsContext *stats_context = cls;
328 331
329 if ((0 == strstr(subsystem, "nse")) && (0 == strstr(name, "# flood messages received"))) 332 if ( (0 == strstr(subsystem, "nse")) &&
330 { 333 (0 == strstr(name, "# flood messages received")) )
331 stats_context->total_nse_bytes += value; 334 stats_context->total_nse_bytes += value;
332 }
333
334 return GNUNET_OK; 335 return GNUNET_OK;
335} 336}
336 337
337 338
338/**
339 * @param cls struct StatsContext
340 * @param tc task context
341 */
342static void
343get_statistics (void *cls,
344 const struct GNUNET_SCHEDULER_TaskContext *tc)
345{
346 struct StatsContext *stats_context = (struct StatsContext *)cls;
347
348 GNUNET_TESTING_get_statistics(pg,
349 &stats_finished_callback,
350 &statistics_iterator,
351 stats_context);
352}
353
354
355static void 339static void
356disconnect_nse_peers (void *cls, 340disconnect_nse_peers (void *cls,
357 const struct GNUNET_SCHEDULER_TaskContext *tc) 341 const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -359,11 +343,11 @@ disconnect_nse_peers (void *cls,
359 struct NSEPeer *pos; 343 struct NSEPeer *pos;
360 char *buf; 344 char *buf;
361 struct StatsContext *stats_context; 345 struct StatsContext *stats_context;
362 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
363 pos = peer_head;
364 346
365 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
366 "disconnecting nse service of peers\n"); 348 "disconnecting nse service of peers\n");
349 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
350 pos = peer_head;
367 while (NULL != (pos = peer_head)) 351 while (NULL != (pos = peer_head))
368 { 352 {
369 if (pos->nse_handle != NULL) 353 if (pos->nse_handle != NULL)
@@ -392,19 +376,17 @@ disconnect_nse_peers (void *cls,
392 stats_context = GNUNET_malloc(sizeof(struct StatsContext)); 376 stats_context = GNUNET_malloc(sizeof(struct StatsContext));
393 GNUNET_SCHEDULER_cancel(shutdown_handle); 377 GNUNET_SCHEDULER_cancel(shutdown_handle);
394 shutdown_handle = GNUNET_SCHEDULER_NO_TASK; 378 shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
395 stats_context->task = &shutdown_task; 379 GNUNET_TESTING_get_statistics(pg,
396 stats_context->task_cls = NULL; 380 &stats_finished_callback,
397 stats_context->task_id = &shutdown_handle; 381 &statistics_iterator,
398 GNUNET_SCHEDULER_add_now(&get_statistics, stats_context); 382 stats_context);
399 //shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
400 } 383 }
401 GNUNET_free(buf); 384 GNUNET_free(buf);
402} 385}
403 386
404 387
405/** 388/**
406 * Prototype of a function that will be called when a 389 * FIXME.
407 * particular operation was completed the testing library.
408 * 390 *
409 * @param cls unused 391 * @param cls unused
410 * @param emsg NULL on success 392 * @param emsg NULL on success
@@ -412,17 +394,14 @@ disconnect_nse_peers (void *cls,
412static void 394static void
413topology_output_callback (void *cls, const char *emsg) 395topology_output_callback (void *cls, const char *emsg)
414{ 396{
415 struct StatsContext *stats_context; 397 disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time,
416 stats_context = GNUNET_malloc(sizeof(struct StatsContext)); 398 &disconnect_nse_peers, NULL);
417
418 disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time, &disconnect_nse_peers, NULL);
419 GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL); 399 GNUNET_SCHEDULER_add_now(&connect_nse_service, NULL);
420} 400}
421 401
422 402
423/** 403/**
424 * Prototype of a function that will be called when a 404 * FIXME.
425 * particular operation was completed the testing library.
426 * 405 *
427 * @param cls closure 406 * @param cls closure
428 * @param emsg NULL on success 407 * @param emsg NULL on success
@@ -436,11 +415,11 @@ churn_callback (void *cls, const char *emsg)
436 { 415 {
437 peers_running = peers_next_round; 416 peers_running = peers_next_round;
438 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 417 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
439 "Round %lu, churn finished successfully.\n", 418 "Round %llu, churn finished successfully.\n",
440 current_round); 419 current_round);
441 GNUNET_assert(disconnect_task == GNUNET_SCHEDULER_NO_TASK); 420 GNUNET_assert(disconnect_task == GNUNET_SCHEDULER_NO_TASK);
442 GNUNET_asprintf(&temp_output_file, 421 GNUNET_asprintf(&temp_output_file,
443 "%s_%lu.dot", 422 "%s_%llu.dot",
444 topology_file, 423 topology_file,
445 current_round); 424 current_round);
446 GNUNET_TESTING_peergroup_topology_to_file(pg, 425 GNUNET_TESTING_peergroup_topology_to_file(pg,
@@ -455,10 +434,10 @@ churn_callback (void *cls, const char *emsg)
455 else 434 else
456 { 435 {
457 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 436 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
458 "Round %lu, churn FAILED!!\n", 437 "Round %llu, churn FAILED!!\n",
459 current_round); 438 current_round);
460 GNUNET_SCHEDULER_cancel(shutdown_handle); 439 GNUNET_SCHEDULER_cancel(shutdown_handle);
461 GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 440 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
462 } 441 }
463} 442}
464 443
@@ -490,20 +469,23 @@ churn_peers (void *cls,
490 GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 469 GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
491 } 470 }
492 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 471 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
493 "Round %lu, turning off %lu peers, turning on %lu peers!\n", 472 "Round %llu, turning off %llu peers, turning on %llu peers!\n",
494 current_round, 473 current_round,
495 (peers_running > peers_next_round) ? peers_running 474 (peers_running > peers_next_round)
496 - peers_next_round : 0, 475 ? peers_running - peers_next_round
497 (peers_next_round > peers_running) ? peers_next_round 476 : 0,
498 - peers_running : 0); 477 (peers_next_round > peers_running)
478 ? peers_next_round - peers_running
479 : 0);
499 GNUNET_TESTING_daemons_churn (pg, "nse", 480 GNUNET_TESTING_daemons_churn (pg, "nse",
500 (peers_running > peers_next_round) ? peers_running 481 (peers_running > peers_next_round)
501 - peers_next_round 482 ? peers_running - peers_next_round
502 : 0, 483 : 0,
503 (peers_next_round > peers_running) ? peers_next_round 484 (peers_next_round > peers_running)
504 - peers_running 485 ? peers_next_round - peers_running
505 : 0, wait_time, &churn_callback, 486 : 0,
506 NULL); 487 wait_time,
488 &churn_callback, NULL);
507 } 489 }
508} 490}
509 491
@@ -515,6 +497,7 @@ nse_started_cb(void *cls, const char *emsg)
515 disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time, &disconnect_nse_peers, NULL); 497 disconnect_task = GNUNET_SCHEDULER_add_delayed(wait_time, &disconnect_nse_peers, NULL);
516} 498}
517 499
500
518static void 501static void
519my_cb (void *cls, 502my_cb (void *cls,
520 const char *emsg) 503 const char *emsg)
@@ -535,7 +518,8 @@ my_cb (void *cls,
535 "Peer Group started successfully, connecting to NSE service for each peer!\n"); 518 "Peer Group started successfully, connecting to NSE service for each peer!\n");
536#endif 519#endif
537 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 520 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
538 "Have %u connections\n", total_connections); 521 "Have %u connections\n",
522 total_connections);
539 if (data_file != NULL) 523 if (data_file != NULL)
540 { 524 {
541 buf = NULL; 525 buf = NULL;
@@ -555,6 +539,7 @@ my_cb (void *cls,
555 539
556} 540}
557 541
542
558/** 543/**
559 * Function that will be called whenever two daemons are connected by 544 * Function that will be called whenever two daemons are connected by
560 * the testing library. 545 * the testing library.
@@ -596,12 +581,12 @@ run (void *cls,
596 581
597 ok = 1; 582 ok = 1;
598 testing_cfg = GNUNET_CONFIGURATION_create(); 583 testing_cfg = GNUNET_CONFIGURATION_create();
599 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(testing_cfg, cfgfile));
600#if VERBOSE 584#if VERBOSE
601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 585 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
602 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", 586 GNUNET_CONFIGURATION_set_value_string (testing_cfg,
603 "use_progressbars", 587 "testing",
604 "YES"); 588 "use_progressbars",
589 "YES");
605#endif 590#endif
606 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 591 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg,
607 "testing", 592 "testing",
@@ -716,8 +701,6 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
716int 701int
717main (int argc, char *argv[]) 702main (int argc, char *argv[])
718{ 703{
719 int ret;
720
721 GNUNET_log_setup ("nse-profiler", 704 GNUNET_log_setup ("nse-profiler",
722#if VERBOSE 705#if VERBOSE
723 "DEBUG", 706 "DEBUG",
@@ -725,15 +708,15 @@ main (int argc, char *argv[])
725 "WARNING", 708 "WARNING",
726#endif 709#endif
727 NULL); 710 NULL);
728 ret = 1;
729 GNUNET_PROGRAM_run (argc, 711 GNUNET_PROGRAM_run (argc,
730 argv, "nse-profiler", gettext_noop 712 argv, "nse-profiler",
731 ("Run a test of the NSE service."), 713 gettext_noop ("Measure quality and performance of the NSE service."),
732 options, &run, &ok); 714 options,
715 &run, NULL);
733#if REMOVE_DIR 716#if REMOVE_DIR
734 GNUNET_DISK_directory_remove ("/tmp/nse-profiler"); 717 GNUNET_DISK_directory_remove ("/tmp/nse-profiler");
735#endif 718#endif
736 return ret; 719 return ok;
737} 720}
738 721
739/* end of nse-profiler.c */ 722/* end of nse-profiler.c */