From: Jiri Pirko Date: Sat, 25 Nov 2017 14:48:26 +0000 (+0100) Subject: tc: jsonify stats2 X-Git-Tag: v4.15.0~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fcec7f3665b;p=thirdparty%2Fiproute2.git tc: jsonify stats2 Add json output to stats2. Signed-off-by: Jiri Pirko --- diff --git a/tc/tc_util.c b/tc/tc_util.c index 5532d40be..d27698793 100644 --- a/tc/tc_util.c +++ b/tc/tc_util.c @@ -781,16 +781,19 @@ void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtat struct gnet_stats_basic bs = {0}; memcpy(&bs, RTA_DATA(tbs[TCA_STATS_BASIC]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_BASIC]), sizeof(bs))); - fprintf(fp, "%sSent %llu bytes %u pkt", - prefix, (unsigned long long) bs.bytes, bs.packets); + print_string(PRINT_FP, NULL, "%s", prefix); + print_lluint(PRINT_ANY, "bytes", "Sent %llu bytes", bs.bytes); + print_uint(PRINT_ANY, "packets", " %u pkt", bs.packets); } if (tbs[TCA_STATS_QUEUE]) { struct gnet_stats_queue q = {0}; memcpy(&q, RTA_DATA(tbs[TCA_STATS_QUEUE]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), sizeof(q))); - fprintf(fp, " (dropped %u, overlimits %u requeues %u) ", - q.drops, q.overlimits, q.requeues); + print_uint(PRINT_ANY, "drops", " (dropped %u", q.drops); + print_uint(PRINT_ANY, "overlimits", ", overlimits %u", + q.overlimits); + print_uint(PRINT_ANY, "requeues", " requeues %u) ", q.requeues); } if (tbs[TCA_STATS_RATE_EST64]) { @@ -799,8 +802,11 @@ void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtat memcpy(&re, RTA_DATA(tbs[TCA_STATS_RATE_EST64]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_RATE_EST64]), sizeof(re))); - fprintf(fp, "\n%srate %s %llupps ", - prefix, sprint_rate(re.bps, b1), re.pps); + print_string(PRINT_FP, NULL, "\n%s", prefix); + print_lluint(PRINT_JSON, "rate", NULL, re.bps); + print_string(PRINT_FP, NULL, "rate %s", + sprint_rate(re.bps, b1)); + print_lluint(PRINT_ANY, "pps", " %llupps", re.pps); } else if (tbs[TCA_STATS_RATE_EST]) { struct gnet_stats_rate_est re = {0}; @@ -808,6 +814,11 @@ void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtat MIN(RTA_PAYLOAD(tbs[TCA_STATS_RATE_EST]), sizeof(re))); fprintf(fp, "\n%srate %s %upps ", prefix, sprint_rate(re.bps, b1), re.pps); + print_string(PRINT_FP, NULL, "\n%s", prefix); + print_uint(PRINT_JSON, "rate", NULL, re.bps); + print_string(PRINT_FP, NULL, "rate %s", + sprint_rate(re.bps, b1)); + print_uint(PRINT_ANY, "pps", " %upps", re.pps); } if (tbs[TCA_STATS_QUEUE]) { @@ -815,9 +826,12 @@ void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtat memcpy(&q, RTA_DATA(tbs[TCA_STATS_QUEUE]), MIN(RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), sizeof(q))); if (!tbs[TCA_STATS_RATE_EST]) - fprintf(fp, "\n%s", prefix); - fprintf(fp, "backlog %s %up requeues %u ", - sprint_size(q.backlog, b1), q.qlen, q.requeues); + print_string(PRINT_FP, NULL, "\n%s", prefix); + print_uint(PRINT_JSON, "backlog", NULL, q.backlog); + print_string(PRINT_FP, NULL, "backlog %s", + sprint_size(q.backlog, b1)); + print_uint(PRINT_ANY, "qlen", " %up", q.qlen); + print_uint(PRINT_ANY, "requeues", " requeues %u", q.qlen); } if (xstats)