From: Stephen Hemminger <sthem...@microsoft.com> Signed-off-by: Stephen Hemminger <step...@networkplumber.org> --- tc/q_gred.c | 73 ++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 35 deletions(-)
diff --git a/tc/q_gred.c b/tc/q_gred.c index e63fac72a883..957d3c0950f1 100644 --- a/tc/q_gred.c +++ b/tc/q_gred.c @@ -274,10 +274,6 @@ static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) __u32 *limit = NULL; unsigned int i; - SPRINT_BUF(b1); - SPRINT_BUF(b2); - SPRINT_BUF(b3); - if (opt == NULL) return 0; @@ -298,49 +294,56 @@ static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) qopt = RTA_DATA(tb[TCA_GRED_PARMS]); if (RTA_PAYLOAD(tb[TCA_GRED_DPS]) < sizeof(*sopt) || RTA_PAYLOAD(tb[TCA_GRED_PARMS]) < sizeof(*qopt)*MAX_DPs) { - fprintf(f, "\n GRED received message smaller than expected\n"); + fprintf(stderr, "\n GRED received message smaller than expected\n"); return -1; } -/* Bad hack! should really return a proper message as shown above*/ - - fprintf(f, "vqs %u default %u %s", - sopt->DPs, - sopt->def_DP, - sopt->grio ? "grio " : ""); + /* Bad hack! should really return a proper message as shown above*/ + print_uint(PRINT_ANY, "num_dp", "vqs %u", sopt->DPs); + print_uint(PRINT_ANY, "default", " default %u", sopt->def_DP); + if (sopt->grio) + print_null(PRINT_ANY, "grio", "grio ", NULL); if (limit) - fprintf(f, "limit %s ", - sprint_size(*limit, b1)); + print_size("limit", "limit %s ", *limit); + open_json_array(PRINT_JSON, "dp"); for (i = 0; i < MAX_DPs; i++, qopt++) { - if (qopt->DP >= MAX_DPs) continue; - fprintf(f, "\n vq %u prio %hhu limit %s min %s max %s ", - qopt->DP, - qopt->prio, - sprint_size(qopt->limit, b1), - sprint_size(qopt->qth_min, b2), - sprint_size(qopt->qth_max, b3)); + if (qopt->DP >= MAX_DPs) + continue; + print_string(PRINT_FP, NULL, "%s", _SL_); + open_json_object(NULL); + print_uint(PRINT_ANY, "vq", "vq %u ", qopt->DP); + print_uint(PRINT_ANY, "prio", "prio %u ", qopt->prio); + print_size("limit", "limit %s ", qopt->limit); + print_size("min", "min %s ", qopt->qth_min); + print_size("max", "min %s ", qopt->qth_max); + 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[i] / pow(2, 32)); + print_float(PRINT_ANY, "probability", + "probability %lg ", max_p[i] / 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); } if (show_stats) { - fprintf(f, "\n Queue size: average %s current %s ", - sprint_size(qopt->qave, b1), - sprint_size(qopt->backlog, b2)); - fprintf(f, "\n Dropped packets: forced %u early %u pdrop %u other %u ", - qopt->forced, - qopt->early, - qopt->pdrop, - qopt->other); - fprintf(f, "\n Total packets: %u (%s) ", - qopt->packets, - sprint_size(qopt->bytesin, b1)); + print_string(PRINT_FP, NULL, "%s", _SL_); + print_size("average", " Queue size: average %s", qopt->qave); + print_size("backlog", " current %s ", qopt->backlog); + + print_string(PRINT_FP, NULL, "%s Dropped packets: ", _SL_); + print_uint(PRINT_ANY, "forced", " forced %u ", qopt->forced); + print_uint(PRINT_ANY, "early", "early %u ", qopt->early); + print_uint(PRINT_ANY, "pdrop", "pdrop %u ", qopt->pdrop); + print_uint(PRINT_ANY, "other", "other %u ", qopt->other); + + print_string(PRINT_FP, NULL, "%s Total ", _SL_); + print_uint(PRINT_ANY, "packets", "packets: %u ", qopt->packets); + print_size("bytes", "(%s) ", qopt->bytesin); } } return 0; -- 2.18.0