blob: e7417fe97a9775eae8712d5bb58be2db0d1d7363 [file] [log] [blame]
Ingo Molnar8035e422009-06-06 15:19:13 +02001/*
2 * builtin-annotate.c
3 *
4 * Builtin annotate command: Analyze the perf.data input file,
5 * look up and read DSOs and symbol information and display
6 * a histogram of results, along various sorting keys.
7 */
8#include "builtin.h"
9
10#include "util/util.h"
Ingo Molnar8035e422009-06-06 15:19:13 +020011#include "util/color.h"
Arnaldo Carvalho de Melo5da50252009-07-01 14:46:08 -030012#include <linux/list.h>
Ingo Molnar8035e422009-06-06 15:19:13 +020013#include "util/cache.h"
Arnaldo Carvalho de Melo43cbcd82009-07-01 12:28:37 -030014#include <linux/rbtree.h>
Ingo Molnar8035e422009-06-06 15:19:13 +020015#include "util/symbol.h"
Ingo Molnar8035e422009-06-06 15:19:13 +020016
17#include "perf.h"
Frederic Weisbecker8f28827a2009-08-16 22:05:48 +020018#include "util/debug.h"
Ingo Molnar8035e422009-06-06 15:19:13 +020019
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030020#include "util/evlist.h"
21#include "util/evsel.h"
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -020022#include "util/annotate.h"
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -020023#include "util/event.h"
Ingo Molnar8035e422009-06-06 15:19:13 +020024#include "util/parse-options.h"
25#include "util/parse-events.h"
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020026#include "util/thread.h"
John Kacurdd68ada2009-09-24 18:02:49 +020027#include "util/sort.h"
John Kacur3d1d07e2009-09-28 15:32:55 +020028#include "util/hist.h"
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -020029#include "util/session.h"
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020030#include "util/tool.h"
Jiri Olsaf5fc1412013-10-15 16:27:32 +020031#include "util/data.h"
Irina Tirdea68e94f42012-10-16 02:33:38 +030032#include "arch/common.h"
Ingo Molnar8035e422009-06-06 15:19:13 +020033
Namhyung Kimfc672972013-09-13 15:27:43 +090034#include <dlfcn.h>
Anton Blanchard5d67be92011-07-04 21:57:50 +100035#include <linux/bitmap.h>
36
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020037struct perf_annotate {
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020038 struct perf_tool tool;
Namhyung Kimfa10f312014-08-12 15:40:35 +090039 struct perf_session *session;
40 bool use_tui, use_stdio, use_gtk;
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -020041 bool full_paths;
42 bool print_line;
Namhyung Kim18c9e5c2013-02-07 18:02:14 +090043 bool skip_missing;
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -020044 const char *sym_hist_filter;
45 const char *cpu_list;
46 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020047};
Anton Blanchard5d67be92011-07-04 21:57:50 +100048
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -020049static int perf_evsel__add_sample(struct perf_evsel *evsel,
Namhyung Kim820bc812014-04-22 11:44:21 +090050 struct perf_sample *sample __maybe_unused,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020051 struct addr_location *al,
52 struct perf_annotate *ann)
Ingo Molnar8035e422009-06-06 15:19:13 +020053{
Arnaldo Carvalho de Melo4ea062ed2014-10-09 13:13:41 -030054 struct hists *hists = evsel__hists(evsel);
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030055 struct hist_entry *he;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030056 int ret;
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030057
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -020058 if (ann->sym_hist_filter != NULL &&
59 (al->sym == NULL ||
60 strcmp(ann->sym_hist_filter, al->sym->name) != 0)) {
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030061 /* We're only interested in a symbol named sym_hist_filter */
62 if (al->sym != NULL) {
63 rb_erase(&al->sym->rb_node,
64 &al->map->dso->symbols[al->map->type]);
65 symbol__delete(al->sym);
66 }
67 return 0;
68 }
69
Arnaldo Carvalho de Melo4ea062ed2014-10-09 13:13:41 -030070 he = __hists__add_entry(hists, al, NULL, NULL, NULL, 1, 1, 0, true);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -030071 if (he == NULL)
Ingo Molnar8035e422009-06-06 15:19:13 +020072 return -ENOMEM;
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030073
Arnaldo Carvalho de Melo00e55212013-12-18 15:46:32 -030074 ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
Arnaldo Carvalho de Melo4ea062ed2014-10-09 13:13:41 -030075 hists__inc_nr_samples(hists, true);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030076 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +020077}
78
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020079static int process_sample_event(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020080 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020081 struct perf_sample *sample,
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -030082 struct perf_evsel *evsel,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020083 struct machine *machine)
Ingo Molnar8035e422009-06-06 15:19:13 +020084{
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020085 struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020086 struct addr_location al;
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020087
Adrian Huntere44baa32013-08-08 14:32:25 +030088 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
Arnaldo Carvalho de Melo29a9f662010-02-03 16:52:06 -020089 pr_warning("problem processing %d event, skipping it.\n",
90 event->header.type);
Ingo Molnar8035e422009-06-06 15:19:13 +020091 return -1;
92 }
93
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -020094 if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
Anton Blanchard5d67be92011-07-04 21:57:50 +100095 return 0;
96
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020097 if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al, ann)) {
Arnaldo Carvalho de Melo29a9f662010-02-03 16:52:06 -020098 pr_warning("problem incrementing symbol count, "
99 "skipping event\n");
Arnaldo Carvalho de Meloec218fc2009-10-03 20:30:48 -0300100 return -1;
Ingo Molnar8035e422009-06-06 15:19:13 +0200101 }
Ingo Molnar8035e422009-06-06 15:19:13 +0200102
103 return 0;
104}
105
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900106static int hist_entry__tty_annotate(struct hist_entry *he,
107 struct perf_evsel *evsel,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200108 struct perf_annotate *ann)
Ingo Molnar0b73da32009-06-06 15:48:52 +0200109{
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900110 return symbol__tty_annotate(he->ms.sym, he->ms.map, evsel,
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200111 ann->print_line, ann->full_paths, 0, 0);
Ingo Molnar0b73da32009-06-06 15:48:52 +0200112}
113
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300114static void hists__find_annotations(struct hists *hists,
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900115 struct perf_evsel *evsel,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200116 struct perf_annotate *ann)
Ingo Molnar0b73da32009-06-06 15:48:52 +0200117{
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300118 struct rb_node *nd = rb_first(&hists->entries), *next;
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200119 int key = K_RIGHT;
Ingo Molnar0b73da32009-06-06 15:48:52 +0200120
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300121 while (nd) {
Arnaldo Carvalho de Meloed52ce22009-10-19 17:17:57 -0200122 struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200123 struct annotation *notes;
Ingo Molnar0b73da32009-06-06 15:48:52 +0200124
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300125 if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
126 goto find_next;
Ingo Molnar0b73da32009-06-06 15:48:52 +0200127
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200128 notes = symbol__annotation(he->ms.sym);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200129 if (notes->src == NULL) {
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300130find_next:
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200131 if (key == K_LEFT)
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300132 nd = rb_prev(nd);
133 else
134 nd = rb_next(nd);
Arnaldo Carvalho de Meloe4204992009-10-20 14:25:40 -0200135 continue;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300136 }
Arnaldo Carvalho de Meloe4204992009-10-20 14:25:40 -0200137
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900138 if (use_browser == 2) {
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900139 int ret;
Namhyung Kimfc672972013-09-13 15:27:43 +0900140 int (*annotate)(struct hist_entry *he,
141 struct perf_evsel *evsel,
142 struct hist_browser_timer *hbt);
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900143
Namhyung Kimfc672972013-09-13 15:27:43 +0900144 annotate = dlsym(perf_gtk_handle,
145 "hist_entry__gtk_annotate");
146 if (annotate == NULL) {
147 ui__error("GTK browser not found!\n");
148 return;
149 }
150
151 ret = annotate(he, evsel, NULL);
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900152 if (!ret || !ann->skip_missing)
153 return;
154
155 /* skip missing symbols */
156 nd = rb_next(nd);
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900157 } else if (use_browser == 1) {
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900158 key = hist_entry__tui_annotate(he, evsel, NULL);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300159 switch (key) {
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900160 case -1:
161 if (!ann->skip_missing)
162 return;
163 /* fall through */
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200164 case K_RIGHT:
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300165 next = rb_next(nd);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300166 break;
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200167 case K_LEFT:
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300168 next = rb_prev(nd);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300169 break;
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300170 default:
171 return;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300172 }
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300173
174 if (next != NULL)
175 nd = next;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300176 } else {
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900177 hist_entry__tty_annotate(he, evsel, ann);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300178 nd = rb_next(nd);
179 /*
180 * Since we have a hist_entry per IP for the same
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200181 * symbol, free he->ms.sym->src to signal we already
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300182 * processed this symbol.
183 */
Arnaldo Carvalho de Melo04662522013-12-26 17:41:15 -0300184 zfree(&notes->src);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300185 }
Ingo Molnar0b73da32009-06-06 15:48:52 +0200186 }
Ingo Molnar0b73da32009-06-06 15:48:52 +0200187}
188
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200189static int __cmd_annotate(struct perf_annotate *ann)
Ingo Molnar8035e422009-06-06 15:19:13 +0200190{
Li Zefanbab81b62009-12-01 14:04:49 +0800191 int ret;
Namhyung Kimfa10f312014-08-12 15:40:35 +0900192 struct perf_session *session = ann->session;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300193 struct perf_evsel *pos;
194 u64 total_nr_samples;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200195
Adrian Hunter476d35c2013-08-08 14:32:24 +0300196 machines__set_symbol_filter(&session->machines, symbol__annotate_init);
197
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200198 if (ann->cpu_list) {
199 ret = perf_session__cpu_bitmap(session, ann->cpu_list,
200 ann->cpu_bitmap);
Anton Blanchard5d67be92011-07-04 21:57:50 +1000201 if (ret)
Namhyung Kimfa10f312014-08-12 15:40:35 +0900202 goto out;
Anton Blanchard5d67be92011-07-04 21:57:50 +1000203 }
204
Irina Tirdea68e94f42012-10-16 02:33:38 +0300205 if (!objdump_path) {
206 ret = perf_session_env__lookup_objdump(&session->header.env);
207 if (ret)
Namhyung Kimfa10f312014-08-12 15:40:35 +0900208 goto out;
Irina Tirdea68e94f42012-10-16 02:33:38 +0300209 }
210
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200211 ret = perf_session__process_events(session, &ann->tool);
Li Zefanbab81b62009-12-01 14:04:49 +0800212 if (ret)
Namhyung Kimfa10f312014-08-12 15:40:35 +0900213 goto out;
Ingo Molnar8035e422009-06-06 15:19:13 +0200214
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200215 if (dump_trace) {
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300216 perf_session__fprintf_nr_events(session, stdout);
Arnaldo Carvalho de Melo2a1731f2014-10-10 15:49:21 -0300217 perf_evlist__fprintf_nr_events(session->evlist, stdout);
Namhyung Kimfa10f312014-08-12 15:40:35 +0900218 goto out;
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200219 }
Ingo Molnar8035e422009-06-06 15:19:13 +0200220
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300221 if (verbose > 3)
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200222 perf_session__fprintf(session, stdout);
Ingo Molnar8035e422009-06-06 15:19:13 +0200223
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300224 if (verbose > 2)
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300225 perf_session__fprintf_dsos(session, stdout);
Ingo Molnar8035e422009-06-06 15:19:13 +0200226
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300227 total_nr_samples = 0;
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -0300228 evlist__for_each(session->evlist, pos) {
Arnaldo Carvalho de Melo4ea062ed2014-10-09 13:13:41 -0300229 struct hists *hists = evsel__hists(pos);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300230 u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
Ingo Molnar8035e422009-06-06 15:19:13 +0200231
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300232 if (nr_samples > 0) {
233 total_nr_samples += nr_samples;
Namhyung Kimc1fb5652013-10-11 14:15:38 +0900234 hists__collapse_resort(hists, NULL);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300235 hists__output_resort(hists);
Namhyung Kimb1dd4432013-03-05 14:53:25 +0900236
237 if (symbol_conf.event_group &&
238 !perf_evsel__is_group_leader(pos))
239 continue;
240
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900241 hists__find_annotations(hists, pos, ann);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300242 }
243 }
244
245 if (total_nr_samples == 0) {
Namhyung Kimfa10f312014-08-12 15:40:35 +0900246 ui__error("The %s file has no samples!\n", session->file->path);
247 goto out;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300248 }
Namhyung Kim7a60ba92013-02-07 18:02:09 +0900249
Namhyung Kimfc672972013-09-13 15:27:43 +0900250 if (use_browser == 2) {
251 void (*show_annotations)(void);
252
253 show_annotations = dlsym(perf_gtk_handle,
254 "perf_gtk__show_annotations");
255 if (show_annotations == NULL) {
256 ui__error("GTK browser not found!\n");
Namhyung Kimfa10f312014-08-12 15:40:35 +0900257 goto out;
Namhyung Kimfc672972013-09-13 15:27:43 +0900258 }
259 show_annotations();
260 }
Namhyung Kim7a60ba92013-02-07 18:02:09 +0900261
Namhyung Kimfa10f312014-08-12 15:40:35 +0900262out:
Li Zefanbab81b62009-12-01 14:04:49 +0800263 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200264}
265
266static const char * const annotate_usage[] = {
Namhyung Kim99345252012-01-08 02:25:30 +0900267 "perf annotate [<options>]",
Ingo Molnar8035e422009-06-06 15:19:13 +0200268 NULL
269};
270
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300271int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200272{
273 struct perf_annotate annotate = {
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200274 .tool = {
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200275 .sample = process_sample_event,
276 .mmap = perf_event__process_mmap,
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200277 .mmap2 = perf_event__process_mmap2,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200278 .comm = perf_event__process_comm,
Arnaldo Carvalho de Meloec4622f2012-10-06 15:53:41 -0300279 .exit = perf_event__process_exit,
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300280 .fork = perf_event__process_fork,
Jiri Olsa0a8cb852014-07-06 14:18:21 +0200281 .ordered_events = true,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200282 .ordering_requires_timestamps = true,
283 },
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200284 };
Namhyung Kimfa10f312014-08-12 15:40:35 +0900285 struct perf_data_file file = {
286 .path = input_name,
287 .mode = PERF_DATA_MODE_READ,
288 };
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200289 const struct option options[] = {
Feng Tang70cb4e92012-10-30 11:56:02 +0800290 OPT_STRING('i', "input", &input_name, "file",
Ingo Molnar8035e422009-06-06 15:19:13 +0200291 "input file name"),
Arnaldo Carvalho de Meloac73c5a2010-03-24 16:40:16 -0300292 OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
293 "only consider symbols in these dsos"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200294 OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol",
Ingo Molnar0b73da32009-06-06 15:48:52 +0200295 "symbol to annotate"),
Namhyung Kimfa10f312014-08-12 15:40:35 +0900296 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
Ian Munsiec0555642010-04-13 18:37:33 +1000297 OPT_INCR('v', "verbose", &verbose,
Ingo Molnar8035e422009-06-06 15:19:13 +0200298 "be more verbose (show symbol address, etc)"),
299 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
300 "dump raw trace in ASCII"),
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900301 OPT_BOOLEAN(0, "gtk", &annotate.use_gtk, "Use the GTK interface"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200302 OPT_BOOLEAN(0, "tui", &annotate.use_tui, "Use the TUI interface"),
303 OPT_BOOLEAN(0, "stdio", &annotate.use_stdio, "Use the stdio interface"),
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200304 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
305 "file", "vmlinux pathname"),
306 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
Mike Galbraith42976482009-07-02 08:09:46 +0200307 "load module symbols - WARNING: use only with -k and LIVE kernel"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200308 OPT_BOOLEAN('l', "print-line", &annotate.print_line,
Frederic Weisbecker301406b2009-06-13 00:11:21 +0200309 "print matching source lines (may be slow)"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200310 OPT_BOOLEAN('P', "full-paths", &annotate.full_paths,
Mike Galbraith42976482009-07-02 08:09:46 +0200311 "Don't shorten the displayed pathnames"),
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900312 OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
313 "Skip symbols that cannot be annotated"),
David Ahernc8e66722011-11-13 11:30:08 -0700314 OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
Stephane Eraniane71a0592011-07-30 01:20:40 +0200315 OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
316 "Look for files with symbols relative to this directory"),
Arnaldo Carvalho de Melo64c6f0c2011-10-06 12:48:31 -0300317 OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +0200318 "Interleave source code with assembly code (default)"),
Arnaldo Carvalho de Melo64c6f0c2011-10-06 12:48:31 -0300319 OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +0200320 "Display raw encoding of assembly instructions (default)"),
Andi Kleenf69b64f2011-09-15 14:31:41 -0700321 OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
322 "Specify disassembler style (e.g. -M intel for intel syntax)"),
Maciek Borzecki7a4ec932012-09-04 12:32:30 +0200323 OPT_STRING(0, "objdump", &objdump_path, "path",
324 "objdump binary to use for disassembly and annotations"),
Namhyung Kimb1dd4432013-03-05 14:53:25 +0900325 OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
326 "Show event group information together"),
Ingo Molnar8035e422009-06-06 15:19:13 +0200327 OPT_END()
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200328 };
Arnaldo Carvalho de Meloa635fc52014-10-09 16:16:00 -0300329 int ret = hists__init();
330
331 if (ret < 0)
332 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200333
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -0200334 argc = parse_options(argc, argv, options, annotate_usage, 0);
335
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200336 if (annotate.use_stdio)
Arnaldo Carvalho de Melo8b9e74e2010-08-21 10:38:16 -0300337 use_browser = 0;
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200338 else if (annotate.use_tui)
Arnaldo Carvalho de Melo8b9e74e2010-08-21 10:38:16 -0300339 use_browser = 1;
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900340 else if (annotate.use_gtk)
341 use_browser = 2;
Arnaldo Carvalho de Melo8b9e74e2010-08-21 10:38:16 -0300342
Arnaldo Carvalho de Melo229ade92011-01-31 18:08:39 -0200343 setup_browser(true);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300344
Namhyung Kimfa10f312014-08-12 15:40:35 +0900345 annotate.session = perf_session__new(&file, false, &annotate.tool);
346 if (annotate.session == NULL)
Taeung Song52e028342014-09-24 10:33:37 +0900347 return -1;
Namhyung Kimfa10f312014-08-12 15:40:35 +0900348
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200349 symbol_conf.priv_size = sizeof(struct annotation);
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200350 symbol_conf.try_vmlinux_path = true;
351
Namhyung Kim0a7e6d12014-08-12 15:40:45 +0900352 ret = symbol__init(&annotate.session->header.env);
Namhyung Kimfa10f312014-08-12 15:40:35 +0900353 if (ret < 0)
354 goto out_delete;
Ingo Molnar8035e422009-06-06 15:19:13 +0200355
Namhyung Kim55309982013-02-06 14:57:16 +0900356 if (setup_sorting() < 0)
357 usage_with_options(annotate_usage, options);
Ingo Molnar8035e422009-06-06 15:19:13 +0200358
Ingo Molnar0b73da32009-06-06 15:48:52 +0200359 if (argc) {
360 /*
Dongsheng Yang6f1d0c82013-12-09 17:47:48 -0500361 * Special case: if there's an argument left then assume that
Ingo Molnar0b73da32009-06-06 15:48:52 +0200362 * it's a symbol filter:
363 */
364 if (argc > 1)
365 usage_with_options(annotate_usage, options);
366
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200367 annotate.sym_hist_filter = argv[0];
Ingo Molnar0b73da32009-06-06 15:48:52 +0200368 }
369
Namhyung Kimfa10f312014-08-12 15:40:35 +0900370 ret = __cmd_annotate(&annotate);
371
372out_delete:
373 /*
374 * Speed up the exit process, for large files this can
375 * take quite a while.
376 *
377 * XXX Enable this when using valgrind or if we ever
378 * librarize this command.
379 *
380 * Also experiment with obstacks to see how much speed
381 * up we'll get here.
382 *
383 * perf_session__delete(session);
384 */
385 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200386}