Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b04df400 authored by Yonghong Song's avatar Yonghong Song Committed by Alexei Starovoitov
Browse files

tools/bpftool: add perf subcommand



The new command "bpftool perf [show | list]" will traverse
all processes under /proc, and if any fd is associated
with a perf event, it will print out related perf event
information. Documentation is also added.

Below is an example to show the results using bcc commands.
Running the following 4 bcc commands:
  kprobe:     trace.py '__x64_sys_nanosleep'
  kretprobe:  trace.py 'r::__x64_sys_nanosleep'
  tracepoint: trace.py 't:syscalls:sys_enter_nanosleep'
  uprobe:     trace.py 'p:/home/yhs/a.out:main'

The bpftool command line and result:

  $ bpftool perf
  pid 21711  fd 5: prog_id 5  kprobe  func __x64_sys_write  offset 0
  pid 21765  fd 5: prog_id 7  kretprobe  func __x64_sys_nanosleep  offset 0
  pid 21767  fd 5: prog_id 8  tracepoint  sys_enter_nanosleep
  pid 21800  fd 5: prog_id 9  uprobe  filename /home/yhs/a.out  offset 1159

  $ bpftool -j perf
  [{"pid":21711,"fd":5,"prog_id":5,"fd_type":"kprobe","func":"__x64_sys_write","offset":0}, \
   {"pid":21765,"fd":5,"prog_id":7,"fd_type":"kretprobe","func":"__x64_sys_nanosleep","offset":0}, \
   {"pid":21767,"fd":5,"prog_id":8,"fd_type":"tracepoint","tracepoint":"sys_enter_nanosleep"}, \
   {"pid":21800,"fd":5,"prog_id":9,"fd_type":"uprobe","filename":"/home/yhs/a.out","offset":1159}]

  $ bpftool prog
  5: kprobe  name probe___x64_sys  tag e495a0c82f2c7a8d  gpl
	  loaded_at 2018-05-15T04:46:37-0700  uid 0
	  xlated 200B  not jited  memlock 4096B  map_ids 4
  7: kprobe  name probe___x64_sys  tag f2fdee479a503abf  gpl
	  loaded_at 2018-05-15T04:48:32-0700  uid 0
	  xlated 200B  not jited  memlock 4096B  map_ids 7
  8: tracepoint  name tracepoint__sys  tag 5390badef2395fcf  gpl
	  loaded_at 2018-05-15T04:48:48-0700  uid 0
	  xlated 200B  not jited  memlock 4096B  map_ids 8
  9: kprobe  name probe_main_1  tag 0a87bdc2e2953b6d  gpl
	  loaded_at 2018-05-15T04:49:52-0700  uid 0
	  xlated 200B  not jited  memlock 4096B  map_ids 9

  $ ps ax | grep "python ./trace.py"
  21711 pts/0    T      0:03 python ./trace.py __x64_sys_write
  21765 pts/0    S+     0:00 python ./trace.py r::__x64_sys_nanosleep
  21767 pts/2    S+     0:00 python ./trace.py t:syscalls:sys_enter_nanosleep
  21800 pts/3    S+     0:00 python ./trace.py p:/home/yhs/a.out:main
  22374 pts/1    S+     0:00 grep --color=auto python ./trace.py

Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarYonghong Song <yhs@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent f699cf7a
Loading
Loading
Loading
Loading
+81 −0
Original line number Diff line number Diff line
================
bpftool-perf
================
-------------------------------------------------------------------------------
tool for inspection of perf related bpf prog attachments
-------------------------------------------------------------------------------

:Manual section: 8

SYNOPSIS
========

	**bpftool** [*OPTIONS*] **perf** *COMMAND*

	*OPTIONS* := { [{ **-j** | **--json** }] [{ **-p** | **--pretty** }] }

	*COMMANDS* :=
	{ **show** | **list** | **help** }

PERF COMMANDS
=============

|	**bpftool** **perf { show | list }**
|	**bpftool** **perf help**

