[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f38fe2b8a9b0505cb8be954286647d7a0773e2d3.1761078778.git.aclaudi@redhat.com>
Date: Tue, 21 Oct 2025 22:39:17 +0200
From: Andrea Claudi <aclaudi@...hat.com>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <stephen@...workplumber.org>,
David Ahern <dsahern@...nel.org>
Subject: [PATCH iproute2-next 2/3] nstat: convert to high-level json_print API
Replace the low-level json_writer API calls with the high-level
json_print API to maintain consistency with the rest of the iproute2
codebase.
Signed-off-by: Andrea Claudi <aclaudi@...hat.com>
---
misc/nstat.c | 48 +++++++++++++++++++++---------------------------
1 file changed, 21 insertions(+), 27 deletions(-)
diff --git a/misc/nstat.c b/misc/nstat.c
index b2e19bde..4a9f3326 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -24,7 +24,7 @@
#include <math.h>
#include <getopt.h>
-#include <json_writer.h>
+#include "json_print.h"
#include "version.h"
#include "utils.h"
@@ -309,15 +309,13 @@ static void load_netstat(void)
static void dump_kern_db(FILE *fp, int to_hist)
{
- json_writer_t *jw = json_output ? jsonw_new(fp) : NULL;
struct nstat_ent *n, *h;
h = hist_db;
- if (jw) {
- jsonw_start_object(jw);
- jsonw_pretty(jw, pretty);
- jsonw_name(jw, info_source);
- jsonw_start_object(jw);
+ new_json_obj_plain(json_output);
+ if (is_json_context()) {
+ open_json_object(NULL);
+ open_json_object(info_source);
} else
fprintf(fp, "#%s\n", info_source);
@@ -340,31 +338,28 @@ static void dump_kern_db(FILE *fp, int to_hist)
}
}
- if (jw)
- jsonw_uint_field(jw, n->id, val);
+ if (is_json_context())
+ print_lluint(PRINT_JSON, n->id, NULL, val);
else
fprintf(fp, "%-32s%-16llu%6.1f\n", n->id, val, n->rate);
}
- if (jw) {
- jsonw_end_object(jw);
-
- jsonw_end_object(jw);
- jsonw_destroy(&jw);
+ if (is_json_context()) {
+ close_json_object();
+ close_json_object();
}
+ delete_json_obj_plain();
}
static void dump_incr_db(FILE *fp)
{
- json_writer_t *jw = json_output ? jsonw_new(fp) : NULL;
struct nstat_ent *n, *h;
h = hist_db;
- if (jw) {
- jsonw_start_object(jw);
- jsonw_pretty(jw, pretty);
- jsonw_name(jw, info_source);
- jsonw_start_object(jw);
+ new_json_obj_plain(json_output);
+ if (is_json_context()) {
+ open_json_object(NULL);
+ open_json_object(info_source);
} else
fprintf(fp, "#%s\n", info_source);
@@ -389,19 +384,18 @@ static void dump_incr_db(FILE *fp)
if (!match(n->id))
continue;
- if (jw)
- jsonw_uint_field(jw, n->id, val);
+ if (is_json_context())
+ print_lluint(PRINT_JSON, n->id, NULL, val);
else
fprintf(fp, "%-32s%-16llu%6.1f%s\n", n->id, val,
n->rate, ovfl?" (overflow)":"");
}
- if (jw) {
- jsonw_end_object(jw);
-
- jsonw_end_object(jw);
- jsonw_destroy(&jw);
+ if (is_json_context()) {
+ close_json_object();
+ close_json_object();
}
+ delete_json_obj_plain();
}
static int children;
--
2.51.0
Powered by blists - more mailing lists