aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-inject.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-inject.c')
-rw-r--r--tools/perf/builtin-inject.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index afe377b2884f..6a2508589460 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -15,6 +15,7 @@
15#include "util/tool.h" 15#include "util/tool.h"
16#include "util/debug.h" 16#include "util/debug.h"
17#include "util/build-id.h" 17#include "util/build-id.h"
18#include "util/data.h"
18 19
19#include "util/parse-options.h" 20#include "util/parse-options.h"
20 21
@@ -71,12 +72,17 @@ static int perf_event__repipe_attr(struct perf_tool *tool,
71 union perf_event *event, 72 union perf_event *event,
72 struct perf_evlist **pevlist) 73 struct perf_evlist **pevlist)
73{ 74{
75 struct perf_inject *inject = container_of(tool, struct perf_inject,
76 tool);
74 int ret; 77 int ret;
75 78
76 ret = perf_event__process_attr(tool, event, pevlist); 79 ret = perf_event__process_attr(tool, event, pevlist);
77 if (ret) 80 if (ret)
78 return ret; 81 return ret;
79 82
83 if (!inject->pipe_output)
84 return 0;
85
80 return perf_event__repipe_synth(tool, event); 86 return perf_event__repipe_synth(tool, event);
81} 87}
82 88
@@ -100,8 +106,8 @@ static int perf_event__repipe_sample(struct perf_tool *tool,
100 struct perf_evsel *evsel, 106 struct perf_evsel *evsel,
101 struct machine *machine) 107 struct machine *machine)
102{ 108{
103 if (evsel->handler.func) { 109 if (evsel->handler) {
104 inject_handler f = evsel->handler.func; 110 inject_handler f = evsel->handler;
105 return f(tool, event, sample, evsel, machine); 111 return f(tool, event, sample, evsel, machine);
106 } 112 }
107 113
@@ -161,38 +167,38 @@ static int perf_event__repipe_tracing_data(struct perf_tool *tool,
161 return err; 167 return err;
162} 168}
163 169
164static int dso__read_build_id(struct dso *self) 170static int dso__read_build_id(struct dso *dso)
165{ 171{
166 if (self->has_build_id) 172 if (dso->has_build_id)
167 return 0; 173 return 0;
168 174
169 if (filename__read_build_id(self->long_name, self->build_id, 175 if (filename__read_build_id(dso->long_name, dso->build_id,
170 sizeof(self->build_id)) > 0) { 176 sizeof(dso->build_id)) > 0) {
171 self->has_build_id = true; 177 dso->has_build_id = true;
172 return 0; 178 return 0;
173 } 179 }
174 180
175 return -1; 181 return -1;
176} 182}
177 183
178static int dso__inject_build_id(struct dso *self, struct perf_tool *tool, 184static int dso__inject_build_id(struct dso *dso, struct perf_tool *tool,
179 struct machine *machine) 185 struct machine *machine)
180{ 186{
181 u16 misc = PERF_RECORD_MISC_USER; 187 u16 misc = PERF_RECORD_MISC_USER;
182 int err; 188 int err;
183 189
184 if (dso__read_build_id(self) < 0) { 190 if (dso__read_build_id(dso) < 0) {
185 pr_debug("no build_id found for %s\n", self->long_name); 191 pr_debug("no build_id found for %s\n", dso->long_name);
186 return -1; 192 return -1;
187 } 193 }
188 194
189 if (self->kernel) 195 if (dso->kernel)
190 misc = PERF_RECORD_MISC_KERNEL; 196 misc = PERF_RECORD_MISC_KERNEL;
191 197
192 err = perf_event__synthesize_build_id(tool, self, misc, perf_event__repipe, 198 err = perf_event__synthesize_build_id(tool, dso, misc, perf_event__repipe,
193 machine); 199 machine);
194 if (err) { 200 if (err) {
195 pr_err("Can't synthesize build_id event for %s\n", self->long_name); 201 pr_err("Can't synthesize build_id event for %s\n", dso->long_name);
196 return -1; 202 return -1;
197 } 203 }
198 204
@@ -231,7 +237,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
231 * account this as unresolved. 237 * account this as unresolved.
232 */ 238 */
233 } else { 239 } else {
234#ifdef LIBELF_SUPPORT 240#ifdef HAVE_LIBELF_SUPPORT
235 pr_warning("no symbols found in %s, maybe " 241 pr_warning("no symbols found in %s, maybe "
236 "install a debug package?\n", 242 "install a debug package?\n",
237 al.map->dso->long_name); 243 al.map->dso->long_name);
@@ -345,6 +351,10 @@ static int __cmd_inject(struct perf_inject *inject)
345{ 351{
346 struct perf_session *session; 352 struct perf_session *session;
347 int ret = -EINVAL; 353 int ret = -EINVAL;
354 struct perf_data_file file = {
355 .path = inject->input_name,
356 .mode = PERF_DATA_MODE_READ,
357 };
348 358
349 signal(SIGINT, sig_handler); 359 signal(SIGINT, sig_handler);
350 360
@@ -355,7 +365,7 @@ static int __cmd_inject(struct perf_inject *inject)
355 inject->tool.tracing_data = perf_event__repipe_tracing_data; 365 inject->tool.tracing_data = perf_event__repipe_tracing_data;
356 } 366 }
357 367
358 session = perf_session__new(inject->input_name, O_RDONLY, false, true, &inject->tool); 368 session = perf_session__new(&file, true, &inject->tool);
359 if (session == NULL) 369 if (session == NULL)
360 return -ENOMEM; 370 return -ENOMEM;
361 371
@@ -373,11 +383,11 @@ static int __cmd_inject(struct perf_inject *inject)
373 if (perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID")) 383 if (perf_evsel__check_stype(evsel, PERF_SAMPLE_TID, "TID"))
374 return -EINVAL; 384 return -EINVAL;
375 385
376 evsel->handler.func = perf_inject__sched_switch; 386 evsel->handler = perf_inject__sched_switch;
377 } else if (!strcmp(name, "sched:sched_process_exit")) 387 } else if (!strcmp(name, "sched:sched_process_exit"))
378 evsel->handler.func = perf_inject__sched_process_exit; 388 evsel->handler = perf_inject__sched_process_exit;
379 else if (!strncmp(name, "sched:sched_stat_", 17)) 389 else if (!strncmp(name, "sched:sched_stat_", 17))
380 evsel->handler.func = perf_inject__sched_stat; 390 evsel->handler = perf_inject__sched_stat;
381 } 391 }
382 } 392 }
383 393