mirror of
https://github.com/torvalds/linux.git
synced 2026-05-26 08:02:27 +02:00
perf annotate: Factor out evsel__get_arch()
The evsel__get_arch() is to get architecture info from the environment. It'll be used by other places later so let's factor it out. Also add arch__is() to check the arch info by name. Committer notes: "get" is usually associated with refcounting, so we better rename this at some point to a better name. Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: linux-toolchains@vger.kernel.org Cc: linux-trace-devel@vger.kernel.org Link: https://lore.kernel.org/r/20231213001323.718046-6-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
fc044c53b9
commit
0669729eb0
|
|
@ -843,6 +843,11 @@ static struct arch *arch__find(const char *name)
|
||||||
return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key_cmp);
|
return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key_cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool arch__is(struct arch *arch, const char *name)
|
||||||
|
{
|
||||||
|
return !strcmp(arch->name, name);
|
||||||
|
}
|
||||||
|
|
||||||
static struct annotated_source *annotated_source__new(void)
|
static struct annotated_source *annotated_source__new(void)
|
||||||
{
|
{
|
||||||
struct annotated_source *src = zalloc(sizeof(*src));
|
struct annotated_source *src = zalloc(sizeof(*src));
|
||||||
|
|
@ -2378,6 +2383,33 @@ void symbol__calc_percent(struct symbol *sym, struct evsel *evsel)
|
||||||
annotation__calc_percent(notes, evsel, symbol__size(sym));
|
annotation__calc_percent(notes, evsel, symbol__size(sym));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int evsel__get_arch(struct evsel *evsel, struct arch **parch)
|
||||||
|
{
|
||||||
|
struct perf_env *env = evsel__env(evsel);
|
||||||
|
const char *arch_name = perf_env__arch(env);
|
||||||
|
struct arch *arch;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (!arch_name)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
*parch = arch = arch__find(arch_name);
|
||||||
|
if (arch == NULL) {
|
||||||
|
pr_err("%s: unsupported arch %s\n", __func__, arch_name);
|
||||||
|
return ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arch->init) {
|
||||||
|
err = arch->init(arch, env ? env->cpuid : NULL);
|
||||||
|
if (err) {
|
||||||
|
pr_err("%s: failed to initialize %s arch priv area\n",
|
||||||
|
__func__, arch->name);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
|
int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
|
||||||
struct arch **parch)
|
struct arch **parch)
|
||||||
{
|
{
|
||||||
|
|
@ -2387,31 +2419,17 @@ int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
|
||||||
.evsel = evsel,
|
.evsel = evsel,
|
||||||
.options = &annotate_opts,
|
.options = &annotate_opts,
|
||||||
};
|
};
|
||||||
struct perf_env *env = evsel__env(evsel);
|
struct arch *arch = NULL;
|
||||||
const char *arch_name = perf_env__arch(env);
|
|
||||||
struct arch *arch;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!arch_name)
|
err = evsel__get_arch(evsel, &arch);
|
||||||
return errno;
|
if (err < 0)
|
||||||
|
return err;
|
||||||
args.arch = arch = arch__find(arch_name);
|
|
||||||
if (arch == NULL) {
|
|
||||||
pr_err("%s: unsupported arch %s\n", __func__, arch_name);
|
|
||||||
return ENOTSUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parch)
|
if (parch)
|
||||||
*parch = arch;
|
*parch = arch;
|
||||||
|
|
||||||
if (arch->init) {
|
args.arch = arch;
|
||||||
err = arch->init(arch, env ? env->cpuid : NULL);
|
|
||||||
if (err) {
|
|
||||||
pr_err("%s: failed to initialize %s arch priv area\n", __func__, arch->name);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
args.ms = *ms;
|
args.ms = *ms;
|
||||||
if (annotate_opts.full_addr)
|
if (annotate_opts.full_addr)
|
||||||
notes->start = map__objdump_2mem(ms->map, ms->sym->start);
|
notes->start = map__objdump_2mem(ms->map, ms->sym->start);
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,8 @@ struct ins_operands {
|
||||||
|
|
||||||
struct arch;
|
struct arch;
|
||||||
|
|
||||||
|
bool arch__is(struct arch *arch, const char *name);
|
||||||
|
|
||||||
struct ins_ops {
|
struct ins_ops {
|
||||||
void (*free)(struct ins_operands *ops);
|
void (*free)(struct ins_operands *ops);
|
||||||
int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);
|
int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user