gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18537 - gnunet-gtk/src/statistics


From: gnunet
Subject: [GNUnet-SVN] r18537 - gnunet-gtk/src/statistics
Date: Fri, 9 Dec 2011 17:59:03 +0100

Author: grothoff
Date: 2011-12-09 17:59:03 +0100 (Fri, 09 Dec 2011)
New Revision: 18537

Modified:
   gnunet-gtk/src/statistics/gnunet-statistics-gtk.c
   gnunet-gtk/src/statistics/gtk_statistics.c
   gnunet-gtk/src/statistics/gtk_statistics.h
   gnunet-gtk/src/statistics/test.c
Log:
polishing statistics widget, integration with main gnunet-statistics-gtk GUI

Modified: gnunet-gtk/src/statistics/gnunet-statistics-gtk.c
===================================================================
--- gnunet-gtk/src/statistics/gnunet-statistics-gtk.c   2011-12-09 16:26:53 UTC 
(rev 18536)
+++ gnunet-gtk/src/statistics/gnunet-statistics-gtk.c   2011-12-09 16:59:03 UTC 
(rev 18537)
@@ -49,6 +49,11 @@
   const char *name;
 
   /**
+   * Label to use in legend.
+   */
+  const char *label;
+
+  /**
    * Name of color to use when plotting.
    */
   const char *color_name;
@@ -58,11 +63,37 @@
 
 static const struct PlotInfo connection_data[] = 
   {
-    { "core", "entries in session map", "white" },
+    { "fs", "# peers connected", "file-sharing connections", "blue" },
+    { "core", "# entries in session map", "encrypted connections (core)", 
"green" },
+    { "core", "# neighbour entries allocated", "transport connections (core)", 
"yellow" },
+    { "transport", "# peers connected", "total connections (transport)", 
"orange" },
+    { "transport", "# TCP sessions active", "tcp connections", "red" },
+    { "peerinfo", "# peers known", "peers known", "brown" },
+    { "nse", "# nodes in the network (estimate)", "network size (estimate)", 
"purple" },
     { NULL, NULL, NULL}
   };
 
 
