Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf list: Do event name substring search as last resort when no events found

Before:

# perf list _alloc_ | head -10
#

After:

# perf list _alloc_ | head -10
ext4:ext4_alloc_da_blocks [Tracepoint event]
ext4:ext4_get_implied_cluster_alloc_exit [Tracepoint event]
kmem:kmem_cache_alloc_node [Tracepoint event]
kmem:mm_page_alloc_extfrag [Tracepoint event]
kmem:mm_page_alloc_zone_locked [Tracepoint event]
xen:xen_mmu_alloc_ptpage [Tracepoint event]
#

And it works for all types of events:

# perf list br

List of pre-defined events (to be used in -e):

branch-instructions OR branches [Hardware event]
branch-misses [Hardware event]

branch-load-misses [Hardware cache event]
branch-loads [Hardware cache event]

branch-instructions OR cpu/branch-instructions/ [Kernel PMU event]
branch-misses OR cpu/branch-misses/ [Kernel PMU event]

filelock:break_lease_block [Tracepoint event]
filelock:break_lease_noblock [Tracepoint event]
filelock:break_lease_unblock [Tracepoint event]
syscalls:sys_enter_brk [Tracepoint event]
syscalls:sys_exit_brk [Tracepoint event]

#

Suggested-by: Ingo Molnar <mingo@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-qieivl18jdemoaghgndj36e6@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+18 -2
+2
tools/perf/Documentation/perf-list.txt
··· 125 125 . If none of the above is matched, it will apply the supplied glob to all 126 126 events, printing the ones that match. 127 127 128 + . As a last resort, it will do a substring search in all event names. 129 + 128 130 One or more types can be used at the same time, listing the events for the 129 131 types specified. 130 132
+16 -2
tools/perf/builtin-list.c
··· 45 45 } 46 46 47 47 for (i = 0; i < argc; ++i) { 48 + char *sep, *s; 49 + 48 50 if (strcmp(argv[i], "tracepoint") == 0) 49 51 print_tracepoint_events(NULL, NULL, raw_dump); 50 52 else if (strcmp(argv[i], "hw") == 0 || ··· 62 60 print_hwcache_events(NULL, raw_dump); 63 61 else if (strcmp(argv[i], "pmu") == 0) 64 62 print_pmu_events(NULL, raw_dump); 65 - else { 66 - char *sep = strchr(argv[i], ':'), *s; 63 + else if ((sep = strchr(argv[i], ':')) != NULL) { 67 64 int sep_idx; 68 65 69 66 if (sep == NULL) { ··· 76 75 77 76 s[sep_idx] = '\0'; 78 77 print_tracepoint_events(s, s + sep_idx + 1, raw_dump); 78 + free(s); 79 + } else { 80 + if (asprintf(&s, "*%s*", argv[i]) < 0) { 81 + printf("Critical: Not enough memory! Trying to continue...\n"); 82 + continue; 83 + } 84 + print_symbol_events(s, PERF_TYPE_HARDWARE, 85 + event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump); 86 + print_symbol_events(s, PERF_TYPE_SOFTWARE, 87 + event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump); 88 + print_hwcache_events(s, raw_dump); 89 + print_pmu_events(s, raw_dump); 90 + print_tracepoint_events(NULL, s, raw_dump); 79 91 free(s); 80 92 } 81 93 }