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>
This commit is contained in:
Eric Dumazet 2020-05-05 08:37:41 -07:00 committed by Stephen Hemminger
parent 0501fe734f
commit e133fa9c73
1 changed files with 6 additions and 4 deletions

View File

@ -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);