Skip to contentSkip to conversation

ip-link: allow human readable output with base of 1024 only for byte counts

PATCH In review Christian Hesse 2 participants 3 messages Mar 26, 2015 – Mar 30, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip-link: allow human readable output with base of 1024 only for byte counts

From: Christian Hesse <[email protected]>

Counting bytes with a base of 1024 is ok. Counting packets, errors, etc that way makes no sense.
So only print byte counts with a base of 1024 if option -iec is given.

---
 ip/ipaddress.c | 98 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 49 insertions(+), 49 deletions(-)
ip/ipaddress.c +49 -49
index 99a6ab5..016ce60 100644
@@ -361,7 +361,7 @@ static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
 	}
 }
 
-static void print_num(FILE *fp, unsigned width, uint64_t count)
+static void print_num(FILE *fp, unsigned width, uint64_t count, int use_iec)
 {
 	const char *prefix = "kMGTPE";
 	const unsigned int base = use_iec ? 1024 : 1000;
@@ -408,14 +408,14 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
 		s->rx_compressed ? "compressed" : "", _SL_);
 
 	fprintf(fp, "    ");
-	print_num(fp, 10, s->rx_bytes);
-	print_num(fp, 8, s->rx_packets);
-	print_num(fp, 7, s->rx_errors);
-	print_num(fp, 7, s->rx_dropped);
-	print_num(fp, 7, s->rx_over_errors);
-	print_num(fp, 7, s->multicast);
+	print_num(fp, 10, s->rx_bytes, use_iec);
+	print_num(fp, 8, s->rx_packets, 0);
+	print_num(fp, 7, s->rx_errors, 0);
+	print_num(fp, 7, s->rx_dropped, 0);
+	print_num(fp, 7, s->rx_over_errors,0 );
+	print_num(fp, 7, s->multicast, 0);
 	if (s->rx_compressed)
-		print_num(fp, 7, s->rx_compressed);
+		print_num(fp, 7, s->rx_compressed, 0);
 
 	/* RX error stats */
 	if (show_stats > 1) {
@@ -423,11 +423,11 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
 		fprintf(fp, "    RX errors: length   crc     frame   fifo    missed%s", _SL_);
 
 		fprintf(fp, "               ");
-		print_num(fp, 8, s->rx_length_errors);
-		print_num(fp, 7, s->rx_crc_errors);
-		print_num(fp, 7, s->rx_frame_errors);
-		print_num(fp, 7, s->rx_fifo_errors);
-		print_num(fp, 7, s->rx_missed_errors);
+		print_num(fp, 8, s->rx_length_errors, 0);
+		print_num(fp, 7, s->rx_crc_errors, 0);
+		print_num(fp, 7, s->rx_frame_errors, 0);
+		print_num(fp, 7, s->rx_fifo_errors, 0);
+		print_num(fp, 7, s->rx_missed_errors, 0);
 	}
 	fprintf(fp, "%s", _SL_);
 
@@ -437,14 +437,14 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
 
 
 	fprintf(fp, "    ");
-	print_num(fp, 10, s->tx_bytes);
-	print_num(fp, 8, s->tx_packets);
-	print_num(fp, 7, s->tx_errors);
-	print_num(fp, 7, s->tx_dropped);
-	print_num(fp, 7, s->tx_carrier_errors);
-	print_num(fp, 7, s->collisions);
+	print_num(fp, 10, s->tx_bytes, use_iec);
+	print_num(fp, 8, s->tx_packets, 0);
+	print_num(fp, 7, s->tx_errors, 0);
+	print_num(fp, 7, s->tx_dropped, 0);
+	print_num(fp, 7, s->tx_carrier_errors, 0);
+	print_num(fp, 7, s->collisions, 0);
 	if (s->tx_compressed)
-		print_num(fp, 7, s->tx_compressed);
+		print_num(fp, 7, s->tx_compressed, 0);
 
 	/* TX error stats */
 	if (show_stats > 1) {
@@ -455,12 +455,12 @@ static void print_link_stats64(FILE *fp, const struct rtnl_link_stats64 *s,
 		fprintf(fp, "%s", _SL_);
 
 		fprintf(fp, "               ");
-		print_num(fp, 8, s->tx_aborted_errors);
-		print_num(fp, 7, s->tx_fifo_errors);
-		print_num(fp, 7, s->tx_window_errors);
-		print_num(fp, 7, s->tx_heartbeat_errors);
+		print_num(fp, 8, s->tx_aborted_errors, 0);
+		print_num(fp, 7, s->tx_fifo_errors, 0);
+		print_num(fp, 7, s->tx_window_errors, 0);
+		print_num(fp, 7, s->tx_heartbeat_errors, 0);
 		if (carrier_changes)
-			print_num(fp, 7, *(uint32_t*)RTA_DATA(carrier_changes));
+			print_num(fp, 7, *(uint32_t*)RTA_DATA(carrier_changes), 0);
 	}
 }
 
@@ -473,25 +473,25 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s,
 
 
 	fprintf(fp, "    ");
