[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180710210558.20278-28-stephen@networkplumber.org>
Date: Tue, 10 Jul 2018 14:05:54 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <sthemmin@...rosoft.com>,
Stephen Hemminger <stephen@...workplumber.org>
Subject: [PATCH v2 iproute2-next 27/31] tc/cbq: convert to JSON output
From: Stephen Hemminger <sthemmin@...rosoft.com>
Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
tc/q_cbq.c | 73 ++++++++++++++++++++++++++++++------------------------
1 file changed, 40 insertions(+), 33 deletions(-)
diff --git a/tc/q_cbq.c b/tc/q_cbq.c
index ad0170c41858..525a5823b808 100644
--- a/tc/q_cbq.c
+++ b/tc/q_cbq.c
@@ -453,9 +453,6 @@ static int cbq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
struct tc_cbq_ovl *ovl = NULL;
unsigned int linklayer;
- SPRINT_BUF(b1);
- SPRINT_BUF(b2);
-
if (opt == NULL)
return 0;
@@ -495,76 +492,84 @@ static int cbq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
}
if (r) {
+ print_rate("rate", "rate %s ", r->rate);
- fprintf(f, "rate %s ",
- sprint_rate(r->rate, b1));
linklayer = (r->linklayer & TC_LINKLAYER_MASK);
if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
- fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2));
+ print_linklayer("linklayer", "linklayer %s ", linklayer);
+
if (show_details) {
- fprintf(f, "cell %ub ", 1<<r->cell_log);
+ print_uint(PRINT_ANY, "cell", "cell %ub ", 1<<r->cell_log);
if (r->mpu)
- fprintf(f, "mpu %ub ", r->mpu);
+ print_uint(PRINT_ANY, "mpu", "mpu %ub ", r->mpu);
if (r->overhead)
- fprintf(f, "overhead %ub ", r->overhead);
+ print_uint(PRINT_ANY, "overhead",
+ "overhead %ub ", r->overhead);
}
}
+
if (lss && lss->flags) {
int comma = 0;
- fprintf(f, "(");
+ print_string(PRINT_FP, NULL, "(", NULL);
if (lss->flags&TCF_CBQ_LSS_BOUNDED) {
- fprintf(f, "bounded");
+ print_null(PRINT_ANY, "bounded", "bounded", NULL);
comma = 1;
}
if (lss->flags&TCF_CBQ_LSS_ISOLATED) {
if (comma)
- fprintf(f, ",");
- fprintf(f, "isolated");
+ print_string(PRINT_FP, NULL, ",", NULL);
+ print_null(PRINT_ANY, "isolated", "isolated", NULL);
}
- fprintf(f, ") ");
+ print_string(PRINT_FP, NULL, ") ", NULL);
}
+
if (wrr) {
if (wrr->priority != TC_CBQ_MAXPRIO)
- fprintf(f, "prio %u", wrr->priority);
+ print_uint(PRINT_ANY, "prio", "prio %u", wrr->priority);
else
- fprintf(f, "prio no-transmit");
+ print_null(PRINT_ANY, "no-transmit", "prio no-transmit", NULL);
if (show_details) {
- fprintf(f, "/%u ", wrr->cpriority);
+ print_uint(PRINT_ANY, "cpriority", "/%u ", wrr->cpriority);
if (wrr->weight != 1)
- fprintf(f, "weight %s ",
- sprint_rate(wrr->weight, b1));
+ print_rate("weight", "weight %s ", wrr->weight);
if (wrr->allot)
- fprintf(f, "allot %ub ", wrr->allot);
+ print_uint(PRINT_ANY, "allot", "allot %ub ", wrr->allot);
}
}
+
if (lss && show_details) {
- fprintf(f, "\nlevel %u ewma %u avpkt %ub ", lss->level, lss->ewma_log, lss->avpkt);
+ print_string(PRINT_FP, NULL, "%s", _SL_);
+ print_uint(PRINT_ANY, "level", "level %u", lss->level);
+ print_uint(PRINT_ANY, "ewma", " ewma %u", lss->ewma_log);
+ print_uint(PRINT_ANY, "avpkt", " avpkt %ub ", lss->avpkt);
+
if (lss->maxidle) {
- fprintf(f, "maxidle %s ", sprint_ticks(lss->maxidle>>lss->ewma_log, b1));
+ print_ticks("maxidle", "maxidle %s ", lss->maxidle >> lss->ewma_log);
if (show_raw)
- fprintf(f, "[%08x] ", lss->maxidle);
+ print_0xhex(PRINT_FP, NULL, "[%08x] ", lss->maxidle);
}
if (lss->minidle != 0x7fffffff) {
- fprintf(f, "minidle %s ", sprint_ticks(lss->minidle>>lss->ewma_log, b1));
+ print_ticks("minidle", "minidle %s ", lss->minidle >> lss->ewma_log);
if (show_raw)
- fprintf(f, "[%08x] ", lss->minidle);
+ print_0xhex(PRINT_FP, NULL, "[%08x] ", lss->minidle);
}
if (lss->offtime) {
- fprintf(f, "offtime %s ", sprint_ticks(lss->offtime, b1));
+ print_ticks("offtime", "offtime %s ", lss->offtime);
if (show_raw)
- fprintf(f, "[%08x] ", lss->offtime);
+ print_0xhex(PRINT_FP, NULL, "[%08x] ", lss->offtime);
}
}
+
if (fopt && show_details) {
char buf[64];
print_tc_classid(buf, sizeof(buf), fopt->split);
- fprintf(f, "\nsplit %s ", buf);
- if (fopt->defmap) {
- fprintf(f, "defmap %08x", fopt->defmap);
- }
+ print_string(PRINT_FP, NULL, "%s", _SL_);
+ print_string(PRINT_ANY, "split", "split %s ", buf);
+ if (fopt->defmap)
+ print_0xhex(PRINT_ANY, "defmap", "defmap %08x", fopt->defmap);
}
return 0;
}
@@ -580,8 +585,10 @@ static int cbq_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstat
return -1;
st = RTA_DATA(xstats);
- fprintf(f, " borrowed %u overactions %u avgidle %g undertime %g", st->borrows,
- st->overactions, (double)st->avgidle, (double)st->undertime);
+ print_uint(PRINT_ANY, "borrowed", " borrowed %u", st->borrows);
+ print_uint(PRINT_ANY, "overactions", " overactions %u", st->overactions);
+ print_float(PRINT_ANY, "avgidle", " avgidle %g", (double) st->avgidle);
+ print_float(PRINT_ANY, "undertime", " undertime %g", (double)st->undertime);
return 0;
}
--
2.18.0
Powered by blists - more mailing lists