+static const struct PlotInfo traffic_data[] = 
+  {
+    { "core", "# bytes encrypted", "bytes encrypted", "blue" },
+    { "core", "# bytes decrypted", "bytes decrypted", "green" },
+    { "transport", "# bytes received via TCP", "received via tcp", "yellow" },
+    { "transport", "# bytes transmitted via TCP", "sent via tcp", "brown" },
+    { NULL, NULL, NULL}
+  };
+
+
+static const struct PlotInfo storage_data[] = 
+  {
+    { "datastore", "# quota", "datastore capacity", "blue" },
+    { "datastore", "# bytes stored", "datastore utilization", "yellow" },
+    { "datastore", "# cache size", "reservation for datastore cache", "green" 
},
+    { "datastore", "# bytes purged (low-priority)", "discarded due to limited 
space", "red" },
+    { NULL, NULL, NULL}
+  };
+
+
 /**
  * Handle to our main loop.
  */
@@ -83,7 +114,12 @@
  */
 static GNUNET_SCHEDULER_TaskIdentifier connection_task;
 
+/**
+ * When did this process start?
+ */
+static struct GNUNET_TIME_Absolute start_time;
 
+
 /**
  * Callback function to process statistic values.
  *
@@ -103,8 +139,8 @@
 
   gtk_statistics_update_value (stats,
                               name,
-                              value,
-                              GNUNET_TIME_absolute_get().abs_value);
+                              GNUNET_TIME_absolute_get_duration 
(start_time).rel_value / 1000LL,
+                              value);
   return GNUNET_OK;
 }
 
@@ -128,17 +164,22 @@
  * @param widget size and style information for the plot
  * @param info what to draw
  */
-/* static */ GtkStatistics *
-create_plot (const struct PlotInfo *info)
+static void
+create_plot (const char *box_name,
+            const struct PlotInfo *info)
 {
+  GtkBox *box;
   GtkStatistics *ret;
   unsigned int i;
 
   ret = GTK_STATISTICS (gtk_statistics_new ());
+  box = GTK_BOX (get_object (box_name));
+  
   for (i=0; NULL != info[i].subsystem; i++)
   {
-    gtk_statistics_add_line (ret,
+    gtk_statistics_add_line (ret,                           
                             info[i].name,
+                            info[i].label,
                             info[i].color_name);
     GNUNET_STATISTICS_watch (statistics,
                             info[i].subsystem,
@@ -146,7 +187,12 @@
                             &process_value_update,
                             ret);
   }
-  return ret;
+  gtk_widget_show (GTK_WIDGET (ret));
+  gtk_box_pack_start (box,
+                     GTK_WIDGET (ret),
+                     TRUE,
+                     TRUE,
+                     0);
 }
 
 
@@ -209,6 +255,14 @@
   GNUNET_GTK_tray_icon_create (GTK_WINDOW (main_window),
                                "gnunet-gtk" /* FIXME: different icon? */ ,
                                "gnunet-statistics-gtk");
+
+  create_plot ("GNUNET_STATISTICS_GTK_connectivity_box",
+              connection_data);
+  create_plot ("GNUNET_STATISTICS_GTK_traffic_box",
+              traffic_data);
+  create_plot ("GNUNET_STATISTICS_GTK_storage_box",
+              storage_data);
+
   /* make GUI visible */
   if (!tray_only)
   {
@@ -228,6 +282,7 @@
     GNUNET_GETOPT_OPTION_END
   };
 
+  start_time = GNUNET_TIME_absolute_get ();
   if (GNUNET_OK !=
       GNUNET_GTK_main_loop_start ("gnunet-statistics-gtk",
                                   "GTK GUI for viewing GNUnet statistics", 
argc,

Modified: gnunet-gtk/src/statistics/gtk_statistics.c
===================================================================
--- gnunet-gtk/src/statistics/gtk_statistics.c  2011-12-09 16:26:53 UTC (rev 
18536)
+++ gnunet-gtk/src/statistics/gtk_statistics.c  2011-12-09 16:59:03 UTC (rev 
18537)
@@ -39,6 +39,9 @@
  */
 #define YTICKS 5
 
+/**
+ * Additional distance between text and lines / borders in pixels.
+ */
 #define BORDER 10.0
 
 
@@ -66,6 +69,11 @@
 {
 
   /**
+   * ID for value updates.
+   */
+  char *id;
+
+  /**
    * Label for the subsystem.
    */
   char *label;
@@ -172,9 +180,16 @@
 
 
 /**
+ * Add another data series to plot by the statistics widget.
+ *
+ * @param statistics widget to modify
+ * @param id identifier for the series
+ * @param label label to use
+ * @param color_name name of the color to use
  */
 void
 gtk_statistics_add_line (GtkStatistics *statistics,
+                        const char *id,
                         const char *label,
                         const char *color_name)
 {
@@ -188,6 +203,7 @@
   priv->values = g_realloc (priv->values,
                            sizeof (struct ValueHistory*) * (1 + 
priv->num_values));
   priv->values[priv->num_values++] = vh = g_malloc (sizeof (struct 
ValueHistory));
+  vh->id = strdup (id);
   vh->label = strdup (label);
   vh->red = c.red / 65535.0;
   vh->green = c.green / 65535.0;
@@ -196,10 +212,16 @@
 
 
 /**
+ * Add another value to a data series.
+ * 
+ * @param statistics widget to update
+ * @param id identifier of the series
+ * @param x new x-value
+ * @param y new y-value
  */
 void
 gtk_statistics_update_value (GtkStatistics      *statistics,
-                            const char *label,
+                            const char *id,
                             uint64_t x,
                             uint64_t y)
 {
@@ -213,14 +235,15 @@
   for (i=0;i<priv->num_values;i++)
   {
     vh = priv->values[i];
-    if (0 != strcmp (label, vh->label))
+    if (0 != strcmp (id, vh->id))
       continue;
+
     if (++vh->last_history_offset == MAX_HISTORY)
       vh->last_history_offset = 0;
     if (vh->history_size < MAX_HISTORY)
       vh->history_size++;
     vh->history[vh->last_history_offset].x = x;
-    vh->history[vh->last_history_offset].y = y;
+    vh->history[vh->last_history_offset].y = y;  
     widget = GTK_WIDGET (statistics);
     if (gtk_widget_is_drawable (widget))
       gtk_widget_queue_draw (widget);
@@ -228,11 +251,19 @@
 }
 
 
+/**
+ * Convert a number to a nice label for the axis.
+ *
+ * @param num number to convert
+ * @param label where to store the string (must be big enough!)
+ */
 static void
 num_to_label (unsigned long long num,
              char *label)
 {
-  if (num > 1000LL * 1000 * 1000 * 3)
+  if (num > 1000LL * 1000 * 1000 * 1000 * 3)
+    sprintf (label, "%llu t", num / 1000LL / 1000LL / 1000LL / 1000LL);
+  else if (num > 1000LL * 1000 * 1000 * 3)
     sprintf (label, "%llu g", num / 1000LL / 1000LL / 1000LL);
   else if (num > 1000LL * 1000 * 3)
     sprintf (label, "%llu m", num / 1000LL / 1000LL);
@@ -243,6 +274,12 @@
 }
 
 
+/**
+ * Draw the statistics widget.
+ *
+ * @param widget widget to draw
+ * @param cr drawing context
+ */
 static gboolean
 gtk_statistics_draw (GtkWidget *widget,
                 cairo_t   *cr)
@@ -264,6 +301,7 @@
   cairo_text_extents_t tey_max;
   double rx;
   double ry;
+  unsigned int h;
 
   /* collect basic data */
   xmin = UINT64_MAX;
@@ -292,7 +330,7 @@
   cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
   cairo_paint(cr);
   
-  if (0 == priv->num_values)
+ if ( (0 == priv->num_values) || (ymax == 0) )
     return FALSE; /* done */
   /* select font */
   cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
@@ -379,10 +417,26 @@
 
   /* finally, plot lines */
   cairo_set_line_width (cr, 2.0);
+
+  cairo_set_font_size (cr, 
+                      GNUNET_MIN (20, (height - 3.0 * BORDER - tex_max.height 
- tey_max.height / 2) / (priv->num_values + 1)));
+
+  h = 2.0 * BORDER + tey_max.height / 2;
+
   for (i=0;i<priv->num_values;i++)
   {
     vh = priv->values[i];
     cairo_set_source_rgb(cr, vh->red, vh->green, vh->blue);
+    cairo_text_extents (cr, vh->label, &te);
+    h += te.height / 2;
+    cairo_move_to (cr, 
+                  3.0 * BORDER + tey_max.width,
+                  h);
+    h += te.height / 2 + 1.0;
+    cairo_show_text (cr, vh->label);
+    if (xmax == xmin) 
+      continue;
+
     for (j=0;j<vh->history_size;j++)
     {
       hv = &vh->history[(vh->last_history_offset - j + MAX_HISTORY) % 
MAX_HISTORY];
@@ -391,14 +445,15 @@
       
       rx = tey_max.width + BORDER * 2.0 + (rx * (width - BORDER * 3.0 - 
tey_max.width - tex_max.width / 2.0));
       ry = BORDER + tex_max.height / 2.0 + (1.0 - ry) * (height - BORDER * 2.0 
- tey_max.height - tex_max.height);
-      if (j == 0)
-      {
-       cairo_move_to (cr, rx, ry);
-      }
-      else
-      {
-       cairo_line_to (cr, rx, ry);
-      }
+
+      /* if y-values are small, offset y-values a bit to allow overlapping 
curves to still show up */
+      if (ymax < height / (priv->num_values * 4))
+       ry += priv->num_values * 2 - (4 * i);
+      if (j == 0) 
+       cairo_move_to (cr, 
+                      width - BORDER - tex_max.width / 2.0, 
+                      ry);      
+      cairo_line_to (cr, rx, ry);
     }
     cairo_stroke (cr);
   }
@@ -406,6 +461,11 @@
 }
 
 
+/**
+ * Free memory used by statistics object.
+ *
+ * @param object object to release
+ */
 static void
 gtk_statistics_finalize (GObject *object)
 {
@@ -416,6 +476,7 @@
   for (i=0;i<priv->num_values;i++)
   {
     g_free (priv->values[i]->label);
+    g_free (priv->values[i]->id);
     g_free (priv->values[i]);  
   }
   g_free (priv->values);  

Modified: gnunet-gtk/src/statistics/gtk_statistics.h
===================================================================
--- gnunet-gtk/src/statistics/gtk_statistics.h  2011-12-09 16:26:53 UTC (rev 
18536)
+++ gnunet-gtk/src/statistics/gtk_statistics.h  2011-12-09 16:59:03 UTC (rev 
18537)
@@ -66,10 +66,11 @@
 GType      gtk_statistics_get_type   (void) G_GNUC_CONST;
 GtkWidget* gtk_statistics_new        (void);
 void       gtk_statistics_add_line   (GtkStatistics *statistics,
+                                     const char *id,
                                      const char *label,
                                      const char *color_name);
 void       gtk_statistics_update_value (GtkStatistics *statistics,
-                                       const char *label,
+                                       const char *id,
                                        uint64_t x,
                                        uint64_t y);
 

Modified: gnunet-gtk/src/statistics/test.c
===================================================================
--- gnunet-gtk/src/statistics/test.c    2011-12-09 16:26:53 UTC (rev 18536)
+++ gnunet-gtk/src/statistics/test.c    2011-12-09 16:59:03 UTC (rev 18537)
@@ -41,6 +41,7 @@
   statistics = gtk_statistics_new();
   gtk_statistics_add_line (GTK_STATISTICS (statistics),
                           "sin",
+                          "sin",
                           "red");
   for (i=0;i<600;i++)
     gtk_statistics_update_value (GTK_STATISTICS (statistics),
@@ -49,6 +50,7 @@
                                 (uint64_t) (500 * (1.0 + sin(i/100.0))));
   gtk_statistics_add_line (GTK_STATISTICS (statistics),
                           "cos",
+                          "cos",
                           "blue");
   for (i=0;i<600;i++)
     gtk_statistics_update_value (GTK_STATISTICS (statistics),




reply via email to

[Prev in Thread] Current Thread [Next in Thread]