*/
struct GNUNET_TESTBED_Peer **peers;
+ /**
+ * The subsystem of peers for which statistics are requested
+ */
+ char *subsystem;
+
+ /**
+ * The particular statistics value of interest
+ */
+ char *name;
+
/**
* The iterator to call with statistics information
*/
*/
struct GNUNET_STATISTICS_GetHandle *get_handle;
+ /**
+ * Task to mark the statistics service connect operation as done
+ */
+ GNUNET_SCHEDULER_TaskIdentifier op_done_task_id;
+
/**
* The index of this peer in the peers array of GetStatsContext
*/
}
+/**
+ * Task to mark statistics service connect operation as done. We call it here
+ * as we cannot destroy the statistics handle in iteration_completion_cb()
+ *
+ * @param cls the PeerGetStatsContext
+ * @param tc the scheduler task context
+ */
+static void
+op_done_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct PeerGetStatsContext *peer_sc = cls;
+ struct GetStatsContext *sc;
+ struct GNUNET_TESTBED_Operation **op;
+
+ sc = peer_sc->sc;
+ peer_sc->op_done_task_id = GNUNET_SCHEDULER_NO_TASK;
+ op = &sc->ops[peer_sc->peer_index];
+ GNUNET_assert (NULL != *op);
+ GNUNET_TESTBED_operation_done (*op);
+ *op = NULL;
+}
+
+
/**
* Continuation called by the "get_all" and "get" functions.
*
struct PeerGetStatsContext *peer_sc = cls;
struct GetStatsContext *sc;
- if (NULL == peer_sc->get_handle)
- {
- /* We are being called after we cancelled the GetHandle */
- GNUNET_assert (GNUNET_SYSERR == success);
- return;
- }
GNUNET_break (GNUNET_OK == success);
sc = peer_sc->sc;
peer_sc->get_handle = NULL;
sc->num_completed++;
+ peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now (&op_done_task, peer_sc);
if (sc->num_completed == sc->num_peers)
{
LOG_DEBUG ("Scheduling to call iteration completion callback\n");
{
struct PeerGetStatsContext *peer_sc = cls;
struct GNUNET_STATISTICS_Handle *h = ca_result;
-
+
LOG_DEBUG ("Retrieving statistics of peer %u\n", peer_sc->peer_index);
peer_sc->get_handle =
- GNUNET_STATISTICS_get (h, NULL, NULL,
+ GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem, peer_sc->sc->name,
GNUNET_TIME_UNIT_FOREVER_REL,
&iteration_completion_cb,
iterator_cb, peer_sc);
statistics_da (void *cls, void *op_result)
{
struct PeerGetStatsContext *peer_sc = cls;
+ struct GNUNET_STATISTICS_Handle *sh = op_result;
if (NULL != peer_sc->get_handle)
{
GNUNET_STATISTICS_get_cancel (peer_sc->get_handle);
peer_sc->get_handle = NULL;
}
- GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) op_result,
- GNUNET_NO);
+ GNUNET_STATISTICS_destroy (sh, GNUNET_NO);
+ if (GNUNET_SCHEDULER_NO_TASK != peer_sc->op_done_task_id)
+ GNUNET_SCHEDULER_cancel (peer_sc->op_done_task_id);
GNUNET_free (peer_sc);
}
sizeof (struct GNUNET_TESTBED_Operation *));
for (peer = 0; peer < sc->num_peers; peer++)
{
+ if (NULL == sc->peers[peer])
+ {
+ GNUNET_break (0);
+ continue;
+ }
peer_sc = GNUNET_malloc (sizeof (struct PeerGetStatsContext));
peer_sc->sc = sc;
peer_sc->peer_index = peer;
for (peer = 0; peer < sc->num_peers; peer++)
{
if (NULL != sc->ops[peer])
+ {
GNUNET_TESTBED_operation_done (sc->ops[peer]);
+ sc->ops[peer] = NULL;
+ }
}
GNUNET_free (sc->ops);
}
+ GNUNET_free_non_null (sc->subsystem);
+ GNUNET_free_non_null (sc->name);
GNUNET_free (sc);
if (GNUNET_YES ==
GNUNET_TESTBED_operation_queue_destroy_empty_ (no_wait_queue))
*
* @param num_peers number of peers to iterate over
* @param peers array of peers to iterate over
+ * @param subsystem limit to the specified subsystem, NULL for all subsystems
+ * @param name name of the statistic value, NULL for all values
* @param proc processing function for each statistic retrieved
* @param cont continuation to call once call is completed(?)
* @param cls closure to pass to proc and cont
struct GNUNET_TESTBED_Operation *
GNUNET_TESTBED_get_statistics (unsigned int num_peers,
struct GNUNET_TESTBED_Peer **peers,
+ const char *subsystem, const char *name,
GNUNET_TESTBED_StatisticsIterator proc,
GNUNET_TESTBED_OperationCompletionCallback cont,
void *cls)
GNUNET_TESTBED_operation_queue_create_ (UINT_MAX);
sc = GNUNET_malloc (sizeof (struct GetStatsContext));
sc->peers = peers;
+ sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup (subsystem);
+ sc->name = (NULL == name) ? NULL : GNUNET_strdup (name);
sc->proc = proc;
sc->cont = cont;
sc->cb_cls = cls;