diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-28 04:56:39 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-28 07:39:12 -0500 |
commit | 743eb868657bdb1b26c7b24077ca21c67c82c777 (patch) | |
tree | 4803b557725213043ccd5d3f83d2eec796a49f69 /tools/perf/builtin-inject.c | |
parent | d20deb64e0490ee9442b5181bc08a62d2cadcb90 (diff) |
perf tools: Resolve machine earlier and pass it to perf_event_ops
Reducing the exposure of perf_session further, so that we can use the
classes in cases where no perf.data file is created.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-stua66dcscsezzrcdugvbmvd@git.kernel.org
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.c | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 6ce6d80b59db..a5bcf81776fc 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c | |||
@@ -18,7 +18,7 @@ static bool inject_build_ids; | |||
18 | 18 | ||
19 | static int perf_event__repipe_synth(struct perf_event_ops *ops __used, | 19 | static int perf_event__repipe_synth(struct perf_event_ops *ops __used, |
20 | union perf_event *event, | 20 | union perf_event *event, |
21 | struct perf_session *session __used) | 21 | struct machine *machine __used) |
22 | { | 22 | { |
23 | uint32_t size; | 23 | uint32_t size; |
24 | void *buf = event; | 24 | void *buf = event; |
@@ -37,10 +37,23 @@ static int perf_event__repipe_synth(struct perf_event_ops *ops __used, | |||
37 | return 0; | 37 | return 0; |
38 | } | 38 | } |
39 | 39 | ||
40 | static int perf_event__repipe_op2_synth(struct perf_event_ops *ops, | ||
41 | union perf_event *event, | ||
42 | struct perf_session *session __used) | ||
43 | { | ||
44 | return perf_event__repipe_synth(ops, event, NULL); | ||
45 | } | ||
46 | |||
47 | static int perf_event__repipe_event_type_synth(struct perf_event_ops *ops, | ||
48 | union perf_event *event) | ||
49 | { | ||
50 | return perf_event__repipe_synth(ops, event, NULL); | ||
51 | } | ||
52 | |||
40 | static int perf_event__repipe_tracing_data_synth(union perf_event *event, | 53 | static int perf_event__repipe_tracing_data_synth(union perf_event *event, |
41 | struct perf_session *session) | 54 | struct perf_session *session __used) |
42 | { | 55 | { |
43 | return perf_event__repipe_synth(NULL, event, session); | 56 | return perf_event__repipe_synth(NULL, event, NULL); |
44 | } | 57 | } |
45 | 58 | ||
46 | static int perf_event__repipe_attr(union perf_event *event, | 59 | static int perf_event__repipe_attr(union perf_event *event, |
@@ -52,29 +65,29 @@ static int perf_event__repipe_attr(union perf_event *event, | |||
52 | static int perf_event__repipe(struct perf_event_ops *ops, | 65 | static int perf_event__repipe(struct perf_event_ops *ops, |
53 | union perf_event *event, | 66 | union perf_event *event, |
54 | struct perf_sample *sample __used, | 67 | struct perf_sample *sample __used, |
55 | struct perf_session *session) | 68 | struct machine *machine) |
56 | { | 69 | { |
57 | return perf_event__repipe_synth(ops, event, session); | 70 | return perf_event__repipe_synth(ops, event, machine); |
58 | } | 71 | } |
59 | 72 | ||
60 | static int perf_event__repipe_sample(struct perf_event_ops *ops, | 73 | static int perf_event__repipe_sample(struct perf_event_ops *ops, |
61 | union perf_event *event, | 74 | union perf_event *event, |
62 | struct perf_sample *sample __used, | 75 | struct perf_sample *sample __used, |
63 | struct perf_evsel *evsel __used, | 76 | struct perf_evsel *evsel __used, |
64 | struct perf_session *session) | 77 | struct machine *machine) |
65 | { | 78 | { |
66 | return perf_event__repipe_synth(ops, event, session); | 79 | return perf_event__repipe_synth(ops, event, machine); |
67 | } | 80 | } |
68 | 81 | ||
69 | static int perf_event__repipe_mmap(struct perf_event_ops *ops, | 82 | static int perf_event__repipe_mmap(struct perf_event_ops *ops, |
70 | union perf_event *event, | 83 | union perf_event *event, |
71 | struct perf_sample *sample, | 84 | struct perf_sample *sample, |
72 | struct perf_session *session) | 85 | struct machine *machine) |
73 | { | 86 | { |
74 | int err; | 87 | int err; |
75 | 88 | ||
76 | err = perf_event__process_mmap(ops, event, sample, session); | 89 | err = perf_event__process_mmap(ops, event, sample, machine); |
77 | perf_event__repipe(ops, event, sample, session); | 90 | perf_event__repipe(ops, event, sample, machine); |
78 | 91 | ||
79 | return err; | 92 | return err; |
80 | } | 93 | } |
@@ -82,12 +95,12 @@ static int perf_event__repipe_mmap(struct perf_event_ops *ops, | |||
82 | static int perf_event__repipe_task(struct perf_event_ops *ops, | 95 | static int perf_event__repipe_task(struct perf_event_ops *ops, |
83 | union perf_event *event, | 96 | union perf_event *event, |
84 | struct perf_sample *sample, | 97 | struct perf_sample *sample, |
85 | struct perf_session *session) | 98 | struct machine *machine) |
86 | { | 99 | { |
87 | int err; | 100 | int err; |
88 | 101 | ||
89 | err = perf_event__process_task(ops, event, sample, session); | 102 | err = perf_event__process_task(ops, event, sample, machine); |
90 | perf_event__repipe(ops, event, sample, session); | 103 | perf_event__repipe(ops, event, sample, machine); |
91 | 104 | ||
92 | return err; | 105 | return err; |
93 | } | 106 | } |
@@ -97,7 +110,7 @@ static int perf_event__repipe_tracing_data(union perf_event *event, | |||
97 | { | 110 | { |
98 | int err; | 111 | int err; |
99 | 112 | ||
100 | perf_event__repipe_synth(NULL, event, session); | 113 | perf_event__repipe_synth(NULL, event, NULL); |
101 | err = perf_event__process_tracing_data(event, session); | 114 | err = perf_event__process_tracing_data(event, session); |
102 | 115 | ||
103 | return err; | 116 | return err; |
@@ -118,10 +131,9 @@ static int dso__read_build_id(struct dso *self) | |||
118 | } | 131 | } |
119 | 132 | ||
120 | static int dso__inject_build_id(struct dso *self, struct perf_event_ops *ops, | 133 | static int dso__inject_build_id(struct dso *self, struct perf_event_ops *ops, |
121 | struct perf_session *session) | 134 | struct machine *machine) |
122 | { | 135 | { |
123 | u16 misc = PERF_RECORD_MISC_USER; | 136 | u16 misc = PERF_RECORD_MISC_USER; |
124 | struct machine *machine; | ||
125 | int err; | 137 | int err; |
126 | 138 | ||
127 | if (dso__read_build_id(self) < 0) { | 139 | if (dso__read_build_id(self) < 0) { |
@@ -129,17 +141,11 @@ static int dso__inject_build_id(struct dso *self, struct perf_event_ops *ops, | |||
129 | return -1; | 141 | return -1; |
130 | } | 142 | } |
131 | 143 | ||
132 | machine = perf_session__find_host_machine(session); | ||
133 | if (machine == NULL) { | ||
134 | pr_err("Can't find machine for session\n"); | ||
135 | return -1; | ||
136 | } | ||
137 | |||
138 | if (self->kernel) | 144 | if (self->kernel) |
139 | misc = PERF_RECORD_MISC_KERNEL; | 145 | misc = PERF_RECORD_MISC_KERNEL; |
140 | 146 | ||
141 | err = perf_event__synthesize_build_id(ops, self, misc, perf_event__repipe, | 147 | err = perf_event__synthesize_build_id(ops, self, misc, perf_event__repipe, |
142 | machine, session); | 148 | machine); |
143 | if (err) { | 149 | if (err) { |
144 | pr_err("Can't synthesize build_id event for %s\n", self->long_name); | 150 | pr_err("Can't synthesize build_id event for %s\n", self->long_name); |
145 | return -1; | 151 | return -1; |
@@ -152,7 +158,7 @@ static int perf_event__inject_buildid(struct perf_event_ops *ops, | |||
152 | union perf_event *event, | 158 | union perf_event *event, |
153 | struct perf_sample *sample, | 159 | struct perf_sample *sample, |
154 | struct perf_evsel *evsel __used, | 160 | struct perf_evsel *evsel __used, |
155 | struct perf_session *session) | 161 | struct machine *machine) |
156 | { | 162 | { |
157 | struct addr_location al; | 163 | struct addr_location al; |
158 | struct thread *thread; | 164 | struct thread *thread; |
@@ -160,21 +166,21 @@ static int perf_event__inject_buildid(struct perf_event_ops *ops, | |||
160 | 166 | ||
161 | cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | 167 | cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; |
162 | 168 | ||
163 | thread = perf_session__findnew(session, event->ip.pid); | 169 | thread = machine__findnew_thread(machine, event->ip.pid); |
164 | if (thread == NULL) { | 170 | if (thread == NULL) { |
165 | pr_err("problem processing %d event, skipping it.\n", | 171 | pr_err("problem processing %d event, skipping it.\n", |
166 | event->header.type); | 172 | event->header.type); |
167 | goto repipe; | 173 | goto repipe; |
168 | } | 174 | } |
169 | 175 | ||
170 | thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION, | 176 | thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION, |
171 | event->ip.pid, event->ip.ip, &al); | 177 | event->ip.ip, &al); |
172 | 178 | ||
173 | if (al.map != NULL) { | 179 | if (al.map != NULL) { |
174 | if (!al.map->dso->hit) { | 180 | if (!al.map->dso->hit) { |
175 | al.map->dso->hit = 1; | 181 | al.map->dso->hit = 1; |
176 | if (map__load(al.map, NULL) >= 0) { | 182 | if (map__load(al.map, NULL) >= 0) { |
177 | dso__inject_build_id(al.map->dso, ops, session); | 183 | dso__inject_build_id(al.map->dso, ops, machine); |
178 | /* | 184 | /* |
179 | * If this fails, too bad, let the other side | 185 | * If this fails, too bad, let the other side |
180 | * account this as unresolved. | 186 | * account this as unresolved. |
@@ -187,7 +193,7 @@ static int perf_event__inject_buildid(struct perf_event_ops *ops, | |||
187 | } | 193 | } |
188 | 194 | ||
189 | repipe: | 195 | repipe: |
190 | perf_event__repipe(ops, event, sample, session); | 196 | perf_event__repipe(ops, event, sample, machine); |
191 | return 0; | 197 | return 0; |
192 | } | 198 | } |
193 | 199 | ||
@@ -198,13 +204,13 @@ struct perf_event_ops inject_ops = { | |||
198 | .fork = perf_event__repipe, | 204 | .fork = perf_event__repipe, |
199 | .exit = perf_event__repipe, | 205 | .exit = perf_event__repipe, |
200 | .lost = perf_event__repipe, | 206 | .lost = perf_event__repipe, |
201 | .read = perf_event__repipe, | 207 | .read = perf_event__repipe_sample, |
202 | .throttle = perf_event__repipe, | 208 | .throttle = perf_event__repipe, |
203 | .unthrottle = perf_event__repipe, | 209 | .unthrottle = perf_event__repipe, |
204 | .attr = perf_event__repipe_attr, | 210 | .attr = perf_event__repipe_attr, |
205 | .event_type = perf_event__repipe_synth, | 211 | .event_type = perf_event__repipe_event_type_synth, |
206 | .tracing_data = perf_event__repipe_tracing_data_synth, | 212 | .tracing_data = perf_event__repipe_tracing_data_synth, |
207 | .build_id = perf_event__repipe_synth, | 213 | .build_id = perf_event__repipe_op2_synth, |
208 | }; | 214 | }; |
209 | 215 | ||
210 | extern volatile int session_done; | 216 | extern volatile int session_done; |