-/**
- * Continuation called by the "get_all" and "get" functions at the
- * end of a round. Obtains the final statistics and writes them to
- * the file, then either starts the next round, or, if this was the
- * last round, terminates the run.
- *
- * @param cls struct StatsContext
- * @param op operation handle
- * @param emsg error message, NULL on success
- */
-static void
-stats_finished_callback (void *cls,
- struct GNUNET_TESTBED_Operation *op,
- const char *emsg)
-{
- struct StatsContext *stats_context = cls;
- char buf[512];
- size_t buf_len;
-
- GNUNET_TESTBED_operation_done (get_stats_op);
- get_stats_op = NULL;
- if (NULL != emsg)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to get statistics: %s\n",
- emsg);
- GNUNET_SCHEDULER_shutdown ();
- GNUNET_free (stats_context);
- return;
- }
- LOG_DEBUG ("Finished collecting statistics\n");
- if (NULL != data_file)
- {
- /* Stats lookup successful, write out data */
- buf_len =
- GNUNET_snprintf (buf, sizeof (buf),
- "TOTAL_NSE_RECEIVED_MESSAGES_%u: %u \n",
- current_round,
- stats_context->total_nse_received_messages);
- GNUNET_DISK_file_write (data_file, buf, buf_len);
- buf_len =
- GNUNET_snprintf (buf, sizeof (buf),
- "TOTAL_NSE_TRANSMITTED_MESSAGES_%u: %u\n",
- current_round,
- stats_context->total_nse_transmitted_messages);
- GNUNET_DISK_file_write (data_file, buf, buf_len);
- buf_len =
- GNUNET_snprintf (buf, sizeof (buf),
- "TOTAL_NSE_CROSS_%u: %u \n",
- current_round,
- stats_context->total_nse_cross);
- GNUNET_DISK_file_write (data_file, buf, buf_len);
- buf_len =
- GNUNET_snprintf (buf, sizeof (buf),
- "TOTAL_NSE_EXTRA_%u: %u \n",
- current_round,
- stats_context->total_nse_extra);
- GNUNET_DISK_file_write (data_file, buf, buf_len);
- buf_len =
- GNUNET_snprintf (buf, sizeof (buf),
- "TOTAL_NSE_DISCARDED_%u: %u \n",
- current_round,
- stats_context->total_discarded);
- GNUNET_DISK_file_write (data_file, buf, buf_len);
- }
- GNUNET_SCHEDULER_add_now (&next_round, NULL);
- GNUNET_free (stats_context);
-}
-
-
-/**
- * Callback function to process statistic values.
- *
- * @param cls struct StatsContext
- * @param peer the peer the statistics belong to
- * @param subsystem name of subsystem that created the statistic
- * @param name the name of the datum
- * @param value the current value
- * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
- * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
- */
-static int
-statistics_iterator (void *cls,
- const struct GNUNET_TESTBED_Peer *peer,
- const char *subsystem, const char *name, uint64_t value,
- int is_persistent)
-{
- struct StatsContext *stats_context = cls;
- char buf[512];
- size_t buf_len;
-
- if (0 != strcasecmp (subsystem, "nse"))
- return GNUNET_SYSERR;
- if (0 == strcmp (name, "# flood messages received"))
- {
- stats_context->total_nse_received_messages += value;
- if ( (verbose > 1) &&
- (NULL != data_file) )
- {
- buf_len =
- GNUNET_snprintf (buf, sizeof (buf),
- "%p %u RECEIVED\n",
- peer, value);
- GNUNET_DISK_file_write (data_file, buf, buf_len);
- }
- }
- if (0 == strcmp (name, "# flood messages transmitted"))
- {
- stats_context->total_nse_transmitted_messages += value;
- if ( (verbose > 1) &&
- (NULL != data_file) )
- {
- buf_len =
- GNUNET_snprintf (buf, sizeof (buf),
- "%p %u TRANSMITTED\n",
- peer, value);
- GNUNET_DISK_file_write (data_file, buf, buf_len);
- }
- }
- if (0 == strcmp (name, "# cross messages"))
- stats_context->total_nse_cross += value;
- if (0 == strcmp (name, "# extra messages"))
- stats_context->total_nse_extra += value;
- if (0 == strcmp (name, "# flood messages discarded (clock skew too large)"))
- stats_context->total_discarded += value;
- return GNUNET_OK;
-}
-
-