gnome-applets r11093 - trunk/multiload



Author: callum
Date: Tue Nov  4 10:02:50 2008
New Revision: 11093
URL: http://svn.gnome.org/viewvc/gnome-applets?rev=11093&view=rev

Log:
Change the netload categories from slip/plip/ethernet/other to in/out/local. See bug 327509.

Modified:
   trunk/multiload/ChangeLog
   trunk/multiload/linux-proc.c
   trunk/multiload/linux-proc.h
   trunk/multiload/main.c
   trunk/multiload/multiload.schemas.in
   trunk/multiload/properties.c

Modified: trunk/multiload/linux-proc.c
==============================================================================
--- trunk/multiload/linux-proc.c	(original)
+++ trunk/multiload/linux-proc.c	Tue Nov  4 10:02:50 2008
@@ -271,17 +271,48 @@
     data [1] = Maximum - data[0];
 }
 
+/*
+ * Return true if a network device (identified by its name) is virtual
+ * (ie: not corresponding to a physical device). In case it is a physical
+ * device or unknown, returns false.
+ */
+static gboolean
+is_net_device_virtual(char *device)
+{
+    /*
+     * There is not definitive way to find out. On some systems (Linux
+     * kernels â 2.19 without option SYSFS_DEPRECATED), there exist a
+     * directory /sys/devices/virtual/net which only contains virtual
+     * devices.  It's also possible to detect by the fact that virtual
+     * devices do not have a symlink "device" in
+     * /sys/class/net/name-of-dev/ .  This second method is more complex
+     * but more reliable.
+     */
+    char path[PATH_MAX];
+
+    /* Check if /sys/class/net/name-of-dev/ exists (may be old linux kernel
+     * or not linux at all). */
+    if (sprintf(path, "/sys/class/net/%s", device) < 0)
+        return FALSE;
+    if (access(path, F_OK) != 0)
+        return FALSE; /* unknown */
+
+    if (sprintf(path, "/sys/class/net/%s/device", device) < 0)
+        return FALSE;
+    if (access(path, F_OK) != 0)
+        return TRUE;
 
+    return FALSE;
+}
 
 void
-GetNet (int Maximum, int data [5], LoadGraph *g)
+GetNet (int Maximum, int data [4], LoadGraph *g)
 {
     enum Types {
-	SLIP_COUNT  = 0,
-	PPP_COUNT   = 1,
-	ETH_COUNT   = 2,
-	OTHER_COUNT = 3,
-	COUNT_TYPES = 4
+	IN_COUNT = 0,
+	OUT_COUNT = 1,
+	LOCAL_COUNT = 2,
+	COUNT_TYPES = 3
 	};
 
     static int ticks = 0;
@@ -315,22 +346,21 @@
 	if (!(netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP)))
 	    continue;
 
-	if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK))
+	if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK)) {
+	    /* for loopback in and out are identical, so only count in */
+	    present[LOCAL_COUNT] += netload.bytes_in;
 	    continue;
-
-	if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_POINTOPOINT))
-	{
-	    if (g_str_has_prefix(devices[i], "sl"))
-		index = SLIP_COUNT;
-	    else
-		index = PPP_COUNT;
 	}
-	else if (g_str_has_prefix(devices[i], "eth"))
-	    index = ETH_COUNT;
-	else
-	    index = OTHER_COUNT;
 
-	present[index] += netload.bytes_total;
+	/*
+	 * Do not include virtual devices (VPN, PPPOE...) to avoid
+	 * counting the same throughput several times.
+	 */
+	if (is_net_device_virtual(devices[i]))
+		continue;
+
+	present[IN_COUNT] += netload.bytes_in;
+	present[OUT_COUNT] += netload.bytes_out;
     }
 
     g_strfreev(devices);
@@ -361,17 +391,12 @@
 
 	for (i = 0; i < COUNT_TYPES; i++)
 	    data[i]   = rint (Maximum * (float)delta[i]  / max);
-
-#if 0
-	printf("dSLIP: %9d  dPPP: %9d   dOther: %9d, max: %9d\n",
-	       delta[SLIP_COUNT], delta[PPP_COUNT], delta[OTHER_COUNT], max);
-
-	printf("vSLIP: %9d  vPPP: %9d   vOther: %9d, Maximum: %9d\n",
-	       data[0], data[1], data[2], Maximum);
-#endif
     }
 
-    data[4] = Maximum - data[3] - data[2] - data[1] - data[0];
+    //data[4] = Maximum - data[3] - data[2] - data[1] - data[0];
+    data[COUNT_TYPES] = Maximum;
+    for (i = 0; i < COUNT_TYPES; i++)
+	data[COUNT_TYPES] -= data[i];
 
     memcpy(past, present, sizeof past);
 }

Modified: trunk/multiload/linux-proc.h
==============================================================================
--- trunk/multiload/linux-proc.h	(original)
+++ trunk/multiload/linux-proc.h	Tue Nov  4 10:02:50 2008
@@ -11,6 +11,6 @@
 G_GNUC_INTERNAL void GetMemory (int Maximum, int data [4], LoadGraph *g);
 G_GNUC_INTERNAL void GetSwap (int Maximum, int data [2], LoadGraph *g);
 G_GNUC_INTERNAL void GetLoadAvg (int Maximum, int data [2], LoadGraph *g);
-G_GNUC_INTERNAL void GetNet (int Maximum, int data [3], LoadGraph *g);
+G_GNUC_INTERNAL void GetNet (int Maximum, int data [4], LoadGraph *g);
 
 #endif

