perf trace-event-info: Add tracepoint_id_to_name() helper
authorYang Jihong <yangjihong1@huawei.com>
Fri, 23 Jun 2023 05:44:13 +0000 (05:44 +0000)
committerNamhyung Kim <namhyung@kernel.org>
Sat, 24 Jun 2023 05:30:16 +0000 (22:30 -0700)
Add tracepoint_id_to_name() helper to search for the trace events directory
by given event id and return the corresponding tracepoint.

Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: anshuman.khandual@arm.com
Cc: mark.rutland@arm.com
Cc: irogers@google.com
Cc: jesussanp@google.com
Cc: peterz@infradead.org
Cc: acme@kernel.org
Cc: jolsa@kernel.org
Cc: alexander.shishkin@linux.intel.com
Cc: mingo@redhat.com
Link: https://lore.kernel.org/r/20230623054416.160858-2-yangjihong1@huawei.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/trace-event-info.c
tools/perf/util/trace-event.h

index c24b3a15e319675b2ddf9de760ff81f1f2468854..319ccf09a4351efd30d3959545ab10b791463290 100644 (file)
@@ -466,6 +466,18 @@ next:
        return NULL;
 }
 
+char *tracepoint_id_to_name(u64 config)
+{
+       struct tracepoint_path *path = tracepoint_id_to_path(config);
+       char *buf = NULL;
+
+       if (path && asprintf(&buf, "%s:%s", path->system, path->name) < 0)
+               buf = NULL;
+
+       put_tracepoints_path(path);
+       return buf;
+}
+
 static struct tracepoint_path *tracepoint_name_to_path(const char *name)
 {
        struct tracepoint_path *path = zalloc(sizeof(*path));
index a0cff184b1cdcdc3d022c531ef520d6a2968bdff..a69ee29419f3c889f6e244413bcd5496661ec09e 100644 (file)
@@ -62,6 +62,12 @@ unsigned long long eval_flag(const char *flag);
 
 int read_tracing_data(int fd, struct list_head *pattrs);
 
+/*
+ * Return the tracepoint name in the format "subsystem:event_name",
+ * callers should free the returned string.
+ */
+char *tracepoint_id_to_name(u64 config);
+
 struct tracing_data {
        /* size is only valid if temp is 'true' */
        ssize_t size;