[v4,1/4] perf trace-event-info: Add tracepoint_id_to_name() helper
Commit Message
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>
---
tools/perf/util/trace-event-info.c | 11 +++++++++++
tools/perf/util/trace-event.h | 6 ++++++
2 files changed, 17 insertions(+)
@@ -466,6 +466,17 @@ static struct tracepoint_path *tracepoint_id_to_path(u64 config)
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)
+ return buf;
+
+ return NULL;
+}
+
static struct tracepoint_path *tracepoint_name_to_path(const char *name)
{
struct tracepoint_path *path = zalloc(sizeof(*path));
@@ -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;