diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-07-31 16:34:47 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-08-01 12:33:50 -0400 |
| commit | 81e3d8b2af2e7417f1d5164aab5c1a75955e8a5d (patch) | |
| tree | ad38718594bf0b73eeda692d47463b5d8bd47484 /tools | |
| parent | ec6dd85f6e39bf516f4420d62270380b96bbee57 (diff) | |
perf trace beautify ioctl: Beautify perf ioctl's 'cmd' arg
Also trying a new approach, using the copy of uapi/linux/perf_event.h we
auto generate the string tables, then include it in the ioctl cmd
beautifier.
This way either the perf developers will add the new commands to the
tools/ copy, like is happening with other areas of tools/include/ (bpf.h
comes to mind), or we'll be notified when building perf that our copy
drifted.
E.g., looking at some of the perf ioctls issued by the 'perf test' test cases:
# (perf trace -e perf_event_open,ioctl perf test) 2>&1 | egrep "(cmd: PERF_|perf_event_open)"
4: Read samples using the mmap interface :
348.811 ( 0.062 ms): perf/23351 perf_event_open(attr_uptr: 0x414a5e8, pid: 23351 (perf), group_fd: -1, flags: FD_CLOEXEC) = 3
348.878 ( 0.039 ms): perf/23351 perf_event_open(attr_uptr: 0x414a5e8, pid: 23351 (perf), cpu: 1, group_fd: -1, flags: FD_CLOEXEC) = 4
348.919 ( 0.036 ms): perf/23351 perf_event_open(attr_uptr: 0x414a5e8, pid: 23351 (perf), cpu: 2, group_fd: -1, flags: FD_CLOEXEC) = 5
348.958 ( 0.036 ms): perf/23351 perf_event_open(attr_uptr: 0x414a5e8, pid: 23351 (perf), cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 6
349.070 ( 0.046 ms): perf/23351 perf_event_open(attr_uptr: 0x414aa38, pid: 23351 (perf), group_fd: -1, flags: FD_CLOEXEC) = 7
349.120 ( 0.037 ms): perf/23351 perf_event_open(attr_uptr: 0x414aa38, pid: 23351 (perf), cpu: 1, group_fd: -1, flags: FD_CLOEXEC) = 8
349.161 ( 0.036 ms): perf/23351 perf_event_open(attr_uptr: 0x414aa38, pid: 23351 (perf), cpu: 2, group_fd: -1, flags: FD_CLOEXEC) = 9
349.201 ( 0.035 ms): perf/23351 perf_event_open(attr_uptr: 0x414aa38, pid: 23351 (perf), cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 10
349.306 ( 0.041 ms): perf/23351 perf_event_open(attr_uptr: 0x414b2d8, pid: 23351 (perf), group_fd: -1, flags: FD_CLOEXEC) = 11
349.611 ( 0.005 ms): perf/23351 ioctl(fd: 3<anon_inode:[perf_event]>, cmd: PERF_ID, arg: 0x7fff025999b8) = 0
349.619 ( 0.002 ms): perf/23351 ioctl(fd: 7<anon_inode:[perf_event]>, cmd: PERF_SET_OUTPUT, arg: 0x3 ) = 0
349.623 ( 0.002 ms): perf/23351 ioctl(fd: 7<anon_inode:[perf_event]>, cmd: PERF_ID, arg: 0x7fff025999b8) = 0
349.627 ( 0.002 ms): perf/23351 ioctl(fd: 11<anon_inode:[perf_event]>, cmd: PERF_SET_OUTPUT, arg: 0x3 ) = 0
349.630 ( 0.001 ms): perf/23351 ioctl(fd: 11<anon_inode:[perf_event]>, cmd: PERF_ID, arg: 0x7fff025999b8) = 0
<SNIP>
7: PERF_RECORD_* events & perf_sample fields :
647.150 ( 0.014 ms): perf/23354 perf_event_open(attr_uptr: 0x7fff02599920, pid: -1, cpu: 2, group_fd: -1, flags: FD_CLOEXEC) = 3
647.197 ( 0.076 ms): perf/23354 perf_event_open(attr_uptr: 0x414b478, pid: -1, group_fd: -1, flags: FD_CLOEXEC) = 3
647.289 ( 0.040 ms): perf/23354 perf_event_open(attr_uptr: 0x414b478, pid: -1, group_fd: -1, flags: FD_CLOEXEC) = 3
647.368 ( 0.011 ms): perf/23354 perf_event_open(attr_uptr: 0x414a5e8, pid: 23355 (perf), group_fd: -1, flags: FD_CLOEXEC) = 3
647.381 ( 0.005 ms): perf/23354 perf_event_open(attr_uptr: 0x414a5e8, pid: 23355 (perf), cpu: 1, group_fd: -1, flags: FD_CLOEXEC) = 4
647.387 ( 0.005 ms): perf/23354 perf_event_open(attr_uptr: 0x414a5e8, pid: 23355 (perf), cpu: 2, group_fd: -1, flags: FD_CLOEXEC) = 5
647.393 ( 0.004 ms): perf/23354 perf_event_open(attr_uptr: 0x414a5e8, pid: 23355 (perf), cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 7
648.026 ( 0.011 ms): perf/23354 ioctl(fd: 3<anon_inode:[perf_event]>, cmd: PERF_ENABLE) = 0
648.038 ( 0.002 ms): perf/23354 ioctl(fd: 4<anon_inode:[perf_event]>, cmd: PERF_ENABLE) = 0
648.042 ( 0.002 ms): perf/23354 ioctl(fd: 5<anon_inode:[perf_event]>, cmd: PERF_ENABLE) = 0
648.045 ( 0.002 ms): perf/23354 ioctl(fd: 7<anon_inode:[perf_event]>, cmd: PERF_ENABLE) = 0
<SNIP>
18: Breakpoint overflow signal handler :
2772.721 ( 0.017 ms): perf/23375 perf_event_open(attr_uptr: 0x7fff02599d20, pid: -1, cpu: 3, group_fd: -1, flags: FD_CLOEXEC) = 3
2772.748 ( 0.009 ms): perf/23375 perf_event_open(attr_uptr: 0x7fff02599e60, cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 3
2772.768 ( 0.002 ms): perf/23375 ioctl(fd: 3, cmd: PERF_RESET) = 0
2772.776 ( 0.008 ms): perf/23375 perf_event_open(attr_uptr: 0x7fff02599e60, cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 4
2772.788 ( 0.002 ms): perf/23375 ioctl(fd: 4, cmd: PERF_RESET) = 0
2772.791 ( 0.006 ms): perf/23375 perf_event_open(attr_uptr: 0x7fff02599e60, cpu: -1, group_fd: -1, flags: FD_CLOEXEC) = 5
2772.800 ( 0.001 ms): perf/23375 ioctl(fd: 5, cmd: PERF_RESET) = 0
2772.803 ( 0.005 ms): perf/23375 ioctl(fd: 3, cmd: PERF_ENABLE) = 0
2772.810 ( 0.004 ms): perf/23375 ioctl(fd: 4, cmd: PERF_ENABLE) = 0
2772.815 ( 0.004 ms): perf/23375 ioctl(fd: 5, cmd: PERF_ENABLE) = 0
<SNIP>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-ahotwscqt080ae0ulu3zznh2@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/perf/Makefile.perf | 13 | ||||
| -rw-r--r-- | tools/perf/trace/beauty/ioctl.c | 24 | ||||
| -rwxr-xr-x | tools/perf/trace/beauty/perf_ioctl.sh | 10 |
3 files changed, 39 insertions, 8 deletions
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 606358d67f8a..c1f7884979e2 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
| @@ -420,6 +420,13 @@ vhost_virtio_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/vhost_virtio_ioctl. | |||
| 420 | $(vhost_virtio_ioctl_array): $(vhost_virtio_hdr_dir)/vhost.h $(vhost_virtio_ioctl_tbl) | 420 | $(vhost_virtio_ioctl_array): $(vhost_virtio_hdr_dir)/vhost.h $(vhost_virtio_ioctl_tbl) |
| 421 | $(Q)$(SHELL) '$(vhost_virtio_ioctl_tbl)' $(vhost_virtio_hdr_dir) > $@ | 421 | $(Q)$(SHELL) '$(vhost_virtio_ioctl_tbl)' $(vhost_virtio_hdr_dir) > $@ |
| 422 | 422 | ||
| 423 | perf_ioctl_array := $(beauty_ioctl_outdir)/perf_ioctl_array.c | ||
| 424 | perf_hdr_dir := $(srctree)/tools/include/uapi/linux | ||
| 425 | perf_ioctl_tbl := $(srctree)/tools/perf/trace/beauty/perf_ioctl.sh | ||
| 426 | |||
| 427 | $(perf_ioctl_array): $(perf_hdr_dir)/perf_event.h $(perf_ioctl_tbl) | ||
| 428 | $(Q)$(SHELL) '$(perf_ioctl_tbl)' $(perf_hdr_dir) > $@ | ||
| 429 | |||
| 423 | all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS) | 430 | all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS) |
| 424 | 431 | ||
| 425 | $(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) $(LIBTRACEEVENT_DYNAMIC_LIST) | 432 | $(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) $(LIBTRACEEVENT_DYNAMIC_LIST) |
| @@ -518,7 +525,8 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioc | |||
| 518 | $(sndrv_pcm_ioctl_array) \ | 525 | $(sndrv_pcm_ioctl_array) \ |
| 519 | $(sndrv_ctl_ioctl_array) \ | 526 | $(sndrv_ctl_ioctl_array) \ |
| 520 | $(kvm_ioctl_array) \ | 527 | $(kvm_ioctl_array) \ |
| 521 | $(vhost_virtio_ioctl_array) | 528 | $(vhost_virtio_ioctl_array) \ |
| 529 | $(perf_ioctl_array) | ||
| 522 | 530 | ||
| 523 | $(OUTPUT)%.o: %.c prepare FORCE | 531 | $(OUTPUT)%.o: %.c prepare FORCE |
| 524 | $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@ | 532 | $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@ |
| @@ -788,7 +796,8 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clea | |||
| 788 | $(OUTPUT)$(sndrv_ctl_ioctl_array) \ | 796 | $(OUTPUT)$(sndrv_ctl_ioctl_array) \ |
| 789 | $(OUTPUT)$(sndrv_pcm_ioctl_array) \ | 797 | $(OUTPUT)$(sndrv_pcm_ioctl_array) \ |
| 790 | $(OUTPUT)$(kvm_ioctl_array) \ | 798 | $(OUTPUT)$(kvm_ioctl_array) \ |
| 791 | $(OUTPUT)$(vhost_virtio_ioctl_array) | 799 | $(OUTPUT)$(vhost_virtio_ioctl_array) \ |
| 800 | $(OUTPUT)$(perf_ioctl_array) | ||
| 792 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean | 801 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean |
| 793 | $(python-clean) | 802 | $(python-clean) |
| 794 | 803 | ||
diff --git a/tools/perf/trace/beauty/ioctl.c b/tools/perf/trace/beauty/ioctl.c index 95434b27873d..1be3b4cf0827 100644 --- a/tools/perf/trace/beauty/ioctl.c +++ b/tools/perf/trace/beauty/ioctl.c | |||
| @@ -101,6 +101,17 @@ static size_t ioctl__scnprintf_vhost_virtio_cmd(int nr, int dir, char *bf, size_ | |||
| 101 | return scnprintf(bf, size, "(%#x, %#x, %#x)", 0xAF, nr, dir); | 101 | return scnprintf(bf, size, "(%#x, %#x, %#x)", 0xAF, nr, dir); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | static size_t ioctl__scnprintf_perf_cmd(int nr, int dir, char *bf, size_t size) | ||
| 105 | { | ||
| 106 | #include "trace/beauty/generated/ioctl/perf_ioctl_array.c" | ||
| 107 | static DEFINE_STRARRAY(perf_ioctl_cmds); | ||
| 108 | |||
| 109 | if (nr < strarray__perf_ioctl_cmds.nr_entries && strarray__perf_ioctl_cmds.entries[nr] != NULL) | ||
| 110 | return scnprintf(bf, size, "PERF_%s", strarray__perf_ioctl_cmds.entries[nr]); | ||
| 111 | |||
| 112 | return scnprintf(bf, size, "(%#x, %#x, %#x)", 0xAE, nr, dir); | ||
| 113 | } | ||
| 114 | |||
| 104 | static size_t ioctl__scnprintf_cmd(unsigned long cmd, char *bf, size_t size) | 115 | static size_t ioctl__scnprintf_cmd(unsigned long cmd, char *bf, size_t size) |
| 105 | { | 116 | { |
| 106 | int dir = _IOC_DIR(cmd), | 117 | int dir = _IOC_DIR(cmd), |
| @@ -112,12 +123,13 @@ static size_t ioctl__scnprintf_cmd(unsigned long cmd, char *bf, size_t size) | |||
| 112 | int type; | 123 | int type; |
| 113 | size_t (*scnprintf)(int nr, int dir, char *bf, size_t size); | 124 | size_t (*scnprintf)(int nr, int dir, char *bf, size_t size); |
| 114 | } ioctl_types[] = { /* Must be ordered by type */ | 125 | } ioctl_types[] = { /* Must be ordered by type */ |
| 115 | { .type = 'A', .scnprintf = ioctl__scnprintf_sndrv_pcm_cmd, }, | 126 | { .type = '$', .scnprintf = ioctl__scnprintf_perf_cmd, }, |
| 116 | ['T' - 'A']= { .type = 'T', .scnprintf = ioctl__scnprintf_tty_cmd, }, | 127 | ['A' - '$'] = { .type = 'A', .scnprintf = ioctl__scnprintf_sndrv_pcm_cmd, }, |
| 117 | ['U' - 'A']= { .type = 'U', .scnprintf = ioctl__scnprintf_sndrv_ctl_cmd, }, | 128 | ['T' - '$'] = { .type = 'T', .scnprintf = ioctl__scnprintf_tty_cmd, }, |
| 118 | ['d' - 'A'] = { .type = 'd', .scnprintf = ioctl__scnprintf_drm_cmd, }, | 129 | ['U' - '$'] = { .type = 'U', .scnprintf = ioctl__scnprintf_sndrv_ctl_cmd, }, |
| 119 | [0xAE - 'A'] = { .type = 0xAE, .scnprintf = ioctl__scnprintf_kvm_cmd, }, | 130 | ['d' - '$'] = { .type = 'd', .scnprintf = ioctl__scnprintf_drm_cmd, }, |
| 120 | [0xAF - 'A'] = { .type = 0xAF, .scnprintf = ioctl__scnprintf_vhost_virtio_cmd, }, | 131 | [0xAE - '$'] = { .type = 0xAE, .scnprintf = ioctl__scnprintf_kvm_cmd, }, |
| 132 | [0xAF - '$'] = { .type = 0xAF, .scnprintf = ioctl__scnprintf_vhost_virtio_cmd, }, | ||
| 121 | }; | 133 | }; |
| 122 | const int nr_types = ARRAY_SIZE(ioctl_types); | 134 | const int nr_types = ARRAY_SIZE(ioctl_types); |
| 123 | 135 | ||
diff --git a/tools/perf/trace/beauty/perf_ioctl.sh b/tools/perf/trace/beauty/perf_ioctl.sh new file mode 100755 index 000000000000..faea4237c793 --- /dev/null +++ b/tools/perf/trace/beauty/perf_ioctl.sh | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | header_dir=$1 | ||
| 4 | |||
| 5 | printf "static const char *perf_ioctl_cmds[] = {\n" | ||
| 6 | regex='^#[[:space:]]*define[[:space:]]+PERF_EVENT_IOC_(\w+)[[:space:]]+_IO[RW]*[[:space:]]*\([[:space:]]*.\$.[[:space:]]*,[[:space:]]*([[:digit:]]+).*' | ||
| 7 | egrep $regex ${header_dir}/perf_event.h | \ | ||
| 8 | sed -r "s/$regex/\2 \1/g" | \ | ||
| 9 | sort | xargs printf "\t[%s] = \"%s\",\n" | ||
| 10 | printf "};\n" | ||
