diff options
Diffstat (limited to 'src/statistics/gnunet-statistics.c')
-rw-r--r-- | src/statistics/gnunet-statistics.c | 815 |
1 files changed, 407 insertions, 408 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index f1ea8cb19..470bb2ed8 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c | |||
@@ -16,7 +16,7 @@ | |||
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 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file statistics/gnunet-statistics.c | 22 | * @file statistics/gnunet-statistics.c |
@@ -93,8 +93,7 @@ static int set_value; | |||
93 | /** | 93 | /** |
94 | * @brief Representation of all (testbed) nodes. | 94 | * @brief Representation of all (testbed) nodes. |
95 | */ | 95 | */ |
96 | static struct Node | 96 | static struct Node { |
97 | { | ||
98 | /** | 97 | /** |
99 | * @brief Index of the node in this array. | 98 | * @brief Index of the node in this array. |
100 | */ | 99 | */ |
@@ -128,8 +127,7 @@ static unsigned num_nodes; | |||
128 | /** | 127 | /** |
129 | * @brief Set of values for a combination of subsystem and name. | 128 | * @brief Set of values for a combination of subsystem and name. |
130 | */ | 129 | */ |
131 | struct ValueSet | 130 | struct ValueSet { |
132 | { | ||
133 | /** | 131 | /** |
134 | * @brief Subsystem of the valueset. | 132 | * @brief Subsystem of the valueset. |
135 | */ | 133 | */ |
@@ -177,17 +175,17 @@ static int num_nodes_ready_shutdown; | |||
177 | * @return Newly allocated #ValueSet. | 175 | * @return Newly allocated #ValueSet. |
178 | */ | 176 | */ |
179 | static struct ValueSet * | 177 | static struct ValueSet * |
180 | new_value_set (const char *subsystem, | 178 | new_value_set(const char *subsystem, |
181 | const char *name, | 179 | const char *name, |
182 | unsigned num_values, | 180 | unsigned num_values, |
183 | int is_persistent) | 181 | int is_persistent) |
184 | { | 182 | { |
185 | struct ValueSet *value_set; | 183 | struct ValueSet *value_set; |
186 | 184 | ||
187 | value_set = GNUNET_new (struct ValueSet); | 185 | value_set = GNUNET_new(struct ValueSet); |
188 | value_set->subsystem = GNUNET_strdup (subsystem); | 186 | value_set->subsystem = GNUNET_strdup(subsystem); |
189 | value_set->name = GNUNET_strdup (name); | 187 | value_set->name = GNUNET_strdup(name); |
190 | value_set->values = GNUNET_new_array (num_values, uint64_t); | 188 | value_set->values = GNUNET_new_array(num_values, uint64_t); |
191 | value_set->is_persistent = persistent; | 189 | value_set->is_persistent = persistent; |
192 | return value_set; | 190 | return value_set; |
193 | } | 191 | } |
@@ -205,56 +203,56 @@ new_value_set (const char *subsystem, | |||
205 | * @return GNUNET_YES - continue iteration. | 203 | * @return GNUNET_YES - continue iteration. |
206 | */ | 204 | */ |
207 | static int | 205 | static int |
208 | printer (void *cls, const struct GNUNET_HashCode *key, void *value) | 206 | printer(void *cls, const struct GNUNET_HashCode *key, void *value) |
209 | { | 207 | { |
210 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 208 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); |
211 | const char *now_str; | 209 | const char *now_str; |
212 | struct ValueSet *value_set = value; | 210 | struct ValueSet *value_set = value; |
213 | 211 | ||
214 | if (quiet == GNUNET_NO) | 212 | if (quiet == GNUNET_NO) |
215 | { | ||
216 | if (GNUNET_YES == watch) | ||
217 | { | 213 | { |
218 | now_str = GNUNET_STRINGS_absolute_time_to_string (now); | 214 | if (GNUNET_YES == watch) |
219 | fprintf (stdout, | 215 | { |
220 | "%24s%s %s%s%12s%s %s%50s%s%s ", | 216 | now_str = GNUNET_STRINGS_absolute_time_to_string(now); |
221 | now_str, | 217 | fprintf(stdout, |
222 | csv_separator, | 218 | "%24s%s %s%s%12s%s %s%50s%s%s ", |
223 | value_set->is_persistent ? "!" : " ", | 219 | now_str, |
224 | csv_separator, | 220 | csv_separator, |
225 | value_set->subsystem, | 221 | value_set->is_persistent ? "!" : " ", |
226 | csv_separator, | 222 | csv_separator, |
227 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ | 223 | value_set->subsystem, |
228 | _ (value_set->name), | 224 | csv_separator, |
229 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ | 225 | (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ |
230 | (0 == strlen (csv_separator) ? ":" : csv_separator)); | 226 | _(value_set->name), |
227 | (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ | ||
228 | (0 == strlen(csv_separator) ? ":" : csv_separator)); | ||
229 | } | ||
230 | else | ||
231 | { | ||
232 | fprintf(stdout, | ||
233 | "%s%s%12s%s %s%50s%s%s ", | ||
234 | value_set->is_persistent ? "!" : " ", | ||
235 | csv_separator, | ||
236 | value_set->subsystem, | ||
237 | csv_separator, | ||
238 | (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ | ||
239 | _(value_set->name), | ||
240 | (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ | ||
241 | (0 == strlen(csv_separator) ? ":" : csv_separator)); | ||
242 | } | ||
231 | } | 243 | } |
232 | else | 244 | for (unsigned i = 0; i < num_nodes; i++) |
233 | { | 245 | { |
234 | fprintf (stdout, | 246 | fprintf(stdout, |
235 | "%s%s%12s%s %s%50s%s%s ", | 247 | "%16llu%s", |
236 | value_set->is_persistent ? "!" : " ", | 248 | (unsigned long long)value_set->values[i], |
237 | csv_separator, | 249 | csv_separator); |
238 | value_set->subsystem, | ||
239 | csv_separator, | ||
240 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ | ||
241 | _ (value_set->name), | ||
242 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ | ||
243 | (0 == strlen (csv_separator) ? ":" : csv_separator)); | ||
244 | } | 250 | } |
245 | } | 251 | fprintf(stdout, "\n"); |
246 | for (unsigned i = 0; i < num_nodes; i++) | 252 | GNUNET_free(value_set->subsystem); |
247 | { | 253 | GNUNET_free(value_set->name); |
248 | fprintf (stdout, | 254 | GNUNET_free(value_set->values); |
249 | "%16llu%s", | 255 | GNUNET_free(value_set); |
250 | (unsigned long long) value_set->values[i], | ||
251 | csv_separator); | ||
252 | } | ||
253 | fprintf (stdout, "\n"); | ||
254 | GNUNET_free (value_set->subsystem); | ||
255 | GNUNET_free (value_set->name); | ||
256 | GNUNET_free (value_set->values); | ||
257 | GNUNET_free (value_set); | ||
258 | return GNUNET_YES; | 256 | return GNUNET_YES; |
259 | } | 257 | } |
260 | 258 | ||
@@ -269,51 +267,51 @@ printer (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
269 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | 267 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration |
270 | */ | 268 | */ |
271 | static int | 269 | static int |
272 | printer_watch (void *cls, | 270 | printer_watch(void *cls, |
273 | const char *subsystem, | 271 | const char *subsystem, |
274 | const char *name, | 272 | const char *name, |
275 | uint64_t value, | 273 | uint64_t value, |
276 | int is_persistent) | 274 | int is_persistent) |
277 | { | 275 | { |
278 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 276 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get(); |
279 | const char *now_str; | 277 | const char *now_str; |
280 | 278 | ||
281 | if (quiet == GNUNET_NO) | 279 | if (quiet == GNUNET_NO) |
282 | { | ||
283 | if (GNUNET_YES == watch) | ||
284 | { | 280 | { |
285 | now_str = GNUNET_STRINGS_absolute_time_to_string (now); | 281 | if (GNUNET_YES == watch) |
286 | fprintf (stdout, | 282 | { |
287 | "%24s%s %s%s%12s%s %s%50s%s%s %16llu\n", | 283 | now_str = GNUNET_STRINGS_absolute_time_to_string(now); |
288 | now_str, | 284 | fprintf(stdout, |
289 | csv_separator, | 285 | "%24s%s %s%s%12s%s %s%50s%s%s %16llu\n", |
290 | is_persistent ? "!" : " ", | 286 | now_str, |
291 | csv_separator, | 287 | csv_separator, |
292 | subsystem, | 288 | is_persistent ? "!" : " ", |
293 | csv_separator, | 289 | csv_separator, |
294 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ | 290 | subsystem, |
295 | _ (name), | 291 | csv_separator, |
296 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ | 292 | (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ |
297 | (0 == strlen (csv_separator) ? ":" : csv_separator), | 293 | _(name), |
298 | (unsigned long long) value); | 294 | (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ |
295 | (0 == strlen(csv_separator) ? ":" : csv_separator), | ||
296 | (unsigned long long)value); | ||
297 | } | ||
298 | else | ||
299 | { | ||
300 | fprintf(stdout, | ||
301 | "%s%s%12s%s %s%50s%s%s %16llu\n", | ||
302 | is_persistent ? "!" : " ", | ||
303 | csv_separator, | ||
304 | subsystem, | ||
305 | csv_separator, | ||
306 | (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ | ||
307 | _(name), | ||
308 | (0 == strlen(csv_separator) ? "" : "\""), /* quotes if csv */ | ||
309 | (0 == strlen(csv_separator) ? ":" : csv_separator), | ||
310 | (unsigned long long)value); | ||
311 | } | ||
299 | } | 312 | } |
300 | else | ||
301 | { | ||
302 | fprintf (stdout, | ||
303 | "%s%s%12s%s %s%50s%s%s %16llu\n", | ||
304 | is_persistent ? "!" : " ", | ||
305 | csv_separator, | ||
306 | subsystem, | ||
307 | csv_separator, | ||
308 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ | ||
309 | _ (name), | ||
310 | (0 == strlen (csv_separator) ? "" : "\""), /* quotes if csv */ | ||
311 | (0 == strlen (csv_separator) ? ":" : csv_separator), | ||
312 | (unsigned long long) value); | ||
313 | } | ||
314 | } | ||
315 | else | 313 | else |
316 | fprintf (stdout, "%llu\n", (unsigned long long) value); | 314 | fprintf(stdout, "%llu\n", (unsigned long long)value); |
317 | 315 | ||
318 | return GNUNET_OK; | 316 | return GNUNET_OK; |
319 | } | 317 | } |
@@ -326,50 +324,50 @@ printer_watch (void *cls, | |||
326 | * @param cls the index of the node | 324 | * @param cls the index of the node |
327 | */ | 325 | */ |
328 | static void | 326 | static void |
329 | clean_node (void *cls) | 327 | clean_node(void *cls) |
330 | { | 328 | { |
331 | const unsigned index_node = *(unsigned *) cls; | 329 | const unsigned index_node = *(unsigned *)cls; |
332 | struct GNUNET_STATISTICS_Handle *h; | 330 | struct GNUNET_STATISTICS_Handle *h; |
333 | struct GNUNET_STATISTICS_GetHandle *gh; | 331 | struct GNUNET_STATISTICS_GetHandle *gh; |
334 | 332 | ||
335 | if ((NULL != path_testbed) && /* were issued with -t <testbed-path> option */ | 333 | if ((NULL != path_testbed) && /* were issued with -t <testbed-path> option */ |
336 | (NULL != nodes[index_node].conf)) | 334 | (NULL != nodes[index_node].conf)) |
337 | { | 335 | { |
338 | GNUNET_CONFIGURATION_destroy (nodes[index_node].conf); | 336 | GNUNET_CONFIGURATION_destroy(nodes[index_node].conf); |
339 | nodes[index_node].conf = NULL; | 337 | nodes[index_node].conf = NULL; |
340 | } | 338 | } |
341 | 339 | ||
342 | h = nodes[index_node].handle; | 340 | h = nodes[index_node].handle; |
343 | gh = nodes[index_node].gh; | 341 | gh = nodes[index_node].gh; |
344 | 342 | ||
345 | if (NULL != gh) | 343 | if (NULL != gh) |
346 | { | 344 | { |
347 | GNUNET_STATISTICS_get_cancel (gh); | 345 | GNUNET_STATISTICS_get_cancel(gh); |
348 | gh = NULL; | 346 | gh = NULL; |
349 | } | 347 | } |
350 | if (GNUNET_YES == watch) | 348 | if (GNUNET_YES == watch) |
351 | { | 349 | { |
352 | GNUNET_assert ( | 350 | GNUNET_assert( |
353 | GNUNET_OK == | 351 | GNUNET_OK == |
354 | GNUNET_STATISTICS_watch_cancel (h, | 352 | GNUNET_STATISTICS_watch_cancel(h, |
355 | subsystem, | 353 | subsystem, |
356 | name, | 354 | name, |
357 | &printer_watch, | 355 | &printer_watch, |
358 | &nodes[index_node].index_node)); | 356 | &nodes[index_node].index_node)); |
359 | } | 357 | } |
360 | 358 | ||
361 | if (NULL != h) | 359 | if (NULL != h) |
362 | { | 360 | { |
363 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 361 | GNUNET_STATISTICS_destroy(h, GNUNET_NO); |
364 | h = NULL; | 362 | h = NULL; |
365 | } | 363 | } |
366 | 364 | ||
367 | num_nodes_ready_shutdown++; | 365 | num_nodes_ready_shutdown++; |
368 | if (num_nodes == num_nodes_ready_shutdown) | 366 | if (num_nodes == num_nodes_ready_shutdown) |
369 | { | 367 | { |
370 | GNUNET_array_grow (nodes, num_nodes, 0); | 368 | GNUNET_array_grow(nodes, num_nodes, 0); |
371 | GNUNET_CONTAINER_multihashmap_destroy (values); | 369 | GNUNET_CONTAINER_multihashmap_destroy(values); |
372 | } | 370 | } |
373 | } | 371 | } |
374 | 372 | ||
375 | /** | 373 | /** |
@@ -378,10 +376,10 @@ clean_node (void *cls) | |||
378 | * @param cls unused | 376 | * @param cls unused |
379 | */ | 377 | */ |
380 | static void | 378 | static void |
381 | print_finish (void *cls) | 379 | print_finish(void *cls) |
382 | { | 380 | { |
383 | GNUNET_CONTAINER_multihashmap_iterate (values, printer, NULL); | 381 | GNUNET_CONTAINER_multihashmap_iterate(values, printer, NULL); |
384 | GNUNET_SCHEDULER_shutdown (); | 382 | GNUNET_SCHEDULER_shutdown(); |
385 | } | 383 | } |
386 | 384 | ||
387 | /** | 385 | /** |
@@ -393,33 +391,33 @@ print_finish (void *cls) | |||
393 | * @param succes Whether statistics were obtained successfully. | 391 | * @param succes Whether statistics were obtained successfully. |
394 | */ | 392 | */ |
395 | static void | 393 | static void |
396 | continuation_print (void *cls, int success) | 394 | continuation_print(void *cls, int success) |
397 | { | 395 | { |
398 | const unsigned index_node = *(unsigned *) cls; | 396 | const unsigned index_node = *(unsigned *)cls; |
399 | 397 | ||
400 | nodes[index_node].gh = NULL; | 398 | nodes[index_node].gh = NULL; |
401 | if (GNUNET_OK != success) | 399 | if (GNUNET_OK != success) |
402 | { | 400 | { |
403 | if (NULL == remote_host) | 401 | if (NULL == remote_host) |
404 | fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n")); | 402 | fprintf(stderr, "%s", _("Failed to obtain statistics.\n")); |
405 | else | 403 | else |
406 | fprintf (stderr, | 404 | fprintf(stderr, |
407 | _ ("Failed to obtain statistics from host `%s:%llu'\n"), | 405 | _("Failed to obtain statistics from host `%s:%llu'\n"), |
408 | remote_host, | 406 | remote_host, |
409 | remote_port); | 407 | remote_port); |
410 | ret = 1; | 408 | ret = 1; |
411 | } | 409 | } |
412 | if (NULL != nodes[index_node].shutdown_task) | 410 | if (NULL != nodes[index_node].shutdown_task) |
413 | { | 411 | { |
414 | GNUNET_SCHEDULER_cancel (nodes[index_node].shutdown_task); | 412 | GNUNET_SCHEDULER_cancel(nodes[index_node].shutdown_task); |
415 | nodes[index_node].shutdown_task = NULL; | 413 | nodes[index_node].shutdown_task = NULL; |
416 | } | 414 | } |
417 | GNUNET_SCHEDULER_add_now (clean_node, &nodes[index_node].index_node); | 415 | GNUNET_SCHEDULER_add_now(clean_node, &nodes[index_node].index_node); |
418 | num_nodes_ready++; | 416 | num_nodes_ready++; |
419 | if (num_nodes_ready == num_nodes) | 417 | if (num_nodes_ready == num_nodes) |
420 | { | 418 | { |
421 | GNUNET_SCHEDULER_add_now (print_finish, NULL); | 419 | GNUNET_SCHEDULER_add_now(print_finish, NULL); |
422 | } | 420 | } |
423 | } | 421 | } |
424 | 422 | ||
425 | /** | 423 | /** |
@@ -430,24 +428,24 @@ continuation_print (void *cls, int success) | |||
430 | * successfully obtained, #GNUNET_SYSERR if not. | 428 | * successfully obtained, #GNUNET_SYSERR if not. |
431 | */ | 429 | */ |
432 | static void | 430 | static void |
433 | cleanup (void *cls, int success) | 431 | cleanup(void *cls, int success) |
434 | { | 432 | { |
435 | for (unsigned i = 0; i < num_nodes; i++) | 433 | for (unsigned i = 0; i < num_nodes; i++) |
436 | { | 434 | { |
437 | nodes[i].gh = NULL; | 435 | nodes[i].gh = NULL; |
438 | } | 436 | } |
439 | if (GNUNET_OK != success) | 437 | if (GNUNET_OK != success) |
440 | { | 438 | { |
441 | if (NULL == remote_host) | 439 | if (NULL == remote_host) |
442 | fprintf (stderr, "%s", _ ("Failed to obtain statistics.\n")); | 440 | fprintf(stderr, "%s", _("Failed to obtain statistics.\n")); |
443 | else | 441 | else |
444 | fprintf (stderr, | 442 | fprintf(stderr, |
445 | _ ("Failed to obtain statistics from host `%s:%llu'\n"), | 443 | _("Failed to obtain statistics from host `%s:%llu'\n"), |
446 | remote_host, | 444 | remote_host, |
447 | remote_port); | 445 | remote_port); |
448 | ret = 1; | 446 | ret = 1; |
449 | } | 447 | } |
450 | GNUNET_SCHEDULER_shutdown (); | 448 | GNUNET_SCHEDULER_shutdown(); |
451 | } | 449 | } |
452 | 450 | ||
453 | /** | 451 | /** |
@@ -463,40 +461,40 @@ cleanup (void *cls, int success) | |||
463 | * @return GNUNET_OK - continue. | 461 | * @return GNUNET_OK - continue. |
464 | */ | 462 | */ |
465 | static int | 463 | static int |
466 | collector (void *cls, | 464 | collector(void *cls, |
467 | const char *subsystem, | 465 | const char *subsystem, |
468 | const char *name, | 466 | const char *name, |
469 | uint64_t value, | 467 | uint64_t value, |
470 | int is_persistent) | 468 | int is_persistent) |
471 | { | 469 | { |
472 | const unsigned index_node = *(unsigned *) cls; | 470 | const unsigned index_node = *(unsigned *)cls; |
473 | struct GNUNET_HashCode *key; | 471 | struct GNUNET_HashCode *key; |
474 | struct GNUNET_HashCode hc; | 472 | struct GNUNET_HashCode hc; |
475 | char *subsys_name; | 473 | char *subsys_name; |
476 | unsigned len_subsys_name; | 474 | unsigned len_subsys_name; |
477 | struct ValueSet *value_set; | 475 | struct ValueSet *value_set; |
478 | 476 | ||
479 | len_subsys_name = strlen (subsystem) + 3 + strlen (name) + 1; | 477 | len_subsys_name = strlen(subsystem) + 3 + strlen(name) + 1; |
480 | subsys_name = GNUNET_malloc (len_subsys_name); | 478 | subsys_name = GNUNET_malloc(len_subsys_name); |
481 | sprintf (subsys_name, "%s---%s", subsystem, name); | 479 | sprintf(subsys_name, "%s---%s", subsystem, name); |
482 | key = &hc; | 480 | key = &hc; |
483 | GNUNET_CRYPTO_hash (subsys_name, len_subsys_name, key); | 481 | GNUNET_CRYPTO_hash(subsys_name, len_subsys_name, key); |
484 | GNUNET_free (subsys_name); | 482 | GNUNET_free(subsys_name); |
485 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (values, key)) | 483 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(values, key)) |
486 | { | 484 | { |
487 | value_set = GNUNET_CONTAINER_multihashmap_get (values, key); | 485 | value_set = GNUNET_CONTAINER_multihashmap_get(values, key); |
488 | } | 486 | } |
489 | else | 487 | else |
490 | { | 488 | { |
491 | value_set = new_value_set (subsystem, name, num_nodes, is_persistent); | 489 | value_set = new_value_set(subsystem, name, num_nodes, is_persistent); |
492 | } | 490 | } |
493 | value_set->values[index_node] = value; | 491 | value_set->values[index_node] = value; |
494 | GNUNET_assert (GNUNET_YES == | 492 | GNUNET_assert(GNUNET_YES == |
495 | GNUNET_CONTAINER_multihashmap_put ( | 493 | GNUNET_CONTAINER_multihashmap_put( |
496 | values, | 494 | values, |
497 | key, | 495 | key, |
498 | value_set, | 496 | value_set, |
499 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 497 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
500 | return GNUNET_OK; | 498 | return GNUNET_OK; |
501 | } | 499 | } |
502 | 500 | ||
@@ -506,80 +504,80 @@ collector (void *cls, | |||
506 | * @param cls closure with our configuration | 504 | * @param cls closure with our configuration |
507 | */ | 505 | */ |
508 | static void | 506 | static void |
509 | main_task (void *cls) | 507 | main_task(void *cls) |
510 | { | 508 | { |
511 | unsigned index_node = *(unsigned *) cls; | 509 | unsigned index_node = *(unsigned *)cls; |
512 | const struct GNUNET_CONFIGURATION_Handle *cfg = nodes[index_node].conf; | 510 | const struct GNUNET_CONFIGURATION_Handle *cfg = nodes[index_node].conf; |
513 | 511 | ||
514 | if (set_value) | 512 | if (set_value) |
515 | { | ||
516 | if (NULL == subsystem) | ||
517 | { | 513 | { |
518 | fprintf (stderr, "%s", _ ("Missing argument: subsystem \n")); | 514 | if (NULL == subsystem) |
519 | ret = 1; | 515 | { |
520 | return; | 516 | fprintf(stderr, "%s", _("Missing argument: subsystem \n")); |
521 | } | 517 | ret = 1; |
522 | if (NULL == name) | 518 | return; |
523 | { | 519 | } |
524 | fprintf (stderr, "%s", _ ("Missing argument: name\n")); | 520 | if (NULL == name) |
525 | ret = 1; | 521 | { |
522 | fprintf(stderr, "%s", _("Missing argument: name\n")); | ||
523 | ret = 1; | ||
524 | return; | ||
525 | } | ||
526 | nodes[index_node].handle = GNUNET_STATISTICS_create(subsystem, cfg); | ||
527 | if (NULL == nodes[index_node].handle) | ||
528 | { | ||
529 | ret = 1; | ||
530 | return; | ||
531 | } | ||
532 | GNUNET_STATISTICS_set(nodes[index_node].handle, | ||
533 | name, | ||
534 | (uint64_t)set_val, | ||
535 | persistent); | ||
536 | GNUNET_STATISTICS_destroy(nodes[index_node].handle, GNUNET_YES); | ||
537 | nodes[index_node].handle = NULL; | ||
526 | return; | 538 | return; |
527 | } | 539 | } |
528 | nodes[index_node].handle = GNUNET_STATISTICS_create (subsystem, cfg); | 540 | if (NULL == (nodes[index_node].handle = |
529 | if (NULL == nodes[index_node].handle) | 541 | GNUNET_STATISTICS_create("gnunet-statistics", cfg))) |
530 | { | 542 | { |
531 | ret = 1; | 543 | ret = 1; |
532 | return; | 544 | return; |
533 | } | 545 | } |
534 | GNUNET_STATISTICS_set (nodes[index_node].handle, | ||
535 | name, | ||
536 | (uint64_t) set_val, | ||
537 | persistent); | ||
538 | GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_YES); | ||
539 | nodes[index_node].handle = NULL; | ||
540 | return; | ||
541 | } | ||
542 | if (NULL == (nodes[index_node].handle = | ||
543 | GNUNET_STATISTICS_create ("gnunet-statistics", cfg))) | ||
544 | { | ||
545 | ret = 1; | ||
546 | return; | ||
547 | } | ||
548 | if (GNUNET_NO == watch) | 546 | if (GNUNET_NO == watch) |
549 | { | ||
550 | if (NULL == (nodes[index_node].gh = | ||
551 | GNUNET_STATISTICS_get (nodes[index_node].handle, | ||
552 | subsystem, | ||
553 | name, | ||
554 | &continuation_print, | ||
555 | &collector, | ||
556 | &nodes[index_node].index_node))) | ||
557 | cleanup (nodes[index_node].handle, GNUNET_SYSERR); | ||
558 | } | ||
559 | else | ||
560 | { | ||
561 | if ((NULL == subsystem) || (NULL == name)) | ||
562 | { | 547 | { |
563 | printf (_ ("No subsystem or name given\n")); | 548 | if (NULL == (nodes[index_node].gh = |
564 | GNUNET_STATISTICS_destroy (nodes[index_node].handle, GNUNET_NO); | 549 | GNUNET_STATISTICS_get(nodes[index_node].handle, |
565 | nodes[index_node].handle = NULL; | 550 | subsystem, |
566 | ret = 1; | 551 | name, |
567 | return; | 552 | &continuation_print, |
553 | &collector, | ||
554 | &nodes[index_node].index_node))) | ||
555 | cleanup(nodes[index_node].handle, GNUNET_SYSERR); | ||
568 | } | 556 | } |
569 | if (GNUNET_OK != GNUNET_STATISTICS_watch (nodes[index_node].handle, | 557 | else |
570 | subsystem, | ||
571 | name, | ||
572 | &printer_watch, | ||
573 | &nodes[index_node].index_node)) | ||
574 | { | 558 | { |
575 | fprintf (stderr, _ ("Failed to initialize watch routine\n")); | 559 | if ((NULL == subsystem) || (NULL == name)) |
576 | nodes[index_node].shutdown_task = | 560 | { |
577 | GNUNET_SCHEDULER_add_now (&clean_node, &nodes[index_node].index_node); | 561 | printf(_("No subsystem or name given\n")); |
578 | return; | 562 | GNUNET_STATISTICS_destroy(nodes[index_node].handle, GNUNET_NO); |
563 | nodes[index_node].handle = NULL; | ||
564 | ret = 1; | ||
565 | return; | ||
566 | } | ||
567 | if (GNUNET_OK != GNUNET_STATISTICS_watch(nodes[index_node].handle, | ||
568 | subsystem, | ||
569 | name, | ||
570 | &printer_watch, | ||
571 | &nodes[index_node].index_node)) | ||
572 | { | ||
573 | fprintf(stderr, _("Failed to initialize watch routine\n")); | ||
574 | nodes[index_node].shutdown_task = | ||
575 | GNUNET_SCHEDULER_add_now(&clean_node, &nodes[index_node].index_node); | ||
576 | return; | ||
577 | } | ||
579 | } | 578 | } |
580 | } | ||
581 | nodes[index_node].shutdown_task = | 579 | nodes[index_node].shutdown_task = |
582 | GNUNET_SCHEDULER_add_shutdown (&clean_node, &nodes[index_node].index_node); | 580 | GNUNET_SCHEDULER_add_shutdown(&clean_node, &nodes[index_node].index_node); |
583 | } | 581 | } |
584 | 582 | ||
585 | /** | 583 | /** |
@@ -594,27 +592,27 @@ main_task (void *cls) | |||
594 | * @return to continue iteration or not to | 592 | * @return to continue iteration or not to |
595 | */ | 593 | */ |
596 | static int | 594 | static int |
597 | iter_check_config (void *cls, const char *filename) | 595 | iter_check_config(void *cls, const char *filename) |
598 | { | 596 | { |
599 | if (0 == strncmp (GNUNET_STRINGS_get_short_name (filename), "config", 6)) | 597 | if (0 == strncmp(GNUNET_STRINGS_get_short_name(filename), "config", 6)) |
600 | { | ||
601 | /* Found the config - stop iteration successfully */ | ||
602 | GNUNET_array_grow (nodes, num_nodes, num_nodes + 1); | ||
603 | nodes[num_nodes - 1].conf = GNUNET_CONFIGURATION_create (); | ||
604 | nodes[num_nodes - 1].index_node = num_nodes - 1; | ||
605 | if (GNUNET_OK != | ||
606 | GNUNET_CONFIGURATION_load (nodes[num_nodes - 1].conf, filename)) | ||
607 | { | 598 | { |
608 | fprintf (stderr, "Failed loading config `%s'\n", filename); | 599 | /* Found the config - stop iteration successfully */ |
609 | return GNUNET_SYSERR; | 600 | GNUNET_array_grow(nodes, num_nodes, num_nodes + 1); |
601 | nodes[num_nodes - 1].conf = GNUNET_CONFIGURATION_create(); | ||
602 | nodes[num_nodes - 1].index_node = num_nodes - 1; | ||
603 | if (GNUNET_OK != | ||
604 | GNUNET_CONFIGURATION_load(nodes[num_nodes - 1].conf, filename)) | ||
605 | { | ||
606 | fprintf(stderr, "Failed loading config `%s'\n", filename); | ||
607 | return GNUNET_SYSERR; | ||
608 | } | ||
609 | return GNUNET_NO; | ||
610 | } | 610 | } |
611 | return GNUNET_NO; | ||
612 | } | ||
613 | else | 611 | else |
614 | { | 612 | { |
615 | /* Continue iteration */ | 613 | /* Continue iteration */ |
616 | return GNUNET_OK; | 614 | return GNUNET_OK; |
617 | } | 615 | } |
618 | } | 616 | } |
619 | 617 | ||
620 | /** | 618 | /** |
@@ -631,21 +629,21 @@ iter_check_config (void *cls, const char *filename) | |||
631 | * @return status whether to continue iteration | 629 | * @return status whether to continue iteration |
632 | */ | 630 | */ |
633 | static int | 631 | static int |
634 | iter_testbed_path (void *cls, const char *filename) | 632 | iter_testbed_path(void *cls, const char *filename) |
635 | { | 633 | { |
636 | unsigned index_node; | 634 | unsigned index_node; |
637 | 635 | ||
638 | GNUNET_assert (NULL != filename); | 636 | GNUNET_assert(NULL != filename); |
639 | if (1 == sscanf (GNUNET_STRINGS_get_short_name (filename), "%u", &index_node)) | 637 | if (1 == sscanf(GNUNET_STRINGS_get_short_name(filename), "%u", &index_node)) |
640 | { | ||
641 | if (-1 == GNUNET_DISK_directory_scan (filename, iter_check_config, NULL)) | ||
642 | { | 638 | { |
643 | /* This is probably no directory for a testbed node | 639 | if (-1 == GNUNET_DISK_directory_scan(filename, iter_check_config, NULL)) |
644 | * Go on with iteration */ | 640 | { |
641 | /* This is probably no directory for a testbed node | ||
642 | * Go on with iteration */ | ||
643 | return GNUNET_OK; | ||
644 | } | ||
645 | return GNUNET_OK; | 645 | return GNUNET_OK; |
646 | } | 646 | } |
647 | return GNUNET_OK; | ||
648 | } | ||
649 | return GNUNET_OK; | 647 | return GNUNET_OK; |
650 | } | 648 | } |
651 | 649 | ||
@@ -657,17 +655,17 @@ iter_testbed_path (void *cls, const char *filename) | |||
657 | * @return number of running nodes | 655 | * @return number of running nodes |
658 | */ | 656 | */ |
659 | static int | 657 | static int |
660 | discover_testbed_nodes (const char *path_testbed) | 658 | discover_testbed_nodes(const char *path_testbed) |
661 | { | 659 | { |
662 | int num_dir_entries; | 660 | int num_dir_entries; |
663 | 661 | ||
664 | num_dir_entries = | 662 | num_dir_entries = |
665 | GNUNET_DISK_directory_scan (path_testbed, iter_testbed_path, NULL); | 663 | GNUNET_DISK_directory_scan(path_testbed, iter_testbed_path, NULL); |
666 | if (-1 == num_dir_entries) | 664 | if (-1 == num_dir_entries) |
667 | { | 665 | { |
668 | fprintf (stderr, "Failure during scanning directory `%s'\n", path_testbed); | 666 | fprintf(stderr, "Failure during scanning directory `%s'\n", path_testbed); |
669 | return -1; | 667 | return -1; |
670 | } | 668 | } |
671 | return 0; | 669 | return 0; |
672 | } | 670 | } |
673 | 671 | ||
@@ -680,90 +678,90 @@ discover_testbed_nodes (const char *path_testbed) | |||
680 | * @param cfg configuration | 678 | * @param cfg configuration |
681 | */ | 679 | */ |
682 | static void | 680 | static void |
683 | run (void *cls, | 681 | run(void *cls, |
684 | char *const *args, | 682 | char *const *args, |
685 | const char *cfgfile, | 683 | const char *cfgfile, |
686 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 684 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
687 | { | 685 | { |
688 | struct GNUNET_CONFIGURATION_Handle *c; | 686 | struct GNUNET_CONFIGURATION_Handle *c; |
689 | 687 | ||
690 | c = (struct GNUNET_CONFIGURATION_Handle *) cfg; | 688 | c = (struct GNUNET_CONFIGURATION_Handle *)cfg; |
691 | set_value = GNUNET_NO; | 689 | set_value = GNUNET_NO; |
692 | if (NULL == csv_separator) | 690 | if (NULL == csv_separator) |
693 | csv_separator = ""; | 691 | csv_separator = ""; |
694 | if (NULL != args[0]) | 692 | if (NULL != args[0]) |
695 | { | ||
696 | if (1 != sscanf (args[0], "%llu", &set_val)) | ||
697 | { | 693 | { |
698 | fprintf (stderr, _ ("Invalid argument `%s'\n"), args[0]); | 694 | if (1 != sscanf(args[0], "%llu", &set_val)) |
699 | ret = 1; | 695 | { |
700 | return; | 696 | fprintf(stderr, _("Invalid argument `%s'\n"), args[0]); |
697 | ret = 1; | ||
698 | return; | ||
699 | } | ||
700 | set_value = GNUNET_YES; | ||
701 | } | 701 | } |
702 | set_value = GNUNET_YES; | ||
703 | } | ||
704 | if (NULL != remote_host) | 702 | if (NULL != remote_host) |
705 | { | ||
706 | if (0 == remote_port) | ||
707 | { | 703 | { |
708 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 704 | if (0 == remote_port) |
709 | "statistics", | 705 | { |
710 | "PORT", | 706 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
711 | &remote_port)) | 707 | "statistics", |
712 | { | 708 | "PORT", |
713 | fprintf (stderr, | 709 | &remote_port)) |
714 | _ ("A port is required to connect to host `%s'\n"), | 710 | { |
715 | remote_host); | 711 | fprintf(stderr, |
716 | return; | 712 | _("A port is required to connect to host `%s'\n"), |
717 | } | 713 | remote_host); |
714 | return; | ||
715 | } | ||
716 | } | ||
717 | else if (65535 <= remote_port) | ||
718 | { | ||
719 | fprintf(stderr, | ||
720 | _( | ||
721 | "A port has to be between 1 and 65535 to connect to host `%s'\n"), | ||
722 | remote_host); | ||
723 | return; | ||
724 | } | ||
725 | |||
726 | /* Manipulate configuration */ | ||
727 | GNUNET_CONFIGURATION_set_value_string(c, "statistics", "UNIXPATH", ""); | ||
728 | GNUNET_CONFIGURATION_set_value_string(c, | ||
729 | "statistics", | ||
730 | "HOSTNAME", | ||
731 | remote_host); | ||
732 | GNUNET_CONFIGURATION_set_value_number(c, | ||
733 | "statistics", | ||
734 | "PORT", | ||
735 | remote_port); | ||
718 | } | 736 | } |
719 | else if (65535 <= remote_port) | ||
720 | { | ||
721 | fprintf (stderr, | ||
722 | _ ( | ||
723 | "A port has to be between 1 and 65535 to connect to host `%s'\n"), | ||
724 | remote_host); | ||
725 | return; | ||
726 | } | ||
727 | |||
728 | /* Manipulate configuration */ | ||
729 | GNUNET_CONFIGURATION_set_value_string (c, "statistics", "UNIXPATH", ""); | ||
730 | GNUNET_CONFIGURATION_set_value_string (c, | ||
731 | "statistics", | ||
732 | "HOSTNAME", | ||
733 | remote_host); | ||
734 | GNUNET_CONFIGURATION_set_value_number (c, | ||
735 | "statistics", | ||
736 | "PORT", | ||
737 | remote_port); | ||
738 | } | ||
739 | if (NULL == path_testbed) | 737 | if (NULL == path_testbed) |
740 | { | ||
741 | values = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | ||
742 | GNUNET_array_grow (nodes, num_nodes, 1); | ||
743 | nodes[0].index_node = 0; | ||
744 | nodes[0].conf = c; | ||
745 | GNUNET_SCHEDULER_add_now (&main_task, &nodes[0].index_node); | ||
746 | } | ||
747 | else | ||
748 | { | ||
749 | if (GNUNET_YES == watch) | ||
750 | { | ||
751 | printf ( | ||
752 | _ ("Not able to watch testbed nodes (yet - feel free to implement)\n")); | ||
753 | ret = 1; | ||
754 | return; | ||
755 | } | ||
756 | values = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); | ||
757 | if (-1 == discover_testbed_nodes (path_testbed)) | ||
758 | { | 738 | { |
759 | return; | 739 | values = GNUNET_CONTAINER_multihashmap_create(1, GNUNET_NO); |
740 | GNUNET_array_grow(nodes, num_nodes, 1); | ||
741 | nodes[0].index_node = 0; | ||
742 | nodes[0].conf = c; | ||
743 | GNUNET_SCHEDULER_add_now(&main_task, &nodes[0].index_node); | ||
760 | } | 744 | } |
761 | /* For each config/node collect statistics */ | 745 | else |
762 | for (unsigned i = 0; i < num_nodes; i++) | ||
763 | { | 746 | { |
764 | GNUNET_SCHEDULER_add_now (&main_task, &nodes[i].index_node); | 747 | if (GNUNET_YES == watch) |
748 | { | ||
749 | printf( | ||
750 | _("Not able to watch testbed nodes (yet - feel free to implement)\n")); | ||
751 | ret = 1; | ||
752 | return; | ||
753 | } | ||
754 | values = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); | ||
755 | if (-1 == discover_testbed_nodes(path_testbed)) | ||
756 | { | ||
757 | return; | ||
758 | } | ||
759 | /* For each config/node collect statistics */ | ||
760 | for (unsigned i = 0; i < num_nodes; i++) | ||
761 | { | ||
762 | GNUNET_SCHEDULER_add_now(&main_task, &nodes[i].index_node); | ||
763 | } | ||
765 | } | 764 | } |
766 | } | ||
767 | } | 765 | } |
768 | 766 | ||
769 | 767 | ||
@@ -775,84 +773,85 @@ run (void *cls, | |||
775 | * @return 0 ok, 1 on error | 773 | * @return 0 ok, 1 on error |
776 | */ | 774 | */ |
777 | int | 775 | int |
778 | main (int argc, char *const *argv) | 776 | main(int argc, char *const *argv) |
779 | { | 777 | { |
780 | struct GNUNET_GETOPT_CommandLineOption options[] = | 778 | struct GNUNET_GETOPT_CommandLineOption options[] = |
781 | {GNUNET_GETOPT_option_string ( | 779 | { GNUNET_GETOPT_option_string( |
782 | 'n', | 780 | 'n', |
783 | "name", | 781 | "name", |
784 | "NAME", | 782 | "NAME", |
785 | gettext_noop ("limit output to statistics for the given NAME"), | 783 | gettext_noop("limit output to statistics for the given NAME"), |
786 | &name), | 784 | &name), |
787 | 785 | ||
788 | GNUNET_GETOPT_option_flag ('p', | 786 | GNUNET_GETOPT_option_flag('p', |
789 | "persistent", | 787 | "persistent", |
790 | gettext_noop ( | 788 | gettext_noop( |
791 | "make the value being set persistent"), | 789 | "make the value being set persistent"), |
792 | &persistent), | 790 | &persistent), |
793 | 791 | ||
794 | GNUNET_GETOPT_option_string ('s', | 792 | GNUNET_GETOPT_option_string('s', |
795 | "subsystem", | 793 | "subsystem", |
796 | "SUBSYSTEM", | 794 | "SUBSYSTEM", |
797 | gettext_noop ( | 795 | gettext_noop( |
798 | "limit output to the given SUBSYSTEM"), | 796 | "limit output to the given SUBSYSTEM"), |
799 | &subsystem), | 797 | &subsystem), |
800 | 798 | ||
801 | GNUNET_GETOPT_option_string ('S', | 799 | GNUNET_GETOPT_option_string('S', |
802 | "csv-separator", | 800 | "csv-separator", |
803 | "CSV_SEPARATOR", | 801 | "CSV_SEPARATOR", |
804 | gettext_noop ("use as csv separator"), | 802 | gettext_noop("use as csv separator"), |
805 | &csv_separator), | 803 | &csv_separator), |
806 | 804 | ||
807 | GNUNET_GETOPT_option_filename ( | 805 | GNUNET_GETOPT_option_filename( |
808 | 't', | 806 | 't', |
809 | "testbed", | 807 | "testbed", |
810 | "TESTBED", | 808 | "TESTBED", |
811 | gettext_noop ("path to the folder containing the testbed data"), | 809 | gettext_noop("path to the folder containing the testbed data"), |
812 | &path_testbed), | 810 | &path_testbed), |
813 | 811 | ||
814 | GNUNET_GETOPT_option_flag ('q', | 812 | GNUNET_GETOPT_option_flag('q', |
815 | "quiet", | 813 | "quiet", |
816 | gettext_noop ( | 814 | gettext_noop( |
817 | "just print the statistics value"), | 815 | "just print the statistics value"), |
818 | &quiet), | 816 | &quiet), |
819 | 817 | ||
820 | GNUNET_GETOPT_option_flag ('w', | 818 | GNUNET_GETOPT_option_flag('w', |
821 | "watch", | 819 | "watch", |
822 | gettext_noop ("watch value continuously"), | 820 | gettext_noop("watch value continuously"), |
823 | &watch), | 821 | &watch), |
824 | 822 | ||
825 | GNUNET_GETOPT_option_string ('r', | 823 | GNUNET_GETOPT_option_string('r', |
826 | "remote", | 824 | "remote", |
827 | "REMOTE", | 825 | "REMOTE", |
828 | gettext_noop ("connect to remote host"), | 826 | gettext_noop("connect to remote host"), |
829 | &remote_host), | 827 | &remote_host), |
830 | 828 | ||
831 | GNUNET_GETOPT_option_ulong ('o', | 829 | GNUNET_GETOPT_option_ulong('o', |
832 | "port", | 830 | "port", |
833 | "PORT", | 831 | "PORT", |
834 | gettext_noop ("port for remote host"), | 832 | gettext_noop("port for remote host"), |
835 | &remote_port), | 833 | &remote_port), |
836 | 834 | ||
837 | GNUNET_GETOPT_OPTION_END}; | 835 | GNUNET_GETOPT_OPTION_END }; |
836 | |||
838 | remote_port = 0; | 837 | remote_port = 0; |
839 | remote_host = NULL; | 838 | remote_host = NULL; |
840 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 839 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
841 | return 2; | 840 | return 2; |
842 | 841 | ||
843 | ret = (GNUNET_OK == | 842 | ret = (GNUNET_OK == |
844 | GNUNET_PROGRAM_run (argc, | 843 | GNUNET_PROGRAM_run(argc, |
845 | argv, | 844 | argv, |
846 | "gnunet-statistics [options [value]]", | 845 | "gnunet-statistics [options [value]]", |
847 | gettext_noop ( | 846 | gettext_noop( |
848 | "Print statistics about GNUnet operations."), | 847 | "Print statistics about GNUnet operations."), |
849 | options, | 848 | options, |
850 | &run, | 849 | &run, |
851 | NULL)) | 850 | NULL)) |
852 | ? ret | 851 | ? ret |
853 | : 1; | 852 | : 1; |
854 | GNUNET_free_non_null (remote_host); | 853 | GNUNET_free_non_null(remote_host); |
855 | GNUNET_free ((void *) argv); | 854 | GNUNET_free((void *)argv); |
856 | return ret; | 855 | return ret; |
857 | } | 856 | } |
858 | 857 | ||