aboutsummaryrefslogtreecommitdiff
path: root/src/statistics
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-11 23:11:43 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-11 23:11:43 +0200
commit7bcd5338f4c340e31eaf0d1cf36d393b66595acf (patch)
treeb47789968880fa8d0355add63d984c9c09621b31 /src/statistics
parentf490c0f3f5beb9ada5d05e01a6a01889d9902a2b (diff)
downloadgnunet-7bcd5338f4c340e31eaf0d1cf36d393b66595acf.tar.gz
gnunet-7bcd5338f4c340e31eaf0d1cf36d393b66595acf.zip
fix gnunet-statistics CLI
Diffstat (limited to 'src/statistics')
-rw-r--r--src/statistics/gnunet-statistics.c105
1 files changed, 57 insertions, 48 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index ae99662c4..47bdbf2c1 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -151,6 +151,7 @@ struct ValueSet
151 int is_persistent; 151 int is_persistent;
152}; 152};
153 153
154
154/** 155/**
155 * @brief Collection of all values (represented with #ValueSet). 156 * @brief Collection of all values (represented with #ValueSet).
156 */ 157 */
@@ -166,6 +167,7 @@ static int num_nodes_ready;
166 */ 167 */
167static int num_nodes_ready_shutdown; 168static int num_nodes_ready_shutdown;
168 169
170
169/** 171/**
170 * @brief Create a new #ValueSet 172 * @brief Create a new #ValueSet
171 * 173 *
@@ -173,7 +175,6 @@ static int num_nodes_ready_shutdown;
173 * @param name Name of the valueset. 175 * @param name Name of the valueset.
174 * @param num_values Number of values in valueset - number of peers. 176 * @param num_values Number of values in valueset - number of peers.
175 * @param is_persistent Persistence status of values. 177 * @param is_persistent Persistence status of values.
176 *
177 * @return Newly allocated #ValueSet. 178 * @return Newly allocated #ValueSet.
178 */ 179 */
179static struct ValueSet * 180static struct ValueSet *
@@ -187,7 +188,8 @@ new_value_set (const char *subsystem,
187 value_set = GNUNET_new (struct ValueSet); 188 value_set = GNUNET_new (struct ValueSet);
188 value_set->subsystem = GNUNET_strdup (subsystem); 189 value_set->subsystem = GNUNET_strdup (subsystem);
189 value_set->name = GNUNET_strdup (name); 190 value_set->name = GNUNET_strdup (name);
190 value_set->values = GNUNET_new_array (num_values, uint64_t); 191 value_set->values = GNUNET_new_array (num_values,
192 uint64_t);
191 value_set->is_persistent = persistent; 193 value_set->is_persistent = persistent;
192 return value_set; 194 return value_set;
193} 195}
@@ -202,11 +204,12 @@ new_value_set (const char *subsystem,
202 * @param key #GNUNET_HashCode key of #GNUNET_CONTAINER_MultiHashMap iterator - 204 * @param key #GNUNET_HashCode key of #GNUNET_CONTAINER_MultiHashMap iterator -
203 * unused 205 * unused
204 * @param value Values represented as #ValueSet. 206 * @param value Values represented as #ValueSet.
205 * 207 * @return #GNUNET_YES - continue iteration.
206 * @return GNUNET_YES - continue iteration.
207 */ 208 */
208static int 209static int
209printer (void *cls, const struct GNUNET_HashCode *key, void *value) 210printer (void *cls,
211 const struct GNUNET_HashCode *key,
212 void *value)
210{ 213{
211 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 214 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
212 const char *now_str; 215 const char *now_str;
@@ -368,10 +371,6 @@ clean_node (void *cls)
368 } 371 }
369 372
370 num_nodes_ready_shutdown++; 373 num_nodes_ready_shutdown++;
371 if (num_nodes == num_nodes_ready_shutdown)
372 {
373 GNUNET_array_grow (nodes, num_nodes, 0);
374 }
375} 374}
376 375
377 376
@@ -443,7 +442,8 @@ continuation_print (void *cls,
443 * successfully obtained, #GNUNET_SYSERR if not. 442 * successfully obtained, #GNUNET_SYSERR if not.
444 */ 443 */
445static void 444static void
446cleanup (void *cls, int success) 445cleanup (void *cls,
446 int success)
447{ 447{
448 for (unsigned i = 0; i < num_nodes; i++) 448 for (unsigned i = 0; i < num_nodes; i++)
449 { 449 {
@@ -473,8 +473,7 @@ cleanup (void *cls, int success)
473 * @param name Name of the value. 473 * @param name Name of the value.
474 * @param value Value itself. 474 * @param value Value itself.
475 * @param is_persistent Persistence. 475 * @param is_persistent Persistence.
476 * 476 * @return #GNUNET_OK - continue.
477 * @return GNUNET_OK - continue.
478 */ 477 */
479static int 478static int
480collector (void *cls, 479collector (void *cls,
@@ -610,7 +609,8 @@ main_task (void *cls)
610 * @return to continue iteration or not to 609 * @return to continue iteration or not to
611 */ 610 */
612static int 611static int
613iter_check_config (void *cls, const char *filename) 612iter_check_config (void *cls,
613 const char *filename)
614{ 614{
615 if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6)) 615 if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6))
616 { 616 {
@@ -644,18 +644,22 @@ iter_check_config (void *cls, const char *filename)
644 * 644 *
645 * @param cls counter of nodes 645 * @param cls counter of nodes
646 * @param filename full path of the file in testbed 646 * @param filename full path of the file in testbed
647 *
648 * @return status whether to continue iteration 647 * @return status whether to continue iteration
649 */ 648 */
650static int 649static int
651iter_testbed_path (void *cls, const char *filename) 650iter_testbed_path (void *cls,
651 const char *filename)
652{ 652{
653 unsigned index_node; 653 unsigned index_node;
654 654
655 GNUNET_assert (NULL != filename); 655 GNUNET_assert (NULL != filename);
656 if (1 == sscanf (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node)) 656 if (1 == sscanf (GNUNET_STRINGS_get_short_name (filename),
657 "%u",
658 &index_node))
657 { 659 {
658 if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL)) 660 if (-1 == GNUNET_DISK_directory_scan (filename,
661 iter_check_config,
662 NULL))
659 { 663 {
660 /* This is probably no directory for a testbed node 664 /* This is probably no directory for a testbed node
661 * Go on with iteration */ 665 * Go on with iteration */
@@ -680,10 +684,14 @@ discover_testbed_nodes (const char *path_testbed)
680 int num_dir_entries; 684 int num_dir_entries;
681 685
682 num_dir_entries = 686 num_dir_entries =
683 GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL); 687 GNUNET_DISK_directory_scan (path_testbed,
688 &iter_testbed_path,
689 NULL);
684 if (-1 == num_dir_entries) 690 if (-1 == num_dir_entries)
685 { 691 {
686 fprintf (stderr, "Failure during scanning directory `%s'\n", path_testbed); 692 fprintf (stderr,
693 "Failure during scanning directory `%s'\n",
694 path_testbed);
687 return -1; 695 return -1;
688 } 696 }
689 return 0; 697 return 0;
@@ -724,10 +732,11 @@ run (void *cls,
724 { 732 {
725 if (0 == remote_port) 733 if (0 == remote_port)
726 { 734 {
727 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, 735 if (GNUNET_SYSERR ==
728 "statistics", 736 GNUNET_CONFIGURATION_get_value_number (cfg,
729 "PORT", 737 "statistics",
730 &remote_port)) 738 "PORT",
739 &remote_port))
731 { 740 {
732 fprintf (stderr, 741 fprintf (stderr,
733 _ ("A port is required to connect to host `%s'\n"), 742 _ ("A port is required to connect to host `%s'\n"),
@@ -745,7 +754,10 @@ run (void *cls,
745 } 754 }
746 755
747 /* Manipulate configuration */ 756 /* Manipulate configuration */
748 GNUNET_CONFIGURATION_set_value_string (c, "statistics", "UNIXPATH", ""); 757 GNUNET_CONFIGURATION_set_value_string (c,
758 "statistics",
759 "UNIXPATH",
760 "");
749 GNUNET_CONFIGURATION_set_value_string (c, 761 GNUNET_CONFIGURATION_set_value_string (c,
750 "statistics", 762 "statistics",
751 "HOSTNAME", 763 "HOSTNAME",
@@ -796,68 +808,62 @@ run (void *cls,
796int 808int
797main (int argc, char *const *argv) 809main (int argc, char *const *argv)
798{ 810{
799 struct GNUNET_GETOPT_CommandLineOption options[] = 811 struct GNUNET_GETOPT_CommandLineOption options[] = {
800 { GNUNET_GETOPT_option_string ( 812 GNUNET_GETOPT_option_string ('n',
801 'n', 813 "name",
802 "name", 814 "NAME",
803 "NAME", 815 gettext_noop (
804 gettext_noop ("limit output to statistics for the given NAME"), 816 "limit output to statistics for the given NAME"),
805 &name), 817 &name),
806
807 GNUNET_GETOPT_option_flag ('p', 818 GNUNET_GETOPT_option_flag ('p',
808 "persistent", 819 "persistent",
809 gettext_noop ( 820 gettext_noop (
810 "make the value being set persistent"), 821 "make the value being set persistent"),
811 &persistent), 822 &persistent),
812
813 GNUNET_GETOPT_option_string ('s', 823 GNUNET_GETOPT_option_string ('s',
814 "subsystem", 824 "subsystem",
815 "SUBSYSTEM", 825 "SUBSYSTEM",
816 gettext_noop ( 826 gettext_noop (
817 "limit output to the given SUBSYSTEM"), 827 "limit output to the given SUBSYSTEM"),
818 &subsystem), 828 &subsystem),
819
820 GNUNET_GETOPT_option_string ('S', 829 GNUNET_GETOPT_option_string ('S',
821 "csv-separator", 830 "csv-separator",
822 "CSV_SEPARATOR", 831 "CSV_SEPARATOR",
823 gettext_noop ("use as csv separator"), 832 gettext_noop ("use as csv separator"),
824 &csv_separator), 833 &csv_separator),
825 834 GNUNET_GETOPT_option_filename ('t',
826 GNUNET_GETOPT_option_filename ( 835 "testbed",
827 't', 836 "TESTBED",
828 "testbed", 837 gettext_noop (
829 "TESTBED", 838 "path to the folder containing the testbed data"),
830 gettext_noop ("path to the folder containing the testbed data"), 839 &path_testbed),
831 &path_testbed),
832
833 GNUNET_GETOPT_option_flag ('q', 840 GNUNET_GETOPT_option_flag ('q',
834 "quiet", 841 "quiet",
835 gettext_noop ( 842 gettext_noop (
836 "just print the statistics value"), 843 "just print the statistics value"),
837 &quiet), 844 &quiet),
838
839 GNUNET_GETOPT_option_flag ('w', 845 GNUNET_GETOPT_option_flag ('w',
840 "watch", 846 "watch",
841 gettext_noop ("watch value continuously"), 847 gettext_noop ("watch value continuously"),
842 &watch), 848 &watch),
843
844 GNUNET_GETOPT_option_string ('r', 849 GNUNET_GETOPT_option_string ('r',
845 "remote", 850 "remote",
846 "REMOTE", 851 "REMOTE",
847 gettext_noop ("connect to remote host"), 852 gettext_noop ("connect to remote host"),
848 &remote_host), 853 &remote_host),
849
850 GNUNET_GETOPT_option_ulong ('o', 854 GNUNET_GETOPT_option_ulong ('o',
851 "port", 855 "port",
852 "PORT", 856 "PORT",
853 gettext_noop ("port for remote host"), 857 gettext_noop ("port for remote host"),
854 &remote_port), 858 &remote_port),
855 859 GNUNET_GETOPT_OPTION_END
856 GNUNET_GETOPT_OPTION_END }; 860 };
857 861
858 remote_port = 0; 862 remote_port = 0;
859 remote_host = NULL; 863 remote_host = NULL;
860 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 864 if (GNUNET_OK !=
865 GNUNET_STRINGS_get_utf8_args (argc, argv,
866 &argc, &argv))
861 return 2; 867 return 2;
862 868
863 ret = (GNUNET_OK == 869 ret = (GNUNET_OK ==
@@ -871,6 +877,9 @@ main (int argc, char *const *argv)
871 NULL)) 877 NULL))
872 ? ret 878 ? ret
873 : 1; 879 : 1;
880 GNUNET_array_grow (nodes,
881 num_nodes,
882 0);
874 GNUNET_free_non_null (remote_host); 883 GNUNET_free_non_null (remote_host);
875 GNUNET_free ((void *) argv); 884 GNUNET_free ((void *) argv);
876 return ret; 885 return ret;