perf env: Introduce perf_env__arch_strerrno()
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 1 Dec 2023 17:52:00 +0000 (14:52 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 4 Dec 2023 19:42:09 +0000 (16:42 -0300)
That will cache the arch specific function translating error numbers to
strings.

Reviewed-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Laight <David.Laight@ACULAB.COM>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/lkml/20231201203046.486596-2-acme@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-trace.c
tools/perf/util/env.c
tools/perf/util/env.h

index e541d0e2777ab935a6274d0a8aeaa46ffe3f8247..109b8e64fe69ae32fee0ee7b6937d260d32b6203 100644 (file)
@@ -2470,9 +2470,8 @@ static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sam
 static const char *errno_to_name(struct evsel *evsel, int err)
 {
        struct perf_env *env = evsel__env(evsel);
-       const char *arch_name = perf_env__arch(env);
 
-       return arch_syscalls__strerrno(arch_name, err);
+       return perf_env__arch_strerrno(env, err);
 }
 
 static int trace__sys_exit(struct trace *trace, struct evsel *evsel,
@@ -4264,12 +4263,11 @@ static size_t thread__dump_stats(struct thread_trace *ttrace,
                        printed += fprintf(fp, " %9.3f %9.2f%%\n", max, pct);
 
                        if (trace->errno_summary && stats->nr_failures) {
-                               const char *arch_name = perf_env__arch(trace->host->env);
                                int e;
 
                                for (e = 0; e < stats->max_errno; ++e) {
                                        if (stats->errnos[e] != 0)
-                                               fprintf(fp, "\t\t\t\t%s: %d\n", arch_syscalls__strerrno(arch_name, e + 1), stats->errnos[e]);
+                                               fprintf(fp, "\t\t\t\t%s: %d\n", perf_env__arch_strerrno(trace->host->env, e + 1), stats->errnos[e]);
                                }
                        }
                }
index cbc18b22ace5231eb1101ab6dfd95b1b23995057..a632f33646bb3afbca5d8f168dff78f918a269f6 100644 (file)
@@ -3,6 +3,7 @@
 #include "debug.h"
 #include "env.h"
 #include "util/header.h"
+#include "linux/compiler.h"
 #include <linux/ctype.h>
 #include <linux/zalloc.h>
 #include "cgroup.h"
@@ -12,6 +13,7 @@
 #include <string.h>
 #include "pmus.h"
 #include "strbuf.h"
+#include "trace/beauty/beauty.h"
 
 struct perf_env perf_env;
 
@@ -453,6 +455,16 @@ const char *perf_env__arch(struct perf_env *env)
        return normalize_arch(arch_name);
 }
 
+const char *perf_env__arch_strerrno(struct perf_env *env __maybe_unused, int err __maybe_unused)
+{
+#if defined(HAVE_SYSCALL_TABLE_SUPPORT) && defined(HAVE_LIBTRACEEVENT)
+       const char *arch_name = perf_env__arch(env);
+       return arch_syscalls__strerrno(arch_name, err);
+#else
+       return "!(HAVE_SYSCALL_TABLE_SUPPORT && HAVE_LIBTRACEEVENT)";
+#endif
+}
+
 const char *perf_env__cpuid(struct perf_env *env)
 {
        int status;
index 94596ff124d541884a6d1573f00f09d7cf81029e..79f371879f45bafc24309b884e6129fce6c781c1 100644 (file)
@@ -164,6 +164,7 @@ int perf_env__read_cpu_topology_map(struct perf_env *env);
 void cpu_cache_level__free(struct cpu_cache_level *cache);
 
 const char *perf_env__arch(struct perf_env *env);
+const char *perf_env__arch_strerrno(struct perf_env *env, int err);
 const char *perf_env__cpuid(struct perf_env *env);
 const char *perf_env__raw_arch(struct perf_env *env);
 int perf_env__nr_cpus_avail(struct perf_env *env);