From: Jiri Pirko Subject: [patch iproute2 02/11] tc: jsonify stats2 Date: Sat, 25 Nov 2017 15:48:26 +0100 Message-ID: <20171125144835.5045-3-jiri@resnulli.us> References: <20171125144835.5045-1-jiri@resnulli.us> Cc: stephen@networkplumber.org, jhs@mojatatu.com, mlxsw@mellanox.com To: netdev@vger.kernel.org Return-path: Received: from mail-wr0-f194.google.com ([209.85.128.194]:40290 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751762AbdKYOsk (ORCPT ); Sat, 25 Nov 2017 09:48:40 -0500 Received: by mail-wr0-f194.google.com with SMTP id s41so17140022wrc.7 for ; Sat, 25 Nov 2017 06:48:39 -0800 (PST) In-Reply-To: <20171125144835.5045-1-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org List-ID: From: Jiri Pirko Add json output to stats2. Signed-off-by: Jiri Pirko --- tc/tc_util.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tc/tc_util.c b/tc/tc_util.c index 5532d40..d276987 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) -- 2.9.5