Skip to content

Commit c41dc33

Browse files
fweisbecIngo Molnar
authored and
Ingo Molnar
committed
perf_counter tools: Resolve symbols in callchains
This patch resolves the names, when possible, of each ip present in the callchains while using the -c option with perf report. Example: 5.40% [k] __d_lookup 5.37% perf_callchain perf_counter_overflow intel_pmu_handle_irq perf_counter_nmi_handler notifier_call_chain atomic_notifier_call_chain notify_die do_nmi nmi do_lookup __link_path_walk path_walk do_path_lookup user_path_at sys_faccessat sys_access system_call_fastpath 0x7fb609846f77 0.01% perf_callchain perf_counter_overflow intel_pmu_handle_irq perf_counter_nmi_handler notifier_call_chain atomic_notifier_call_chain notify_die do_nmi nmi do_lookup __link_path_walk path_walk do_path_lookup user_path_at sys_faccessat Signed-off-by: Frederic Weisbecker <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Anton Blanchard <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> --- yaml --- svn_rev: 155183 current_ref: refs/heads/rpi-3.18.y current_commit: 4424961 head_branch: refs/heads/rpi-3.18.y migrated_from: v3
1 parent e7cb51d commit c41dc33

File tree

4 files changed

+91
-51
lines changed

4 files changed

+91
-51
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/rpi-3.18.y: 9198aa77b69647d1d91207f8075763abe7dc0bf4
2+
refs/heads/rpi-3.18.y: 4424961ad6621a02c6b4c9093e801002c1bb9f65

trunk/tools/perf/builtin-report.c

Lines changed: 67 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,15 @@ callchain__fprintf(FILE *fp, struct callchain_node *self, u64 total_samples)
794794
ret += callchain__fprintf(fp, self->parent, total_samples);
795795

796796

797-
list_for_each_entry(chain, &self->val, list)
798-
ret += fprintf(fp, " %p\n", (void *)chain->ip);
797+
list_for_each_entry(chain, &self->val, list) {
798+
if (chain->ip >= PERF_CONTEXT_MAX)
799+
continue;
800+
if (chain->sym)
801+
ret += fprintf(fp, " %s\n", chain->sym->name);
802+
else
803+
ret += fprintf(fp, " %p\n",
804+
(void *)chain->ip);
805+
}
799806

800807
return ret;
801808
}
@@ -930,6 +937,55 @@ static int call__match(struct symbol *sym)
930937
return 0;
931938
}
932939

940+
static struct symbol **
941+
resolve_callchain(struct thread *thread, struct map *map,
942+
struct ip_callchain *chain, struct hist_entry *entry)
943+
{
944+
int i;
945+
struct symbol **syms;
946+
u64 context = PERF_CONTEXT_MAX;
947+
948+
if (callchain) {
949+
syms = calloc(chain->nr, sizeof(*syms));
950+
if (!syms) {
951+
fprintf(stderr, "Can't allocate memory for symbols\n");
952+
exit(-1);
953+
}
954+
}
955+
956+
for (i = 0; i < chain->nr; i++) {
957+
u64 ip = chain->ips[i];
958+
struct dso *dso = NULL;
959+
struct symbol *sym;
960+
961+
if (ip >= PERF_CONTEXT_MAX) {
962+
context = ip;
963+
continue;
964+
}
965+
966+
switch (context) {
967+
case PERF_CONTEXT_KERNEL:
968+
dso = kernel_dso;
969+
break;
970+
default:
971+
break;
972+
}
973+
974+
sym = resolve_symbol(thread, NULL, &dso, &ip);
975+
976+
if (sym) {
977+
if (sort__has_parent && call__match(sym) &&
978+
!entry->parent)
979+
entry->parent = sym;
980+
if (!callchain)
981+
break;
982+
syms[i] = sym;
983+
}
984+
}
985+
986+
return syms;
987+
}
988+
933989
/*
934990
* collect histogram counts
935991
*/
@@ -942,6 +998,7 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
942998
struct rb_node **p = &hist.rb_node;
943999
struct rb_node *parent = NULL;
9441000
struct hist_entry *he;
1001+
struct symbol **syms = NULL;
9451002
struct hist_entry entry = {
9461003
.thread = thread,
9471004
.map = map,
@@ -955,39 +1012,11 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
9551012
};
9561013
int cmp;
9571014

958-
if (sort__has_parent && chain) {
959-
u64 context = PERF_CONTEXT_MAX;
960-
int i;
961-
962-
for (i = 0; i < chain->nr; i++) {
963-
u64 ip = chain->ips[i];
964-
struct dso *dso = NULL;
965-
struct symbol *sym;
966-
967-
if (ip >= PERF_CONTEXT_MAX) {
968-
context = ip;
969-
continue;
970-
}
971-
972-
switch (context) {
9731015
case PERF_CONTEXT_HV:
9741016
dso = hypervisor_dso;
9751017
break;
976-
case PERF_CONTEXT_KERNEL:
977-
dso = kernel_dso;
978-
break;
979-
default:
980-
break;
981-
}
982-
983-
sym = resolve_symbol(thread, NULL, &dso, &ip);
984-
985-
if (sym && call__match(sym)) {
986-
entry.parent = sym;
987-
break;
988-
}
989-
}
990-
}
1018+
if ((sort__has_parent || callchain) && chain)
1019+
syms = resolve_callchain(thread, map, chain, &entry);
9911020