DESCRIPTION
===========
	**bpftool perf { show | list }**
		  List all raw_tracepoint, tracepoint, kprobe attachment in the system.

		  Output will start with process id and file descriptor in that process,
		  followed by bpf program id, attachment information, and attachment point.
		  The attachment point for raw_tracepoint/tracepoint is the trace probe name.
		  The attachment point for k[ret]probe is either symbol name and offset,
		  or a kernel virtual address.
		  The attachment point for u[ret]probe is the file name and the file offset.

	**bpftool perf help**
		  Print short help message.

OPTIONS
=======
	-h, --help
		  Print short generic help message (similar to **bpftool help**).

	-v, --version
		  Print version number (similar to **bpftool version**).

	-j, --json
		  Generate JSON output. For commands that cannot produce JSON, this
		  option has no effect.

	-p, --pretty
		  Generate human-readable JSON output. Implies **-j**.

EXAMPLES
========

| **# bpftool perf**

::

      pid 21711  fd 5: prog_id 5  kprobe  func __x64_sys_write  offset 0
      pid 21765  fd 5: prog_id 7  kretprobe  func __x64_sys_nanosleep  offset 0
      pid 21767  fd 5: prog_id 8  tracepoint  sys_enter_nanosleep
      pid 21800  fd 5: prog_id 9  uprobe  filename /home/yhs/a.out  offset 1159

|
| **# bpftool -j perf**

::

    [{"pid":21711,"fd":5,"prog_id":5,"fd_type":"kprobe","func":"__x64_sys_write","offset":0}, \
     {"pid":21765,"fd":5,"prog_id":7,"fd_type":"kretprobe","func":"__x64_sys_nanosleep","offset":0}, \
     {"pid":21767,"fd":5,"prog_id":8,"fd_type":"tracepoint","tracepoint":"sys_enter_nanosleep"}, \
     {"pid":21800,"fd":5,"prog_id":9,"fd_type":"uprobe","filename":"/home/yhs/a.out","offset":1159}]


SEE ALSO
========
	**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-map**\ (8)
+4 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ SYNOPSIS

	**bpftool** **version**

	*OBJECT* := { **map** | **program** | **cgroup** }
	*OBJECT* := { **map** | **program** | **cgroup** | **perf** }

	*OPTIONS* := { { **-V** | **--version** } | { **-h** | **--help** }
	| { **-j** | **--json** } [{ **-p** | **--pretty** }] }
@@ -30,6 +30,8 @@ SYNOPSIS

	*CGROUP-COMMANDS* := { **show** | **list** | **attach** | **detach** | **help** }

	*PERF-COMMANDS* := { **show** | **list** | **help** }

DESCRIPTION
===========
	*bpftool* allows for inspection and simple modification of BPF objects
@@ -56,3 +58,4 @@ OPTIONS
SEE ALSO
========
	**bpftool-map**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)
        **bpftool-perf**\ (8)
+9 −0
Original line number Diff line number Diff line
@@ -448,6 +448,15 @@ _bpftool()
                    ;;
            esac
            ;;
        perf)
            case $command in
                *)
                    [[ $prev == $object ]] && \
                        COMPREPLY=( $( compgen -W 'help \
                            show list' -- "$cur" ) )
                    ;;
            esac
            ;;
    esac
} &&
complete -F _bpftool bpftool
+2 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ static int do_help(int argc, char **argv)
		"       %s batch file FILE\n"
		"       %s version\n"
		"\n"
		"       OBJECT := { prog | map | cgroup }\n"
		"       OBJECT := { prog | map | cgroup | perf }\n"
		"       " HELP_SPEC_OPTIONS "\n"
		"",
		bin_name, bin_name, bin_name);
@@ -216,6 +216,7 @@ static const struct cmd cmds[] = {
	{ "prog",	do_prog },
	{ "map",	do_map },
	{ "cgroup",	do_cgroup },
	{ "perf",	do_perf },
	{ "version",	do_version },
	{ 0 }
};
+1 −0
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ int do_prog(int argc, char **arg);
int do_map(int argc, char **arg);
int do_event_pipe(int argc, char **argv);
int do_cgroup(int argc, char **arg);
int do_perf(int argc, char **arg);

int prog_parse_fd(int *argc, char ***argv);
int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len);
Loading