From: Vimalkumar <j.vimal@gmail.com>
To: netdev@vger.kernel.org, shemminger@vyatta.com, eric.dumazet@gmail.com
Cc: Vimalkumar <j.vimal@gmail.com>
Subject: [PATCH] print_rate: use knowledge in rate_suffix table for human readable rates.
Date: Sat, 9 Mar 2013 19:26:38 -0800 [thread overview]
Message-ID: <1362885998-14292-1-git-send-email-j.vimal@gmail.com> (raw)
Signed-off-by: Vimalkumar <j.vimal@gmail.com>
---
tc/tc_util.c | 26 ++++++++++++--------------
1 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/tc/tc_util.c b/tc/tc_util.c
index 0939536..6e68d87 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -139,7 +139,8 @@ static const struct rate_suffix {
{ "GBps", 8000000000. },
{ "TiBps", 8.*1024.*1024.*1024.*1024. },
{ "TBps", 8000000000000. },
- { NULL }
+ { NULL },
+ { NULL },
};
@@ -171,21 +172,18 @@ void print_rate(char *buf, int len, __u64 rate)
{
double tmp = (double)rate*8;
extern int use_iec;
+ int start = 0;
+ const struct rate_suffix *s;
if (use_iec) {
- if (tmp >= 1000.0*1024.0*1024.0)
- snprintf(buf, len, "%.0fMibit", tmp/(1024.0*1024.0));
- else if (tmp >= 1000.0*1024)
- snprintf(buf, len, "%.0fKibit", tmp/1024);
- else
- snprintf(buf, len, "%.0fbit", tmp);
- } else {
- if (tmp >= 1000.0*1000000.0)
- snprintf(buf, len, "%.0fMbit", tmp/1000000.0);
- else if (tmp >= 1000.0 * 1000.0)
- snprintf(buf, len, "%.0fKbit", tmp/1000.0);
- else
- snprintf(buf, len, "%.0fbit", tmp);
+ start = 1;
+ }
+
+ snprintf(buf, len, "%.0fbit", tmp);
+ for (s = &suffixes[start]; s->name; s += 2) {
+ if (tmp >= s->scale) {
+ snprintf(buf, len, "%.3f%s", tmp / s->scale, s->name);
+ }
}
}
--
1.7.5.3
next reply other threads:[~2013-03-10 3:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-10 3:26 Vimalkumar [this message]
2013-03-10 4:08 ` [PATCH] print_rate: use knowledge in rate_suffix table for human readable rates Eric Dumazet
2013-03-12 0:00 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1362885998-14292-1-git-send-email-j.vimal@gmail.com \
--to=j.vimal@gmail.com \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).