Skip to content

Commit f645744

Browse files
ahunter6acmel
authored andcommitted
perf dlfilter: Add resolve_address() to perf_dlfilter_fns
Add a function, for use by dlfilters, to resolve addresses from branch stacks or callchains. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20210627131818.810-7-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 0beb218 commit f645744

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

tools/perf/Documentation/perf-dlfilter.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ struct perf_dlfilter_fns {
123123
const struct perf_dlfilter_al *(*resolve_ip)(void *ctx);
124124
const struct perf_dlfilter_al *(*resolve_addr)(void *ctx);
125125
char **(*args)(void *ctx, int *dlargc);
126-
void *(*reserved[125])(void *);
126+
__s32 (*resolve_address)(void *ctx, __u64 address, struct perf_dlfilter_al *al);
127+
void *(*reserved[124])(void *);
127128
};
128129
----
129130

@@ -133,6 +134,9 @@ struct perf_dlfilter_fns {
133134

134135
'args' returns arguments from --dlarg options.
135136

137+
'resolve_address' provides information about 'address'. al->size must be set
138+
before calling. Returns 0 on success, -1 otherwise.
139+
136140
The perf_dlfilter_al structure
137141
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138142

tools/perf/util/dlfilter.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,39 @@ static char **dlfilter__args(void *ctx, int *dlargc)
149149
return d->dlargv;
150150
}
151151

152+
static __s32 dlfilter__resolve_address(void *ctx, __u64 address, struct perf_dlfilter_al *d_al_p)
153+
{
154+
struct dlfilter *d = (struct dlfilter *)ctx;
155+
struct perf_dlfilter_al d_al;
156+
struct addr_location al;
157+
struct thread *thread;
158+
__u32 sz;
159+
160+
if (!d->ctx_valid || !d_al_p)
161+
return -1;
162+
163+
thread = get_thread(d);
164+
if (!thread)
165+
return -1;
166+
167+
thread__find_symbol_fb(thread, d->sample->cpumode, address, &al);
168+
169+
al_to_d_al(&al, &d_al);
170+
171+
d_al.is_kernel_ip = machine__kernel_ip(d->machine, address);
172+
173+
sz = d_al_p->size;
174+
memcpy(d_al_p, &d_al, min((size_t)sz, sizeof(d_al)));
175+
d_al_p->size = sz;
176+
177+
return 0;
178+
}
179+
152180
static const struct perf_dlfilter_fns perf_dlfilter_fns = {
153181
.resolve_ip = dlfilter__resolve_ip,
154182
.resolve_addr = dlfilter__resolve_addr,
155183
.args = dlfilter__args,
184+
.resolve_address = dlfilter__resolve_address,
156185
};
157186

158187
static char *find_dlfilter(const char *file)

tools/perf/util/perf_dlfilter.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ struct perf_dlfilter_fns {
9292
const struct perf_dlfilter_al *(*resolve_addr)(void *ctx);
9393
/* Return arguments from --dlarg option */
9494
char **(*args)(void *ctx, int *dlargc);
95+
/*
96+
* Return information about address (al->size must be set before
97+
* calling). Returns 0 on success, -1 otherwise.
98+
*/
99+
__s32 (*resolve_address)(void *ctx, __u64 address, struct perf_dlfilter_al *al);
95100
/* Reserved */
96-
void *(*reserved[125])(void *);
101+
void *(*reserved[124])(void *);
97102
};
98103

99104
/*

0 commit comments

Comments
 (0)