Skip to contentSkip to conversation

devices: Fix processing /proc/net/dev file

PATCH In review Namhyung Kim 3 participants 5 messages Oct 15, 2012

lore
Share & tools
lore

Namhyung Kim

author
#0 lore raw

PATCH 1/1 devices: Fix processing /proc/net/dev file

The do_proc_net_dev() reads the /proc/net/dev file and counts tx/rx packets for each interface. However index for rx packet (1) is not match to the file:

$ cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
       (1)      (2)     (3)  (4)  (5)  (6)   (7)        (8)       (9)      (10)    (11) (12) (13) (14)  (15)    (16)

Change the index to 2 to match to the number of receive packets.

Signed-off-by Namhyung Kim <namhyung(a)gmail.com>
---
 src/devices/network.cpp |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/devices/network.cpp +1 -1
index b8a5c9c..3b67610 100644
@@ -114,7 +114,7 @@ static void do_proc_net_dev(void)
 			c2 = c;
 			val = strtoull(c, &c, 10);
 			i++;
-			if (i == 1 || i == 10)
+			if (i == 2 || i == 10)
 				pkt += val;
 
 		}
Signature · 1 line
1.7.9.2
#1 lore raw
Quoted 22 lines · Namhyung Kim

The do_proc_net_dev() reads the /proc/net/dev file and counts tx/rx packets for each interface. However index for rx packet (1) is not match to the file:

$ cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
       (1)      (2)     (3)  (4)  (5)  (6)   (7)        (8)       (9)      (10)    (11) (12) (13) (14)  (15)    (16)

Change the index to 2 to match to the number of receive packets.

Signed-off-by Namhyung Kim <namhyung(a)gmail.com>
---
 src/devices/network.cpp |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/devices/network.cpp +0 -0
index b8a5c9c..3b67610 100644

src/devices/network.cpp static void do_proc_net_dev(void) · line 120

Quoted 8 lines
src/devices/network.cpp +1 -1
@@ -114,7 +114,7 @@ static void do_proc_net_dev(void)
 			c2 = c;
 			val = strtoull(c, &c, 10);
 			i++;
-			if (i == 1 || i == 10)
+			if (i == 2 || i == 10)
 				pkt += val;
 
 		}

or i++' after if (i == 1 || i == 10)'.

the patch looks good to me, nice catch.

	-ss
author
#2 lore raw

2012-10-15 (월), 07:47 -0700, Sergey Senozhatsky:

Quoted 9 lines · Namhyung Kim
Quoted 8 lines
src/devices/network.cpp +1 -1
@@ -114,7 +114,7 @@ static void do_proc_net_dev(void)
 			c2 = c;
 			val = strtoull(c, &c, 10);
 			i++;
-			if (i == 1 || i == 10)
+			if (i == 2 || i == 10)
 				pkt += val;
 
Quoted 4 lines

Review static void do_proc_net_dev(void) · line 120

Quoted 2 lines
(quoted diff) +0 -0
 		}

or i++' after if (i == 1 || i == 10)'.

But if we moved i++', it should be if (i == 1 || i == 9)'.

Thanks,
Namhyung

#3 lore raw
Quoted 10 lines · Namhyung Kim

2012-10-15 (월), 07:47 -0700, Sergey Senozhatsky:

Quoted 9 lines · Namhyung Kim
Quoted 8 lines
src/devices/network.cpp +1 -1
@@ -114,7 +114,7 @@ static void do_proc_net_dev(void)
 			c2 = c;
 			val = strtoull(c, &c, 10);
 			i++;
-			if (i == 1 || i == 10)
+			if (i == 2 || i == 10)
 				pkt += val;
 
Quoted 7 lines
Quoted 4 lines

Review static void do_proc_net_dev(void) · line 120

Quoted 2 lines
(quoted diff) +0 -0
 		}

or i++' after if (i == 1 || i == 10)'.

But if we moved i++', it should be if (i == 1 || i == 9)'.

yeah, right :)

	-ss
#4 lore raw
In reply to Namhyung Kim
Quoted 21 lines · Namhyung Kim

The do_proc_net_dev() reads the /proc/net/dev file and counts tx/rx packets for each interface. However index for rx packet (1) is not match to the file:

$ cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
  face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
        (1)      (2)     (3)  (4)  (5)  (6)   (7)        (8)       (9)      (10)    (11) (12) (13) (14)  (15)    (16)

Change the index to 2 to match to the number of receive packets.

Signed-off-by Namhyung Kim <namhyung(a)gmail.com>
---
  src/devices/network.cpp |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
src/devices/network.cpp +0 -0
index b8a5c9c..3b67610 100644

src/devices/network.cpp static void do_proc_net_dev(void) · line 120

Quoted 8 lines
src/devices/network.cpp +1 -1
@@ -114,7 +114,7 @@ static void do_proc_net_dev(void)
  			c2 = c;
  			val = strtoull(c, &c, 10);
  			i++;
-			if (i == 1 || i == 10)
+			if (i == 2 || i == 10)
  				pkt += val;
 
  		}

Your patch has been merged
Thank You
-C