diff options
author | YiFei Zhu <zhuyifei@google.com> | 2020-09-16 01:45:42 +0200 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2020-09-16 03:28:27 +0200 |
commit | aff52e685eb39984f3a613e8a5c570d97e5d2414 (patch) | |
tree | f1dc82bbe179c8fcf5886ae4b2f14e7c8ca05526 /tools/bpf/bpftool/json_writer.c | |
parent | libbpf: Add BPF_PROG_BIND_MAP syscall and use it on .rodata section (diff) | |
download | linux-aff52e685eb39984f3a613e8a5c570d97e5d2414.tar.xz linux-aff52e685eb39984f3a613e8a5c570d97e5d2414.zip |
bpftool: Support dumping metadata
Dump metadata in the 'bpftool prog' list if it's present.
For some formatting some BTF code is put directly in the
metadata dumping. Sanity checks on the map and the kind of the btf_type
to make sure we are actually dumping what we are expecting.
A helper jsonw_reset is added to json writer so we can reuse the same
json writer without having extraneous commas.
Sample output:
$ bpftool prog
6: cgroup_skb name prog tag bcf7977d3b93787c gpl
[...]
btf_id 4
metadata:
a = "foo"
b = 1
$ bpftool prog --json --pretty
[{
"id": 6,
[...]
"btf_id": 4,
"metadata": {
"a": "foo",
"b": 1
}
}
]
Signed-off-by: YiFei Zhu <zhuyifei@google.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: YiFei Zhu <zhuyifei1999@gmail.com>
Link: https://lore.kernel.org/bpf/20200915234543.3220146-5-sdf@google.com
Diffstat (limited to 'tools/bpf/bpftool/json_writer.c')
-rw-r--r-- | tools/bpf/bpftool/json_writer.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/bpf/bpftool/json_writer.c b/tools/bpf/bpftool/json_writer.c index 86501cd3c763..7fea83bedf48 100644 --- a/tools/bpf/bpftool/json_writer.c +++ b/tools/bpf/bpftool/json_writer.c @@ -119,6 +119,12 @@ void jsonw_pretty(json_writer_t *self, bool on) self->pretty = on; } +void jsonw_reset(json_writer_t *self) +{ + assert(self->depth == 0); + self->sep = '\0'; +} + /* Basic blocks */ static void jsonw_begin(json_writer_t *self, int c) { |