-	print_num(fp, 10, s->rx_bytes);
-	print_num(fp, 8, s->rx_packets);
-	print_num(fp, 7, s->rx_errors);
-	print_num(fp, 7, s->rx_dropped);
-	print_num(fp, 7, s->rx_over_errors);
-	print_num(fp, 7, s->multicast);
+	print_num(fp, 10, s->rx_bytes, use_iec);
+	print_num(fp, 8, s->rx_packets, 0);
+	print_num(fp, 7, s->rx_errors, 0);
+	print_num(fp, 7, s->rx_dropped, 0);
+	print_num(fp, 7, s->rx_over_errors, 0);
+	print_num(fp, 7, s->multicast, 0);
 	if (s->rx_compressed)
-		print_num(fp, 7, s->rx_compressed);
+		print_num(fp, 7, s->rx_compressed, 0);
 
 	/* RX error stats */
 	if (show_stats > 1) {
 		fprintf(fp, "%s", _SL_);
 		fprintf(fp, "    RX errors: length   crc     frame   fifo    missed%s", _SL_);
 		fprintf(fp, "               ");
-		print_num(fp, 8, s->rx_length_errors);
-		print_num(fp, 7, s->rx_crc_errors);
-		print_num(fp, 7, s->rx_frame_errors);
-		print_num(fp, 7, s->rx_fifo_errors);
-		print_num(fp, 7, s->rx_missed_errors);
+		print_num(fp, 8, s->rx_length_errors, 0);
+		print_num(fp, 7, s->rx_crc_errors, 0);
+		print_num(fp, 7, s->rx_frame_errors, 0);
+		print_num(fp, 7, s->rx_fifo_errors, 0);
+		print_num(fp, 7, s->rx_missed_errors, 0);
 	}
 	fprintf(fp, "%s", _SL_);
 
@@ -500,14 +500,14 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s,
 		s->tx_compressed ? "compressed" : "", _SL_);
 
 	fprintf(fp, "    ");
-	print_num(fp, 10, s->tx_bytes);
-	print_num(fp, 8, s->tx_packets);
-	print_num(fp, 7, s->tx_errors);
-	print_num(fp, 7, s->tx_dropped);
-	print_num(fp, 7, s->tx_carrier_errors);
-	print_num(fp, 7, s->collisions);
+	print_num(fp, 10, s->tx_bytes, use_iec);
+	print_num(fp, 8, s->tx_packets, 0);
+	print_num(fp, 7, s->tx_errors, 0);
+	print_num(fp, 7, s->tx_dropped, 0);
+	print_num(fp, 7, s->tx_carrier_errors, 0);
+	print_num(fp, 7, s->collisions, 0);
 	if (s->tx_compressed)
-		print_num(fp, 7, s->tx_compressed);
+		print_num(fp, 7, s->tx_compressed, 0);
 
 	/* TX error stats */
 	if (show_stats > 1) {
@@ -518,12 +518,12 @@ static void print_link_stats32(FILE *fp, const struct rtnl_link_stats *s,
 		fprintf(fp, "%s", _SL_);
 
 		fprintf(fp, "               ");
-		print_num(fp, 8, s->tx_aborted_errors);
-		print_num(fp, 7, s->tx_fifo_errors);
-		print_num(fp, 7, s->tx_window_errors);
-		print_num(fp, 7, s->tx_heartbeat_errors);
+		print_num(fp, 8, s->tx_aborted_errors, 0);
+		print_num(fp, 7, s->tx_fifo_errors, 0);
+		print_num(fp, 7, s->tx_window_errors, 0);
+		print_num(fp, 7, s->tx_heartbeat_errors, 0);
 		if (carrier_changes)
-			print_num(fp, 7, *(uint32_t*)RTA_DATA(carrier_changes));
+			print_num(fp, 7, *(uint32_t*)RTA_DATA(carrier_changes), 0);
 	}
 }
 
Signature · 1 line
2.3.4
#1 lore raw
Quoted 7 lines · On Thu, 26 Mar 2015 12:24:08 +0100 Christian Hesse <[email protected]> wrote:

From: Christian Hesse <[email protected]>

Counting bytes with a base of 1024 is ok. Counting packets, errors, etc that way makes no sense.
So only print byte counts with a base of 1024 if option -iec is given.

This changes the output which users expect, especially the packet counts should follow existing practice. And I doubt anyone would have 1024 errors.

#2 lore raw

Stephen Hemminger <[email protected]> on Sun, 2015/03/29 22:58:

Quoted 5 lines
Quoted 2 lines · On Thu, 26 Mar 2015 12:24:08 +0100 Christian Hesse <[email protected]> wrote:

From: Christian Hesse <[email protected]>

Quoted 8 lines
Quoted 5 lines

Counting bytes with a base of 1024 is ok. Counting packets, errors, etc that way makes no sense.
So only print byte counts with a base of 1024 if option -iec is given.

This changes the output which users expect, especially the packet counts should follow existing practice. And I doubt anyone would have 1024 errors.

With current code you can give -iec and everything (including errors) is printed with IEC units. This patch changes it to only print byte counts with IEC units, so error will be displayed with a base of 1000 always.

I think my patch changes things to what user expects, no?

Signature · 3 lines
main(a){char*c=/*    Schoene Gruesse                         */"B?IJj;MEH"
"CX:;",b;for(a/*    Chris           get my mail address:    */=0;b=c[a++];)
putchar(b-1/(/*               gcc -o sig sig.c && ./sig    */b/42*2-3)*42);}