- remove dead assignments
[oweals/gnunet.git] / src / testbed / testbed_api_statistics.c
index ec0f126b15ac3fcc5a02944a468a4ce490ef6040..1e12a7c64fa9bf7655b19326284d2632b231d5aa 100644 (file)
@@ -65,6 +65,16 @@ struct GetStatsContext
    */
   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
    */
@@ -190,13 +200,6 @@ iteration_completion_cb (void *cls, int success)
   struct PeerGetStatsContext *peer_sc = cls;
   struct GetStatsContext *sc;
 
-  if (NULL == peer_sc->get_handle)
-  {
-    /* We are being called synchronously in call to GNUNET_STATISTICS_destroy()
-       in statistics_da() 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; 
@@ -260,10 +263,10 @@ service_connect_comp (void *cls,
 {
   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);
@@ -301,14 +304,14 @@ static void
 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);
@@ -333,7 +336,10 @@ opstart_get_stats (void *cls)
   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;
@@ -374,6 +380,8 @@ oprelease_get_stats (void *cls)
     }
     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))
@@ -387,6 +395,8 @@ oprelease_get_stats (void *cls)
  *
  * @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
@@ -395,6 +405,7 @@ oprelease_get_stats (void *cls)
 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)
@@ -408,6 +419,8 @@ GNUNET_TESTBED_get_statistics (unsigned int num_peers,
         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;