8f43df0ffb11020a854e74166a27f45000637f5a
[oweals/gnunet.git] / src / statistics / gnunet-statistics.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001, 2002, 2004-2007, 2009, 2016 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14     
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/>.
17 */
18
19 /**
20  * @file statistics/gnunet-statistics.c
21  * @brief tool to obtain statistics
22  * @author Christian Grothoff
23  * @author Igor Wronsky
24  */
25 #include "platform.h"
26 #include "gnunet_util_lib.h"
27 #include "gnunet_statistics_service.h"
28 #include "statistics.h"
29
30
31 /**
32  * Final status code.
33  */
34 static int ret;
35
36 /**
37  * Set to subsystem that we're going to get stats for (or NULL for all).
38  */
39 static char *subsystem;
40
41 /**
42  * The path of the testbed data.
43  */
44 static char *path_testbed;
45
46 /**
47  * Set to the specific stat value that we are after (or NULL for all).
48  */
49 static char *name;
50
51 /**
52  * Make the value that is being set persistent.
53  */
54 static int persistent;
55
56 /**
57  * Watch value continuously
58  */
59 static int watch;
60
61 /**
62  * Quiet mode
63  */
64 static int quiet;
65
66 /**
67  * @brief Separator string for csv.
68  */
69 static char *csv_separator;
70
71 /**
72  * Remote host
73  */
74 static char *remote_host;
75
76 /**
77  * Remote host's port
78  */
79 static unsigned long long remote_port;
80
81 /**
82  * Value to set
83  */
84 static unsigned long long set_val;
85
86 /**
87  * Set operation
88  */
89 static int set_value;
90
91 /**
92  * @brief Representation of all (testbed) nodes.
93  */
94 static struct Node {
95   /**
96    * @brief Index of the node in this array.
97    */
98   unsigned index_node;
99
100   /**
101    * @brief Configuration handle for this node
102    */
103   struct GNUNET_CONFIGURATION_Handle *conf;
104
105   /**
106    * Handle for pending GET operation.
107    */
108   struct GNUNET_STATISTICS_GetHandle *gh;
109
110   /**
111    * @brief Statistics handle nodes.
112    */
113   struct GNUNET_STATISTICS_Handle *handle;
114   /**
115    * @brief Identifier for shutdown task for this node.
116    */
117   struct GNUNET_SCHEDULER_Task *shutdown_task;
118 } *nodes;
119
120 /**
121  * @brief Number of configurations of all (testbed) nodes.
122  */
123 static unsigned num_nodes;
124
125 /**
126  * @brief Set of values for a combination of subsystem and name.
127  */
128 struct ValueSet
129 {
130   /**
131    * @brief Subsystem of the valueset.
132    */
133   char *subsystem;
134
135   /**
136    * @brief Name of the valueset.
137    */
138   char *name;
139
140   /**
141    * @brief The values.
142    */
143   uint64_t *values;
144
145   /**
146    * @brief Persistence of the values.
147    */
148   int is_persistent;
149 };
150
151 /**
152  * @brief Collection of all values (represented with #ValueSet).
153  */
154 static struct GNUNET_CONTAINER_MultiHashMap *values;
155
156 /**
157  * @brief Number of nodes that have their values ready.
158  */
159 static int num_nodes_ready;
160
161 /**
162  * @brief Number of nodes that have their values ready.
163  */
164 static int num_nodes_ready_shutdown;
165
166 /**
167  * @brief Create a new #ValueSet
168  *
169  * @param subsystem Subsystem of the valueset.
170  * @param name Name of the valueset.
171  * @param num_values Number of values in valueset - number of peers.
172  * @param is_persistent Persistence status of values.
173  *
174  * @return Newly allocated #ValueSet.
175  */
176 static struct ValueSet *
177 new_value_set (const char *subsystem,
178                const char *name,
179                unsigned num_values,
180                int is_persistent)
181 {
182   struct ValueSet *value_set;
183
184   value_set = GNUNET_new (struct ValueSet);
185   value_set->subsystem = GNUNET_strdup (subsystem);
186   value_set->name = GNUNET_strdup (name);
187   value_set->values = GNUNET_new_array (num_values, uint64_t);
188   value_set->is_persistent = persistent;
189   return value_set;
190 }
191
192 /**
193  * @brief Print the (collected) values.
194  *
195  * Implements #GNUNET_CONTAINER_HashMapIterator.
196  *
197  * @param cls Closure - unused
198  * @param key #GNUNET_HashCode key of #GNUNET_CONTAINER_MultiHashMap iterator -
199  *        unused
200  * @param value Values represented as #ValueSet.
201  *
202  * @return GNUNET_YES - continue iteration.
203  */
204 static int
205 printer (void *cls,
206          const struct GNUNET_HashCode *key,
207          void *value)
208 {
209   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
210   const char *now_str;
211   struct ValueSet *value_set = value;
212
213   if (quiet == GNUNET_NO)
214   {
215     if (GNUNET_YES == watch)
216     {
217       now_str = GNUNET_STRINGS_absolute_time_to_string (now);
218       FPRINTF (stdout,
219                "%24s%s %s%s%12s%s %s%50s%s%s ",
220                now_str,
221                csv_separator,
222                value_set->is_persistent ? "!" : " ",
223                csv_separator,
224                value_set->subsystem,
225                csv_separator,
226                (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
227                      _(value_set->name),
228                (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
229                (0 == strlen (csv_separator) ? ":": csv_separator));
230     }
231     else
232     {
233       FPRINTF (stdout,
234                "%s%s%12s%s %s%50s%s%s ",
235                value_set->is_persistent ? "!" : " ",
236                csv_separator,
237                value_set->subsystem,
238                csv_separator,
239                (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
240                _(value_set->name),
241                (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
242                (0 == strlen (csv_separator) ? ":": csv_separator));
243     }
244   }
245   for (unsigned i = 0; i < num_nodes; i++)
246   {
247     FPRINTF (stdout,
248             "%16llu%s",
249             (unsigned long long) value_set->values[i],
250             csv_separator);
251   }
252   FPRINTF (stdout, "\n");
253   GNUNET_free (value_set->subsystem);
254   GNUNET_free (value_set->name);
255   GNUNET_free (value_set->values);
256   GNUNET_free (value_set);
257   return GNUNET_YES;
258 }
259
260 /**
261  * Callback function to process statistic values.
262  *
263  * @param cls closure
264  * @param subsystem name of subsystem that created the statistic
265  * @param name the name of the datum
266  * @param value the current value
267  * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
268  * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
269  */
270 static int
271 printer_watch (void *cls,
272                const char *subsystem,
273                const char *name,
274                uint64_t value,
275                int is_persistent)
276 {
277   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
278   const char *now_str;
279
280   if (quiet == GNUNET_NO)
281   {
282     if (GNUNET_YES == watch)
283     {
284       now_str = GNUNET_STRINGS_absolute_time_to_string (now);
285       FPRINTF (stdout,
286                "%24s%s %s%s%12s%s %s%50s%s%s %16llu\n",
287                now_str,
288                csv_separator,
289                is_persistent ? "!" : " ",
290                csv_separator,
291                subsystem,
292                csv_separator,
293                (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
294                _(name),
295                (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
296                (0 == strlen (csv_separator) ? ":": csv_separator),
297                (unsigned long long) value);
298     }
299     else
300     {
301       FPRINTF (stdout,
302                "%s%s%12s%s %s%50s%s%s %16llu\n",
303                is_persistent ? "!" : " ",
304                csv_separator,
305                subsystem,
306                csv_separator,
307                (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
308                _(name),
309                (0 == strlen (csv_separator) ? "": "\""), /* quotes if csv */
310                (0 == strlen (csv_separator) ? ":": csv_separator),
311                (unsigned long long) value);
312     }
313   }
314   else
315     FPRINTF (stdout,
316              "%llu\n",
317              (unsigned long long) value);
318
319   return GNUNET_OK;
320 }
321
322 /**
323  * @brief Clean all data structures related to given node.
324  *
325  * Also clears global structures if we are the last node to clean.
326  *
327  * @param cls the index of the node
328  */
329 static void
330 clean_node (void *cls)
331 {
332   const unsigned index_node = *(unsigned *) cls;
333   struct GNUNET_STATISTICS_Handle *h;
334   struct GNUNET_STATISTICS_GetHandle *gh;
335
336   if ( (NULL != path_testbed) && /* were issued with -t <testbed-path> option */
337        (NULL != nodes[index_node].conf) )
338   {
339     GNUNET_CONFIGURATION_destroy (nodes[index_node].conf);
340     nodes[index_node].conf = NULL;
341   }
342
343   h = nodes[index_node].handle;
344   gh = nodes[index_node].gh;
345
346   if (NULL != gh)
347   {
348     GNUNET_STATISTICS_get_cancel (gh);
349     gh = NULL;
350   }
351   if (GNUNET_YES == watch)
352   {
353     GNUNET_assert (GNUNET_OK ==
354       GNUNET_STATISTICS_watch_cancel (h,
355                                       subsystem,
356                                       name,
357                                       &printer_watch,
358                                       &nodes[index_node].index_node));
359   }
360
361   if (NULL != h)
362   {
363     GNUNET_STATISTICS_destroy (h, GNUNET_NO);
364     h = NULL;
365   }
366
367   num_nodes_ready_shutdown++;
368   if (num_nodes == num_nodes_ready_shutdown)
369   {
370     GNUNET_array_grow (nodes, num_nodes, 0);
371     GNUNET_CONTAINER_multihashmap_destroy (values);
372   }
373 }
374
375 /**
376  * @brief Print and shutdown
377  *
378  * @param cls unused
379  */
380 static void
381 print_finish (void *cls)
382 {
383   GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL);
384   GNUNET_SCHEDULER_shutdown();
385 }
386
387 /**
388  * @brief Called once all statistic values are available.
389  *
390  * Implements #GNUNET_STATISTICS_Callback
391  *
392  * @param cls Closure - The index of the node.
393  * @param succes Whether statistics were obtained successfully.
394  */
395 static void
396 continuation_print (void *cls,
397                     int success)
398 {
399   const unsigned index_node = *(unsigned *) cls;
400
401   nodes[index_node].gh = NULL;
402   if (GNUNET_OK != success)
403   {
404     if (NULL == remote_host)
405       FPRINTF (stderr,
406                "%s",
407                _("Failed to obtain statistics.\n"));
408     else
409       FPRINTF (stderr,
410                _("Failed to obtain statistics from host `%s:%llu'\n"),
411                remote_host,
412                remote_port);
413     ret = 1;
414   }
415   if (NULL != nodes[index_node].shutdown_task)
416   {
417     GNUNET_SCHEDULER_cancel (nodes[index_node].shutdown_task);
418     nodes[index_node].shutdown_task = NULL;
419   }
420   GNUNET_SCHEDULER_add_now (clean_node, &nodes[index_node].index_node);
421   num_nodes_ready++;
422   if (num_nodes_ready == num_nodes)
423   {
424     GNUNET_SCHEDULER_add_now (print_finish, NULL);
425   }
426 }
427
428 /**
429  * Function called last by the statistics code.
430  *
431  * @param cls closure
432  * @param success #GNUNET_OK if statistics were
433  *        successfully obtained, #GNUNET_SYSERR if not.
434  */
435 static void
436 cleanup (void *cls,
437          int success)
438 {
439   for (unsigned i = 0; i < num_nodes; i++)
440   {
441     nodes[i].gh = NULL;
442   }
443   if (GNUNET_OK != success)
444   {
445     if (NULL == remote_host)
446       FPRINTF (stderr,
447                "%s",
448                _("Failed to obtain statistics.\n"));
449     else
450       FPRINTF (stderr,
451                _("Failed to obtain statistics from host `%s:%llu'\n"),
452                remote_host,
453                remote_port);
454     ret = 1;
455   }
456   GNUNET_SCHEDULER_shutdown ();
457 }
458
459 /**
460  * @brief Iterate over statistics values and store them in #values.
461  * They will be printed once all are available.
462  *
463  * @param cls Cosure - Node index.
464  * @param subsystem Subsystem of the value.
465  * @param name Name of the value.
466  * @param value Value itself.
467  * @param is_persistent Persistence.
468  *
469  * @return GNUNET_OK - continue.
470  */
471 static int
472 collector (void *cls,
473            const char *subsystem,
474            const char *name,
475            uint64_t value,
476            int is_persistent)
477 {
478   const unsigned index_node = *(unsigned *) cls;
479   struct GNUNET_HashCode *key;
480   struct GNUNET_HashCode hc;
481   char *subsys_name;
482   unsigned len_subsys_name;
483   struct ValueSet *value_set;
484
485   len_subsys_name = strlen (subsystem) + 3 + strlen (name) + 1;
486   subsys_name = GNUNET_malloc (len_subsys_name);
487   SPRINTF (subsys_name, "%s---%s", subsystem, name);
488   key = &hc;
489   GNUNET_CRYPTO_hash (subsys_name, len_subsys_name, key);
490   GNUNET_free (subsys_name);
491   if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (values, key))
492   {
493     // get
494     value_set = GNUNET_CONTAINER_multihashmap_get (values, key);
495   }
496   else
497   {
498     // new
499     value_set = new_value_set (subsystem, name, num_nodes, is_persistent);
500   }
501   // write
502   value_set->values[index_node] = value;
503   // put
504   GNUNET_CONTAINER_multihashmap_put (values, key, value_set,
505       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
506   return GNUNET_OK;
507 }
508
509 /**
510  * Main task that does the actual work.
511  *
512  * @param cls closure with our configuration
513  */
514 static void
515 main_task (void *cls)
516 {
517   unsigned index_node = *(unsigned *) cls;
518   const struct GNUNET_CONFIGURATION_Handle *cfg = nodes[index_node].conf;
519
520   if (set_value)
521   {
522     if (NULL == subsystem)
523     {
524       FPRINTF (stderr,
525                "%s",
526                _("Missing argument: subsystem \n"));
527       ret = 1;
528       return;
529     }
530     if (NULL == name)
531     {
532       FPRINTF (stderr,
533                "%s",
534                _("Missing argument: name\n"));
535       ret = 1;
536       return;
537     }
538     nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem,
539                                   cfg);
540     if (NULL == nodes[index_node].handle)
541     {
542       ret = 1;
543       return;
544     }
545     GNUNET_STATISTICS_set (nodes[index_node].handle,
546                            name,
547                            (uint64_t) set_val,
548                            persistent);
549     GNUNET_STATISTICS_destroy (nodes[index_node].handle,
550                                GNUNET_YES);
551     nodes[index_node].handle = NULL;
552     return;
553   }
554   if (NULL == (nodes[index_node].handle = GNUNET_STATISTICS_create ("gnunet-statistics",
555                                              cfg)))
556   {
557     ret = 1;
558     return;
559   }
560   if (GNUNET_NO == watch)
561   {
562     if (NULL ==
563         (nodes[index_node].gh = GNUNET_STATISTICS_get (nodes[index_node].handle,
564                                                        subsystem,
565                                                        name,
566                                                        &continuation_print,
567                                                        &collector,
568                                      &nodes[index_node].index_node)) )
569       cleanup (nodes[index_node].handle,
570                GNUNET_SYSERR);
571   }
572   else
573   {
574     if ( (NULL == subsystem) ||
575          (NULL == name) )
576     {
577       printf (_("No subsystem or name given\n"));
578       GNUNET_STATISTICS_destroy (nodes[index_node].handle,
579                                  GNUNET_NO);
580       nodes[index_node].handle = NULL;
581       ret = 1;
582       return;
583     }
584     if (GNUNET_OK !=
585         GNUNET_STATISTICS_watch (nodes[index_node].handle,
586                                  subsystem,
587                                  name,
588                                  &printer_watch,
589                                  &nodes[index_node].index_node))
590     {
591       fprintf (stderr,
592                _("Failed to initialize watch routine\n"));
593       nodes[index_node].shutdown_task =
594         GNUNET_SCHEDULER_add_now (&clean_node,
595                                   &nodes[index_node].index_node);
596       return;
597     }
598   }
599   nodes[index_node].shutdown_task =
600     GNUNET_SCHEDULER_add_shutdown (&clean_node,
601                                    &nodes[index_node].index_node);
602 }
603
604 /**
605  * @brief Iter over content of a node's directory to check for existence of a
606  * config file.
607  *
608  * Implements #GNUNET_FileNameCallback
609  *
610  * @param cls pointer to indicate success
611  * @param filename filename inside the directory of the potential node
612  *
613  * @return to continue iteration or not to
614  */
615 static int
616 iter_check_config (void *cls,
617                    const char *filename)
618 {
619   if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6))
620   {
621     /* Found the config - stop iteration successfully */
622     GNUNET_array_grow (nodes, num_nodes, num_nodes+1);
623     nodes[num_nodes-1].conf = GNUNET_CONFIGURATION_create();
624     nodes[num_nodes-1].index_node = num_nodes-1;
625     if (GNUNET_OK != GNUNET_CONFIGURATION_load (nodes[num_nodes-1].conf, filename))
626     {
627       FPRINTF (stderr, "Failed loading config `%s'\n", filename);
628       return GNUNET_SYSERR;
629     }
630     return GNUNET_NO;
631   }
632   else
633   {
634     /* Continue iteration */
635     return GNUNET_OK;
636   }
637 }
638
639 /**
640  * @brief Iterates over filenames in testbed directory.
641  *
642  * Implements #GNUNET_FileNameCallback
643  *
644  * Checks if the file is a directory for a testbed node
645  * and counts the nodes.
646  *
647  * @param cls counter of nodes
648  * @param filename full path of the file in testbed
649  *
650  * @return status whether to continue iteration
651  */
652 static int
653 iter_testbed_path (void *cls,
654                    const char *filename)
655 {
656   unsigned index_node;
657
658   GNUNET_assert (NULL != filename);
659   if (1 == SSCANF (GNUNET_STRINGS_get_short_name (filename),
660                   "%u",
661                   &index_node))
662   {
663     if (-1 == GNUNET_DISK_directory_scan (filename,
664                                           iter_check_config,
665                                           NULL))
666     {
667       /* This is probably no directory for a testbed node
668        * Go on with iteration */
669       return GNUNET_OK;
670     }
671     return GNUNET_OK;
672   }
673   return GNUNET_OK;
674 }
675
676 /**
677  * @brief Count the number of nodes running in the testbed
678  *
679  * @param path_testbed path to the testbed data
680  *
681  * @return number of running nodes
682  */
683 static int
684 discover_testbed_nodes (const char *path_testbed)
685 {
686   int num_dir_entries;
687
688   num_dir_entries = GNUNET_DISK_directory_scan (path_testbed,
689                                                 iter_testbed_path,
690                                                 NULL);
691   if (-1 == num_dir_entries)
692   {
693     FPRINTF (stderr,
694             "Failure during scanning directory `%s'\n",
695             path_testbed);
696     return -1;
697   }
698   return 0;
699 }
700
701 /**
702  * Main function that will be run by the scheduler.
703  *
704  * @param cls closure
705  * @param args remaining command-line arguments
706  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
707  * @param cfg configuration
708  */
709 static void
710 run (void *cls,
711      char *const *args,
712      const char *cfgfile,
713      const struct GNUNET_CONFIGURATION_Handle *cfg)
714 {
715   struct GNUNET_CONFIGURATION_Handle *c;
716
717   c = (struct GNUNET_CONFIGURATION_Handle *) cfg;
718   set_value = GNUNET_NO;
719   if (NULL == csv_separator) csv_separator = "";
720   if (NULL != args[0])
721   {
722     if (1 != SSCANF (args[0],
723                      "%llu",
724                      &set_val))
725     {
726       FPRINTF (stderr,
727                _("Invalid argument `%s'\n"),
728                args[0]);
729       ret = 1;
730       return;
731     }
732     set_value = GNUNET_YES;
733   }
734   if (NULL != remote_host)
735   {
736     if (0 == remote_port)
737     {
738       if (GNUNET_SYSERR ==
739           GNUNET_CONFIGURATION_get_value_number (cfg,
740                                                  "statistics",
741                                                  "PORT",
742                                                  &remote_port))
743       {
744         FPRINTF (stderr,
745                  _("A port is required to connect to host `%s'\n"),
746                  remote_host);
747         return;
748       }
749     }
750     else if (65535 <= remote_port)
751     {
752       FPRINTF (stderr,
753                _("A port has to be between 1 and 65535 to connect to host `%s'\n"),
754                remote_host);
755       return;
756     }
757
758     /* Manipulate configuration */
759     GNUNET_CONFIGURATION_set_value_string (c,
760                                            "statistics",
761                                            "UNIXPATH",
762                                            "");
763     GNUNET_CONFIGURATION_set_value_string (c,
764                                            "statistics",
765                                            "HOSTNAME",
766                                            remote_host);
767     GNUNET_CONFIGURATION_set_value_number (c,
768                                            "statistics",
769                                            "PORT",
770                                            remote_port);
771   }
772   if (NULL == path_testbed)
773   {
774     values = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
775     GNUNET_array_grow (nodes, num_nodes, 1);
776     nodes[0].index_node = 0;
777     nodes[0].conf = c;
778     GNUNET_SCHEDULER_add_now (&main_task, &nodes[0].index_node);
779   }
780   else
781   {
782     if (GNUNET_YES == watch)
783     {
784       printf (_("Not able to watch testbed nodes (yet - feel free to implement)\n"));
785       ret = 1;
786       return;
787     }
788     values = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
789     if (-1 == discover_testbed_nodes (path_testbed))
790     {
791       return;
792     }
793     /* For each config/node collect statistics */
794     for (unsigned i = 0; i < num_nodes; i++)
795     {
796       GNUNET_SCHEDULER_add_now (&main_task,
797               &nodes[i].index_node);
798     }
799   }
800 }
801
802
803 /**
804  * The main function to obtain statistics in GNUnet.
805  *
806  * @param argc number of arguments from the command line
807  * @param argv command line arguments
808  * @return 0 ok, 1 on error
809  */
810 int
811 main (int argc, char *const *argv)
812 {
813   struct GNUNET_GETOPT_CommandLineOption options[] = {
814     GNUNET_GETOPT_option_string ('n',
815                                  "name",
816                                  "NAME",
817                                  gettext_noop ("limit output to statistics for the given NAME"),
818                                  &name),
819
820     GNUNET_GETOPT_option_flag ('p',
821                                   "persistent",
822                                   gettext_noop ("make the value being set persistent"),
823                                   &persistent),
824
825     GNUNET_GETOPT_option_string ('s',
826                                  "subsystem",
827                                  "SUBSYSTEM",
828                                  gettext_noop ("limit output to the given SUBSYSTEM"),
829                                  &subsystem),
830
831     GNUNET_GETOPT_option_string ('S',
832                                  "csv-separator",
833                                  "CSV_SEPARATOR",
834                                  gettext_noop ("use as csv separator"),
835                                  &csv_separator),
836
837     GNUNET_GETOPT_option_filename ('t',
838                                   "testbed",
839                                   "TESTBED",
840                                   gettext_noop ("path to the folder containing the testbed data"),
841                                   &path_testbed),
842
843     GNUNET_GETOPT_option_flag ('q',
844                                   "quiet",
845                                   gettext_noop ("just print the statistics value"),
846                                   &quiet),
847
848     GNUNET_GETOPT_option_flag ('w',
849                                   "watch",
850                                   gettext_noop ("watch value continuously"),
851                                   &watch),
852
853     GNUNET_GETOPT_option_string ('r',
854                                  "remote",
855                                  "REMOTE",
856                                  gettext_noop ("connect to remote host"),
857                                  &remote_host),
858
859     GNUNET_GETOPT_option_ulong ('o',
860                                     "port",
861                                     "PORT",
862                                     gettext_noop ("port for remote host"),
863                                     &remote_port),
864
865     GNUNET_GETOPT_OPTION_END
866   };
867   remote_port = 0;
868   remote_host = NULL;
869   if (GNUNET_OK !=
870       GNUNET_STRINGS_get_utf8_args (argc, argv,
871                                     &argc, &argv))
872     return 2;
873
874   ret = (GNUNET_OK ==
875          GNUNET_PROGRAM_run (argc,
876                              argv,
877                              "gnunet-statistics [options [value]]",
878                              gettext_noop
879                              ("Print statistics about GNUnet operations."),
880                              options,
881                              &run,
882                              NULL)) ? ret : 1;
883   GNUNET_free_non_null (remote_host);
884   GNUNET_free ((void*) argv);
885   return ret;
886 }
887
888 /* end of gnunet-statistics.c */