aboutsummaryrefslogtreecommitdiff
path: root/src/statistics
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-04 11:57:59 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-04 11:57:59 +0200
commit58002acac13b2eef407a20ee3ddc5f458cd5e483 (patch)
tree8285fc1b32a8c9ac55f970667e7d29b791b6758e /src/statistics
parent9ce956ea4c93f038995a21c6c1c0133eee6bff75 (diff)
downloadgnunet-58002acac13b2eef407a20ee3ddc5f458cd5e483.tar.gz
gnunet-58002acac13b2eef407a20ee3ddc5f458cd5e483.zip
nicer loop structure
Diffstat (limited to 'src/statistics')
-rw-r--r--src/statistics/gnunet-statistics.c387
1 files changed, 178 insertions, 209 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index bf111ade2..bc30670e9 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -93,7 +93,8 @@ static int set_value;
93/** 93/**
94 * @brief Representation of all (testbed) nodes. 94 * @brief Representation of all (testbed) nodes.
95 */ 95 */
96static struct Node { 96static struct Node
97{
97 /** 98 /**
98 * @brief Index of the node in this array. 99 * @brief Index of the node in this array.
99 */ 100 */
@@ -117,7 +118,7 @@ static struct Node {
117 * @brief Identifier for shutdown task for this node. 118 * @brief Identifier for shutdown task for this node.
118 */ 119 */
119 struct GNUNET_SCHEDULER_Task *shutdown_task; 120 struct GNUNET_SCHEDULER_Task *shutdown_task;
120} *nodes; 121} * nodes;
121 122
122/** 123/**
123 * @brief Number of configurations of all (testbed) nodes. 124 * @brief Number of configurations of all (testbed) nodes.
@@ -204,11 +205,9 @@ new_value_set (const char *subsystem,
204 * @return GNUNET_YES - continue iteration. 205 * @return GNUNET_YES - continue iteration.
205 */ 206 */
206static int 207static int
207printer (void *cls, 208printer (void *cls, const struct GNUNET_HashCode *key, void *value)
208 const struct GNUNET_HashCode *key,
209 void *value)
210{ 209{
211 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 210 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
212 const char *now_str; 211 const char *now_str;
213 struct ValueSet *value_set = value; 212 struct ValueSet *value_set = value;
214 213
@@ -218,38 +217,38 @@ printer (void *cls,
218 { 217 {
219 now_str = GNUNET_STRINGS_absolute_time_to_string (now); 218 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
220 FPRINTF (stdout, 219 FPRINTF (stdout,
221 "%24s%s %s%s%12s%s %s%50s%s%s ", 220 "%24s%s %s%s%12s%s %s%50s%s%s ",
222 now_str, 221 now_str,
223 csv_separator, 222 csv_separator,
224 value_set->is_persistent ? "!" : " ", 223 value_set->is_persistent ? "!" : " ",
225 csv_separator, 224 csv_separator,
226 value_set->subsystem, 225 value_set->subsystem,
227 csv_separator, 226 csv_separator,
228 (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ 227 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
229 _(value_set->name), 228 _ (value_set->name),
230 (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ 229 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
231 (0 == strlen (csv_separator) ? ":": csv_separator)); 230 (0 == strlen (csv_separator) ? ":" : csv_separator));
232 } 231 }
233 else 232 else
234 { 233 {
235 FPRINTF (stdout, 234 FPRINTF (stdout,
236 "%s%s%12s%s %s%50s%s%s ", 235 "%s%s%12s%s %s%50s%s%s ",
237 value_set->is_persistent ? "!" : " ", 236 value_set->is_persistent ? "!" : " ",
238 csv_separator, 237 csv_separator,
239 value_set->subsystem, 238 value_set->subsystem,
240 csv_separator, 239 csv_separator,
241 (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ 240 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
242 _(value_set->name), 241 _ (value_set->name),
243 (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ 242 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
244 (0 == strlen (csv_separator) ? ":": csv_separator)); 243 (0 == strlen (csv_separator) ? ":" : csv_separator));
245 } 244 }
246 } 245 }
247 for (unsigned i = 0; i < num_nodes; i++) 246 for (unsigned i = 0; i < num_nodes; i++)
248 { 247 {
249 FPRINTF (stdout, 248 FPRINTF (stdout,
250 "%16llu%s", 249 "%16llu%s",
251 (unsigned long long) value_set->values[i], 250 (unsigned long long) value_set->values[i],
252 csv_separator); 251 csv_separator);
253 } 252 }
254 FPRINTF (stdout, "\n"); 253 FPRINTF (stdout, "\n");
255 GNUNET_free (value_set->subsystem); 254 GNUNET_free (value_set->subsystem);
@@ -276,7 +275,7 @@ printer_watch (void *cls,
276 uint64_t value, 275 uint64_t value,
277 int is_persistent) 276 int is_persistent)
278{ 277{
279 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 278 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
280 const char *now_str; 279 const char *now_str;
281 280
282 if (quiet == GNUNET_NO) 281 if (quiet == GNUNET_NO)
@@ -292,10 +291,10 @@ printer_watch (void *cls,
292 csv_separator, 291 csv_separator,
293 subsystem, 292 subsystem,
294 csv_separator, 293 csv_separator,
295 (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ 294 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
296 _(name), 295 _ (name),
297 (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ 296 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
298 (0 == strlen (csv_separator) ? ":": csv_separator), 297 (0 == strlen (csv_separator) ? ":" : csv_separator),
299 (unsigned long long) value); 298 (unsigned long long) value);
300 } 299 }
301 else 300 else
@@ -306,17 +305,15 @@ printer_watch (void *cls,
306 csv_separator, 305 csv_separator,
307 subsystem, 306 subsystem,
308 csv_separator, 307 csv_separator,
309 (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ 308 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
310 _(name), 309 _ (name),
311 (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */ 310 (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */
312 (0 == strlen (csv_separator) ? ":": csv_separator), 311 (0 == strlen (csv_separator) ? ":" : csv_separator),
313 (unsigned long long) value); 312 (unsigned long long) value);
314 } 313 }
315 } 314 }
316 else 315 else
317 FPRINTF (stdout, 316 FPRINTF (stdout, "%llu\n", (unsigned long long) value);
318 "%llu\n",
319 (unsigned long long) value);
320 317
321 return GNUNET_OK; 318 return GNUNET_OK;
322} 319}
@@ -335,8 +332,8 @@ clean_node (void *cls)
335 struct GNUNET_STATISTICS_Handle *h; 332 struct GNUNET_STATISTICS_Handle *h;
336 struct GNUNET_STATISTICS_GetHandle *gh; 333 struct GNUNET_STATISTICS_GetHandle *gh;
337 334
338 if ( (NULL != path_testbed) && /* were issued with -t <testbed-path> option */ 335 if ((NULL != path_testbed) && /* were issued with -t <testbed-path> option */
339 (NULL != nodes[index_node].conf) ) 336 (NULL != nodes[index_node].conf))
340 { 337 {
341 GNUNET_CONFIGURATION_destroy (nodes[index_node].conf); 338 GNUNET_CONFIGURATION_destroy (nodes[index_node].conf);
342 nodes[index_node].conf = NULL; 339 nodes[index_node].conf = NULL;
@@ -352,7 +349,8 @@ clean_node (void *cls)
352 } 349 }
353 if (GNUNET_YES == watch) 350 if (GNUNET_YES == watch)
354 { 351 {
355 GNUNET_assert (GNUNET_OK == 352 GNUNET_assert (
353 GNUNET_OK ==
356 GNUNET_STATISTICS_watch_cancel (h, 354 GNUNET_STATISTICS_watch_cancel (h,
357 subsystem, 355 subsystem,
358 name, 356 name,
@@ -383,7 +381,7 @@ static void
383print_finish (void *cls) 381print_finish (void *cls)
384{ 382{
385 GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL); 383 GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL);
386 GNUNET_SCHEDULER_shutdown(); 384 GNUNET_SCHEDULER_shutdown ();
387} 385}
388 386
389/** 387/**
@@ -395,8 +393,7 @@ print_finish (void *cls)
395 * @param succes Whether statistics were obtained successfully. 393 * @param succes Whether statistics were obtained successfully.
396 */ 394 */
397static void 395static void
398continuation_print (void *cls, 396continuation_print (void *cls, int success)
399 int success)
400{ 397{
401 const unsigned index_node = *(unsigned *) cls; 398 const unsigned index_node = *(unsigned *) cls;
402 399
@@ -404,12 +401,10 @@ continuation_print (void *cls,
404 if (GNUNET_OK != success) 401 if (GNUNET_OK != success)
405 { 402 {
406 if (NULL == remote_host) 403 if (NULL == remote_host)
407 FPRINTF (stderr, 404 FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n"));
408 "%s",
409 _("Failed to obtain statistics.\n"));
410 else 405 else
411 FPRINTF (stderr, 406 FPRINTF (stderr,
412 _("Failed to obtain statistics from host `%s:%llu'\n"), 407 _ ("Failed to obtain statistics from host `%s:%llu'\n"),
413 remote_host, 408 remote_host,
414 remote_port); 409 remote_port);
415 ret = 1; 410 ret = 1;
@@ -435,8 +430,7 @@ continuation_print (void *cls,
435 * successfully obtained, #GNUNET_SYSERR if not. 430 * successfully obtained, #GNUNET_SYSERR if not.
436 */ 431 */
437static void 432static void
438cleanup (void *cls, 433cleanup (void *cls, int success)
439 int success)
440{ 434{
441 for (unsigned i = 0; i < num_nodes; i++) 435 for (unsigned i = 0; i < num_nodes; i++)
442 { 436 {
@@ -445,12 +439,10 @@ cleanup (void *cls,
445 if (GNUNET_OK != success) 439 if (GNUNET_OK != success)
446 { 440 {
447 if (NULL == remote_host) 441 if (NULL == remote_host)
448 FPRINTF (stderr, 442 FPRINTF (stderr, "%s", _ ("Failed to obtain statistics.\n"));
449 "%s",
450 _("Failed to obtain statistics.\n"));
451 else 443 else
452 FPRINTF (stderr, 444 FPRINTF (stderr,
453 _("Failed to obtain statistics from host `%s:%llu'\n"), 445 _ ("Failed to obtain statistics from host `%s:%llu'\n"),
454 remote_host, 446 remote_host,
455 remote_port); 447 remote_port);
456 ret = 1; 448 ret = 1;
@@ -492,19 +484,19 @@ collector (void *cls,
492 GNUNET_free (subsys_name); 484 GNUNET_free (subsys_name);
493 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (values, key)) 485 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (values, key))
494 { 486 {
495 // get
496 value_set = GNUNET_CONTAINER_multihashmap_get (values, key); 487 value_set = GNUNET_CONTAINER_multihashmap_get (values, key);
497 } 488 }
498 else 489 else
499 { 490 {
500 // new
501 value_set = new_value_set (subsystem, name, num_nodes, is_persistent); 491 value_set = new_value_set (subsystem, name, num_nodes, is_persistent);
502 } 492 }
503 // write
504 value_set->values[index_node] = value; 493 value_set->values[index_node] = value;
505 // put 494 GNUNET_assert (GNUNET_YES ==
506 GNUNET_CONTAINER_multihashmap_put (values, key, value_set, 495 GNUNET_CONTAINER_multihashmap_put (
507 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 496 values,
497 key,
498 value_set,
499 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
508 return GNUNET_OK; 500 return GNUNET_OK;
509} 501}
510 502
@@ -523,22 +515,17 @@ main_task (void *cls)
523 { 515 {
524 if (NULL == subsystem) 516 if (NULL == subsystem)
525 { 517 {
526 FPRINTF (stderr, 518 FPRINTF (stderr, "%s", _ ("Missing argument: subsystem \n"));
527 "%s",
528 _("Missing argument: subsystem \n"));
529 ret = 1; 519 ret = 1;
530 return; 520 return;
531 } 521 }
532 if (NULL == name) 522 if (NULL == name)
533 { 523 {
534 FPRINTF (stderr, 524 FPRINTF (stderr, "%s", _ ("Missing argument: name\n"));
535 "%s",
536 _("Missing argument: name\n"));
537 ret = 1; 525 ret = 1;
538 return; 526 return;
539 } 527 }
540 nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem, 528 nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem, cfg);
541 cfg);
542 if (NULL == nodes[index_node].handle) 529 if (NULL == nodes[index_node].handle)
543 { 530 {
544 ret = 1; 531 ret = 1;
@@ -548,59 +535,51 @@ main_task (void *cls)
548 name, 535 name,
549 (uint64_t) set_val, 536 (uint64_t) set_val,
550 persistent); 537 persistent);
551 GNUNET_STATISTICS_destroy (nodes[index_node].handle, 538 GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_YES);
552 GNUNET_YES);
553 nodes[index_node].handle = NULL; 539 nodes[index_node].handle = NULL;
554 return; 540 return;
555 } 541 }
556 if (NULL == (nodes[index_node].handle = GNUNET_STATISTICS_create ("gnunet-statistics", 542 if (NULL == (nodes[index_node].handle =
557 cfg))) 543 GNUNET_STATISTICS_create ("gnunet-statistics", cfg)))
558 { 544 {
559 ret = 1; 545 ret = 1;
560 return; 546 return;
561 } 547 }
562 if (GNUNET_NO == watch) 548 if (GNUNET_NO == watch)
563 { 549 {
564 if (NULL == 550 if (NULL == (nodes[index_node].gh =
565 (nodes[index_node].gh = GNUNET_STATISTICS_get (nodes[index_node].handle, 551 GNUNET_STATISTICS_get (nodes[index_node].handle,
566 subsystem, 552 subsystem,
567 name, 553 name,
568 &continuation_print, 554 &continuation_print,
569 &collector, 555 &collector,
570 &nodes[index_node].index_node)) ) 556 &nodes[index_node].index_node)))
571 cleanup (nodes[index_node].handle, 557 cleanup (nodes[index_node].handle, GNUNET_SYSERR);
572 GNUNET_SYSERR);
573 } 558 }
574 else 559 else
575 { 560 {
576 if ( (NULL == subsystem) || 561 if ((NULL == subsystem) || (NULL == name))
577 (NULL == name) )
578 { 562 {
579 printf (_("No subsystem or name given\n")); 563 printf (_ ("No subsystem or name given\n"));
580 GNUNET_STATISTICS_destroy (nodes[index_node].handle, 564 GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_NO);
581 GNUNET_NO);
582 nodes[index_node].handle = NULL; 565 nodes[index_node].handle = NULL;
583 ret = 1; 566 ret = 1;
584 return; 567 return;
585 } 568 }
586 if (GNUNET_OK != 569 if (GNUNET_OK != GNUNET_STATISTICS_watch (nodes[index_node].handle,
587 GNUNET_STATISTICS_watch (nodes[index_node].handle, 570 subsystem,
588 subsystem, 571 name,
589 name, 572 &printer_watch,
590 &printer_watch, 573 &nodes[index_node].index_node))
591 &nodes[index_node].index_node))
592 { 574 {
593 fprintf (stderr, 575 fprintf (stderr, _ ("Failed to initialize watch routine\n"));
594 _("Failed to initialize watch routine\n"));
595 nodes[index_node].shutdown_task = 576 nodes[index_node].shutdown_task =
596 GNUNET_SCHEDULER_add_now (&clean_node, 577 GNUNET_SCHEDULER_add_now (&clean_node, &nodes[index_node].index_node);
597 &nodes[index_node].index_node);
598 return; 578 return;
599 } 579 }
600 } 580 }
601 nodes[index_node].shutdown_task = 581 nodes[index_node].shutdown_task =
602 GNUNET_SCHEDULER_add_shutdown (&clean_node, 582 GNUNET_SCHEDULER_add_shutdown (&clean_node, &nodes[index_node].index_node);
603 &nodes[index_node].index_node);
604} 583}
605 584
606/** 585/**
@@ -615,16 +594,16 @@ main_task (void *cls)
615 * @return to continue iteration or not to 594 * @return to continue iteration or not to
616 */ 595 */
617static int 596static int
618iter_check_config (void *cls, 597iter_check_config (void *cls, const char *filename)
619 const char *filename)
620{ 598{
621 if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6)) 599 if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6))
622 { 600 {
623 /* Found the config - stop iteration successfully */ 601 /* Found the config - stop iteration successfully */
624 GNUNET_array_grow (nodes, num_nodes, num_nodes+1); 602 GNUNET_array_grow (nodes, num_nodes, num_nodes + 1);
625 nodes[num_nodes-1].conf = GNUNET_CONFIGURATION_create(); 603 nodes[num_nodes - 1].conf = GNUNET_CONFIGURATION_create ();
626 nodes[num_nodes-1].index_node = num_nodes-1; 604 nodes[num_nodes - 1].index_node = num_nodes - 1;
627 if (GNUNET_OK != GNUNET_CONFIGURATION_load (nodes[num_nodes-1].conf, filename)) 605 if (GNUNET_OK !=
606 GNUNET_CONFIGURATION_load (nodes[num_nodes - 1].conf, filename))
628 { 607 {
629 FPRINTF (stderr, "Failed loading config `%s'\n", filename); 608 FPRINTF (stderr, "Failed loading config `%s'\n", filename);
630 return GNUNET_SYSERR; 609 return GNUNET_SYSERR;
@@ -652,19 +631,14 @@ iter_check_config (void *cls,
652 * @return status whether to continue iteration 631 * @return status whether to continue iteration
653 */ 632 */
654static int 633static int
655iter_testbed_path (void *cls, 634iter_testbed_path (void *cls, const char *filename)
656 const char *filename)
657{ 635{
658 unsigned index_node; 636 unsigned index_node;
659 637
660 GNUNET_assert (NULL != filename); 638 GNUNET_assert (NULL != filename);
661 if (1 == SSCANF (GNUNET_STRINGS_get_short_name (filename), 639 if (1 == SSCANF (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node))
662 "%u",
663 &index_node))
664 { 640 {
665 if (-1 == GNUNET_DISK_directory_scan (filename, 641 if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL))
666 iter_check_config,
667 NULL))
668 { 642 {
669 /* This is probably no directory for a testbed node 643 /* This is probably no directory for a testbed node
670 * Go on with iteration */ 644 * Go on with iteration */
@@ -687,14 +661,11 @@ discover_testbed_nodes (const char *path_testbed)
687{ 661{
688 int num_dir_entries; 662 int num_dir_entries;
689 663
690 num_dir_entries = GNUNET_DISK_directory_scan (path_testbed, 664 num_dir_entries =
691 iter_testbed_path, 665 GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL);
692 NULL);
693 if (-1 == num_dir_entries) 666 if (-1 == num_dir_entries)
694 { 667 {
695 FPRINTF (stderr, 668 FPRINTF (stderr, "Failure during scanning directory `%s'\n", path_testbed);
696 "Failure during scanning directory `%s'\n",
697 path_testbed);
698 return -1; 669 return -1;
699 } 670 }
700 return 0; 671 return 0;
@@ -718,16 +689,13 @@ run (void *cls,
718 689
719 c = (struct GNUNET_CONFIGURATION_Handle *) cfg; 690 c = (struct GNUNET_CONFIGURATION_Handle *) cfg;
720 set_value = GNUNET_NO; 691 set_value = GNUNET_NO;
721 if (NULL == csv_separator) csv_separator = ""; 692 if (NULL == csv_separator)
693 csv_separator = "";
722 if (NULL != args[0]) 694 if (NULL != args[0])
723 { 695 {
724 if (1 != SSCANF (args[0], 696 if (1 != SSCANF (args[0], "%llu", &set_val))
725 "%llu",
726 &set_val))
727 { 697 {
728 FPRINTF (stderr, 698 FPRINTF (stderr, _ ("Invalid argument `%s'\n"), args[0]);
729 _("Invalid argument `%s'\n"),
730 args[0]);
731 ret = 1; 699 ret = 1;
732 return; 700 return;
733 } 701 }
@@ -737,39 +705,36 @@ run (void *cls,
737 { 705 {
738 if (0 == remote_port) 706 if (0 == remote_port)
739 { 707 {
740 if (GNUNET_SYSERR == 708 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
741 GNUNET_CONFIGURATION_get_value_number (cfg, 709 "statistics",
742 "statistics", 710 "PORT",
743 "PORT", 711 &remote_port))
744 &remote_port))
745 { 712 {
746 FPRINTF (stderr, 713 FPRINTF (stderr,
747 _("A port is required to connect to host `%s'\n"), 714 _ ("A port is required to connect to host `%s'\n"),
748 remote_host); 715 remote_host);
749 return; 716 return;
750 } 717 }
751 } 718 }
752 else if (65535 <= remote_port) 719 else if (65535 <= remote_port)
753 { 720 {
754 FPRINTF (stderr, 721 FPRINTF (stderr,
755 _("A port has to be between 1 and 65535 to connect to host `%s'\n"), 722 _ (
756 remote_host); 723 "A port has to be between 1 and 65535 to connect to host `%s'\n"),
724 remote_host);
757 return; 725 return;
758 } 726 }
759 727
760 /* Manipulate configuration */ 728 /* Manipulate configuration */
729 GNUNET_CONFIGURATION_set_value_string (c, "statistics", "UNIXPATH", "");
761 GNUNET_CONFIGURATION_set_value_string (c, 730 GNUNET_CONFIGURATION_set_value_string (c,
762 "statistics", 731 "statistics",
763 "UNIXPATH", 732 "HOSTNAME",
764 ""); 733 remote_host);
765 GNUNET_CONFIGURATION_set_value_string (c,
766 "statistics",
767 "HOSTNAME",
768 remote_host);
769 GNUNET_CONFIGURATION_set_value_number (c, 734 GNUNET_CONFIGURATION_set_value_number (c,
770 "statistics", 735 "statistics",
771 "PORT", 736 "PORT",
772 remote_port); 737 remote_port);
773 } 738 }
774 if (NULL == path_testbed) 739 if (NULL == path_testbed)
775 { 740 {
@@ -783,7 +748,8 @@ run (void *cls,
783 { 748 {
784 if (GNUNET_YES == watch) 749 if (GNUNET_YES == watch)
785 { 750 {
786 printf (_("Not able to watch testbed nodes (yet - feel free to implement)\n")); 751 printf (
752 _ ("Not able to watch testbed nodes (yet - feel free to implement)\n"));
787 ret = 1; 753 ret = 1;
788 return; 754 return;
789 } 755 }
@@ -795,8 +761,7 @@ run (void *cls,
795 /* For each config/node collect statistics */ 761 /* For each config/node collect statistics */
796 for (unsigned i = 0; i < num_nodes; i++) 762 for (unsigned i = 0; i < num_nodes; i++)
797 { 763 {
798 GNUNET_SCHEDULER_add_now (&main_task, 764 GNUNET_SCHEDULER_add_now (&main_task, &nodes[i].index_node);
799 &nodes[i].index_node);
800 } 765 }
801 } 766 }
802} 767}
@@ -812,78 +777,82 @@ run (void *cls,
812int 777int
813main (int argc, char *const *argv) 778main (int argc, char *const *argv)
814{ 779{
815 struct GNUNET_GETOPT_CommandLineOption options[] = { 780 struct GNUNET_GETOPT_CommandLineOption options[] =
816 GNUNET_GETOPT_option_string ('n', 781 {GNUNET_GETOPT_option_string (
817 "name", 782 'n',
818 "NAME", 783 "name",
819 gettext_noop ("limit output to statistics for the given NAME"), 784 "NAME",
820 &name), 785 gettext_noop ("limit output to statistics for the given NAME"),
821 786 &name),
822 GNUNET_GETOPT_option_flag ('p', 787
823 "persistent", 788 GNUNET_GETOPT_option_flag ('p',
824 gettext_noop ("make the value being set persistent"), 789 "persistent",
825 &persistent), 790 gettext_noop (
826 791 "make the value being set persistent"),
827 GNUNET_GETOPT_option_string ('s', 792 &persistent),
828 "subsystem", 793
829 "SUBSYSTEM", 794 GNUNET_GETOPT_option_string ('s',
830 gettext_noop ("limit output to the given SUBSYSTEM"), 795 "subsystem",
831 &subsystem), 796 "SUBSYSTEM",
832 797 gettext_noop (
833 GNUNET_GETOPT_option_string ('S', 798 "limit output to the given SUBSYSTEM"),
834 "csv-separator", 799 &subsystem),
835 "CSV_SEPARATOR", 800
836 gettext_noop ("use as csv separator"), 801 GNUNET_GETOPT_option_string ('S',
837 &csv_separator), 802 "csv-separator",
838 803 "CSV_SEPARATOR",
839 GNUNET_GETOPT_option_filename ('t', 804 gettext_noop ("use as csv separator"),
840 "testbed", 805 &csv_separator),
841 "TESTBED", 806
842 gettext_noop ("path to the folder containing the testbed data"), 807 GNUNET_GETOPT_option_filename (
843 &path_testbed), 808 't',
844 809 "testbed",
845 GNUNET_GETOPT_option_flag ('q', 810 "TESTBED",
846 "quiet", 811 gettext_noop ("path to the folder containing the testbed data"),
847 gettext_noop ("just print the statistics value"), 812 &path_testbed),
848 &quiet), 813
849 814 GNUNET_GETOPT_option_flag ('q',
850 GNUNET_GETOPT_option_flag ('w', 815 "quiet",
851 "watch", 816 gettext_noop (
852 gettext_noop ("watch value continuously"), 817 "just print the statistics value"),
853 &watch), 818 &quiet),
854 819
855 GNUNET_GETOPT_option_string ('r', 820 GNUNET_GETOPT_option_flag ('w',
856 "remote", 821 "watch",
857 "REMOTE", 822 gettext_noop ("watch value continuously"),
858 gettext_noop ("connect to remote host"), 823 &watch),
859 &remote_host), 824
860 825 GNUNET_GETOPT_option_string ('r',
861 GNUNET_GETOPT_option_ulong ('o', 826 "remote",
862 "port", 827 "REMOTE",
863 "PORT", 828 gettext_noop ("connect to remote host"),
864 gettext_noop ("port for remote host"), 829 &remote_host),
865 &remote_port), 830
866 831 GNUNET_GETOPT_option_ulong ('o',
867 GNUNET_GETOPT_OPTION_END 832 "port",
868 }; 833 "PORT",
834 gettext_noop ("port for remote host"),
835 &remote_port),
836
837 GNUNET_GETOPT_OPTION_END};
869 remote_port = 0; 838 remote_port = 0;
870 remote_host = NULL; 839 remote_host = NULL;
871 if (GNUNET_OK != 840 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
872 GNUNET_STRINGS_get_utf8_args (argc, argv,
873 &argc, &argv))
874 return 2; 841 return 2;
875 842
876 ret = (GNUNET_OK == 843 ret = (GNUNET_OK ==
877 GNUNET_PROGRAM_run (argc, 844 GNUNET_PROGRAM_run (argc,
878 argv, 845 argv,
879 "gnunet-statistics [options [value]]", 846 "gnunet-statistics [options [value]]",
880 gettext_noop 847 gettext_noop (
881 ("Print statistics about GNUnet operations."), 848 "Print statistics about GNUnet operations."),
882 options, 849 options,
883 &run, 850 &run,
884 NULL)) ? ret : 1; 851 NULL))
852 ? ret
853 : 1;
885 GNUNET_free_non_null (remote_host); 854 GNUNET_free_non_null (remote_host);
886 GNUNET_free ((void*) argv); 855 GNUNET_free ((void *) argv);
887 return ret; 856 return ret;
888} 857}
889 858