ss: add support for Gbit speeds in sprint_bw()
Subsystems (2)
PATCH 1/1 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 <[email protected]>
--- misc/ss.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
misc/ss.c +6 -4
@@ -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);
Signature · 1 line
2.26.2.526.g744177e7f7-goog
Stephen Hemminger
AppliedQuoted 10 lines · On Tue, 5 May 2020 08:37:41 -0700 Eric Dumazet <[email protected]> wrote:
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 55GbpsSigned-off-by Eric Dumazet <[email protected]>
Applied, and add terrabit as well.
It looks like tc and ss are not the same in suffix here.
https://en.wikipedia.org/wiki/Data-rate_units
kilobit per sec = kbit/sec or kb/s = kbps kilobyte per sec = kB/s
megabit per sec = Mbit/sec or Mb/s = Mbps
For now, lets get ss to follow the standard. That means "kbps" instead of "Kbps"