Skip to content

Commit 0669729

Browse files
namhyungacmel
authored andcommitted
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>
1 parent fc044c5 commit 0669729

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

tools/perf/util/annotate.c

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,11 @@ static struct arch *arch__find(const char *name)
843843
return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key_cmp);
844844
}
845845

846+
bool arch__is(struct arch *arch, const char *name)
847+
{
848+
return !strcmp(arch->name, name);
849+
}
850+
846851
static struct annotated_source *annotated_source__new(void)
847852
{
848853
struct annotated_source *src = zalloc(sizeof(*src));
@@ -2378,15 +2383,8 @@ void symbol__calc_percent(struct symbol *sym, struct evsel *evsel)
23782383
annotation__calc_percent(notes, evsel, symbol__size(sym));
23792384
}
23802385

2381-
int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
2382-
struct arch **parch)
2386+
static int evsel__get_arch(struct evsel *evsel, struct arch **parch)
23832387
{
2384-
struct symbol *sym = ms->sym;
2385-
struct annotation *notes = symbol__annotation(sym);
2386-
struct annotate_args args = {
2387-
.evsel = evsel,
2388-
.options = &annotate_opts,
2389-
};
23902388
struct perf_env *env = evsel__env(evsel);
23912389
const char *arch_name = perf_env__arch(env);
23922390
struct arch *arch;
@@ -2395,23 +2393,43 @@ int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
23952393
if (!arch_name)
23962394
return errno;
23972395

2398-
args.arch = arch = arch__find(arch_name);
2396+
*parch = arch = arch__find(arch_name);
23992397
if (arch == NULL) {
24002398
pr_err("%s: unsupported arch %s\n", __func__, arch_name);
24012399
return ENOTSUP;
24022400
}
24032401

2404-
if (parch)
2405-
*parch = arch;
2406-
24072402
if (arch->init) {
24082403
err = arch->init(arch, env ? env->cpuid : NULL);
24092404
if (err) {
2410-
pr_err("%s: failed to initialize %s arch priv area\n", __func__, arch->name);
2405+
pr_err("%s: failed to initialize %s arch priv area\n",
2406+
__func__, arch->name);
24112407
return err;
24122408
}
24132409
}
2410+
return 0;
2411+
}
2412+
2413+
int symbol__annotate(struct map_symbol *ms, struct evsel *evsel,
2414+
struct arch **parch)
2415+
{
2416+
struct symbol *sym = ms->sym;
2417+
struct annotation *notes = symbol__annotation(sym);
2418+
struct annotate_args args = {
2419+
.evsel = evsel,
2420+
.options = &annotate_opts,
2421+
};
2422+
struct arch *arch = NULL;
2423+
int err;
2424+
2425+
err = evsel__get_arch(evsel, &arch);
2426+
if (err < 0)
2427+
return err;
2428+
2429+
if (parch)
2430+
*parch = arch;
24142431

2432+
args.arch = arch;
24152433
args.ms = *ms;
24162434
if (annotate_opts.full_addr)
24172435
notes->start = map__objdump_2mem(ms->map, ms->sym->start);

tools/perf/util/annotate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ struct ins_operands {
6161

6262
struct arch;
6363

64+
bool arch__is(struct arch *arch, const char *name);
65+
6466
struct ins_ops {
6567
void (*free)(struct ins_operands *ops);
6668
int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symbol *ms);

0 commit comments

Comments
 (0)