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

perf list: Add tracepoint encoding to detailed output

The tracepoint id holds the config value and is probed in determining
what an event is. Add reading of the id so that we can display the
event encoding as:

$ perf list --details
...
alarmtimer:alarmtimer_cancel [Tracepoint event]
tracepoint/config=0x18c/
...

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20240308001915.4060155-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
525615ef 2316ef58

+26 -11
+26 -11
tools/perf/util/print-events.c
··· 9 9 #include <unistd.h> 10 10 11 11 #include <api/fs/tracing_path.h> 12 + #include <api/io.h> 12 13 #include <linux/stddef.h> 13 14 #include <linux/perf_event.h> 14 15 #include <linux/zalloc.h> ··· 93 92 94 93 evt_items = scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NULL, alphasort); 95 94 for (int j = 0; j < evt_items; j++) { 95 + /* 96 + * Buffer sized at twice the max filename length + 1 97 + * separator + 1 \0 terminator. 98 + */ 99 + char buf[NAME_MAX * 2 + 2]; 100 + /* 16 possible hex digits and 22 other characters and \0. */ 101 + char encoding[16 + 22]; 96 102 struct dirent *evt_dirent = evt_namelist[j]; 97 - char evt_path[MAXPATHLEN]; 98 - int evt_fd; 103 + struct io id; 104 + __u64 config; 99 105 100 106 if (evt_dirent->d_type != DT_DIR || 101 107 !strcmp(evt_dirent->d_name, ".") || 102 108 !strcmp(evt_dirent->d_name, "..")) 103 109 goto next_evt; 104 110 105 - snprintf(evt_path, sizeof(evt_path), "%s/id", evt_dirent->d_name); 106 - evt_fd = openat(dir_fd, evt_path, O_RDONLY); 107 - if (evt_fd < 0) 108 - goto next_evt; 109 - close(evt_fd); 111 + snprintf(buf, sizeof(buf), "%s/id", evt_dirent->d_name); 112 + io__init(&id, openat(dir_fd, buf, O_RDONLY), buf, sizeof(buf)); 110 113 111 - snprintf(evt_path, MAXPATHLEN, "%s:%s", 114 + if (id.fd < 0) 115 + goto next_evt; 116 + 117 + if (io__get_dec(&id, &config) < 0) { 118 + close(id.fd); 119 + goto next_evt; 120 + } 121 + close(id.fd); 122 + 123 + snprintf(buf, sizeof(buf), "%s:%s", 112 124 sys_dirent->d_name, evt_dirent->d_name); 125 + snprintf(encoding, sizeof(encoding), "tracepoint/config=0x%llx/", config); 113 126 print_cb->print_event(print_state, 114 127 /*topic=*/NULL, 115 - /*pmu_name=*/NULL, 116 - evt_path, 128 + /*pmu_name=*/NULL, /* really "tracepoint" */ 129 + /*event_name=*/buf, 117 130 /*event_alias=*/NULL, 118 131 /*scale_unit=*/NULL, 119 132 /*deprecated=*/false, 120 133 "Tracepoint event", 121 134 /*desc=*/NULL, 122 135 /*long_desc=*/NULL, 123 - /*encoding_desc=*/NULL); 136 + encoding); 124 137 next_evt: 125 138 free(evt_namelist[j]); 126 139 }