! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
[PATCH] Units shown on tooltip are wrong
Status:
CLOSED: FIXED
Product:
Xfce4-netload-plugin
Component:
General

Comments

Description Miguel Guedes 2012-07-05 22:39:44 CEST
This patch fixes the units shown on the tooltip when placing the mouse over the netload panel icon. Also removes '/s' (per second) label as it's not correct - values shown represent current sample and not average per second.

 * Using latest git version, units shown are: nnn KiB kBytes/s

 * After patch, units shown are: nnn KiB

 * Also cleaned up code a little in this particular function (update_monitors) but no major changes introduced.
Comment 1 Mike Massonnet editbugs 2012-07-10 15:55:49 CEST
Hi Miguel,

The patch is not attached :)

Regards,
Mike
Comment 2 Mike Massonnet editbugs 2012-07-10 16:02:09 CEST
(In reply to comment #0)
> Also removes '/s' (per second) label

It's a snapshot of the last exchanged bytes minus delta, and that each second, so it actually corresponds to a trafic per second. There is nothing incorrect here.

An interface always reports the total amount of exchanged data since it's up, it never reports values in bits per seconds. It would be incorrect if the snapshot is taken for the last > 1 seconds (2 seconds, 4, 10, etc).

Regards,
Mike
Comment 3 Miguel Guedes 2012-07-10 20:41:39 CEST
(In reply to comment #2)
> > Also removes '/s' (per second) label
> 
> It's a snapshot of the last exchanged bytes minus delta, and that each
> second, so it actually corresponds to a trafic per second. There is nothing
> incorrect here.
> 
> An interface always reports the total amount of exchanged data since it's
> up, it never reports values in bits per seconds. It would be incorrect if
> the snapshot is taken for the last > 1 seconds (2 seconds, 4, 10, etc).

I forget now the exact details but I believe this is the reason why I removed the '/s' bit. If one changes the sample time (default 0.25, 4 times per second), the resulting calculations are wrong since I believe the divider is hardcoded (it's 4 if memory serves me right.) 

Also, screenshot of the tooltip: (notice the units)

http://en.zimagez.com/zimage/netloadtooltip.php
Comment 4 Miguel Guedes 2012-07-10 20:44:36 CEST
(In reply to comment #1)
> Hi Miguel,
> 
> The patch is not attached :)

Oops! Apologies. :)

Bugzilla won't let me attach the patch, so pasting it here.

-----


diff --git a/panel-plugin/netload.c b/panel-plugin/netload.c
index cad0021..b5830aa 100644
--- a/panel-plugin/netload.c
+++ b/panel-plugin/netload.c
@@ -161,8 +161,6 @@ static gboolean update_monitors(t_global_monitor *global)
     gchar sent[BUFSIZ];
     gulong net[SUM+1];
     gulong display[SUM+1], max;
-    guint64 histcalculate;
-    double temp;
     gint i, j;
 
     if (!get_interface_up(&(global->monitor->data)))
@@ -175,43 +173,39 @@ static gboolean update_monitors(t_global_monitor *global)
         return TRUE;
     }
 
-    get_current_netload( &(global->monitor->data), &(net[IN]), &(net[OUT]), &(net[TOT]) );
+    get_current_netload( &(global->monitor->data),
+                         &(net[IN]),
+                         &(net[OUT]),
+                         &(net[TOT]) );
     
 
     for (i = 0; i < SUM; i++)
     {
+        guint64 histcalculate = 0;
+        
         /* correct value to be from 1 ... 100 */
         global->monitor->history[i][0] = net[i];
 
         if (global->monitor->history[i][0] < 0)
-        {
             global->monitor->history[i][0] = 0;
-        }
 
-        histcalculate = 0;
         for( j = 0; j < HISTSIZE_CALCULATE; j++ )
-        {
             histcalculate += global->monitor->history[i][j];
-        }
+
         display[i] = histcalculate / HISTSIZE_CALCULATE;
         
         /* shift for next run */
         for( j = HISTSIZE_STORE - 1; j > 0; j-- )
-        {
             global->monitor->history[i][j] = global->monitor->history[i][j-1];
-        }
         
         /* update maximum */
-        if( global->monitor->options.auto_max )
-        {
+        if( global->monitor->options.auto_max ) {
             max = max_array( global->monitor->history[i], HISTSIZE_STORE );
+            
             if( display[i] > global->monitor->net_max[i] )
-            {
                 global->monitor->net_max[i] = display[i];
-            }
-            else if( max < global->monitor->net_max[i] * SHRINK_MAX 
-                    && global->monitor->net_max[i] * SHRINK_MAX >= MINIMAL_MAX )
-            {
+            else if( max < global->monitor->net_max[i] * SHRINK_MAX &&
+                     global->monitor->net_max[i] * SHRINK_MAX >= MINIMAL_MAX ) {
                 global->monitor->net_max[i] *= SHRINK_MAX;
             }
         }
@@ -233,42 +227,47 @@ static gboolean update_monitors(t_global_monitor *global)
         }
 #endif /* DEBUG */
         
-        temp = (double)display[i] / global->monitor->net_max[i];
-        if (temp > 1)
-        {
-            temp = 1.0;
-        }
-        else if (temp < 0)
-        {
-            temp = 0.0;
+        if (global->monitor->options.show_bars) {
+            double normalized_value = (double)display[i] / global->monitor->net_max[i];
+            
+            if (normalized_value > 1)
+                normalized_value = 1.0;
+            else if (normalized_value < 0)
+                normalized_value = 0.0;
+
+            gtk_progress_bar_set_fraction(
+                GTK_PROGRESS_BAR(global->monitor->status[i]),
+                normalized_value);
         }
-
-        if (global->monitor->options.show_bars)
-            gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(global->monitor->status[i]), temp);
-
+        
         format_byte_humanreadable( buffer[i], BUFSIZ, display[i], 2 );
-        format_byte_humanreadable( buffer_panel[i], BUFSIZ, display[i], 0 );
+
+        if(global->monitor->options.show_values)
+            format_byte_humanreadable( buffer_panel[i], BUFSIZ, display[i], 0 );
     }
     
     format_byte_humanreadable( buffer[TOT], BUFSIZ, (display[IN]+display[OUT]), 2 );
-    
-    {
-        char* ip = get_ip_address(&(global->monitor->data));
-        g_snprintf(caption, sizeof(caption), 
-                _("<< %s >> (%s)\nAverage of last %d measures:\n"
-                    "Incoming: %s/s\nOutgoing: %s/s\nTotal: %s/s"),
-                    get_name(&(global->monitor->data)), ip ? ip : _("no IP address"),
-                    HISTSIZE_CALCULATE, buffer[IN], buffer[OUT], buffer[TOT]);
-        gtk_label_set_text(GTK_LABEL(global->tooltip_text), caption);
 
-        if (global->monitor->options.show_values)
-        {
-            g_snprintf(received, sizeof(received), "%s", buffer_panel[IN]);
-            gtk_label_set_text(GTK_LABEL(global->monitor->rcv_label), received);
+    char* ip = get_ip_address(&(global->monitor->data));
+    g_snprintf(caption, sizeof(caption), 
+               _("<< %s >> (%s)\nAverage of last %d measures:\n"
+                 "Incoming: %s\nOutgoing: %s\nTotal: %s"),
+               get_name(&(global->monitor->data)),
+               ip ? ip : _("no IP address"),
+               HISTSIZE_CALCULATE,
+               buffer[IN],
+               buffer[OUT],
+               buffer[TOT]);
 
-            g_snprintf(sent, sizeof(sent), "%s", buffer_panel[OUT]);
-            gtk_label_set_text(GTK_LABEL(global->monitor->sent_label), sent);
-        }
+    gtk_label_set_text(GTK_LABEL(global->tooltip_text), caption);
+
+    if (global->monitor->options.show_values)
+    {
+        g_snprintf(received, sizeof(received), "%s", buffer_panel[IN]);
+        gtk_label_set_text(GTK_LABEL(global->monitor->rcv_label), received);
+
+        g_snprintf(sent, sizeof(sent), "%s", buffer_panel[OUT]);
+        gtk_label_set_text(GTK_LABEL(global->monitor->sent_label), sent);
     }
 
     return TRUE;
Comment 5 Mike Massonnet editbugs 2012-07-10 20:54:36 CEST
(In reply to comment #3)
> (In reply to comment #2)
> > > Also removes '/s' (per second) label
> > 
> > It's a snapshot of the last exchanged bytes minus delta, and that each
> > second, so it actually corresponds to a trafic per second. There is nothing
> > incorrect here.
> > 
> > An interface always reports the total amount of exchanged data since it's
> > up, it never reports values in bits per seconds. It would be incorrect if
> > the snapshot is taken for the last > 1 seconds (2 seconds, 4, 10, etc).
> 
> I forget now the exact details but I believe this is the reason why I
> removed the '/s' bit. If one changes the sample time (default 0.25, 4 times
> per second), the resulting calculations are wrong since I believe the
> divider is hardcoded (it's 4 if memory serves me right.) 
> 
> Also, screenshot of the tooltip: (notice the units)
> 
> http://en.zimagez.com/zimage/netloadtooltip.php

Right, it can be different than bits per second, the change will be included. Although the default is to display bits per second (last 4 snapshots with each snapshot taken at an interval of 0.25s makes a second).

Regards,
Mike
Comment 6 Mike Massonnet editbugs 2012-07-14 19:53:21 CEST
Hi Miguel,

Fixed in git, but only the part where per second appeared, and the tooltip include a mention about the interval (0.25s for example).

http://git.xfce.org/panel-plugins/xfce4-netload-plugin/commit/?id=0e7c2b2b11dfcee5c2c34796b7ce5a04eea2dc9c

Thank you for your report.

Regards,
Mike

Bug #9089

Reported by:
Miguel Guedes
Reported on: 2012-07-05
Last modified on: 2012-07-15

People

Assignee:
Mike Massonnet
CC List:
1 user

Version

Attachments

Additional information