- fix
[oweals/gnunet.git] / src / nse / gnunet-nse-profiler.c
index cf61d7ee86909385f2759fe85de09fc2403a643e..a10d237918637252dca0fd534b1db6628ab015ed 100644 (file)
@@ -58,10 +58,26 @@ struct StatsContext
    * How many messages have peers received during the test.
    */
   unsigned long long total_nse_received_messages;
+
   /**
    * How many messages have peers send during the test (should be == received).
    */
-  unsigned long long total_nse_sent_messages;
+  unsigned long long total_nse_transmitted_messages;
+
+  /**
+   * How many messages have travelled an edge in both directions.
+   */
+  unsigned long long total_nse_cross;
+
+  /**
+   * How many extra messages per edge (corrections) have been received.
+   */
+  unsigned long long total_nse_extra;
+
+  /**
+   * How many messages have been discarded.
+   */
+  unsigned long long total_discarded;
 };
 
 
@@ -188,7 +204,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct NSEPeer *pos;
 
 #if VERBOSE
-  fprintf (stderr, "Ending test.\n");
+  FPRINTF (stderr, "%s",  "Ending test.\n");
 #endif
 
   if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
@@ -201,6 +217,12 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     if (pos->nse_handle != NULL)
       GNUNET_NSE_disconnect (pos->nse_handle);
     GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, pos);
+    if (GNUNET_SCHEDULER_NO_TASK != pos->stats_task)
+    {
+      GNUNET_SCHEDULER_cancel (pos->stats_task);
+      if (NULL != pos->stats)
+        GNUNET_STATISTICS_destroy(pos->stats, GNUNET_NO);
+    }
     GNUNET_free (pos);
   }
 
@@ -241,7 +263,7 @@ handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
     GNUNET_free (output_buffer);
   }
   else
-    fprintf (stderr,
+    FPRINTF (stderr,
              "Received network size estimate from peer %s. Size: %f std.dev. %f\n",
              GNUNET_i2s (&peer->daemon->id), estimate, std_dev);
 
@@ -297,12 +319,12 @@ static void
 core_get_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct NSEPeer *peer = cls;
-  
-  peer->stats_task = GNUNET_SCHEDULER_NO_TASK;
+
   if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
   {
     GNUNET_STATISTICS_destroy(peer->stats, GNUNET_NO);
     peer->stats = NULL;
+    return;
   }
   else
   {
@@ -316,6 +338,7 @@ core_get_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                           GNUNET_TIME_UNIT_FOREVER_REL,
                           NULL, &core_stats_iterator, peer);
   }
+  peer->stats_task = GNUNET_SCHEDULER_NO_TASK;
 }
 
 /**
@@ -410,16 +433,51 @@ stats_finished_callback (void *cls, int success)
       GNUNET_DISK_file_write (data_file, buf, buf_len);
     }
     GNUNET_free_non_null (buf);
+
     buf = NULL;
     buf_len =
-        GNUNET_asprintf (&buf, "TOTAL_NSE_SENT_MESSAGES_%d: %u\n",
+        GNUNET_asprintf (&buf, "TOTAL_NSE_TRANSMITTED_MESSAGES_%d: %u\n",
                          stats_context->shutdown, 
-                         stats_context->total_nse_received_messages);
+                         stats_context->total_nse_transmitted_messages);
     if (buf_len > 0)
     {
       GNUNET_DISK_file_write (data_file, buf, buf_len);
     }
     GNUNET_free_non_null (buf);
+
+    buf = NULL;
+    buf_len =
+        GNUNET_asprintf (&buf, "TOTAL_NSE_CROSS_%d: %u \n",
+                         stats_context->shutdown, 
+                         stats_context->total_nse_cross);
+    if (buf_len > 0)
+    {
+      GNUNET_DISK_file_write (data_file, buf, buf_len);
+    }
+    GNUNET_free_non_null (buf);
+
+    buf = NULL;
+    buf_len =
+        GNUNET_asprintf (&buf, "TOTAL_NSE_EXTRA_%d: %u \n",
+                         stats_context->shutdown, 
+                         stats_context->total_nse_extra);
+    if (buf_len > 0)
+    {
+      GNUNET_DISK_file_write (data_file, buf, buf_len);
+    }
+    GNUNET_free_non_null (buf);
+
+    buf = NULL;
+    buf_len =
+        GNUNET_asprintf (&buf, "TOTAL_NSE_DISCARDED_%d: %u \n",
+                         stats_context->shutdown, 
+                         stats_context->total_discarded);
+    if (buf_len > 0)
+    {
+      GNUNET_DISK_file_write (data_file, buf, buf_len);
+    }
+    GNUNET_free_non_null (buf);
+
   }
 
   if (GNUNET_YES == stats_context->shutdown)
@@ -476,9 +534,9 @@ statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer,
       }
 #endif
     }
-    if (0 == strcmp (name, "# flood messages sent"))
+    if (0 == strcmp (name, "# flood messages transmitted"))
     {
-      stats_context->total_nse_sent_messages += value;
+      stats_context->total_nse_transmitted_messages += value;
 #if VERBOSE
       if (data_file != NULL)
       {
@@ -487,7 +545,8 @@ statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer,
 
         buf = NULL;
         buf_len =
-            GNUNET_asprintf (&buf, "%s %u SENT\n", GNUNET_i2s(peer), value);
+            GNUNET_asprintf (&buf, "%s %u TRANSMITTED\n", 
+                             GNUNET_i2s(peer), value);
         if (buf_len > 0)
         {
           GNUNET_DISK_file_write (data_file, buf, buf_len);
@@ -496,6 +555,18 @@ statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer,
       }
 #endif
     }
+    if (0 == strcmp (name, "# cross messages"))
+    {
+      stats_context->total_nse_cross += value;
+    }
+    if (0 == strcmp (name, "# extra messages"))
+    {
+      stats_context->total_nse_extra += value;
+    }
+    if (0 == strcmp (name, "# flood messages discarded (clock skew too large)"))
+    {
+      stats_context->total_discarded += value;
+    }
   }
   return GNUNET_OK;
 }
@@ -510,7 +581,6 @@ disconnect_nse_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnecting nse service of peers\n");
   disconnect_task = GNUNET_SCHEDULER_NO_TASK;
-  pos = peer_head;
   while (NULL != (pos = peer_head))
   {
     if (pos->nse_handle != NULL)