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

perf trace: Avoid global perf_env with evsel__env

There is no session in perf trace unless in replay mode, so in host
mode no session can be associated with the evlist. If the evsel__env
call fails resort to the host_env that's part of the trace. Remove
errno_to_name as it becomes a called once 1-line function once the
argument is turned into a perf_env, just call perf_env__arch_strerrno
directly.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250724163302.596743-19-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
003a86bc 69ac7472

+3 -9
+3 -9
tools/perf/builtin-trace.c
··· 2898 2898 return sample__fprintf_callchain(sample, 38, print_opts, get_tls_callchain_cursor(), symbol_conf.bt_stop_list, trace->output); 2899 2899 } 2900 2900 2901 - static const char *errno_to_name(struct evsel *evsel, int err) 2902 - { 2903 - struct perf_env *env = evsel__env(evsel); 2904 - 2905 - return perf_env__arch_strerrno(env, err); 2906 - } 2907 - 2908 2901 static int trace__sys_exit(struct trace *trace, struct evsel *evsel, 2909 2902 union perf_event *event __maybe_unused, 2910 2903 struct perf_sample *sample) ··· 2983 2990 } else if (ret < 0) { 2984 2991 errno_print: { 2985 2992 char bf[STRERR_BUFSIZE]; 2986 - const char *emsg = str_error_r(-ret, bf, sizeof(bf)), 2987 - *e = errno_to_name(evsel, -ret); 2993 + struct perf_env *env = evsel__env(evsel) ?: &trace->host_env; 2994 + const char *emsg = str_error_r(-ret, bf, sizeof(bf)); 2995 + const char *e = perf_env__arch_strerrno(env, err); 2988 2996 2989 2997 fprintf(trace->output, "-1 %s (%s)", e, emsg); 2990 2998 }