[net-next,00/12] tools: bpftool: Add JSON output to bpftool

Message ID 20171023162416.32753-1-jakub.kicinski@netronome.com
Headers show
Series
  • tools: bpftool: Add JSON output to bpftool
Related show

Message

Jakub Kicinski Oct. 23, 2017, 4:24 p.m.
Quentin says:

This series introduces support for JSON output to all bpftool commands. It
adds option parsing, and several options are created:

  * -j, --json     Switch to JSON output.
  * -p, --pretty   Switch to JSON and print it in a human-friendly fashion.
  * -h, --help     Print generic help message.
  * -V, --version  Print version number.

This code uses a "json_writer", which is a copy of the one written by
Stephen Hemminger in iproute2.
---
I don't know if there is an easy way to share the code for json_write
without copying the file, so I am very open to suggestions on this matter.


Quentin Monnet (12):
  tools: bpftool: copy JSON writer from iproute2 repository
  tools: bpftool: add option parsing to bpftool, --help and --version
  tools: bpftool: introduce --json and --pretty options
  tools: bpftool: add JSON output for `bpftool prog show *` command
  tools: bpftool: add JSON output for `bpftool prog dump jited *`
    command
  tools: bpftool: add JSON output for `bpftool prog dump xlated *`
    command
  tools: bpftool: add JSON output for `bpftool map *` commands
  tools: bpftool: add JSON output for `bpftool batch file FILE` command
  tools: bpftool: turn err() and info() macros into functions
  tools: bpftool: provide JSON output for all possible commands
  tools: bpftool: add cosmetic changes for the manual pages
  tools: bpftool: update documentation for --json and --pretty usage

 tools/bpf/bpftool/Documentation/bpftool-map.rst  |  44 ++-
 tools/bpf/bpftool/Documentation/bpftool-prog.rst |  81 +++++-
 tools/bpf/bpftool/Documentation/bpftool.rst      |  30 +-
 tools/bpf/bpftool/common.c                       |  36 ++-
 tools/bpf/bpftool/jit_disasm.c                   |  86 +++++-
 tools/bpf/bpftool/json_writer.c                  | 356 +++++++++++++++++++++++
 tools/bpf/bpftool/json_writer.h                  |  72 +++++
 tools/bpf/bpftool/main.c                         | 121 +++++++-
 tools/bpf/bpftool/main.h                         |  43 ++-
 tools/bpf/bpftool/map.c                          | 253 ++++++++++++----
 tools/bpf/bpftool/prog.c                         | 271 +++++++++++++----
 11 files changed, 1209 insertions(+), 184 deletions(-)
 create mode 100644 tools/bpf/bpftool/json_writer.c
 create mode 100644 tools/bpf/bpftool/json_writer.h

Comments

Alexei Starovoitov Oct. 23, 2017, 5:44 p.m. | #1
On Mon, Oct 23, 2017 at 09:24:04AM -0700, Jakub Kicinski wrote:
> Quentin says:
> 
> This series introduces support for JSON output to all bpftool commands. It
> adds option parsing, and several options are created:
> 
>   * -j, --json     Switch to JSON output.
>   * -p, --pretty   Switch to JSON and print it in a human-friendly fashion.
>   * -h, --help     Print generic help message.
>   * -V, --version  Print version number.
> 
> This code uses a "json_writer", which is a copy of the one written by
> Stephen Hemminger in iproute2.
> ---
> I don't know if there is an easy way to share the code for json_write
> without copying the file, so I am very open to suggestions on this matter.

I think copy-paste is fine in this case.
If we ever decide to remove it from here and move it into iproute2
this json.[hc] can be unified, but I think kernel/tools/bpf/ is
a better place since introspection interface is still evolving a lot
and bpftool is not networking specific. Like would be great if it
can show what programs attached to which cgroups, tracepoints, kprobes.

Overall looks like a nice set of improvements.

Acked-by: Alexei Starovoitov <ast@kernel.org>
David Miller Oct. 24, 2017, 12:25 a.m. | #2
From: Jakub Kicinski <jakub.kicinski@netronome.com>
Date: Mon, 23 Oct 2017 09:24:04 -0700

> Quentin says:
> 
> This series introduces support for JSON output to all bpftool commands. It
> adds option parsing, and several options are created:
> 
>   * -j, --json     Switch to JSON output.
>   * -p, --pretty   Switch to JSON and print it in a human-friendly fashion.
>   * -h, --help     Print generic help message.
>   * -V, --version  Print version number.
> 
> This code uses a "json_writer", which is a copy of the one written by
> Stephen Hemminger in iproute2.
> ---
> I don't know if there is an easy way to share the code for json_write
> without copying the file, so I am very open to suggestions on this matter.

Series applied.