aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2020-05-05 08:37:41 -0700
committerStephen Hemminger <stephen@networkplumber.org>2020-05-05 09:50:22 -0700
commite133fa9c73835f5b80236ae20eaba765f1bfe553 (patch)
tree06ab66810032e0590bc3f6a76a33168b60657909
parent0501fe734fd75ed93b3417266127bfc37b07459b (diff)
downloadiproute2-e133fa9c73835f5b80236ae20eaba765f1bfe553.tar.gz
ss: add support for Gbit speeds in sprint_bw()
Also use 'g' specifier instead of 'f' to remove trailing zeros, and increase precision. Examples of output : Before After 8.0Kbps 8Kbps 9.9Mbps 9.92Mbps 55001Mbps 55Gbps Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r--misc/ss.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/misc/ss.c b/misc/ss.c
index 3ef151fbf..ab206b201 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2382,10 +2382,12 @@ static char *sprint_bw(char *buf, double bw)
{
if (numeric)
sprintf(buf, "%.0f", bw);
- else if (bw > 1000000.)
- sprintf(buf, "%.1fM", bw / 1000000.);
- else if (bw > 1000.)
- sprintf(buf, "%.1fK", bw / 1000.);
+ else if (bw >= 1e9)
+ sprintf(buf, "%.3gG", bw / 1e9);
+ else if (bw >= 1e6)
+ sprintf(buf, "%.3gM", bw / 1e6);
+ else if (bw >= 1e3)
+ sprintf(buf, "%.3gK", bw / 1e3);
else
sprintf(buf, "%g", bw);