Skip to content

Commit 5f0fef8

Browse files
committed
perf callchain: Use 'struct map_symbol' in 'struct callchain_cursor_node'
To ease passing around map+symbol, just like done for other parts of the tree recently. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent c152973 commit 5f0fef8

9 files changed

Lines changed: 71 additions & 62 deletions

File tree

‎tools/perf/builtin-kmem.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ static u64 find_callsite(struct evsel *evsel, struct perf_sample *sample)
412412
sizeof(key), callcmp);
413413
if (!caller) {
414414
/* found */
415-
if (node->map)
416-
addr = map__unmap_ip(node->map, node->ip);
415+
if (node->ms.map)
416+
addr = map__unmap_ip(node->ms.map, node->ip);
417417
else
418418
addr = node->ip;
419419

‎tools/perf/builtin-sched.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ static void save_task_callchain(struct perf_sched *sched,
21722172
if (node == NULL)
21732173
break;
21742174

2175-
sym = node->sym;
2175+
sym = node->ms.sym;
21762176
if (sym) {
21772177
if (!strcmp(sym->name, "schedule") ||
21782178
!strcmp(sym->name, "__schedule") ||

‎tools/perf/util/callchain.c‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,8 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
582582
return -1;
583583
}
584584
call->ip = cursor_node->ip;
585-
call->ms.sym = cursor_node->sym;
586-
call->ms.map = map__get(cursor_node->map);
585+
call->ms = cursor_node->ms;
586+
map__get(call->ms.map);
587587
call->srcline = cursor_node->srcline;
588588

589589
if (cursor_node->branch) {
@@ -720,29 +720,29 @@ static enum match_result match_chain(struct callchain_cursor_node *node,
720720
/* otherwise fall-back to symbol-based comparison below */
721721
__fallthrough;
722722
case CCKEY_FUNCTION:
723-
if (node->sym && cnode->ms.sym) {
723+
if (node->ms.sym && cnode->ms.sym) {
724724
/*
725725
* Compare inlined frames based on their symbol name
726726
* because different inlined frames will have the same
727727
* symbol start. Otherwise do a faster comparison based
728728
* on the symbol start address.
729729
*/
730-
if (cnode->ms.sym->inlined || node->sym->inlined) {
730+
if (cnode->ms.sym->inlined || node->ms.sym->inlined) {
731731
match = match_chain_strings(cnode->ms.sym->name,
732-
node->sym->name);
732+
node->ms.sym->name);
733733
if (match != MATCH_ERROR)
734734
break;
735735
} else {
736736
match = match_chain_dso_addresses(cnode->ms.map, cnode->ms.sym->start,
737-
node->map, node->sym->start);
737+
node->ms.map, node->ms.sym->start);
738738
break;
739739
}
740740
}
741741
/* otherwise fall-back to IP-based comparison below */
742742
__fallthrough;
743743
case CCKEY_ADDRESS:
744744
default:
745-
match = match_chain_dso_addresses(cnode->ms.map, cnode->ip, node->map, node->ip);
745+
match = match_chain_dso_addresses(cnode->ms.map, cnode->ip, node->ms.map, node->ip);
746746
break;
747747
}
748748

@@ -1004,8 +1004,7 @@ merge_chain_branch(struct callchain_cursor *cursor,
10041004
int err = 0;
10051005

10061006
list_for_each_entry_safe(list, next_list, &src->val, list) {
1007-
callchain_cursor_append(cursor, list->ip,
1008-
list->ms.map, list->ms.sym,
1007+
callchain_cursor_append(cursor, list->ip, &list->ms,
10091008
false, NULL, 0, 0, 0, list->srcline);
10101009
list_del_init(&list->list);
10111010
map__zput(list->ms.map);
@@ -1044,7 +1043,7 @@ int callchain_merge(struct callchain_cursor *cursor,
10441043
}
10451044

10461045
int callchain_cursor_append(struct callchain_cursor *cursor,
1047-
u64 ip, struct map *map, struct symbol *sym,
1046+
u64 ip, struct map_symbol *ms,
10481047
bool branch, struct branch_flags *flags,
10491048
int nr_loop_iter, u64 iter_cycles, u64 branch_from,
10501049
const char *srcline)
@@ -1060,9 +1059,9 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
10601059
}
10611060

10621061
node->ip = ip;
1063-
map__zput(node->map);
1064-
node->map = map__get(map);
1065-
node->sym = sym;
1062+
map__zput(node->ms.map);
1063+
node->ms = *ms;
1064+
map__get(node->ms.map);
10661065
node->branch = branch;
10671066
node->nr_loop_iter = nr_loop_iter;
10681067
node->iter_cycles = iter_cycles;
@@ -1107,8 +1106,8 @@ int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *samp
11071106
int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node,
11081107
bool hide_unresolved)
11091108
{
1110-
al->map = node->map;
1111-
al->sym = node->sym;
1109+
al->map = node->ms.map;
1110+
al->sym = node->ms.sym;
11121111
al->srcline = node->srcline;
11131112
al->addr = node->ip;
11141113

@@ -1571,7 +1570,7 @@ int callchain_cursor__copy(struct callchain_cursor *dst,
15711570
if (node == NULL)
15721571
break;
15731572

1574-
rc = callchain_cursor_append(dst, node->ip, node->map, node->sym,
1573+
rc = callchain_cursor_append(dst, node->ip, &node->ms,
15751574
node->branch, &node->branch_flags,
15761575
node->nr_loop_iter,
15771576
node->iter_cycles,
@@ -1597,5 +1596,5 @@ void callchain_cursor_reset(struct callchain_cursor *cursor)
15971596
cursor->last = &cursor->first;
15981597

15991598
for (node = cursor->first; node != NULL; node = node->next)
1600-
map__zput(node->map);
1599+
map__zput(node->ms.map);
16011600
}

‎tools/perf/util/callchain.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ struct callchain_list {
141141
*/
142142
struct callchain_cursor_node {
143143
u64 ip;
144-
struct map *map;
145-
struct symbol *sym;
144+
struct map_symbol ms;
146145
const char *srcline;
147146
bool branch;
148147
struct branch_flags branch_flags;
@@ -195,7 +194,7 @@ int callchain_merge(struct callchain_cursor *cursor,
195194
void callchain_cursor_reset(struct callchain_cursor *cursor);
196195

197196
int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip,
198-
struct map *map, struct symbol *sym,
197+
struct map_symbol *ms,
199198
bool branch, struct branch_flags *flags,
200199
int nr_loop_iter, u64 iter_cycles, u64 branch_from,
201200
const char *srcline);

‎tools/perf/util/db-export.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ static struct call_path *call_path_from_sample(struct db_export *dbe,
249249
* constructing an addr_location struct and then passing it to
250250
* db_ids_from_al() to perform the export.
251251
*/
252-
al.sym = node->sym;
253-
al.map = node->map;
252+
al.sym = node->ms.sym;
253+
al.map = node->ms.map;
254254
al.mg = thread->mg;
255255
al.addr = node->ip;
256256

‎tools/perf/util/evsel_fprintf.c‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,18 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
125125
callchain_cursor_commit(cursor);
126126

127127
while (1) {
128+
struct symbol *sym;
129+
struct map *map;
128130
u64 addr = 0;
129131

130132
node = callchain_cursor_current(cursor);
131133
if (!node)
132134
break;
133135

134-
if (node->sym && node->sym->ignore && print_skip_ignored)
136+
sym = node->ms.sym;
137+
map = node->ms.map;
138+
139+
if (sym && sym->ignore && print_skip_ignored)
135140
goto next;
136141

137142
printed += fprintf(fp, "%-*.*s", left_alignment, left_alignment, " ");
@@ -142,42 +147,42 @@ int sample__fprintf_callchain(struct perf_sample *sample, int left_alignment,
142147
if (print_ip)
143148
printed += fprintf(fp, "%c%16" PRIx64, s, node->ip);
144149

145-
if (node->map)
146-
addr = node->map->map_ip(node->map, node->ip);
150+
if (map)
151+
addr = map->map_ip(map, node->ip);
147152

148153
if (print_sym) {
149154
printed += fprintf(fp, " ");
150155
node_al.addr = addr;
151-
node_al.map = node->map;
156+
node_al.map = map;
152157

153158
if (print_symoffset) {
154-
printed += __symbol__fprintf_symname_offs(node->sym, &node_al,
159+
printed += __symbol__fprintf_symname_offs(sym, &node_al,
155160
print_unknown_as_addr,
156161
true, fp);
157162
} else {
158-
printed += __symbol__fprintf_symname(node->sym, &node_al,
163+
printed += __symbol__fprintf_symname(sym, &node_al,
159164
print_unknown_as_addr, fp);
160165
}
161166
}
162167

163-
if (print_dso && (!node->sym || !node->sym->inlined)) {
168+
if (print_dso && (!sym || !sym->inlined)) {
164169
printed += fprintf(fp, " (");
165-
printed += map__fprintf_dsoname(node->map, fp);
170+
printed += map__fprintf_dsoname(map, fp);
166171
printed += fprintf(fp, ")");
167172
}
168173

169174
if (print_srcline)
170-
printed += map__fprintf_srcline(node->map, addr, "\n ", fp);
175+
printed += map__fprintf_srcline(map, addr, "\n ", fp);
171176

172-
if (node->sym && node->sym->inlined)
177+
if (sym && sym->inlined)
173178
printed += fprintf(fp, " (inlined)");
174179

175180
if (!print_oneline)
176181
printed += fprintf(fp, "\n");
177182

178183
/* Add srccode here too? */
179-
if (bt_stop_list && node->sym &&
180-
strlist__has_entry(bt_stop_list, node->sym->name)) {
184+
if (bt_stop_list && sym &&
185+
strlist__has_entry(bt_stop_list, sym->name)) {
181186
break;
182187
}
183188

‎tools/perf/util/machine.c‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,8 +2006,9 @@ struct mem_info *sample__resolve_mem(struct perf_sample *sample,
20062006
return mi;
20072007
}
20082008

2009-
static char *callchain_srcline(struct map *map, struct symbol *sym, u64 ip)
2009+
static char *callchain_srcline(struct map_symbol *ms, u64 ip)
20102010
{
2011+
struct map *map = ms->map;
20112012
char *srcline = NULL;
20122013

20132014
if (!map || callchain_param.key == CCKEY_FUNCTION)
@@ -2019,7 +2020,7 @@ static char *callchain_srcline(struct map *map, struct symbol *sym, u64 ip)
20192020
bool show_addr = callchain_param.key == CCKEY_ADDRESS;
20202021

20212022
srcline = get_srcline(map->dso, map__rip_2objdump(map, ip),
2022-
sym, show_sym, show_addr, ip);
2023+
ms->sym, show_sym, show_addr, ip);
20232024
srcline__tree_insert(&map->dso->srclines, ip, srcline);
20242025
}
20252026

@@ -2042,6 +2043,7 @@ static int add_callchain_ip(struct thread *thread,
20422043
struct iterations *iter,
20432044
u64 branch_from)
20442045
{
2046+
struct map_symbol ms;
20452047
struct addr_location al;
20462048
int nr_loop_iter = 0;
20472049
u64 iter_cycles = 0;
@@ -2099,8 +2101,10 @@ static int add_callchain_ip(struct thread *thread,
20992101
iter_cycles = iter->cycles;
21002102
}
21012103

2102-
srcline = callchain_srcline(al.map, al.sym, al.addr);
2103-
return callchain_cursor_append(cursor, ip, al.map, al.sym,
2104+
ms.map = al.map;
2105+
ms.sym = al.sym;
2106+
srcline = callchain_srcline(&ms, al.addr);
2107+
return callchain_cursor_append(cursor, ip, &ms,
21042108
branch, flags, nr_loop_iter,
21052109
iter_cycles, branch_from, srcline);
21062110
}
@@ -2472,8 +2476,11 @@ static int append_inlines(struct callchain_cursor *cursor, struct map_symbol *ms
24722476
}
24732477

24742478
list_for_each_entry(ilist, &inline_node->val, list) {
2475-
ret = callchain_cursor_append(cursor, ip, map,
2476-
ilist->symbol, false,
2479+
struct map_symbol ilist_ms = {
2480+
.map = map,
2481+
.sym = ilist->symbol,
2482+
};
2483+
ret = callchain_cursor_append(cursor, ip, &ilist_ms, false,
24772484
NULL, 0, 0, 0, ilist->srcline);
24782485

24792486
if (ret != 0)
@@ -2502,9 +2509,8 @@ static int unwind_entry(struct unwind_entry *entry, void *arg)
25022509
if (entry->ms.map)
25032510
addr = map__map_ip(entry->ms.map, entry->ip);
25042511

2505-
srcline = callchain_srcline(entry->ms.map, entry->ms.sym, addr);
2506-
return callchain_cursor_append(cursor, entry->ip,
2507-
entry->ms.map, entry->ms.sym,
2512+
srcline = callchain_srcline(&entry->ms, addr);
2513+
return callchain_cursor_append(cursor, entry->ip, &entry->ms,
25082514
false, NULL, 0, 0, 0, srcline);
25092515
}
25102516

‎tools/perf/util/scripting-engines/trace-event-perl.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,26 +294,26 @@ static SV *perl_process_callchain(struct perf_sample *sample,
294294
goto exit;
295295
}
296296

297-
if (node->sym) {
297+
if (node->ms.sym) {
298298
HV *sym = newHV();
299299
if (!sym) {
300300
hv_undef(elem);
301301
goto exit;
302302
}
303-
if (!hv_stores(sym, "start", newSVuv(node->sym->start)) ||
304-
!hv_stores(sym, "end", newSVuv(node->sym->end)) ||
305-
!hv_stores(sym, "binding", newSVuv(node->sym->binding)) ||
306-
!hv_stores(sym, "name", newSVpvn(node->sym->name,
307-
node->sym->namelen)) ||
303+
if (!hv_stores(sym, "start", newSVuv(node->ms.sym->start)) ||
304+
!hv_stores(sym, "end", newSVuv(node->ms.sym->end)) ||
305+
!hv_stores(sym, "binding", newSVuv(node->ms.sym->binding)) ||
306+
!hv_stores(sym, "name", newSVpvn(node->ms.sym->name,
307+
node->ms.sym->namelen)) ||
308308
!hv_stores(elem, "sym", newRV_noinc((SV*)sym))) {
309309
hv_undef(sym);
310310
hv_undef(elem);
311311
goto exit;
312312
}
313313
}
314314

315-
if (node->map) {
316-
struct map *map = node->map;
315+
if (node->ms.map) {
316+
struct map *map = node->ms.map;
317317
const char *dsoname = "[unknown]";
318318
if (map && map->dso) {
319319
if (symbol_conf.show_kernel_path && map->dso->long_name)

‎tools/perf/util/scripting-engines/trace-event-python.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,24 +428,24 @@ static PyObject *python_process_callchain(struct perf_sample *sample,
428428
pydict_set_item_string_decref(pyelem, "ip",
429429
PyLong_FromUnsignedLongLong(node->ip));
430430

431-
if (node->sym) {
431+
if (node->ms.sym) {
432432
PyObject *pysym = PyDict_New();
433433
if (!pysym)
434434
Py_FatalError("couldn't create Python dictionary");
435435
pydict_set_item_string_decref(pysym, "start",
436-
PyLong_FromUnsignedLongLong(node->sym->start));
436+
PyLong_FromUnsignedLongLong(node->ms.sym->start));
437437
pydict_set_item_string_decref(pysym, "end",
438-
PyLong_FromUnsignedLongLong(node->sym->end));
438+
PyLong_FromUnsignedLongLong(node->ms.sym->end));
439439
pydict_set_item_string_decref(pysym, "binding",
440-
_PyLong_FromLong(node->sym->binding));
440+
_PyLong_FromLong(node->ms.sym->binding));
441441
pydict_set_item_string_decref(pysym, "name",
442-
_PyUnicode_FromStringAndSize(node->sym->name,
443-
node->sym->namelen));
442+
_PyUnicode_FromStringAndSize(node->ms.sym->name,
443+
node->ms.sym->namelen));
444444
pydict_set_item_string_decref(pyelem, "sym", pysym);
445445
}
446446

447-
if (node->map) {
448-
const char *dsoname = get_dsoname(node->map);
447+
if (node->ms.map) {
448+
const char *dsoname = get_dsoname(node->ms.map);
449449

450450
pydict_set_item_string_decref(pyelem, "dso",
451451
_PyUnicode_FromString(dsoname));

0 commit comments

Comments
 (0)