ss: update to bw print
Display kilobit with the standard suffix. Add comment to describe where data rate suffixes come from. Add support for terrabit. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
parent
e133fa9c73
commit
8142c76232
|
|
@ -2378,16 +2378,23 @@ static int proc_inet_split_line(char *line, char **loc, char **rem, char **data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Display bandwidth in standard units
|
||||||
|
* See: https://en.wikipedia.org/wiki/Data-rate_units
|
||||||
|
* bw is in bits per second
|
||||||
|
*/
|
||||||
static char *sprint_bw(char *buf, double bw)
|
static char *sprint_bw(char *buf, double bw)
|
||||||
{
|
{
|
||||||
if (numeric)
|
if (numeric)
|
||||||
sprintf(buf, "%.0f", bw);
|
sprintf(buf, "%.0f", bw);
|
||||||
|
else if (bw >= 1e12)
|
||||||
|
sprintf(buf, "%.3gT", bw / 1e12);
|
||||||
else if (bw >= 1e9)
|
else if (bw >= 1e9)
|
||||||
sprintf(buf, "%.3gG", bw / 1e9);
|
sprintf(buf, "%.3gG", bw / 1e9);
|
||||||
else if (bw >= 1e6)
|
else if (bw >= 1e6)
|
||||||
sprintf(buf, "%.3gM", bw / 1e6);
|
sprintf(buf, "%.3gM", bw / 1e6);
|
||||||
else if (bw >= 1e3)
|
else if (bw >= 1e3)
|
||||||
sprintf(buf, "%.3gK", bw / 1e3);
|
sprintf(buf, "%.3gk", bw / 1e3);
|
||||||
else
|
else
|
||||||
sprintf(buf, "%g", bw);
|
sprintf(buf, "%g", bw);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue