diff options
author | Namhyung Kim <namhyung@kernel.org> | 2014-08-12 02:40:35 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-08-13 15:31:23 -0400 |
commit | fa10f316d59f39020d19d3f4a323598d05afa65c (patch) | |
tree | 52a6130f83ddb9f44495623ac65d6d9f9bf88b2a /tools/perf/builtin-annotate.c | |
parent | e96c674fe2c228fd5c16fd7a7607c60dea4cdaa2 (diff) |
perf annotate: Move session handling out of __cmd_annotate()
This is a preparation of fixing dso__load_kernel_sym(). It needs a
session info before calling symbol__init().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1407825645-24586-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-annotate.c')
-rw-r--r-- | tools/perf/builtin-annotate.c | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 952b5ece6740..c0464dc38057 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -36,7 +36,8 @@ | |||
36 | 36 | ||
37 | struct perf_annotate { | 37 | struct perf_annotate { |
38 | struct perf_tool tool; | 38 | struct perf_tool tool; |
39 | bool force, use_tui, use_stdio, use_gtk; | 39 | struct perf_session *session; |
40 | bool use_tui, use_stdio, use_gtk; | ||
40 | bool full_paths; | 41 | bool full_paths; |
41 | bool print_line; | 42 | bool print_line; |
42 | bool skip_missing; | 43 | bool skip_missing; |
@@ -188,18 +189,9 @@ find_next: | |||
188 | static int __cmd_annotate(struct perf_annotate *ann) | 189 | static int __cmd_annotate(struct perf_annotate *ann) |
189 | { | 190 | { |
190 | int ret; | 191 | int ret; |
191 | struct perf_session *session; | 192 | struct perf_session *session = ann->session; |
192 | struct perf_evsel *pos; | 193 | struct perf_evsel *pos; |
193 | u64 total_nr_samples; | 194 | u64 total_nr_samples; |
194 | struct perf_data_file file = { | ||
195 | .path = input_name, | ||
196 | .mode = PERF_DATA_MODE_READ, | ||
197 | .force = ann->force, | ||
198 | }; | ||
199 | |||
200 | session = perf_session__new(&file, false, &ann->tool); | ||
201 | if (session == NULL) | ||
202 | return -ENOMEM; | ||
203 | 195 | ||
204 | machines__set_symbol_filter(&session->machines, symbol__annotate_init); | 196 | machines__set_symbol_filter(&session->machines, symbol__annotate_init); |
205 | 197 | ||
@@ -207,22 +199,22 @@ static int __cmd_annotate(struct perf_annotate *ann) | |||
207 | ret = perf_session__cpu_bitmap(session, ann->cpu_list, | 199 | ret = perf_session__cpu_bitmap(session, ann->cpu_list, |
208 | ann->cpu_bitmap); | 200 | ann->cpu_bitmap); |
209 | if (ret) | 201 | if (ret) |
210 | goto out_delete; | 202 | goto out; |
211 | } | 203 | } |
212 | 204 | ||
213 | if (!objdump_path) { | 205 | if (!objdump_path) { |
214 | ret = perf_session_env__lookup_objdump(&session->header.env); | 206 | ret = perf_session_env__lookup_objdump(&session->header.env); |
215 | if (ret) | 207 | if (ret) |
216 | goto out_delete; | 208 | goto out; |
217 | } | 209 | } |
218 | 210 | ||
219 | ret = perf_session__process_events(session, &ann->tool); | 211 | ret = perf_session__process_events(session, &ann->tool); |
220 | if (ret) | 212 | if (ret) |
221 | goto out_delete; | 213 | goto out; |
222 | 214 | ||
223 | if (dump_trace) { | 215 | if (dump_trace) { |
224 | perf_session__fprintf_nr_events(session, stdout); | 216 | perf_session__fprintf_nr_events(session, stdout); |
225 | goto out_delete; | 217 | goto out; |
226 | } | 218 | } |
227 | 219 | ||
228 | if (verbose > 3) | 220 | if (verbose > 3) |
@@ -250,8 +242,8 @@ static int __cmd_annotate(struct perf_annotate *ann) | |||
250 | } | 242 | } |
251 | 243 | ||
252 | if (total_nr_samples == 0) { | 244 | if (total_nr_samples == 0) { |
253 | ui__error("The %s file has no samples!\n", file.path); | 245 | ui__error("The %s file has no samples!\n", session->file->path); |
254 | goto out_delete; | 246 | goto out; |
255 | } | 247 | } |
256 | 248 | ||
257 | if (use_browser == 2) { | 249 | if (use_browser == 2) { |
@@ -261,24 +253,12 @@ static int __cmd_annotate(struct perf_annotate *ann) | |||
261 | "perf_gtk__show_annotations"); | 253 | "perf_gtk__show_annotations"); |
262 | if (show_annotations == NULL) { | 254 | if (show_annotations == NULL) { |
263 | ui__error("GTK browser not found!\n"); | 255 | ui__error("GTK browser not found!\n"); |
264 | goto out_delete; | 256 | goto out; |
265 | } | 257 | } |
266 | show_annotations(); | 258 | show_annotations(); |
267 | } | 259 | } |
268 | 260 | ||
269 | out_delete: | 261 | out: |
270 | /* | ||
271 | * Speed up the exit process, for large files this can | ||
272 | * take quite a while. | ||
273 | * | ||
274 | * XXX Enable this when using valgrind or if we ever | ||
275 | * librarize this command. | ||
276 | * | ||
277 | * Also experiment with obstacks to see how much speed | ||
278 | * up we'll get here. | ||
279 | * | ||
280 | * perf_session__delete(session); | ||
281 | */ | ||
282 | return ret; | 262 | return ret; |
283 | } | 263 | } |
284 | 264 | ||
@@ -301,6 +281,10 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) | |||
301 | .ordering_requires_timestamps = true, | 281 | .ordering_requires_timestamps = true, |
302 | }, | 282 | }, |
303 | }; | 283 | }; |
284 | struct perf_data_file file = { | ||
285 | .path = input_name, | ||
286 | .mode = PERF_DATA_MODE_READ, | ||
287 | }; | ||
304 | const struct option options[] = { | 288 | const struct option options[] = { |
305 | OPT_STRING('i', "input", &input_name, "file", | 289 | OPT_STRING('i', "input", &input_name, "file", |
306 | "input file name"), | 290 | "input file name"), |
@@ -308,7 +292,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) | |||
308 | "only consider symbols in these dsos"), | 292 | "only consider symbols in these dsos"), |
309 | OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol", | 293 | OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol", |
310 | "symbol to annotate"), | 294 | "symbol to annotate"), |
311 | OPT_BOOLEAN('f', "force", &annotate.force, "don't complain, do it"), | 295 | OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"), |
312 | OPT_INCR('v', "verbose", &verbose, | 296 | OPT_INCR('v', "verbose", &verbose, |
313 | "be more verbose (show symbol address, etc)"), | 297 | "be more verbose (show symbol address, etc)"), |
314 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 298 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
@@ -341,6 +325,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) | |||
341 | "Show event group information together"), | 325 | "Show event group information together"), |
342 | OPT_END() | 326 | OPT_END() |
343 | }; | 327 | }; |
328 | int ret; | ||
344 | 329 | ||
345 | argc = parse_options(argc, argv, options, annotate_usage, 0); | 330 | argc = parse_options(argc, argv, options, annotate_usage, 0); |
346 | 331 | ||
@@ -353,11 +338,16 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) | |||
353 | 338 | ||
354 | setup_browser(true); | 339 | setup_browser(true); |
355 | 340 | ||
341 | annotate.session = perf_session__new(&file, false, &annotate.tool); | ||
342 | if (annotate.session == NULL) | ||
343 | return -ENOMEM; | ||
344 | |||
356 | symbol_conf.priv_size = sizeof(struct annotation); | 345 | symbol_conf.priv_size = sizeof(struct annotation); |
357 | symbol_conf.try_vmlinux_path = true; | 346 | symbol_conf.try_vmlinux_path = true; |
358 | 347 | ||
359 | if (symbol__init() < 0) | 348 | ret = symbol__init(); |
360 | return -1; | 349 | if (ret < 0) |
350 | goto out_delete; | ||
361 | 351 | ||
362 | if (setup_sorting() < 0) | 352 | if (setup_sorting() < 0) |
363 | usage_with_options(annotate_usage, options); | 353 | usage_with_options(annotate_usage, options); |
@@ -373,5 +363,20 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) | |||
373 | annotate.sym_hist_filter = argv[0]; | 363 | annotate.sym_hist_filter = argv[0]; |
374 | } | 364 | } |
375 | 365 | ||
376 | return __cmd_annotate(&annotate); | 366 | ret = __cmd_annotate(&annotate); |
367 | |||
368 | out_delete: | ||
369 | /* | ||
370 | * Speed up the exit process, for large files this can | ||
371 | * take quite a while. | ||
372 | * | ||
373 | * XXX Enable this when using valgrind or if we ever | ||
374 | * librarize this command. | ||
375 | * | ||
376 | * Also experiment with obstacks to see how much speed | ||
377 | * up we'll get here. | ||
378 | * | ||
379 | * perf_session__delete(session); | ||
380 | */ | ||
381 | return ret; | ||
377 | } | 382 | } |