Skip to content

Commit

Permalink
bpftool: Add libbpf's version number to "bpftool version" output
Browse files Browse the repository at this point in the history
To help users check what version of libbpf is being used with bpftool,
print the number along with bpftool's own version number.

Output:

    $ ./bpftool version
    ./bpftool v5.16.0
    using libbpf v0.7
    features: libbfd, libbpf_strict, skeletons

    $ ./bpftool version --json --pretty
    {
        "version": "5.16.0",
        "libbpf_version": "0.7",
        "features": {
            "libbfd": true,
            "libbpf_strict": true,
            "skeletons": true
        }
    }

Note that libbpf does not expose its patch number.

Signed-off-by: Quentin Monnet <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
qmonnet committed Feb 16, 2022
1 parent 334c1d8 commit bee3394
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions docs/common_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
Print short help message (similar to **bpftool help**).

-V, --version
Print version number (similar to **bpftool version**), and optional
features that were included when bpftool was compiled. Optional
features include linking against libbfd to provide the disassembler
for JIT-ted programs (**bpftool prog dump jited**) and usage of BPF
skeletons (some features like **bpftool prog profile** or showing
pids associated to BPF objects may rely on it).
Print bpftool's version number (similar to **bpftool version**), the
number of the libbpf version in use, and optional features that were
included when bpftool was compiled. Optional features include linking
against libbfd to provide the disassembler for JIT-ted programs
(**bpftool prog dump jited**) and usage of BPF skeletons (some
features like **bpftool prog profile** or showing pids associated to
BPF objects may rely on it).

-j, --json
Generate JSON output. For commands that cannot produce JSON, this
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ static int do_version(int argc, char **argv)

jsonw_name(json_wtr, "version");
jsonw_printf(json_wtr, "\"%s\"", BPFTOOL_VERSION);
jsonw_name(json_wtr, "libbpf_version");
jsonw_printf(json_wtr, "\"%d.%d\"",
libbpf_major_version(), libbpf_minor_version());

jsonw_name(json_wtr, "features");
jsonw_start_object(json_wtr); /* features */
Expand All @@ -102,6 +105,7 @@ static int do_version(int argc, char **argv)
unsigned int nb_features = 0;

printf("%s v%s\n", bin_name, BPFTOOL_VERSION);
printf("using libbpf %s\n", libbpf_version_string());
printf("features:");
if (has_libbfd) {
printf(" libbfd");
Expand Down

0 comments on commit bee3394

Please sign in to comment.