-nicer logging
[oweals/gnunet.git] / src / ats-tests / perf_ats.c
index 08b6a1518ff1e768f43673545ff1ae5084d0ea78..c769c0762db2bf2062c3bafb89dbaefcdea5eb74 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- (C) 2010-2013 Christian Grothoff (and other contributing authors)
Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors)
 
  GNUnet is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
 /**
  * Shutdown task
  */
-static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
+static struct GNUNET_SCHEDULER_Task * shutdown_task;
 
 /**
  * Progress task
  */
-static GNUNET_SCHEDULER_TaskIdentifier progress_task;
+static struct GNUNET_SCHEDULER_Task * progress_task;
 
 /**
  * Test result
@@ -117,6 +117,8 @@ static unsigned int num_slaves;
  */
 static struct BenchmarkPeer *sps;
 
+static struct LoggingHandle *l;
+
 static void
 evaluate ()
 {
@@ -190,15 +192,15 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
 
   if (GNUNET_YES == logging)
-    GNUNET_ATS_TEST_logging_stop();
+    GNUNET_ATS_TEST_logging_clean_up(l);
 
-  shutdown_task = GNUNET_SCHEDULER_NO_TASK;
-  if (GNUNET_SCHEDULER_NO_TASK != progress_task)
+  shutdown_task = NULL;
+  if (NULL != progress_task)
   {
     fprintf (stderr, "0\n");
     GNUNET_SCHEDULER_cancel (progress_task);
   }
-  progress_task = GNUNET_SCHEDULER_NO_TASK;
+  progress_task = NULL;
 
   evaluate ();
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking done\n"));
@@ -211,7 +213,7 @@ static void
 print_progress ()
 {
   static int calls;
-  progress_task = GNUNET_SCHEDULER_NO_TASK;
+  progress_task = NULL;
 
   fprintf (stderr, "%llu..",
       (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls);
@@ -226,7 +228,7 @@ ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct BenchmarkPeer *me = cls;
 
-  me->ats_task = GNUNET_SCHEDULER_NO_TASK;
+  me->ats_task = NULL;
 
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n",
       me->no, me->pref_partner->no, me->pref_value);
@@ -246,7 +248,7 @@ start_benchmark()
 
   GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Benchmarking start\n"));
 
-  if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
+  if (NULL != shutdown_task)
     GNUNET_SCHEDULER_cancel(shutdown_task);
   shutdown_task = GNUNET_SCHEDULER_add_delayed(perf_duration, &do_shutdown,
       NULL );
@@ -262,14 +264,16 @@ start_benchmark()
       for (c_s = 0; c_s < num_slaves; c_s++)
       {
         GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m], &mps[c_m].partners[c_s],
-            UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL);
+            GNUNET_ATS_TEST_TG_LINEAR, UINT32_MAX, UINT32_MAX,
+            GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_FOREVER_REL);
       }
       if (pref_val != GNUNET_ATS_PREFERENCE_END)
         mps[c_m].ats_task = GNUNET_SCHEDULER_add_now(&ats_pref_task, &mps[c_m]);
     }
 
   if (GNUNET_YES == logging)
-    GNUNET_ATS_TEST_logging_start(log_frequency, testname, mps, num_masters);
+    l = GNUNET_ATS_TEST_logging_start (log_frequency, testname, mps,
+        num_masters, num_slaves, GNUNET_NO);
 }
 
 static void
@@ -313,15 +317,13 @@ test_recv_cb (void *cls,
 
 
 static void
-ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
+log_request_cb (void *cls, const struct GNUNET_HELLO_Address *address,
     int address_active, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
-    const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
+    const struct GNUNET_ATS_Properties *ats)
 {
   struct BenchmarkPeer *me = cls;
   struct BenchmarkPartner *p;
-  int c_a;
-  int log;
   char *peer_id;
 
   p = find_partner (me, &address->peer);
@@ -334,24 +336,19 @@ ats_performance_info_cb (void *cls, const struct GNUNET_HELLO_Address *address,
   }
   peer_id = GNUNET_strdup (GNUNET_i2s (&me->id));
 
-  log = GNUNET_NO;
   if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) ||
       (p->bandwidth_out != ntohl (bandwidth_out.value__)))
-      log = GNUNET_YES;
   p->bandwidth_in = ntohl (bandwidth_in.value__);
   p->bandwidth_out = ntohl (bandwidth_out.value__);
 
-  for (c_a = 0; c_a < ats_count; c_a++)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information: %s %s %u\n",
-        (GNUNET_YES == p->me->master) ? "Master" : "Slave",
-        p->me->no,
-        GNUNET_i2s (&p->dest->id),
-        GNUNET_ATS_print_property_type(ntohl(ats[c_a].type)),
-        ntohl(ats[c_a].value));
-  }
-  GNUNET_free(peer_id);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s [%u] received ATS information for peers `%s'\n",
+      (GNUNET_YES == p->me->master) ? "Master" : "Slave",
+          p->me->no,
+          GNUNET_i2s (&p->dest->id));
 
+  GNUNET_free(peer_id);
+  if (NULL != l)
+    GNUNET_ATS_TEST_logging_now (l);
 }
 
 
@@ -367,22 +364,32 @@ main (int argc, char *argv[])
   char *conf_name;
   char *comm_name;
   char *dotexe;
-  char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
+  char *prefs[] = GNUNET_ATS_PreferenceTypeString;
   int c;
 
   result = 0;
 
-  /* figure out testname */
+  /* Determine testname
+   * perf_ats_<solver>_<transport>_<preference>[.exe]*/
+
+  /* Find test prefix, store in temp */
   tmp = strstr (argv[0], TESTNAME_PREFIX);
   if (NULL == tmp)
   {
     fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]);
     return GNUNET_SYSERR;
   }
+
+  /* Set tmp to end of test name prefix */
   tmp += strlen (TESTNAME_PREFIX);
+
+  /* Determine solver name */
   solver = GNUNET_strdup (tmp);
+  /* Remove .exe prefix */
   if (NULL != (dotexe = strstr (solver, ".exe")) && dotexe[4] == '\0')
     dotexe[0] = '\0';
+
+  /* Determine first '_' after solver */
   tmp_sep = strchr (solver, '_');
   if (NULL == tmp_sep)
   {
@@ -425,7 +432,7 @@ main (int argc, char *argv[])
 
   if (0 != strcmp (pref_str, "NONE"))
   {
-    for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
+    for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
     {
       if (0 == strcmp (pref_str, prefs[c]))
       {
@@ -544,7 +551,7 @@ main (int argc, char *argv[])
       &do_benchmark,
       NULL,
       &test_recv_cb,
-      &ats_performance_info_cb);
+      &log_request_cb);
 
   return result;
 }