aboutsummaryrefslogtreecommitdiff
path: root/src/statistics/gnunet-statistics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statistics/gnunet-statistics.c')
-rw-r--r--src/statistics/gnunet-statistics.c181
1 files changed, 93 insertions, 88 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c
index 192a450ac..ed0c3f27d 100644
--- a/src/statistics/gnunet-statistics.c
+++ b/src/statistics/gnunet-statistics.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 GNUnet e.V. 3 Copyright (C) 2001, 2002, 2004-2007, 2009, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -104,27 +104,35 @@ printer (void *cls,
104 int is_persistent) 104 int is_persistent)
105{ 105{
106 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); 106 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
107 const char * now_str; 107 const char *now_str;
108 108
109 if (quiet == GNUNET_NO) 109 if (quiet == GNUNET_NO)
110 { 110 {
111 if (GNUNET_YES == watch) 111 if (GNUNET_YES == watch)
112 { 112 {
113 now_str = GNUNET_STRINGS_absolute_time_to_string(now); 113 now_str = GNUNET_STRINGS_absolute_time_to_string (now);
114 FPRINTF (stdout, "%24s %s%12s %50s: %16llu \n", 114 FPRINTF (stdout,
115 "%24s %s%12s %50s: %16llu\n",
115 now_str, 116 now_str,
116 is_persistent ? "!" : " ", 117 is_persistent ? "!" : " ",
117 subsystem, _(name), (unsigned long long) value); 118 subsystem,
119 _(name),
120 (unsigned long long) value);
118 } 121 }
119 else 122 else
120 { 123 {
121 FPRINTF (stdout, "%s%12s %50s: %16llu \n", 124 FPRINTF (stdout,
125 "%s%12s %50s: %16llu\n",
122 is_persistent ? "!" : " ", 126 is_persistent ? "!" : " ",
123 subsystem, _(name), (unsigned long long) value); 127 subsystem,
128 _(name),
129 (unsigned long long) value);
124 } 130 }
125 } 131 }
126 else 132 else
127 FPRINTF (stdout, "%llu\n", (unsigned long long) value); 133 FPRINTF (stdout,
134 "%llu\n",
135 (unsigned long long) value);
128 136
129 return GNUNET_OK; 137 return GNUNET_OK;
130} 138}
@@ -183,7 +191,8 @@ shutdown_task (void *cls)
183 GNUNET_STATISTICS_watch_cancel (h, 191 GNUNET_STATISTICS_watch_cancel (h,
184 subsystem, 192 subsystem,
185 name, 193 name,
186 &printer, h)); 194 &printer,
195 h));
187 GNUNET_STATISTICS_destroy (h, 196 GNUNET_STATISTICS_destroy (h,
188 GNUNET_NO); 197 GNUNET_NO);
189 h = NULL; 198 h = NULL;
@@ -205,17 +214,22 @@ main_task (void *cls)
205 { 214 {
206 if (NULL == subsystem) 215 if (NULL == subsystem)
207 { 216 {
208 FPRINTF (stderr, "%s", _("Missing argument: subsystem \n")); 217 FPRINTF (stderr,
218 "%s",
219 _("Missing argument: subsystem \n"));
209 ret = 1; 220 ret = 1;
210 return; 221 return;
211 } 222 }
212 if (NULL == name) 223 if (NULL == name)
213 { 224 {
214 FPRINTF (stderr, "%s", _("Missing argument: name\n")); 225 FPRINTF (stderr,
226 "%s",
227 _("Missing argument: name\n"));
215 ret = 1; 228 ret = 1;
216 return; 229 return;
217 } 230 }
218 h = GNUNET_STATISTICS_create (subsystem, cfg); 231 h = GNUNET_STATISTICS_create (subsystem,
232 cfg);
219 if (NULL == h) 233 if (NULL == h)
220 { 234 {
221 ret = 1; 235 ret = 1;
@@ -243,15 +257,19 @@ main_task (void *cls)
243 subsystem, 257 subsystem,
244 name, 258 name,
245 &cleanup, 259 &cleanup,
246 &printer, h)) ) 260 &printer,
247 cleanup (h, GNUNET_SYSERR); 261 h)) )
262 cleanup (h,
263 GNUNET_SYSERR);
248 } 264 }
249 else 265 else
250 { 266 {
251 if ((NULL == subsystem) || (NULL == name)) 267 if ( (NULL == subsystem) ||
268 (NULL == name) )
252 { 269 {
253 printf (_("No subsystem or name given\n")); 270 printf (_("No subsystem or name given\n"));
254 GNUNET_STATISTICS_destroy (h, GNUNET_NO); 271 GNUNET_STATISTICS_destroy (h,
272 GNUNET_NO);
255 h = NULL; 273 h = NULL;
256 ret = 1; 274 ret = 1;
257 return; 275 return;
@@ -260,7 +278,8 @@ main_task (void *cls)
260 GNUNET_STATISTICS_watch (h, 278 GNUNET_STATISTICS_watch (h,
261 subsystem, 279 subsystem,
262 name, 280 name,
263 &printer, h)) 281 &printer,
282 h))
264 { 283 {
265 fprintf (stderr, 284 fprintf (stderr,
266 _("Failed to initialize watch routine\n")); 285 _("Failed to initialize watch routine\n"));
@@ -275,65 +294,6 @@ main_task (void *cls)
275 294
276 295
277/** 296/**
278 * Function called with th test result to see if the resolver is
279 * running.
280 *
281 * @param cls closure with our configuration
282 * @param result #GNUNET_YES if the resolver is running
283 */
284static void
285resolver_test_task (void *cls,
286 int result)
287{
288 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
289
290 if (GNUNET_YES != result)
291 {
292 FPRINTF (stderr,
293 _("Trying to connect to remote host, but service `%s' is not running\n"),
294 "resolver");
295 return;
296 }
297 /* connect to a remote host */
298 if (0 == remote_port)
299 {
300 if (GNUNET_SYSERR ==
301 GNUNET_CONFIGURATION_get_value_number (cfg, "statistics",
302 "PORT",
303 &remote_port))
304 {
305 FPRINTF (stderr,
306 _("A port is required to connect to host `%s'\n"),
307 remote_host);
308 return;
309 }
310 }
311 else if (65535 <= remote_port)
312 {
313 FPRINTF (stderr,
314 _("A port has to be between 1 and 65535 to connect to host `%s'\n"),
315 remote_host);
316 return;
317 }
318
319 /* Manipulate configuration */
320 GNUNET_CONFIGURATION_set_value_string (cfg,
321 "statistics",
322 "UNIXPATH",
323 "");
324 GNUNET_CONFIGURATION_set_value_string (cfg,
325 "statistics",
326 "HOSTNAME",
327 remote_host);
328 GNUNET_CONFIGURATION_set_value_number (cfg,
329 "statistics",
330 "PORT",
331 remote_port);
332 GNUNET_SCHEDULER_add_now (&main_task, cfg);
333}
334
335
336/**
337 * Main function that will be run by the scheduler. 297 * Main function that will be run by the scheduler.
338 * 298 *
339 * @param cls closure 299 * @param cls closure
@@ -347,24 +307,64 @@ run (void *cls,
347 const char *cfgfile, 307 const char *cfgfile,
348 const struct GNUNET_CONFIGURATION_Handle *cfg) 308 const struct GNUNET_CONFIGURATION_Handle *cfg)
349{ 309{
310 struct GNUNET_CONFIGURATION_Handle *c;
311
312 c = (struct GNUNET_CONFIGURATION_Handle *) cfg;
350 set_value = GNUNET_NO; 313 set_value = GNUNET_NO;
351 if (NULL != args[0]) 314 if (NULL != args[0])
352 { 315 {
353 if (1 != SSCANF (args[0], "%llu", &set_val)) 316 if (1 != SSCANF (args[0],
317 "%llu",
318 &set_val))
354 { 319 {
355 FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]); 320 FPRINTF (stderr,
321 _("Invalid argument `%s'\n"),
322 args[0]);
356 ret = 1; 323 ret = 1;
357 return; 324 return;
358 } 325 }
359 set_value = GNUNET_YES; 326 set_value = GNUNET_YES;
360 } 327 }
361 if (NULL != remote_host) 328 if (NULL != remote_host)
362 GNUNET_CLIENT_service_test ("resolver", 329 {
363 cfg, 330 if (0 == remote_port)
364 GNUNET_TIME_UNIT_SECONDS, 331 {
365 &resolver_test_task, (void *) cfg); 332 if (GNUNET_SYSERR ==
366 else 333 GNUNET_CONFIGURATION_get_value_number (cfg,
367 GNUNET_SCHEDULER_add_now (&main_task, (void *) cfg); 334 "statistics",
335 "PORT",
336 &remote_port))
337 {
338 FPRINTF (stderr,
339 _("A port is required to connect to host `%s'\n"),
340 remote_host);
341 return;
342 }
343 }
344 else if (65535 <= remote_port)
345 {
346 FPRINTF (stderr,
347 _("A port has to be between 1 and 65535 to connect to host `%s'\n"),
348 remote_host);
349 return;
350 }
351
352 /* Manipulate configuration */
353 GNUNET_CONFIGURATION_set_value_string (c,
354 "statistics",
355 "UNIXPATH",
356 "");
357 GNUNET_CONFIGURATION_set_value_string (c,
358 "statistics",
359 "HOSTNAME",
360 remote_host);
361 GNUNET_CONFIGURATION_set_value_number (c,
362 "statistics",
363 "PORT",
364 remote_port);
365 }
366 GNUNET_SCHEDULER_add_now (&main_task,
367 c);
368} 368}
369 369
370 370
@@ -404,15 +404,20 @@ main (int argc, char *const *argv)
404 }; 404 };
405 remote_port = 0; 405 remote_port = 0;
406 remote_host = NULL; 406 remote_host = NULL;
407 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, 407 if (GNUNET_OK !=
408 &argc, &argv)) 408 GNUNET_STRINGS_get_utf8_args (argc, argv,
409 &argc, &argv))
409 return 2; 410 return 2;
410 411
411 ret = (GNUNET_OK == 412 ret = (GNUNET_OK ==
412 GNUNET_PROGRAM_run (argc, argv, "gnunet-statistics [options [value]]", 413 GNUNET_PROGRAM_run (argc,
414 argv,
415 "gnunet-statistics [options [value]]",
413 gettext_noop 416 gettext_noop
414 ("Print statistics about GNUnet operations."), 417 ("Print statistics about GNUnet operations."),
415 options, &run, NULL)) ? ret : 1; 418 options,
419 &run,
420 NULL)) ? ret : 1;
416 GNUNET_free_non_null (remote_host); 421 GNUNET_free_non_null (remote_host);
417 GNUNET_free ((void*) argv); 422 GNUNET_free ((void*) argv);
418 return ret; 423 return ret;