rps profiler: log view sizes
authorJulius Bünger <buenger@mytum.de>
Wed, 21 Mar 2018 06:56:51 +0000 (07:56 +0100)
committerJulius Bünger <buenger@mytum.de>
Wed, 21 Mar 2018 09:12:30 +0000 (10:12 +0100)
src/rps/rps-test_util.c
src/rps/test_rps.c

index 882f945c93e6ede3e8ac54772915ac1cdd8df753..e492b76b764fc9c3b7aa86042fd62f0f7149a7e7 100644 (file)
@@ -43,6 +43,7 @@ to_file_ (char *file_name, char *line)
 {
   struct GNUNET_DISK_FileHandle *f;
   char output_buffer[512];
+  char *output_buffer_p;
   //size_t size;
   int size;
   size_t size2;
@@ -62,8 +63,14 @@ to_file_ (char *file_name, char *line)
          file_name);
     return;
   }
-  size = GNUNET_snprintf (output_buffer,
-                          sizeof (output_buffer),
+  if (512 < strlen (line) + 18)
+  {
+    output_buffer_p = GNUNET_malloc ((strlen (line) + 18) * sizeof (char));
+  } else {
+    output_buffer_p = &output_buffer[0];
+  }
+  size = GNUNET_snprintf (output_buffer_p,
+                          sizeof (output_buffer_p),
                           "%llu %s\n",
                           GNUNET_TIME_absolute_get ().abs_value_us,
                           line);
@@ -75,7 +82,7 @@ to_file_ (char *file_name, char *line)
     return;
   }
 
-  size2 = GNUNET_DISK_file_write (f, output_buffer, size);
+  size2 = GNUNET_DISK_file_write (f, output_buffer_p, size);
   if (size != size2)
   {
     LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -90,6 +97,11 @@ to_file_ (char *file_name, char *line)
     return;
   }
 
+  if (512 < strlen (line) + 18)
+  {
+    GNUNET_free (output_buffer_p);
+  }
+
   if (GNUNET_YES != GNUNET_DISK_file_close (f))
     LOG (GNUNET_ERROR_TYPE_WARNING,
          "Unable to close file\n");
index 127b973acc3c55015fe425733bb221f5c1f1e068..d9f0a2c776c3e3570a1d6f08162d9439f167d579 100644 (file)
@@ -1878,9 +1878,40 @@ void compute_diversity ()
   GNUNET_free (deviation);
 }
 
-void all_views_updated_cb ()
+void print_view_sizes()
 {
-  compute_diversity ();
+  uint32_t i;
+  char *view_sizes_str = NULL;
+  uint32_t view_sizes_str_len = 0;
+  char view_size_curr[32] = { 0 };
+
+  GNUNET_array_grow (view_sizes_str, view_sizes_str_len, num_peers * 3);
+  for (i = 0; i < num_peers; i++) /* Peer to count */
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n",
+               i,
+               GNUNET_i2s (rps_peers[i].peer_id),
+               rps_peers[i].cur_view_count);
+    GNUNET_snprintf (view_size_curr,
+                     sizeof (view_size_curr),
+                     " %" PRIu32 "",
+                     rps_peers[i].cur_view_count);
+    if (view_sizes_str_len < view_sizes_str_len + strlen (view_size_curr))
+    {
+      GNUNET_array_grow (view_sizes_str, view_sizes_str_len, view_sizes_str_len + 10);
+    }
+    strncat (view_sizes_str, view_size_curr, strlen(view_size_curr));
+  }
+  to_file_ ("/tmp/rps/view_sizes.txt",
+           view_sizes_str);
+  GNUNET_array_grow (view_sizes_str, view_sizes_str_len, 0);
+}
+
+void all_views_updated_cb()
+{
+  compute_diversity();
+  print_view_sizes();
 }
 
 void view_update_cb (void *cls,