perf inject: Refactor read_buildid function

Into two functions, one that actually reads the build_id for the dso if
it wasn't already read, and another taht will inject the event if the
build_id is available.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2c9faa06
...@@ -67,46 +67,44 @@ static int event__repipe_tracing_data(event_t *self, ...@@ -67,46 +67,44 @@ static int event__repipe_tracing_data(event_t *self,
return err; return err;
} }
static int read_buildid(struct map *self, struct perf_session *session) static int dso__read_build_id(struct dso *self)
{ {
const char *name = self->dso->long_name; if (self->has_build_id)
int err; return 0;
if (filename__read_build_id(self->dso->long_name, self->dso->build_id,
sizeof(self->dso->build_id)) > 0) {
char sbuild_id[BUILD_ID_SIZE * 2 + 1];
self->dso->has_build_id = true;
build_id__sprintf(self->dso->build_id, if (filename__read_build_id(self->long_name, self->build_id,
sizeof(self->dso->build_id), sizeof(self->build_id)) > 0) {
sbuild_id); self->has_build_id = true;
pr_debug("build id found for %s: %s\n", self->dso->long_name, return 0;
sbuild_id);
} }
if (self->dso->has_build_id) { return -1;
}
static int dso__inject_build_id(struct dso *self, struct perf_session *session)
{
u16 misc = PERF_RECORD_MISC_USER; u16 misc = PERF_RECORD_MISC_USER;
struct machine *machine; struct machine *machine;
int err;
misc = self->dso->kernel ? PERF_RECORD_MISC_KERNEL : misc; if (dso__read_build_id(self) < 0) {
pr_debug("no build_id found for %s\n", self->long_name);
return -1;
}
machine = perf_session__find_host_machine(session); machine = perf_session__find_host_machine(session);
if (!machine) { if (machine == NULL) {
pr_err("Can't find machine for session\n"); pr_err("Can't find machine for session\n");
return -1; return -1;
} }
err = event__synthesize_build_id(self->dso, misc, if (self->kernel)
event__repipe, machine, misc = PERF_RECORD_MISC_KERNEL;
session);
err = event__synthesize_build_id(self, misc, event__repipe,
machine, session);
if (err) { if (err) {
pr_err("Can't synthesize build_id event for %s\n", pr_err("Can't synthesize build_id event for %s\n", self->long_name);
name);
return -1;
}
} else {
pr_debug("no build_id found for %s\n", name);
return -1; return -1;
} }
...@@ -118,7 +116,6 @@ static int event__inject_buildid(event_t *event, struct perf_session *session) ...@@ -118,7 +116,6 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
struct addr_location al; struct addr_location al;
struct thread *thread; struct thread *thread;
u8 cpumode; u8 cpumode;
int err = 0;
cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
...@@ -126,7 +123,6 @@ static int event__inject_buildid(event_t *event, struct perf_session *session) ...@@ -126,7 +123,6 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
if (thread == NULL) { if (thread == NULL) {
pr_err("problem processing %d event, skipping it.\n", pr_err("problem processing %d event, skipping it.\n",
event->header.type); event->header.type);
err = -1;
goto repipe; goto repipe;
} }
...@@ -136,9 +132,13 @@ static int event__inject_buildid(event_t *event, struct perf_session *session) ...@@ -136,9 +132,13 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
if (al.map != NULL) { if (al.map != NULL) {
if (!al.map->dso->hit) { if (!al.map->dso->hit) {
al.map->dso->hit = 1; al.map->dso->hit = 1;
if (map__load(al.map, NULL) >= 0) if (map__load(al.map, NULL) >= 0) {
read_buildid(al.map, session); dso__inject_build_id(al.map->dso, session);
else /*
* If this fails, too bad, let the other side
* account this as unresolved.
*/
} else
pr_warning("no symbols found in %s, maybe " pr_warning("no symbols found in %s, maybe "
"install a debug package?\n", "install a debug package?\n",
al.map->dso->long_name); al.map->dso->long_name);
...@@ -147,7 +147,7 @@ static int event__inject_buildid(event_t *event, struct perf_session *session) ...@@ -147,7 +147,7 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
repipe: repipe:
event__repipe(event, session); event__repipe(event, session);
return err; return 0;
} }
struct perf_event_ops inject_ops = { struct perf_event_ops inject_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment