tc: gred: separate out stats printing

Printing GRED statistics is long and deserves a function on its own.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Jakub Kicinski 2018-11-19 15:03:32 -08:00 committed by David Ahern
parent 6475e6a580
commit c3e1cd28c1

View File

@ -265,6 +265,38 @@ static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct n
return 0;
}
static void gred_print_stats(struct tc_gred_qopt *qopt)
{
SPRINT_BUF(b1);
if (!is_json_context())
printf("\n Queue size: ");
print_uint(PRINT_JSON, "qave", NULL, qopt->qave);
print_string(PRINT_FP, NULL, "average %s ",
sprint_size(qopt->qave, b1));
print_uint(PRINT_JSON, "backlog", NULL, qopt->backlog);
print_string(PRINT_FP, NULL, "current %s ",
sprint_size(qopt->backlog, b1));
if (!is_json_context())
printf("\n Dropped packets: ");
print_uint(PRINT_ANY, "forced_drop", "forced %u ", qopt->forced);
print_uint(PRINT_ANY, "prob_drop", "early %u ", qopt->early);
print_uint(PRINT_ANY, "pdrop", "pdrop %u ", qopt->pdrop);
print_uint(PRINT_ANY, "other", "other %u ", qopt->other);
if (!is_json_context())
printf("\n Total packets: ");
print_uint(PRINT_ANY, "packets", "%u ", qopt->packets);
print_uint(PRINT_JSON, "bytes", NULL, qopt->bytesin);
print_string(PRINT_FP, NULL, "(%s) ", sprint_size(qopt->bytesin, b1));
}
static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
struct rtattr *tb[TCA_GRED_MAX + 1];
@ -348,39 +380,8 @@ static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
print_uint(PRINT_ANY, "Scell_log", "Scell_log %u ",
qopt->Scell_log);
}
if (show_stats) {
if (!is_json_context())
printf("\n Queue size: ");
print_uint(PRINT_JSON, "qave", NULL, qopt->qave);
print_string(PRINT_FP, NULL, "average %s ",
sprint_size(qopt->qave, b1));
print_uint(PRINT_JSON, "backlog", NULL, qopt->backlog);
print_string(PRINT_FP, NULL, "current %s ",
sprint_size(qopt->backlog, b1));
if (!is_json_context())
printf("\n Dropped packets: ");
print_uint(PRINT_ANY, "forced_drop", "forced %u ",
qopt->forced);
print_uint(PRINT_ANY, "prob_drop", "early %u ",
qopt->early);
print_uint(PRINT_ANY, "pdrop", "pdrop %u ",
qopt->pdrop);
print_uint(PRINT_ANY, "other", "other %u ",
qopt->other);
if (!is_json_context())
printf("\n Total packets: ");
print_uint(PRINT_ANY, "packets", "%u ", qopt->packets);
print_uint(PRINT_JSON, "bytes", NULL, qopt->bytesin);
print_string(PRINT_FP, NULL, "(%s) ",
sprint_size(qopt->bytesin, b1));
}
if (show_stats)
gred_print_stats(qopt);
close_json_object();
}
close_json_array(PRINT_JSON, "vqs");