netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leslie Monis <lesliemonis@gmail.com>
To: Linux NetDev <netdev@vger.kernel.org>
Cc: David Ahern <dsahern@gmail.com>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2-next 08/10] tc: sfq: add support for JSON output
Date: Thu, 26 Dec 2019 00:34:16 +0530	[thread overview]
Message-ID: <20191225190418.8806-9-lesliemonis@gmail.com> (raw)
In-Reply-To: <20191225190418.8806-1-lesliemonis@gmail.com>

Enable proper JSON output for the SFQ Qdisc.
Use the long double format specifier to print the value of
"probability".
Also, fix the indentation in the online output of the contents in the
tc_sfqred_stats structure.

Signed-off-by: Leslie Monis <lesliemonis@gmail.com>
---
 tc/q_sfq.c | 66 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 24 deletions(-)

diff --git a/tc/q_sfq.c b/tc/q_sfq.c
index 4998921d..2b9bbcd2 100644
--- a/tc/q_sfq.c
+++ b/tc/q_sfq.c
@@ -217,35 +217,53 @@ static int sfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	if (RTA_PAYLOAD(opt) >= sizeof(*qopt_ext))
 		qopt_ext = RTA_DATA(opt);
 	qopt = RTA_DATA(opt);
-	fprintf(f, "limit %up ", qopt->limit);
-	fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
+
+	print_uint(PRINT_ANY, "limit", "limit %up ", qopt->limit);
+	print_uint(PRINT_JSON, "quantum", NULL, qopt->quantum);
+	print_string(PRINT_FP, NULL, "quantum %s ",
+		     sprint_size(qopt->quantum, b1));
+
 	if (qopt_ext && qopt_ext->depth)
-		fprintf(f, "depth %u ", qopt_ext->depth);
+		print_uint(PRINT_ANY, "depth", "depth %u ", qopt_ext->depth);
 	if (qopt_ext && qopt_ext->headdrop)
-		fprintf(f, "headdrop ");
+		print_bool(PRINT_ANY, "headdrop", "headdrop ", true);
+	if (show_details)
+		print_uint(PRINT_ANY, "flows", "flows %u ", qopt->flows);
+
+	print_uint(PRINT_ANY, "divisor", "divisor %u ", qopt->divisor);
 
-	if (show_details) {
-		fprintf(f, "flows %u/%u ", qopt->flows, qopt->divisor);
-	}
-	fprintf(f, "divisor %u ", qopt->divisor);
 	if (qopt->perturb_period)
-		fprintf(f, "perturb %dsec ", qopt->perturb_period);
+		print_int(PRINT_ANY, "perturb", "perturb %dsec ",
+			   qopt->perturb_period);
 	if (qopt_ext && qopt_ext->qth_min) {
-		fprintf(f, "\n ewma %u ", qopt_ext->Wlog);
-		fprintf(f, "min %s max %s probability %g ",
-			sprint_size(qopt_ext->qth_min, b2),
-			sprint_size(qopt_ext->qth_max, b3),
-			qopt_ext->max_P / pow(2, 32));
+		print_uint(PRINT_ANY, "ewma", "ewma %u ", qopt_ext->Wlog);
+		print_uint(PRINT_JSON, "min", NULL, qopt_ext->qth_min);
+		print_string(PRINT_FP, NULL, "min %s ",
+			     sprint_size(qopt_ext->qth_min, b2));
+		print_uint(PRINT_JSON, "max", NULL, qopt_ext->qth_max);
+		print_string(PRINT_FP, NULL, "max %s ",
+			     sprint_size(qopt_ext->qth_max, b3));
+		print_float(PRINT_ANY, "probability", "probability %lg ",
+			    qopt_ext->max_P / pow(2, 32));
 		tc_red_print_flags(qopt_ext->flags);
 		if (show_stats) {
-			fprintf(f, "\n prob_mark %u prob_mark_head %u prob_drop %u",
-				qopt_ext->stats.prob_mark,
-				qopt_ext->stats.prob_mark_head,
-				qopt_ext->stats.prob_drop);
-			fprintf(f, "\n forced_mark %u forced_mark_head %u forced_drop %u",
-				qopt_ext->stats.forced_mark,
-				qopt_ext->stats.forced_mark_head,
-				qopt_ext->stats.forced_drop);
+			print_nl();
+			print_uint(PRINT_ANY, "prob_mark", "  prob_mark %u",
+				   qopt_ext->stats.prob_mark);
+			print_uint(PRINT_ANY, "prob_mark_head",
+				   " prob_mark_head %u",
+				   qopt_ext->stats.prob_mark_head);
+			print_uint(PRINT_ANY, "prob_drop", " prob_drop %u",
+				   qopt_ext->stats.prob_drop);
+			print_nl();
+			print_uint(PRINT_ANY, "forced_mark",
+				   "  forced_mark %u",
+				   qopt_ext->stats.forced_mark);
+			print_uint(PRINT_ANY, "forced_mark_head",
+				   " forced_mark_head %u",
+				   qopt_ext->stats.forced_mark_head);
+			print_uint(PRINT_ANY, "forced_drop", " forced_drop %u",
+				   qopt_ext->stats.forced_drop);
 		}
 	}
 	return 0;
@@ -262,8 +280,8 @@ static int sfq_print_xstats(struct qdisc_util *qu, FILE *f,
 		return -1;
 	st = RTA_DATA(xstats);
 
-	fprintf(f, " allot %d ", st->allot);
-	fprintf(f, "\n");
+	print_int(PRINT_ANY, "allot", "  allot %d", st->allot);
+
 	return 0;
 }
 
-- 
2.17.1


  parent reply	other threads:[~2019-12-25 19:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-25 19:04 [PATCH iproute2-next 00/10] tc: add support for JSON output in some qdiscs Leslie Monis
2019-12-25 19:04 ` [PATCH iproute2-next 01/10] tc: cbs: add support for JSON output Leslie Monis
2019-12-25 19:04 ` [PATCH iproute2-next 02/10] tc: choke: " Leslie Monis
2019-12-25 19:04 ` [PATCH iproute2-next 03/10] tc: codel: " Leslie Monis
2019-12-25 19:04 ` [PATCH iproute2-next 04/10] tc: fq: " Leslie Monis
2019-12-25 19:04 ` [PATCH iproute2-next 05/10] tc: hhf: " Leslie Monis
2019-12-25 19:04 ` [PATCH iproute2-next 06/10] tc: pie: " Leslie Monis
2019-12-25 19:04 ` [PATCH iproute2-next 07/10] tc: sfb: " Leslie Monis
2019-12-25 19:04 ` Leslie Monis [this message]
2019-12-25 19:04 ` [PATCH iproute2-next 09/10] tc: tbf: " Leslie Monis
2019-12-25 19:04 ` [PATCH iproute2-next 10/10] tc: fq_codel: fix missing statistic in " Leslie Monis
2019-12-27  2:19 ` [PATCH iproute2-next 00/10] tc: add support for JSON output in some qdiscs Stephen Hemminger
2019-12-27 11:13   ` Leslie Monis
2019-12-29 18:04 ` 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=20191225190418.8806-9-lesliemonis@gmail.com \
    --to=lesliemonis@gmail.com \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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).