+/**
+ * Continuation called by #GNUNET_STATISTICS_get() functions.
+ *
+ * Remembers that this specific statistics value was received for this peer.
+ * Checks whether all peers received their statistics yet.
+ * Issues the shutdown.
+ *
+ * @param cls closure
+ * @param success #GNUNET_OK if statistics were
+ * successfully obtained, #GNUNET_SYSERR if not.
+ */
+void
+post_test_shutdown_ready_cb (void *cls,
+ int success)
+{
+ struct STATcls *stat_cls = (struct STATcls *) cls;
+ struct RPSPeer *rps_peer = stat_cls->rps_peer;
+ if (GNUNET_OK == success)
+ {
+ /* set flag that we we got the value */
+ rps_peer->stat_collected_flags |= stat_cls->stat_type;
+ } else {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Peer %u did not receive statistics value\n",
+ rps_peer->index);
+ GNUNET_free (stat_cls);
+ GNUNET_break (0);
+ }
+
+ if (NULL != rps_peer->stat_op &&
+ GNUNET_YES == check_statistics_collect_completed_single_peer (rps_peer))
+ {
+ GNUNET_TESTBED_operation_done (rps_peer->stat_op);
+ }
+
+ if (GNUNET_YES == check_statistics_collect_completed())
+ {
+ GNUNET_free (stat_cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutting down\n");
+ GNUNET_SCHEDULER_shutdown ();
+ } else {
+ GNUNET_free (stat_cls);
+ }
+}
+
+/**
+ * @brief Converts #STAT_TYPE enum to the equivalent string representation that
+ * is stored with the statistics service.
+ *
+ * @param stat_type #STAT_TYPE enum
+ *
+ * @return string representation that matches statistics value
+ */
+char* stat_type_2_str (enum STAT_TYPE stat_type)
+{
+ switch (stat_type)
+ {
+ case STAT_TYPE_ROUNDS:
+ return "# rounds";
+ case STAT_TYPE_BLOCKS:
+ return "# rounds blocked";
+ case STAT_TYPE_BLOCKS_MANY_PUSH:
+ return "# rounds blocked - too many pushes";
+ case STAT_TYPE_BLOCKS_FEW_PUSH:
+ return "# rounds blocked - no pushes";
+ case STAT_TYPE_BLOCKS_FEW_PULL:
+ return "# rounds blocked - no pull replies";
+ case STAT_TYPE_ISSUED_PUSH_SEND:
+ return "# push send issued";
+ case STAT_TYPE_ISSUED_PULL_REQ:
+ return "# pull request send issued";
+ case STAT_TYPE_ISSUED_PULL_REP:
+ return "# pull reply send issued";
+ case STAT_TYPE_SENT_PUSH_SEND:
+ return "# pushes sent";
+ case STAT_TYPE_SENT_PULL_REQ:
+ return "# pull requests sent";
+ case STAT_TYPE_SENT_PULL_REP:
+ return "# pull replys sent";
+ case STAT_TYPE_RECV_PUSH_SEND:
+ return "# push message received";
+ case STAT_TYPE_RECV_PULL_REQ:
+ return "# pull request message received";
+ case STAT_TYPE_RECV_PULL_REP:
+ return "# pull reply messages received";
+ case STAT_TYPE_MAX:
+ default:
+ return "ERROR";
+ ;
+ }
+}
+
+/**
+ * Callback function to process statistic values.
+ *
+ * @param cls closure
+ * @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
+ */
+int
+stat_iterator (void *cls,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
+ int is_persistent)
+{
+ const struct STATcls *stat_cls = (const struct STATcls *) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n",
+ stat_type_2_str (stat_cls->stat_type),
+ value);
+ return GNUNET_OK;
+}
+
+void post_profiler (struct RPSPeer *rps_peer)
+{
+ if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics)
+ {
+ return;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Going to request statistic values with mask 0x%" PRIx32 "\n",
+ cur_test_run.stat_collect_flags);
+
+ struct STATcls *stat_cls;
+ uint32_t stat_type;
+ for (stat_type = STAT_TYPE_ROUNDS;
+ stat_type < STAT_TYPE_MAX;
+ stat_type = stat_type <<1)
+ {
+ if (stat_type & cur_test_run.stat_collect_flags)
+ {
+ stat_cls = GNUNET_malloc (sizeof (struct STATcls));
+ stat_cls->rps_peer = rps_peer;
+ stat_cls->stat_type = stat_type;
+ GNUNET_STATISTICS_get (rps_peer->stats_h,
+ "rps",
+ stat_type_2_str (stat_type),
+ post_test_shutdown_ready_cb,
+ stat_iterator,
+ (struct STATcls *) stat_cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requested statistics for %s (peer %" PRIu32 ")\n",
+ stat_type_2_str (stat_type),
+ rps_peer->index);
+ }
+ }
+}
+