aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-inject.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-05-02 18:46:36 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-05-02 18:46:36 -0400
commit090f7204dfdb5d7f18208ea81dfdba845897cedd (patch)
tree19988fe463ec3dc964d2790bf1bcfaa29dff73c8 /tools/perf/builtin-inject.c
parent2c9faa060064343a4a0b16f5b77f3c61d1d17e23 (diff)
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: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-inject.c')
-rw-r--r--tools/perf/builtin-inject.c76
1 files changed, 38 insertions, 38 deletions
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index a5902a3eadd3..59e981a88908 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -67,46 +67,44 @@ static int event__repipe_tracing_data(event_t *self,
67 return err; 67 return err;
68} 68}
69 69
70static int read_buildid(struct map *self, struct perf_session *session) 70static int dso__read_build_id(struct dso *self)
71{ 71{
72 const char *name = self->dso->long_name; 72 if (self->has_build_id)
73 int err; 73 return 0;
74 74
75 if (filename__read_build_id(self->dso->long_name, self->dso->build_id, 75 if (filename__read_build_id(self->long_name, self->build_id,
76 sizeof(self->dso->build_id)) > 0) { 76 sizeof(self->build_id)) > 0) {
77 char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 77 self->has_build_id = true;
78 return 0;
79 }
78 80
79 self->dso->has_build_id = true; 81 return -1;
82}
80 83
81 build_id__sprintf(self->dso->build_id, 84static int dso__inject_build_id(struct dso *self, struct perf_session *session)
82 sizeof(self->dso->build_id), 85{
83 sbuild_id); 86 u16 misc = PERF_RECORD_MISC_USER;
84 pr_debug("build id found for %s: %s\n", self->dso->long_name, 87 struct machine *machine;
85 sbuild_id); 88 int err;
86 }
87 89
88 if (self->dso->has_build_id) { 90 if (dso__read_build_id(self) < 0) {
89 u16 misc = PERF_RECORD_MISC_USER; 91 pr_debug("no build_id found for %s\n", self->long_name);
90 struct machine *machine; 92 return -1;
93 }
91 94
92 misc = self->dso->kernel ? PERF_RECORD_MISC_KERNEL : misc; 95 machine = perf_session__find_host_machine(session);
96 if (machine == NULL) {
97 pr_err("Can't find machine for session\n");
98 return -1;
99 }
93 100
94 machine = perf_session__find_host_machine(session); 101 if (self->kernel)
95 if (!machine) { 102 misc = PERF_RECORD_MISC_KERNEL;
96 pr_err("Can't find machine for session\n");
97 return -1;
98 }
99 103
100 err = event__synthesize_build_id(self->dso, misc, 104 err = event__synthesize_build_id(self, misc, event__repipe,
101 event__repipe, machine, 105 machine, session);
102 session); 106 if (err) {
103 if (err) { 107 pr_err("Can't synthesize build_id event for %s\n", self->long_name);
104 pr_err("Can't synthesize build_id event for %s\n",
105 name);
106 return -1;
107 }
108 } else {
109 pr_debug("no build_id found for %s\n", name);
110 return -1; 108 return -1;
111 } 109 }
112 110
@@ -118,7 +116,6 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
118 struct addr_location al; 116 struct addr_location al;
119 struct thread *thread; 117 struct thread *thread;
120 u8 cpumode; 118 u8 cpumode;
121 int err = 0;
122 119
123 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 120 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
124 121
@@ -126,7 +123,6 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
126 if (thread == NULL) { 123 if (thread == NULL) {
127 pr_err("problem processing %d event, skipping it.\n", 124 pr_err("problem processing %d event, skipping it.\n",
128 event->header.type); 125 event->header.type);
129 err = -1;
130 goto repipe; 126 goto repipe;
131 } 127 }
132 128
@@ -136,9 +132,13 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
136 if (al.map != NULL) { 132 if (al.map != NULL) {
137 if (!al.map->dso->hit) { 133 if (!al.map->dso->hit) {
138 al.map->dso->hit = 1; 134 al.map->dso->hit = 1;
139 if (map__load(al.map, NULL) >= 0) 135 if (map__load(al.map, NULL) >= 0) {
140 read_buildid(al.map, session); 136 dso__inject_build_id(al.map->dso, session);
141 else 137 /*
138 * If this fails, too bad, let the other side
139 * account this as unresolved.
140 */
141 } else
142 pr_warning("no symbols found in %s, maybe " 142 pr_warning("no symbols found in %s, maybe "
143 "install a debug package?\n", 143 "install a debug package?\n",
144 al.map->dso->long_name); 144 al.map->dso->long_name);
@@ -147,7 +147,7 @@ static int event__inject_buildid(event_t *event, struct perf_session *session)
147 147
148repipe: 148repipe:
149 event__repipe(event, session); 149 event__repipe(event, session);
150 return err; 150 return 0;
151} 151}
152 152
153struct perf_event_ops inject_ops = { 153struct perf_event_ops inject_ops = {