aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Hemminger <stephen@networkplumber.org>2020-05-05 10:18:58 -0700
committerStephen Hemminger <stephen@networkplumber.org>2020-05-05 10:18:58 -0700
commit8142c76232324d13800b6cfd5b110cb6b134a491 (patch)
treef334209d3a08f77cccf40cea9270d47188e5f4c8
parente133fa9c73835f5b80236ae20eaba765f1bfe553 (diff)
downloadiproute2-8142c76232324d13800b6cfd5b110cb6b134a491.tar.gz
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>
-rw-r--r--misc/ss.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/misc/ss.c b/misc/ss.c
index ab206b201..75fde2312 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2378,16 +2378,23 @@ static int proc_inet_split_line(char *line, char **loc, char **rem, char **data)
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)
{
if (numeric)
sprintf(buf, "%.0f", bw);
+ else if (bw >= 1e12)
+ sprintf(buf, "%.3gT", bw / 1e12);
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);
+ sprintf(buf, "%.3gk", bw / 1e3);
else
sprintf(buf, "%g", bw);