From: Eric Dumazet Date: Tue, 5 May 2020 15:37:41 +0000 (-0700) Subject: ss: add support for Gbit speeds in sprint_bw() X-Git-Tag: v5.7.0~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e133fa9c73835f5b80236ae20eaba765f1bfe553;p=thirdparty%2Fiproute2.git 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 Signed-off-by: Stephen Hemminger --- 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);