From e133fa9c73835f5b80236ae20eaba765f1bfe553 Mon Sep 17 00:00:00 2001 From: Eric Dumazet Date: Tue, 5 May 2020 08:37:41 -0700 Subject: [PATCH] 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 --- misc/ss.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/misc/ss.c b/misc/ss.c index 3ef151fb..ab206b20 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);