[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171125144835.5045-3-jiri@resnulli.us>
Date: Sat, 25 Nov 2017 15:48:26 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: stephen@...workplumber.org, jhs@...atatu.com, mlxsw@...lanox.com
Subject: [patch iproute2 02/11] tc: jsonify stats2
From: Jiri Pirko <jiri@...lanox.com>
Add json output to stats2.
Signed-off-by: Jiri Pirko <jiri@...lanox.com>
---
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
Powered by blists - more mailing lists