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