[PATCH v2 03/11] perf evsel: tp_format accessing improvements

Ian Rogers posted 11 patches 9 months, 3 weeks ago
[PATCH v2 03/11] perf evsel: tp_format accessing improvements
Posted by Ian Rogers 9 months, 3 weeks ago
Ensure evsel__clone copies the tp_sys and tp_name variables.
In evsel__tp_format, if tp_sys isn't set, use the config value to find
the tp_format. This succeeds in python code where pyrf__tracepoint has
already found the format.

Reviewed-by: Howard Chu <howardchu95@gmail.com>
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/evsel.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 4a0ef095db92..1974395492d7 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -521,6 +521,16 @@ struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig)
 	}
 	evsel->cgrp = cgroup__get(orig->cgrp);
 #ifdef HAVE_LIBTRACEEVENT
+	if (orig->tp_sys) {
+		evsel->tp_sys = strdup(orig->tp_sys);
+		if (evsel->tp_sys == NULL)
+			goto out_err;
+	}
+	if (orig->tp_name) {
+		evsel->tp_name = strdup(orig->tp_name);
+		if (evsel->tp_name == NULL)
+			goto out_err;
+	}
 	evsel->tp_format = orig->tp_format;
 #endif
 	evsel->handler = orig->handler;
@@ -644,7 +654,11 @@ struct tep_event *evsel__tp_format(struct evsel *evsel)
 	if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT)
 		return NULL;
 
-	tp_format = trace_event__tp_format(evsel->tp_sys, evsel->tp_name);
+	if (!evsel->tp_sys)
+		tp_format = trace_event__tp_format_id(evsel->core.attr.config);
+	else
+		tp_format = trace_event__tp_format(evsel->tp_sys, evsel->tp_name);
+
 	if (IS_ERR(tp_format)) {
 		int err = -PTR_ERR(evsel->tp_format);
 
-- 
2.48.1.711.g2feabab25a-goog
Re: [PATCH v2 03/11] perf evsel: tp_format accessing improvements
Posted by Arnaldo Carvalho de Melo 9 months, 1 week ago
On Fri, Feb 28, 2025 at 02:23:00PM -0800, Ian Rogers wrote:
> Ensure evsel__clone copies the tp_sys and tp_name variables.
> In evsel__tp_format, if tp_sys isn't set, use the config value to find
> the tp_format. This succeeds in python code where pyrf__tracepoint has
> already found the format.

Here those two fields were introduced but evsel__clone() wasn't update
to clone those:

Fixes: 6c8310e8380d472c ("perf evsel: Allow evsel__newtp without libtraceevent")

Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>

- Arnaldo
 
> Reviewed-by: Howard Chu <howardchu95@gmail.com>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/evsel.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 4a0ef095db92..1974395492d7 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -521,6 +521,16 @@ struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig)
>  	}
>  	evsel->cgrp = cgroup__get(orig->cgrp);
>  #ifdef HAVE_LIBTRACEEVENT
> +	if (orig->tp_sys) {
> +		evsel->tp_sys = strdup(orig->tp_sys);
> +		if (evsel->tp_sys == NULL)
> +			goto out_err;
> +	}
> +	if (orig->tp_name) {
> +		evsel->tp_name = strdup(orig->tp_name);
> +		if (evsel->tp_name == NULL)
> +			goto out_err;
> +	}
>  	evsel->tp_format = orig->tp_format;
>  #endif
>  	evsel->handler = orig->handler;
> @@ -644,7 +654,11 @@ struct tep_event *evsel__tp_format(struct evsel *evsel)
>  	if (evsel->core.attr.type != PERF_TYPE_TRACEPOINT)
>  		return NULL;
>  
> -	tp_format = trace_event__tp_format(evsel->tp_sys, evsel->tp_name);
> +	if (!evsel->tp_sys)
> +		tp_format = trace_event__tp_format_id(evsel->core.attr.config);
> +	else
> +		tp_format = trace_event__tp_format(evsel->tp_sys, evsel->tp_name);
> +
>  	if (IS_ERR(tp_format)) {
>  		int err = -PTR_ERR(evsel->tp_format);
>  
> -- 
> 2.48.1.711.g2feabab25a-goog