aboutsummaryrefslogtreecommitdiff
path: root/src/nse/gnunet-nse-profiler.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/nse/gnunet-nse-profiler.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/nse/gnunet-nse-profiler.c')
-rw-r--r--src/nse/gnunet-nse-profiler.c208
1 files changed, 98 insertions, 110 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index b88dbc3fc..df26280c4 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -213,13 +213,12 @@ handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
213 213
214 if (output_file != NULL) 214 if (output_file != NULL)
215 { 215 {
216 size = GNUNET_asprintf (&output_buffer, 216 size =
217 "%s %llu %llu %f %f %f\n", 217 GNUNET_asprintf (&output_buffer, "%s %llu %llu %f %f %f\n",
218 GNUNET_i2s (&peer->daemon->id), 218 GNUNET_i2s (&peer->daemon->id), peers_running,
219 peers_running, 219 timestamp.abs_value,
220 timestamp.abs_value, 220 GNUNET_NSE_log_estimate_to_n (estimate), estimate,
221 GNUNET_NSE_log_estimate_to_n (estimate), 221 std_dev);
222 estimate, std_dev);
223 if (size != GNUNET_DISK_file_write (output_file, output_buffer, size)) 222 if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
224 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); 223 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
225 GNUNET_free (output_buffer); 224 GNUNET_free (output_buffer);
@@ -254,9 +253,9 @@ connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
254 if (GNUNET_YES == 253 if (GNUNET_YES ==
255 GNUNET_TESTING_daemon_running (GNUNET_TESTING_daemon_get (pg, i))) 254 GNUNET_TESTING_daemon_running (GNUNET_TESTING_daemon_get (pg, i)))
256 { 255 {
257 current_peer->nse_handle = GNUNET_NSE_connect (current_peer->daemon->cfg, 256 current_peer->nse_handle =
258 &handle_estimate, 257 GNUNET_NSE_connect (current_peer->daemon->cfg, &handle_estimate,
259 current_peer); 258 current_peer);
260 GNUNET_assert (current_peer->nse_handle != NULL); 259 GNUNET_assert (current_peer->nse_handle != NULL);
261 } 260 }
262 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); 261 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
@@ -264,8 +263,8 @@ connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
264} 263}
265 264
266 265
267static void 266static void churn_peers (void *cls,
268churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 267 const struct GNUNET_SCHEDULER_TaskContext *tc);
269 268
270 269
271/** 270/**
@@ -286,9 +285,9 @@ stats_finished_callback (void *cls, int success)
286 { 285 {
287 /* Stats lookup successful, write out data */ 286 /* Stats lookup successful, write out data */
288 buf = NULL; 287 buf = NULL;
289 buf_len = GNUNET_asprintf (&buf, 288 buf_len =
290 "TOTAL_NSE_BYTES: %u\n", 289 GNUNET_asprintf (&buf, "TOTAL_NSE_BYTES: %u\n",
291 stats_context->total_nse_bytes); 290 stats_context->total_nse_bytes);
292 if (buf_len > 0) 291 if (buf_len > 0)
293 { 292 {
294 GNUNET_DISK_file_write (data_file, buf, buf_len); 293 GNUNET_DISK_file_write (data_file, buf, buf_len);
@@ -314,10 +313,9 @@ stats_finished_callback (void *cls, int success)
314 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 313 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
315 */ 314 */
316static int 315static int
317statistics_iterator (void *cls, 316statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer,
318 const struct GNUNET_PeerIdentity *peer, 317 const char *subsystem, const char *name, uint64_t value,
319 const char *subsystem, 318 int is_persistent)
320 const char *name, uint64_t value, int is_persistent)
321{ 319{
322 struct StatsContext *stats_context = cls; 320 struct StatsContext *stats_context = cls;
323 321
@@ -350,10 +348,9 @@ disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
350 } 348 }
351 349
352 GNUNET_asprintf (&buf, "round%llu", current_round); 350 GNUNET_asprintf (&buf, "round%llu", current_round);
353 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (testing_cfg, 351 if (GNUNET_OK ==
354 "nse-profiler", 352 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "nse-profiler", buf,
355 buf, 353 &peers_next_round))
356 &peers_next_round))
357 { 354 {
358 current_round++; 355 current_round++;
359 GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK); 356 GNUNET_assert (churn_task == GNUNET_SCHEDULER_NO_TASK);
@@ -364,8 +361,7 @@ disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
364 stats_context = GNUNET_malloc (sizeof (struct StatsContext)); 361 stats_context = GNUNET_malloc (sizeof (struct StatsContext));
365 GNUNET_SCHEDULER_cancel (shutdown_handle); 362 GNUNET_SCHEDULER_cancel (shutdown_handle);
366 shutdown_handle = GNUNET_SCHEDULER_NO_TASK; 363 shutdown_handle = GNUNET_SCHEDULER_NO_TASK;
367 GNUNET_TESTING_get_statistics (pg, 364 GNUNET_TESTING_get_statistics (pg, &stats_finished_callback,
368 &stats_finished_callback,
369 &statistics_iterator, stats_context); 365 &statistics_iterator, stats_context);
370 } 366 }
371 GNUNET_free (buf); 367 GNUNET_free (buf);
@@ -381,8 +377,8 @@ disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381static void 377static void
382topology_output_callback (void *cls, const char *emsg) 378topology_output_callback (void *cls, const char *emsg)
383{ 379{
384 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, 380 disconnect_task =
385 &disconnect_nse_peers, NULL); 381 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_nse_peers, NULL);
386 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL); 382 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
387} 383}
388 384
@@ -404,19 +400,18 @@ churn_callback (void *cls, const char *emsg)
404 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 400 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
405 "Round %llu, churn finished successfully.\n", current_round); 401 "Round %llu, churn finished successfully.\n", current_round);
406 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); 402 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
407 GNUNET_asprintf (&temp_output_file, 403 GNUNET_asprintf (&temp_output_file, "%s_%llu.dot", topology_file,
408 "%s_%llu.dot", topology_file, current_round); 404 current_round);
409 GNUNET_TESTING_peergroup_topology_to_file (pg, 405 GNUNET_TESTING_peergroup_topology_to_file (pg, temp_output_file,
410 temp_output_file,
411 &topology_output_callback, NULL); 406 &topology_output_callback, NULL);
412 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 407 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Writing topology to file %s\n",
413 "Writing topology to file %s\n", temp_output_file); 408 temp_output_file);
414 GNUNET_free (temp_output_file); 409 GNUNET_free (temp_output_file);
415 } 410 }
416 else 411 else
417 { 412 {
418 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 413 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %llu, churn FAILED!!\n",
419 "Round %llu, churn FAILED!!\n", current_round); 414 current_round);
420 GNUNET_SCHEDULER_cancel (shutdown_handle); 415 GNUNET_SCHEDULER_cancel (shutdown_handle);
421 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 416 shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
422 } 417 }
@@ -433,9 +428,8 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
433 /* Nothing to do... */ 428 /* Nothing to do... */
434 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL); 429 GNUNET_SCHEDULER_add_now (&connect_nse_service, NULL);
435 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK); 430 GNUNET_assert (disconnect_task == GNUNET_SCHEDULER_NO_TASK);
436 disconnect_task = GNUNET_SCHEDULER_add_delayed (wait_time, 431 disconnect_task =
437 &disconnect_nse_peers, 432 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_nse_peers, NULL);
438 NULL);
439 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n", 433 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Round %lu, doing nothing!\n",
440 current_round); 434 current_round);
441 } 435 }
@@ -451,18 +445,18 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
451 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 445 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
452 "Round %llu, turning off %llu peers, turning on %llu peers!\n", 446 "Round %llu, turning off %llu peers, turning on %llu peers!\n",
453 current_round, 447 current_round,
454 (peers_running > peers_next_round) 448 (peers_running >
455 ? peers_running - peers_next_round 449 peers_next_round) ? peers_running - peers_next_round : 0,
456 : 0, 450 (peers_next_round >
457 (peers_next_round > peers_running) 451 peers_running) ? peers_next_round - peers_running : 0);
458 ? peers_next_round - peers_running : 0);
459 GNUNET_TESTING_daemons_churn (pg, "nse", 452 GNUNET_TESTING_daemons_churn (pg, "nse",
460 (peers_running > peers_next_round) 453 (peers_running >
461 ? peers_running - peers_next_round 454 peers_next_round) ? peers_running -
462 : 0, 455 peers_next_round : 0,
463 (peers_next_round > peers_running) 456 (peers_next_round >
464 ? peers_next_round - peers_running 457 peers_running) ? peers_next_round -
465 : 0, wait_time, &churn_callback, NULL); 458 peers_running : 0, wait_time, &churn_callback,
459 NULL);
466 } 460 }
467} 461}
468 462
@@ -495,8 +489,8 @@ my_cb (void *cls, const char *emsg)
495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
496 "Peer Group started successfully, connecting to NSE service for each peer!\n"); 490 "Peer Group started successfully, connecting to NSE service for each peer!\n");
497#endif 491#endif
498 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 492 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n",
499 "Have %u connections\n", total_connections); 493 total_connections);
500 if (data_file != NULL) 494 if (data_file != NULL)
501 { 495 {
502 buf = NULL; 496 buf = NULL;
@@ -506,9 +500,8 @@ my_cb (void *cls, const char *emsg)
506 GNUNET_free (buf); 500 GNUNET_free (buf);
507 } 501 }
508 peers_running = GNUNET_TESTING_daemons_running (pg); 502 peers_running = GNUNET_TESTING_daemons_running (pg);
509 GNUNET_TESTING_daemons_start_service (pg, 503 GNUNET_TESTING_daemons_start_service (pg, "nse", wait_time, &nse_started_cb,
510 "nse", 504 NULL);
511 wait_time, &nse_started_cb, NULL);
512 505
513} 506}
514 507
@@ -528,10 +521,8 @@ my_cb (void *cls, const char *emsg)
528 * @param emsg error message (NULL on success) 521 * @param emsg error message (NULL on success)
529 */ 522 */
530static void 523static void
531connect_cb (void *cls, 524connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
532 const struct GNUNET_PeerIdentity *first, 525 const struct GNUNET_PeerIdentity *second, uint32_t distance,
533 const struct GNUNET_PeerIdentity *second,
534 uint32_t distance,
535 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 526 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
536 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 527 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
537 struct GNUNET_TESTING_Daemon *first_daemon, 528 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -543,9 +534,8 @@ connect_cb (void *cls,
543 534
544 535
545static void 536static void
546run (void *cls, 537run (void *cls, char *const *args, const char *cfgfile,
547 char *const *args, 538 const struct GNUNET_CONFIGURATION_Handle *cfg)
548 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
549{ 539{
550 char *temp_str; 540 char *temp_str;
551 unsigned long long temp_wait; 541 unsigned long long temp_wait;
@@ -555,100 +545,99 @@ run (void *cls,
555 testing_cfg = GNUNET_CONFIGURATION_create (); 545 testing_cfg = GNUNET_CONFIGURATION_create ();
556#if VERBOSE 546#if VERBOSE
557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
558 GNUNET_CONFIGURATION_set_value_string (testing_cfg, 548 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
559 "testing", "use_progressbars", "YES"); 549 "use_progressbars", "YES");
560#endif 550#endif
561 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 551 if (GNUNET_OK !=
562 "testing", 552 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
563 "num_peers", 553 "num_peers", &num_peers))
564 &num_peers))
565 { 554 {
566 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 555 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
567 "Option TESTING:NUM_PEERS is required!\n"); 556 "Option TESTING:NUM_PEERS is required!\n");
568 return; 557 return;
569 } 558 }
570 559
571 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 560 if (GNUNET_OK !=
572 "nse-profiler", 561 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "nse-profiler",
573 "wait_time", 562 "wait_time", &temp_wait))
574 &temp_wait))
575 { 563 {
576 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 564 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
577 "Option nse-profiler:wait_time is required!\n"); 565 "Option nse-profiler:wait_time is required!\n");
578 return; 566 return;
579 } 567 }
580 568
581 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (testing_cfg, 569 if (GNUNET_OK !=
582 "nse-profiler", 570 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "nse-profiler",
583 "connection_limit", 571 "connection_limit",
584 &connection_limit)) 572 &connection_limit))
585 { 573 {
586 connection_limit = 0; 574 connection_limit = 0;
587 } 575 }
588 576
589 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 577 if (GNUNET_OK !=
590 "nse-profiler", 578 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "nse-profiler",
591 "topology_output_file", 579 "topology_output_file",
592 &topology_file)) 580 &topology_file))
593 { 581 {
594 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 582 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
595 "Option nse-profiler:topology_output_file is required!\n"); 583 "Option nse-profiler:topology_output_file is required!\n");
596 return; 584 return;
597 } 585 }
598 586
599 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (testing_cfg, 587 if (GNUNET_OK !=
600 "nse-profiler", 588 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "nse-profiler",
601 "data_output_file", 589 "data_output_file",
602 &data_filename)) 590 &data_filename))
603 { 591 {
604 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 592 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
605 "Option nse-profiler:data_output_file is required!\n"); 593 "Option nse-profiler:data_output_file is required!\n");
606 return; 594 return;
607 } 595 }
608 596
609 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (testing_cfg, 597 if (GNUNET_YES ==
610 "nse-profiler", 598 GNUNET_CONFIGURATION_get_value_yesno (testing_cfg, "nse-profiler",
611 "skew_clock")) 599 "skew_clock"))
612 { 600 {
613 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Setting our clock as skewed...\n"); 601 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Setting our clock as skewed...\n");
614 clock_skew = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 602 clock_skew =
615 GNUNET_TIME_UNIT_MINUTES.rel_value); 603 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
604 GNUNET_TIME_UNIT_MINUTES.rel_value);
616 } 605 }
617 606
618 607
619 data_file = GNUNET_DISK_file_open (data_filename, 608 data_file =
620 GNUNET_DISK_OPEN_READWRITE 609 GNUNET_DISK_file_open (data_filename,
621 | GNUNET_DISK_OPEN_CREATE, 610 GNUNET_DISK_OPEN_READWRITE |
622 GNUNET_DISK_PERM_USER_READ | 611 GNUNET_DISK_OPEN_CREATE,
623 GNUNET_DISK_PERM_USER_WRITE); 612 GNUNET_DISK_PERM_USER_READ |
613 GNUNET_DISK_PERM_USER_WRITE);
624 if (data_file == NULL) 614 if (data_file == NULL)
625 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 615 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
626 "Failed to open %s for output!\n", data_filename); 616 data_filename);
627 GNUNET_free (data_filename); 617 GNUNET_free (data_filename);
628 618
629 wait_time = 619 wait_time =
630 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); 620 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
631 621
632 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, 622 if (GNUNET_YES ==
633 "nse-profiler", 623 GNUNET_CONFIGURATION_get_value_string (cfg, "nse-profiler", "output_file",
634 "output_file", 624 &temp_str))
635 &temp_str))
636 { 625 {
637 output_file = GNUNET_DISK_file_open (temp_str, GNUNET_DISK_OPEN_READWRITE 626 output_file =
638 | GNUNET_DISK_OPEN_CREATE, 627 GNUNET_DISK_file_open (temp_str,
639 GNUNET_DISK_PERM_USER_READ | 628 GNUNET_DISK_OPEN_READWRITE |
640 GNUNET_DISK_PERM_USER_WRITE); 629 GNUNET_DISK_OPEN_CREATE,
630 GNUNET_DISK_PERM_USER_READ |
631 GNUNET_DISK_PERM_USER_WRITE);
641 if (output_file == NULL) 632 if (output_file == NULL)
642 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 633 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
643 "Failed to open %s for output!\n", temp_str); 634 temp_str);
644 } 635 }
645 GNUNET_free_non_null (temp_str); 636 GNUNET_free_non_null (temp_str);
646 637
647 hosts = GNUNET_TESTING_hosts_load (testing_cfg); 638 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
648 639
649 pg = GNUNET_TESTING_peergroup_start (testing_cfg, 640 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
650 num_peers,
651 TIMEOUT,
652 &connect_cb, &my_cb, NULL, hosts); 641 &connect_cb, &my_cb, NULL, hosts);
653 GNUNET_assert (pg != NULL); 642 GNUNET_assert (pg != NULL);
654 shutdown_handle = 643 shutdown_handle =
@@ -679,8 +668,7 @@ main (int argc, char *argv[])
679 "WARNING", 668 "WARNING",
680#endif 669#endif
681 NULL); 670 NULL);
682 GNUNET_PROGRAM_run (argc, 671 GNUNET_PROGRAM_run (argc, argv, "nse-profiler",
683 argv, "nse-profiler",
684 gettext_noop 672 gettext_noop
685 ("Measure quality and performance of the NSE service."), 673 ("Measure quality and performance of the NSE service."),
686 options, &run, NULL); 674 options, &run, NULL);