static void
run_more (void *cls, char *const *args, const char *cfgfile,
          const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
  GNUNET_break (NULL !=
                GNUNET_STATISTICS_get (h, NULL, "test-3",
                                       GNUNET_TIME_UNIT_SECONDS, &next_fin,
                                       &check_3, cls));
}
static void
next (void *cls, int success)
{
  GNUNET_assert (success == GNUNET_OK);
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
  GNUNET_break (NULL !=
                GNUNET_STATISTICS_get (h, NULL, "test-2",
                                       GNUNET_TIME_UNIT_SECONDS, &next_fin,
                                       &check_2, cls));
}
/**
 * Check the server statistics regularly
 */
static void
check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  char *stat;

  check_task = NULL;
  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
    return;
  GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"),
                   current_adv_uri);
  if (NULL != learn_peer.stats)
  {
    if (NULL != download_stats)
      GNUNET_STATISTICS_get_cancel (download_stats);
    download_stats =
        GNUNET_STATISTICS_get (learn_peer.stats, "hostlist", stat,
                               GNUNET_TIME_UNIT_MINUTES,
                               &process_downloads_done, &process_downloads,
                               &learn_peer);
    if (NULL != urisrecv_stat)
      GNUNET_STATISTICS_get_cancel (urisrecv_stat);
    urisrecv_stat =
        GNUNET_STATISTICS_get (learn_peer.stats, "hostlist",
                               gettext_noop ("# advertised hostlist URIs"),
                               GNUNET_TIME_UNIT_MINUTES,
                               &process_uris_recv_done, &process_uris_recv,
                               &learn_peer);
  }
  GNUNET_free (stat);
  if (NULL != adv_peer.stats)
  {
    if (NULL != advsent_stat)
      GNUNET_STATISTICS_get_cancel (advsent_stat);
    advsent_stat =
        GNUNET_STATISTICS_get (adv_peer.stats, "hostlist",
                               gettext_noop ("# hostlist advertisements send"),
                               GNUNET_TIME_UNIT_MINUTES, &process_adv_sent_done,
                               &process_adv_sent, NULL);
  }
  check_task =
      GNUNET_SCHEDULER_add_delayed (CHECK_INTERVAL, &check_statistics, NULL);
}
static void
run (void *cls,
     const struct GNUNET_CONFIGURATION_Handle *cfg,
     struct GNUNET_TESTING_Peer *peer)
{
  die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
  stats = GNUNET_STATISTICS_create ("ats", cfg);
  GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL);

  initial_get = GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT,
                                       &got_initial_value, &dummy_stat,
                                       GNUNET_CONFIGURATION_dup (cfg));
}
static void
run (void *cls, char *const *args, const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  h = GNUNET_STATISTICS_create ("test-statistics-api", cfg);
  GNUNET_STATISTICS_set (h, "test-1", 1, GNUNET_NO);
  GNUNET_STATISTICS_set (h, "test-2", 2, GNUNET_NO);
  GNUNET_STATISTICS_set (h, "test-3", 2, GNUNET_NO);
  GNUNET_STATISTICS_update (h, "test-3", 1, GNUNET_YES);
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Issuing GET request\n");
  GNUNET_break (NULL !=
                GNUNET_STATISTICS_get (h, NULL, "test-1",
                                       GNUNET_TIME_UNIT_SECONDS, &next,
                                       &check_1, cls));
}
Beispiel #6
0
/**
 * Called after opening a connection to the statistics service of a peer
 *
 * @param cls the PeerGetStatsContext
 * @param op the operation that has been finished
 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
 * @param emsg error message in case the operation has failed; will be NULL if
 *          operation has executed successfully.
 */
static void
service_connect_comp (void *cls,
                      struct GNUNET_TESTBED_Operation *op,
                      void *ca_result,
                      const char *emsg)
{
  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, peer_sc->sc->subsystem,
                             peer_sc->sc->name,
                             &iteration_completion_cb,
                             iterator_cb, peer_sc);
}
/**
 * Function that gathers stats from all daemons.
 */