9921021
while (*p != NULL) {
9931022
parent = *p;
@@ -997,8 +1026,10 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
9971026

9981027
if (!cmp) {
9991028
he->count += count;
1000-
if (callchain)
1001-
append_chain(&he->callchain, chain);
1029+
if (callchain) {
1030+
append_chain(&he->callchain, chain, syms);
1031+
free(syms);
1032+
}
10021033
return 0;
10031034
}
10041035

@@ -1014,7 +1045,8 @@ hist_entry__add(struct thread *thread, struct map *map, struct dso *dso,
10141045
*he = entry;
10151046
if (callchain) {
10161047
callchain_init(&he->callchain);
1017-
append_chain(&he->callchain, chain);
1048+
append_chain(&he->callchain, chain, syms);
1049+
free(syms);
10181050
}
10191051
rb_link_node(&he->rb_node, parent, p);
10201052
rb_insert_color(&he->rb_node, &hist);

trunk/tools/perf/util/callchain.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ static struct callchain_node *create_child(struct callchain_node *parent)
6767
}
6868

6969
static void
70-
fill_node(struct callchain_node *node, struct ip_callchain *chain, int start)
70+
fill_node(struct callchain_node *node, struct ip_callchain *chain, int start,
71+
struct symbol **syms)
7172
{
7273
int i;
7374

@@ -80,24 +81,26 @@ fill_node(struct callchain_node *node, struct ip_callchain *chain, int start)
8081
return;
8182
}
8283
call->ip = chain->ips[i];
84+
call->sym = syms[i];
8385
list_add_tail(&call->list, &node->val);
8486
}
8587
node->val_nr = i - start;
8688
}
8789

88-
static void add_child(struct callchain_node *parent, struct ip_callchain *chain)
90+
static void add_child(struct callchain_node *parent, struct ip_callchain *chain,
91+
struct symbol **syms)
8992
{
9093
struct callchain_node *new;
9194

9295
new = create_child(parent);
93-
fill_node(new, chain, parent->val_nr);
96+
fill_node(new, chain, parent->val_nr, syms);
9497

9598
new->hit = 1;
9699
}
97100

98101
static void
99102
split_add_child(struct callchain_node *parent, struct ip_callchain *chain,
100-
struct callchain_list *to_split, int idx)
103+
struct callchain_list *to_split, int idx, struct symbol **syms)
101104
{
102105
struct callchain_node *new;
103106

@@ -109,21 +112,22 @@ split_add_child(struct callchain_node *parent, struct ip_callchain *chain,
109112
parent->val_nr = idx;
110113

111114
/* create the new one */
112-
add_child(parent, chain);
115+
add_child(parent, chain, syms);
113116
}
114117

115118
static int
116119
__append_chain(struct callchain_node *root, struct ip_callchain *chain,
117-
int start);
120+
int start, struct symbol **syms);
118121

119122
static int
120-
__append_chain_children(struct callchain_node *root, struct ip_callchain *chain)
123+
__append_chain_children(struct callchain_node *root, struct ip_callchain *chain,
124+
struct symbol **syms)
121125
{
122126
struct callchain_node *rnode;
123127

124128
/* lookup in childrens */
125129
list_for_each_entry(rnode, &root->children, brothers) {
126-
int ret = __append_chain(rnode, chain, root->val_nr);
130+
int ret = __append_chain(rnode, chain, root->val_nr, syms);
127131
if (!ret)
128132
return 0;
129133
}
@@ -132,7 +136,7 @@ __append_chain_children(struct callchain_node *root, struct ip_callchain *chain)
132136

133137
static int
134138
__append_chain(struct callchain_node *root, struct ip_callchain *chain,
135-
int start)
139+
int start, struct symbol **syms)
136140
{
137141
struct callchain_list *cnode;
138142
int i = start;
@@ -154,7 +158,7 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain,
154158

155159
/* we match only a part of the node. Split it and add the new chain */
156160
if (i < root->val_nr) {
157-
split_add_child(root, chain, cnode, i);
161+
split_add_child(root, chain, cnode, i, syms);
158162
return 0;
159163
}
160164

@@ -164,11 +168,12 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain,
164168
return 0;
165169
}
166170

167-
return __append_chain_children(root, chain);
171+
return __append_chain_children(root, chain, syms);
168172
}
169173

170-
void append_chain(struct callchain_node *root, struct ip_callchain *chain)
174+
void append_chain(struct callchain_node *root, struct ip_callchain *chain,
175+
struct symbol **syms)
171176
{
172-
if (__append_chain_children(root, chain) == -1)
173-
add_child(root, chain);
177+
if (__append_chain_children(root, chain, syms) == -1)
178+
add_child(root, chain, syms);
174179
}

trunk/tools/perf/util/callchain.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../perf.h"
55
#include "list.h"
66
#include "rbtree.h"
7+
#include "symbol.h"
78

89

910
struct callchain_node {
@@ -18,6 +19,7 @@ struct callchain_node {
1819

1920
struct callchain_list {
2021
unsigned long ip;
22+
struct symbol *sym;
2123
struct list_head list;
2224
};
2325

@@ -28,6 +30,7 @@ static inline void callchain_init(struct callchain_node *node)
2830
INIT_LIST_HEAD(&node->val);
2931
}
3032

31-
void append_chain(struct callchain_node *root, struct ip_callchain *chain);
33+
void append_chain(struct callchain_node *root, struct ip_callchain *chain,
34+
struct symbol **syms);
3235
void sort_chain_to_rbtree(struct rb_root *rb_root, struct callchain_node *node);
3336
#endif

0 commit comments

Comments
 (0)