Make JSON output work with RED Qdiscs. Float/double printing helpers have to be added/uncommented to print the probability. Since TC stats in general are not split out to a separate object the xstats printed by this patch are not separated either.
Signed-off-by: Jakub Kicinski <jakub.kicin...@netronome.com> --- include/json_print.h | 1 + lib/json_print.c | 1 + lib/json_writer.c | 4 ---- tc/q_red.c | 41 ++++++++++++++++++++++++++--------------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/include/json_print.h b/include/json_print.h index dc4d2bb3ba59..2ca7830adbd6 100644 --- a/include/json_print.h +++ b/include/json_print.h @@ -64,6 +64,7 @@ _PRINT_FUNC(hu, unsigned short); _PRINT_FUNC(hex, unsigned int); _PRINT_FUNC(0xhex, unsigned int); _PRINT_FUNC(lluint, unsigned long long int); +_PRINT_FUNC(float, double); #undef _PRINT_FUNC #endif /* _JSON_PRINT_H_ */ diff --git a/lib/json_print.c b/lib/json_print.c index aa527af652c5..6518ba98f5bf 100644 --- a/lib/json_print.c +++ b/lib/json_print.c @@ -120,6 +120,7 @@ _PRINT_FUNC(int, int); _PRINT_FUNC(hu, unsigned short); _PRINT_FUNC(uint, uint64_t); _PRINT_FUNC(lluint, unsigned long long int); +_PRINT_FUNC(float, double); #undef _PRINT_FUNC void print_color_string(enum output_type type, diff --git a/lib/json_writer.c b/lib/json_writer.c index 6b77d288cce2..f3eeaf7bc479 100644 --- a/lib/json_writer.c +++ b/lib/json_writer.c @@ -209,12 +209,10 @@ void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num) jsonw_printf(self, fmt, num); } -#ifdef notused void jsonw_float(json_writer_t *self, double num) { jsonw_printf(self, "%g", num); } -#endif void jsonw_hu(json_writer_t *self, unsigned short num) { @@ -249,13 +247,11 @@ void jsonw_bool_field(json_writer_t *self, const char *prop, bool val) jsonw_bool(self, val); } -#ifdef notused void jsonw_float_field(json_writer_t *self, const char *prop, double val) { jsonw_name(self, prop); jsonw_float(self, val); } -#endif void jsonw_float_field_fmt(json_writer_t *self, const char *prop, diff --git a/tc/q_red.c b/tc/q_red.c index 1949558f14f9..40ba7c3e07c1 100644 --- a/tc/q_red.c +++ b/tc/q_red.c @@ -183,23 +183,34 @@ static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) RTA_PAYLOAD(tb[TCA_RED_MAX_P]) >= sizeof(__u32)) max_P = rta_getattr_u32(tb[TCA_RED_MAX_P]); - fprintf(f, "limit %s min %s max %s ", - sprint_size(qopt->limit, b1), - sprint_size(qopt->qth_min, b2), - sprint_size(qopt->qth_max, b3)); + print_uint(PRINT_JSON, "limit", NULL, qopt->limit); + print_string(PRINT_FP, NULL, "limit %s ", sprint_size(qopt->limit, b1)); + print_uint(PRINT_JSON, "min", NULL, qopt->qth_min); + print_string(PRINT_FP, NULL, "min %s ", sprint_size(qopt->qth_min, b2)); + print_uint(PRINT_JSON, "max", NULL, qopt->qth_max); + print_string(PRINT_FP, NULL, "max %s ", sprint_size(qopt->qth_max, b3)); + if (qopt->flags & TC_RED_ECN) - fprintf(f, "ecn "); + print_bool(PRINT_ANY, "ecn", "ecn ", true); + else + print_bool(PRINT_ANY, "ecn", NULL, false); if (qopt->flags & TC_RED_HARDDROP) - fprintf(f, "harddrop "); + print_bool(PRINT_ANY, "harddrop", "harddrop ", true); + else + print_bool(PRINT_ANY, "harddrop", NULL, false); if (qopt->flags & TC_RED_ADAPTATIVE) - fprintf(f, "adaptive "); + print_bool(PRINT_ANY, "adaptive", "adaptive ", true); + else + print_bool(PRINT_ANY, "adaptive", NULL, false); if (show_details) { - fprintf(f, "ewma %u ", qopt->Wlog); + print_uint(PRINT_ANY, "ewma", "ewma %u ", qopt->Wlog); if (max_P) - fprintf(f, "probability %lg ", max_P / pow(2, 32)); + print_float(PRINT_ANY, "probability", + "probability %lg ", max_P / pow(2, 32)); else - fprintf(f, "Plog %u ", qopt->Plog); - fprintf(f, "Scell_log %u", qopt->Scell_log); + print_uint(PRINT_ANY, "Plog", "Plog %u ", qopt->Plog); + print_uint(PRINT_ANY, "Scell_log", "Scell_log %u", + qopt->Scell_log); } return 0; } @@ -216,10 +227,10 @@ static int red_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstat return -1; st = RTA_DATA(xstats); - fprintf(f, " marked %u early %u pdrop %u other %u", - st->marked, st->early, st->pdrop, st->other); - return 0; - + print_uint(PRINT_ANY, "marked", " marked %u ", st->marked); + print_uint(PRINT_ANY, "early", "early %u ", st->early); + print_uint(PRINT_ANY, "pdrop", "pdrop %u ", st->pdrop); + print_uint(PRINT_ANY, "other", "other %u ", st->other); #endif return 0; } -- 2.15.1