static void
stat_run (void *cls,
	  struct GNUNET_TESTBED_Operation *op,
	  void *ca_result,
	  const char *emsg)
{
  struct StatMaster *sm = cls;

  sm->stat = ca_result;
  GNUNET_assert (NULL != sm->stat);
  if (NULL != stats[sm->value].name)
  {
    GNUNET_STATISTICS_get (sm->stat,
#if 0
                           NULL, NULL,
#else
                           stats[sm->value].subsystem, stats[sm->value].name,
#endif
                           &get_done, &print_stat,
                           sm);
    return;
  }
  GNUNET_TESTBED_operation_done (sm->op);
  sm->value = 0;
  sm->daemon++;
  if (NUM_DAEMONS == sm->daemon)
  {
    GNUNET_free (sm);
    cleanup ();
    return;
  }
  sm->op =
    GNUNET_TESTBED_service_connect (NULL,
				    daemons[sm->daemon],
				    "statistics",
				    &stat_run, sm,
				    &statistics_connect_adapter,
				    &statistics_disconnect_adapter,
				    NULL);
}
static void
run (void *cls,
     char *const *args,
     const char *cfgfile,
     const struct GNUNET_CONFIGURATION_Handle *cfg)
{
  unsigned int i;
  char name[128];

  h = GNUNET_STATISTICS_create ("test-statistics-api-loop", cfg);
  for (i = 0; i < ROUNDS; i++)
  {
    GNUNET_snprintf (name, sizeof (name), "test-%d", i % 32);
    GNUNET_STATISTICS_set (h, name, i, GNUNET_NO);
    GNUNET_snprintf (name, sizeof (name), "test-%d", i % 16);
    GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO);
  }
  i = 0;
  GNUNET_break (NULL !=
                GNUNET_STATISTICS_get (h, NULL, "test-0",
                                       &next,
                                       &check_1, cls));
}
static void
measurement_stop (void *cls,
                  const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  unsigned long long delta;
  unsigned long long throughput_out;
  unsigned long long throughput_in;
  unsigned long long max_quota_in;
  unsigned long long max_quota_out;
  unsigned long long quota_delta;
  enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG;

  measure_task = NULL;
  FPRINTF (stdout, "%s",  "\n");
  running = GNUNET_NO;

  delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us;

  throughput_out = total_bytes_sent * 1000000LL / delta;     /* convert to bytes/s */
  throughput_in = total_bytes_recv * 1000000LL / delta;      /* convert to bytes/s */

  max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in);
  max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out);
  if (max_quota_out < max_quota_in)
    quota_delta = max_quota_in / 3;
  else
    quota_delta = max_quota_out / 3;

  if ((throughput_out > (max_quota_out + quota_delta)) ||
      (throughput_in > (max_quota_in + quota_delta)))
    ok = 1; /* fail */
  else
    ok = 0; /* pass */
  GNUNET_STATISTICS_get (p1.stats, "core", "# discarded CORE_SEND requests",
                         GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);

  GNUNET_STATISTICS_get (p1.stats, "core",
                         "# discarded CORE_SEND request bytes",
                         GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
  GNUNET_STATISTICS_get (p1.stats, "core",
                         "# discarded lower priority CORE_SEND requests",
                         GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, NULL);
  GNUNET_STATISTICS_get (p1.stats, "core",
                         "# discarded lower priority CORE_SEND request bytes",
                         GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p1);
  GNUNET_STATISTICS_get (p2.stats, "core", "# discarded CORE_SEND requests",
                         GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);

  GNUNET_STATISTICS_get (p2.stats, "core",
                         "# discarded CORE_SEND request bytes",
                         GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
  GNUNET_STATISTICS_get (p2.stats, "core",
                         "# discarded lower priority CORE_SEND requests",
                         GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);
  GNUNET_STATISTICS_get (p2.stats, "core",
                         "# discarded lower priority CORE_SEND request bytes",
                         GNUNET_TIME_UNIT_FOREVER_REL, NULL, &print_stat, &p2);

  if (ok != 0)
    kind = GNUNET_ERROR_TYPE_ERROR;
  switch (test)
  {
  case SYMMETRIC:
    GNUNET_log (kind, "Core quota compliance test with symmetric quotas: %s\n",
                (0 == ok) ? "PASSED" : "FAILED");
    break;
  case ASYMMETRIC_SEND_LIMITED:
    GNUNET_log (kind,
                "Core quota compliance test with limited sender quota: %s\n",
                (0 == ok) ? "PASSED" : "FAILED");
    break;
  case ASYMMETRIC_RECV_LIMITED:
    GNUNET_log (kind,
                "Core quota compliance test with limited receiver quota: %s\n",
                (0 == ok) ? "PASSED" : "FAILED");
    break;
  };
  GNUNET_log (kind, "Peer 1 send  rate: %llu b/s (%llu bytes in %llu ms)\n",
              throughput_out, total_bytes_sent, delta);
  GNUNET_log (kind, "Peer 1 send quota: %llu b/s\n", current_quota_p1_out);
  GNUNET_log (kind, "Peer 2 receive  rate: %llu b/s (%llu bytes in %llu ms)\n",
              throughput_in, total_bytes_recv, delta);
  GNUNET_log (kind, "Peer 2 receive quota: %llu b/s\n", current_quota_p2_in);
/*
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound  quota allowed: %llu b/s\n",max_quota_in );
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out);
*/
  GNUNET_SCHEDULER_cancel (err_task);
  err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL);

}
/**
 * Main task that does the actual work.
 *
 * @param cls closure with our configuration
 * @param tc schedueler context
 */
static void
main_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
  struct GNUNET_STATISTICS_Handle *h;

  if (set_value)
  {
    if (subsystem == NULL)
    {
      FPRINTF (stderr, "%s", _("Missing argument: subsystem \n"));
      ret = 1;
      return;
    }
    if (name == NULL)
    {
      FPRINTF (stderr, "%s", _("Missing argument: name\n"));
      ret = 1;
      return;
    }
    h = GNUNET_STATISTICS_create (subsystem, cfg);
    if (NULL == h)
    {
      ret = 1;
      return;
    }
    GNUNET_STATISTICS_set (h, name, (uint64_t) set_val, persistent);
    GNUNET_STATISTICS_destroy (h, GNUNET_YES);
    h = NULL;
    return;
  }
  if (NULL == (h = GNUNET_STATISTICS_create ("gnunet-statistics", cfg)))
  {
    ret = 1;
    return;
  }
  if (GNUNET_NO == watch)
  {
    if (NULL ==
      GNUNET_STATISTICS_get (h, subsystem, name, GET_TIMEOUT, &cleanup,
                             &printer, h))
    cleanup (h, GNUNET_SYSERR);
  }
  else
  {
    if ((NULL == subsystem) || (NULL == name))
    {
      printf (_("No subsystem or name given\n"));
      GNUNET_STATISTICS_destroy (h, GNUNET_NO);
      h = NULL;
      ret = 1;
      return;
    }
    if (GNUNET_OK != GNUNET_STATISTICS_watch (h, subsystem, name, &printer, h))
    {
      fprintf (stderr, _("Failed to initialize watch routine\n"));
      GNUNET_SCHEDULER_add_now (&shutdown_task, h);
      return;
    }
  }
  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                &shutdown_task, h);

}