Skip to content

Commit 696703a

Browse files
committed
perf annotate: Find 'call' instruction target symbol at parsing time
So that we do it just once, not everytime we press enter or -> on a 'call' instruction line. Cc: Adrian Hunter <[email protected]> Cc: David Ahern <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: https://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b09c236 commit 696703a

File tree

3 files changed

+27
-29
lines changed

3 files changed

+27
-29
lines changed

tools/perf/ui/browsers/annotate.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -568,35 +568,28 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
568568
struct map_symbol *ms = browser->b.priv;
569569
struct disasm_line *dl = disasm_line(browser->selection);
570570
struct annotation *notes;
571-
struct addr_map_symbol target = {
572-
.map = ms->map,
573-
.addr = map__objdump_2mem(ms->map, dl->ops.target.addr),
574-
};
575571
char title[SYM_TITLE_MAX_SIZE];
576572

577573
if (!ins__is_call(&dl->ins))
578574
return false;
579575

580-
if (map_groups__find_ams(&target) ||
581-
map__rip_2objdump(target.map, target.map->map_ip(target.map,
582-
target.addr)) !=
583-
dl->ops.target.addr) {
576+
if (!dl->ops.target.sym) {
584577
ui_helpline__puts("The called function was not found.");
585578
return true;
586579
}
587580

588-
notes = symbol__annotation(target.sym);
581+
notes = symbol__annotation(dl->ops.target.sym);
589582
pthread_mutex_lock(&notes->lock);
590583

591-
if (notes->src == NULL && symbol__alloc_hist(target.sym) < 0) {
584+
if (notes->src == NULL && symbol__alloc_hist(dl->ops.target.sym) < 0) {
592585
pthread_mutex_unlock(&notes->lock);
593586
ui__warning("Not enough memory for annotating '%s' symbol!\n",
594-
target.sym->name);
587+
dl->ops.target.sym->name);
595588
return true;
596589
}
597590

598591
pthread_mutex_unlock(&notes->lock);
599-
symbol__tui_annotate(target.sym, target.map, evsel, hbt);
592+
symbol__tui_annotate(dl->ops.target.sym, ms->map, evsel, hbt);
600593
sym_title(ms->sym, ms->map, title, sizeof(title));
601594
ui_browser__show_title(&browser->b, title);
602595
return true;

tools/perf/util/annotate.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2)
187187
static int call__parse(struct arch *arch, struct ins_operands *ops, struct map *map)
188188
{
189189
char *endptr, *tok, *name;
190+
struct addr_map_symbol target = {
191+
.map = map,
192+
};
190193

191194
ops->target.addr = strtoull(ops->raw, &endptr, 16);
192195

@@ -208,28 +211,29 @@ static int call__parse(struct arch *arch, struct ins_operands *ops, struct map *
208211
ops->target.name = strdup(name);
209212
*tok = '>';
210213

211-
return ops->target.name == NULL ? -1 : 0;
214+
if (ops->target.name == NULL)
215+
return -1;
216+
find_target:
217+
target.addr = map__objdump_2mem(map, ops->target.addr);
212218

213-
indirect_call:
214-
tok = strchr(endptr, '*');
215-
if (tok == NULL) {
216-
struct symbol *sym = map__find_symbol(map, map->map_ip(map, ops->target.addr));
217-
if (sym != NULL)
218-
ops->target.name = strdup(sym->name);
219-
else
220-
ops->target.addr = 0;
221-
return 0;
222-
}
219+
if (map_groups__find_ams(&target) == 0 &&
220+
map__rip_2objdump(target.map, map->map_ip(target.map, target.addr)) == ops->target.addr)
221+
ops->target.sym = target.sym;
223222

224-
ops->target.addr = strtoull(tok + 1, NULL, 16);
225223
return 0;
224+
225+
indirect_call:
226+
tok = strchr(endptr, '*');
227+
if (tok != NULL)
228+
ops->target.addr = strtoull(tok + 1, NULL, 16);
229+
goto find_target;
226230
}
227231

228232
static int call__scnprintf(struct ins *ins, char *bf, size_t size,
229233
struct ins_operands *ops)
230234
{
231-
if (ops->target.name)
232-
return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.name);
235+
if (ops->target.sym)
236+
return scnprintf(bf, size, "%-6s %s", ins->name, ops->target.sym->name);
233237

234238
if (ops->target.addr == 0)
235239
return ins__raw_scnprintf(ins, bf, size, ops);
@@ -1283,16 +1287,16 @@ static int symbol__parse_objdump_line(struct symbol *sym, FILE *file,
12831287
dl->ops.target.offset_avail = true;
12841288
}
12851289

1286-
/* kcore has no symbols, so add the call target name */
1287-
if (dl->ins.ops && ins__is_call(&dl->ins) && !dl->ops.target.name) {
1290+
/* kcore has no symbols, so add the call target symbol */
1291+
if (dl->ins.ops && ins__is_call(&dl->ins) && !dl->ops.target.sym) {
12881292
struct addr_map_symbol target = {
12891293
.map = map,
12901294
.addr = dl->ops.target.addr,
12911295
};
12921296

12931297
if (!map_groups__find_ams(&target) &&
12941298
target.sym->start == target.al_addr)
1295-
dl->ops.target.name = strdup(target.sym->name);
1299+
dl->ops.target.sym = target.sym;
12961300
}
12971301

12981302
annotation_line__add(&dl->al, &notes->src->source);

tools/perf/util/annotate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct ins_operands {
2424
struct {
2525
char *raw;
2626
char *name;
27+
struct symbol *sym;
2728
u64 addr;
2829
s64 offset;
2930
bool offset_avail;

0 commit comments

Comments
 (0)