Modified: trunk/multiload/main.c
==============================================================================
--- trunk/multiload/main.c	(original)
+++ trunk/multiload/main.c	Tue Nov  4 10:02:50 2008
@@ -289,7 +289,7 @@
 		name = g_strdup(_("Processor"));
 	else if (!strncmp(g->name, "memload", strlen("memload")))
 		name = g_strdup(_("Memory"));
-	else if (!strncmp(g->name, "netload", strlen("netload")))
+	else if (!strncmp(g->name, "netload2", strlen("netload2")))
 		name = g_strdup(_("Network"));
 	else if (!strncmp(g->name, "swapload", strlen("swapload")))
 		name = g_strdup(_("Swap Space"));
@@ -363,7 +363,7 @@
 	       } graph_types[] = {
 			{ _("CPU Load"),     "cpuload",  5, GetLoad },
 			{ _("Memory Load"),  "memload",  5, GetMemory },
-			{ _("Net Load"),     "netload",  5, GetNet },
+			{ _("Net Load"),     "netload2",  4, GetNet },
 			{ _("Swap Load"),    "swapload", 2, GetSwap },
 			{ _("Load Average"), "loadavg",  2, GetLoadAvg },
 			{ _("Disk Load"),    "diskload", 3, GetDiskLoad }
@@ -382,7 +382,14 @@
 		gboolean visible;
 		char *key;
 
-		key = g_strdup_printf ("view_%s", graph_types[i].name);
+		/* This is a special case to handle migration from an
+		 * older version of netload to a newer one in the
+		 * 2.25.1 release. */
+		if (g_strcmp0 ("netload2", graph_types[i].name) == 0) {
+		  key = g_strdup ("view_netload");
+		} else {
+		  key = g_strdup_printf ("view_%s", graph_types[i].name);
+		}
 		visible = panel_applet_gconf_get_bool (ma->applet, key, NULL);
 		g_free (key);
 

Modified: trunk/multiload/multiload.schemas.in
==============================================================================
--- trunk/multiload/multiload.schemas.in	(original)
+++ trunk/multiload/multiload.schemas.in	Tue Nov  4 10:02:50 2008
@@ -169,43 +169,34 @@
 </schema>
 
 <schema>
-	<key>/schemas/apps/multiload/prefs/netload_color0</key>
+	<key>/schemas/apps/multiload/prefs/netload2_color0</key>
 	<owner>multiload-applet-2</owner>
 	<type>string</type>
-	<default>#00b0b3</default>
+	<default>#fce94f</default>
 	<locale name="C">
-		<short>Graph color for SLIP network activity</short>
+		<short>Graph color for input network activity</short>
 	</locale>
 </schema>
 <schema>
-	<key>/schemas/apps/multiload/prefs/netload_color1</key>
+	<key>/schemas/apps/multiload/prefs/netload2_color1</key>
 	<owner>multiload-applet-2</owner>
 	<type>string</type>
-	<default>#00e2e6</default>
+	<default>#edd400</default>
 	<locale name="C">
-		<short>Graph color for PLIP network activity</short>
+		<short>Graph color for output network activity</short>
 	</locale>
 </schema>
 <schema>
-	<key>/schemas/apps/multiload/prefs/netload_color2</key>
+	<key>/schemas/apps/multiload/prefs/netload2_color2</key>
 	<owner>multiload-applet-2</owner>
 	<type>string</type>
-	<default>#00fbff</default>
+	<default>#c4a000</default>
 	<locale name="C">
-		<short>Graph color for Ethernet network activity</short>
+		<short>Graph color for loopback network usage</short>
 	</locale>
 </schema>
 <schema>
-	<key>/schemas/apps/multiload/prefs/netload_color3</key>
-	<owner>multiload-applet-2</owner>
-	<type>string</type>
-	<default>#B7FEFF</default>
-	<locale name="C">
-		<short>Graph color for other network usage</short>
-	</locale>
-</schema>
-<schema>
-	<key>/schemas/apps/multiload/prefs/netload_color4</key>
+	<key>/schemas/apps/multiload/prefs/netload2_color3</key>
 	<owner>multiload-applet-2</owner>
 	<type>string</type>
 	<default>#000000</default>

Modified: trunk/multiload/properties.c
==============================================================================
--- trunk/multiload/properties.c	(original)
+++ trunk/multiload/properties.c	Tue Nov  4 10:02:50 2008
@@ -262,7 +262,7 @@
 		prop_type = PROP_CPU;
 	else if (strstr(gconf_path, "memload"))
 		prop_type = PROP_MEM;
-	else if (strstr(gconf_path, "netload"))
+	else if (strstr(gconf_path, "netload2"))
 		prop_type = PROP_NET;
 	else if (strstr(gconf_path, "swapload"))
 		prop_type = PROP_SWAP;
@@ -622,11 +622,10 @@
 	
 	page = add_page(ma->notebook,  _("Network"));
 	gtk_container_set_border_width (GTK_CONTAINER (page), 12);
-	add_color_selector (page, _("_SLIP"), "netload_color0", ma);
-	add_color_selector(page, _("PL_IP"), "netload_color1", ma);
-	add_color_selector (page, _("_Ethernet"), "netload_color2", ma);
-	add_color_selector (page, _("Othe_r"), "netload_color3", ma);
-	add_color_selector(page, _("_Background"), "netload_color4", ma);
+	add_color_selector (page, _("_In"), "netload2_color0", ma);
+	add_color_selector(page, _("_Out"), "netload2_color1", ma);
+	add_color_selector (page, _("_Local"), "netload2_color2", ma);
+	add_color_selector(page, _("_Background"), "netload2_color3", ma);
 	
 	page = add_page(ma->notebook,  _("Swap Space"));
 	gtk_container_set_border_width (GTK_CONTAINER (page), 12);



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