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

perf list: Remove tracepoint printing code

Now that the tp_pmu can iterate and describe events remove the custom
tracepoint printing logic, this avoids perf list showing the
tracepoint events twice.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/r/20250725185202.68671-7-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
55c09681 45b6e281

+23 -101
+23 -6
tools/perf/builtin-list.c
··· 614 614 for (i = 0; i < argc; ++i) { 615 615 char *sep, *s; 616 616 617 - if (strcmp(argv[i], "tracepoint") == 0) 618 - print_tracepoint_events(&print_cb, ps); 619 - else if (strcmp(argv[i], "hw") == 0 || 617 + if (strcmp(argv[i], "tracepoint") == 0) { 618 + char *old_pmu_glob = default_ps.pmu_glob; 619 + 620 + default_ps.pmu_glob = strdup("tracepoint"); 621 + if (!default_ps.pmu_glob) { 622 + ret = -1; 623 + goto out; 624 + } 625 + perf_pmus__print_pmu_events(&print_cb, ps); 626 + zfree(&default_ps.pmu_glob); 627 + default_ps.pmu_glob = old_pmu_glob; 628 + } else if (strcmp(argv[i], "hw") == 0 || 620 629 strcmp(argv[i], "hardware") == 0) 621 630 print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE, 622 631 event_symbols_hw, PERF_COUNT_HW_MAX); ··· 667 658 #endif 668 659 else if ((sep = strchr(argv[i], ':')) != NULL) { 669 660 char *old_pmu_glob = default_ps.pmu_glob; 661 + char *old_event_glob = default_ps.event_glob; 670 662 671 663 default_ps.event_glob = strdup(argv[i]); 672 664 if (!default_ps.event_glob) { ··· 675 665 goto out; 676 666 } 677 667 678 - print_tracepoint_events(&print_cb, ps); 668 + default_ps.pmu_glob = strdup("tracepoint"); 669 + if (!default_ps.pmu_glob) { 670 + zfree(&default_ps.event_glob); 671 + ret = -1; 672 + goto out; 673 + } 674 + perf_pmus__print_pmu_events(&print_cb, ps); 675 + zfree(&default_ps.pmu_glob); 676 + default_ps.pmu_glob = old_pmu_glob; 679 677 print_sdt_events(&print_cb, ps); 680 678 default_ps.metrics = true; 681 679 default_ps.metricgroups = true; 682 680 metricgroup__print(&print_cb, ps); 683 681 zfree(&default_ps.event_glob); 684 - default_ps.pmu_glob = old_pmu_glob; 682 + default_ps.event_glob = old_event_glob; 685 683 } else { 686 684 if (asprintf(&s, "*%s*", argv[i]) < 0) { 687 685 printf("Critical: Not enough memory! Trying to continue...\n"); ··· 700 682 event_symbols_hw, PERF_COUNT_HW_MAX); 701 683 print_hwcache_events(&print_cb, ps); 702 684 perf_pmus__print_pmu_events(&print_cb, ps); 703 - print_tracepoint_events(&print_cb, ps); 704 685 print_sdt_events(&print_cb, ps); 705 686 default_ps.metrics = true; 706 687 default_ps.metricgroups = true;
-93
tools/perf/util/print-events.c
··· 44 44 "Hardware breakpoint", 45 45 }; 46 46 47 - /* 48 - * Print the events from <debugfs_mount_point>/tracing/events 49 - */ 50 - void print_tracepoint_events(const struct print_callbacks *print_cb __maybe_unused, void *print_state __maybe_unused) 51 - { 52 - char *events_path = get_tracing_file("events"); 53 - int events_fd = open(events_path, O_PATH); 54 - struct dirent **sys_namelist = NULL; 55 - int sys_items; 56 - 57 - if (events_fd < 0) { 58 - pr_err("Error: failed to open tracing events directory\n"); 59 - pr_err("%s: %s\n", events_path, strerror(errno)); 60 - return; 61 - } 62 - put_tracing_file(events_path); 63 - 64 - sys_items = tracing_events__scandir_alphasort(&sys_namelist); 65 - 66 - for (int i = 0; i < sys_items; i++) { 67 - struct dirent *sys_dirent = sys_namelist[i]; 68 - struct dirent **evt_namelist = NULL; 69 - int dir_fd; 70 - int evt_items; 71 - 72 - if (sys_dirent->d_type != DT_DIR || 73 - !strcmp(sys_dirent->d_name, ".") || 74 - !strcmp(sys_dirent->d_name, "..")) 75 - goto next_sys; 76 - 77 - dir_fd = openat(events_fd, sys_dirent->d_name, O_PATH); 78 - if (dir_fd < 0) 79 - goto next_sys; 80 - 81 - evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort); 82 - for (int j = 0; j < evt_items; j++) { 83 - /* 84 - * Buffer sized at twice the max filename length + 1 85 - * separator + 1 \0 terminator. 86 - */ 87 - char buf[NAME_MAX * 2 + 2]; 88 - /* 16 possible hex digits and 22 other characters and \0. */ 89 - char encoding[16 + 22]; 90 - struct dirent *evt_dirent = evt_namelist[j]; 91 - struct io id; 92 - __u64 config; 93 - 94 - if (evt_dirent->d_type != DT_DIR || 95 - !strcmp(evt_dirent->d_name, ".") || 96 - !strcmp(evt_dirent->d_name, "..")) 97 - goto next_evt; 98 - 99 - snprintf(buf, sizeof(buf), "%s/id", evt_dirent->d_name); 100 - io__init(&id, openat(dir_fd, buf, O_RDONLY), buf, sizeof(buf)); 101 - 102 - if (id.fd < 0) 103 - goto next_evt; 104 - 105 - if (io__get_dec(&id, &config) < 0) { 106 - close(id.fd); 107 - goto next_evt; 108 - } 109 - close(id.fd); 110 - 111 - snprintf(buf, sizeof(buf), "%s:%s", 112 - sys_dirent->d_name, evt_dirent->d_name); 113 - snprintf(encoding, sizeof(encoding), "tracepoint/config=0x%llx/", config); 114 - print_cb->print_event(print_state, 115 - /*topic=*/NULL, 116 - /*pmu_name=*/NULL, /* really "tracepoint" */ 117 - /*event_name=*/buf, 118 - /*event_alias=*/NULL, 119 - /*scale_unit=*/NULL, 120 - /*deprecated=*/false, 121 - "Tracepoint event", 122 - /*desc=*/NULL, 123 - /*long_desc=*/NULL, 124 - encoding); 125 - next_evt: 126 - free(evt_namelist[j]); 127 - } 128 - close(dir_fd); 129 - free(evt_namelist); 130 - next_sys: 131 - free(sys_namelist[i]); 132 - } 133 - 134 - free(sys_namelist); 135 - close(events_fd); 136 - } 137 - 138 47 void print_sdt_events(const struct print_callbacks *print_cb, void *print_state) 139 48 { 140 49 struct strlist *bidlist, *sdtlist; ··· 460 551 /*desc=*/NULL, 461 552 /*long_desc=*/NULL, 462 553 /*encoding_desc=*/NULL); 463 - 464 - print_tracepoint_events(print_cb, print_state); 465 554 466 555 print_sdt_events(print_cb, print_state); 467 556
-2
tools/perf/util/print-events.h
··· 37 37 void print_symbol_events(const struct print_callbacks *print_cb, void *print_state, 38 38 unsigned int type, const struct event_symbol *syms, 39 39 unsigned int max); 40 - 41 - void print_tracepoint_events(const struct print_callbacks *print_cb, void *print_state); 42 40 void metricgroup__print(const struct print_callbacks *print_cb, void *print_state); 43 41 bool is_event_supported(u8 type, u64 config); 44 42