blob: db491e9a812b1b8cf7134f51fedd27c206e4f8fc [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"
Irina Tirdea68e94f42012-10-16 02:33:38 +030031#include "arch/common.h"
Ingo Molnar8035e422009-06-06 15:19:13 +020032
Anton Blanchard5d67be92011-07-04 21:57:50 +100033#include <linux/bitmap.h>
34
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020035struct perf_annotate {
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020036 struct perf_tool tool;
Namhyung Kim2b676bf2013-02-07 18:02:08 +090037 bool force, use_tui, use_stdio, use_gtk;
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -020038 bool full_paths;
39 bool print_line;
Namhyung Kim18c9e5c2013-02-07 18:02:14 +090040 bool skip_missing;
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -020041 const char *sym_hist_filter;
42 const char *cpu_list;
43 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020044};
Anton Blanchard5d67be92011-07-04 21:57:50 +100045
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -020046static int perf_evsel__add_sample(struct perf_evsel *evsel,
47 struct perf_sample *sample,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020048 struct addr_location *al,
49 struct perf_annotate *ann)
Ingo Molnar8035e422009-06-06 15:19:13 +020050{
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030051 struct hist_entry *he;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030052 int ret;
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030053
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -020054 if (ann->sym_hist_filter != NULL &&
55 (al->sym == NULL ||
56 strcmp(ann->sym_hist_filter, al->sym->name) != 0)) {
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030057 /* We're only interested in a symbol named sym_hist_filter */
58 if (al->sym != NULL) {
59 rb_erase(&al->sym->rb_node,
60 &al->map->dso->symbols[al->map->type]);
61 symbol__delete(al->sym);
62 }
63 return 0;
64 }
65
Andi Kleen05484292013-01-24 16:10:29 +010066 he = __hists__add_entry(&evsel->hists, al, NULL, 1, 1);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -030067 if (he == NULL)
Ingo Molnar8035e422009-06-06 15:19:13 +020068 return -ENOMEM;
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030069
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030070 ret = 0;
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020071 if (he->ms.sym != NULL) {
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020072 struct annotation *notes = symbol__annotation(he->ms.sym);
Arnaldo Carvalho de Melod04b35f2011-11-11 22:17:32 -020073 if (notes->src == NULL && symbol__alloc_hist(he->ms.sym) < 0)
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020074 return -ENOMEM;
75
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030076 ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -020077 }
78
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030079 evsel->hists.stats.total_period += sample->period;
80 hists__inc_nr_events(&evsel->hists, PERF_RECORD_SAMPLE);
81 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +020082}
83
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020084static int process_sample_event(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020085 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020086 struct perf_sample *sample,
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -030087 struct perf_evsel *evsel,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020088 struct machine *machine)
Ingo Molnar8035e422009-06-06 15:19:13 +020089{
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020090 struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020091 struct addr_location al;
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020092
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020093 if (perf_event__preprocess_sample(event, machine, &al, sample,
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -020094 symbol__annotate_init) < 0) {
Arnaldo Carvalho de Melo29a9f662010-02-03 16:52:06 -020095 pr_warning("problem processing %d event, skipping it.\n",
96 event->header.type);
Ingo Molnar8035e422009-06-06 15:19:13 +020097 return -1;
98 }
99
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200100 if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
Anton Blanchard5d67be92011-07-04 21:57:50 +1000101 return 0;
102
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200103 if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al, ann)) {
Arnaldo Carvalho de Melo29a9f662010-02-03 16:52:06 -0200104 pr_warning("problem incrementing symbol count, "
105 "skipping event\n");
Arnaldo Carvalho de Meloec218fc2009-10-03 20:30:48 -0300106 return -1;
Ingo Molnar8035e422009-06-06 15:19:13 +0200107 }
Ingo Molnar8035e422009-06-06 15:19:13 +0200108
109 return 0;
110}
111
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900112static int hist_entry__tty_annotate(struct hist_entry *he,
113 struct perf_evsel *evsel,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200114 struct perf_annotate *ann)
Ingo Molnar0b73da32009-06-06 15:48:52 +0200115{
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900116 return symbol__tty_annotate(he->ms.sym, he->ms.map, evsel,
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200117 ann->print_line, ann->full_paths, 0, 0);
Ingo Molnar0b73da32009-06-06 15:48:52 +0200118}
119
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900120static void hists__find_annotations(struct hists *self,
121 struct perf_evsel *evsel,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200122 struct perf_annotate *ann)
Ingo Molnar0b73da32009-06-06 15:48:52 +0200123{
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300124 struct rb_node *nd = rb_first(&self->entries), *next;
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200125 int key = K_RIGHT;
Ingo Molnar0b73da32009-06-06 15:48:52 +0200126
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300127 while (nd) {
Arnaldo Carvalho de Meloed52ce22009-10-19 17:17:57 -0200128 struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200129 struct annotation *notes;
Ingo Molnar0b73da32009-06-06 15:48:52 +0200130
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300131 if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
132 goto find_next;
Ingo Molnar0b73da32009-06-06 15:48:52 +0200133
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200134 notes = symbol__annotation(he->ms.sym);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200135 if (notes->src == NULL) {
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300136find_next:
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200137 if (key == K_LEFT)
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300138 nd = rb_prev(nd);
139 else
140 nd = rb_next(nd);
Arnaldo Carvalho de Meloe4204992009-10-20 14:25:40 -0200141 continue;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300142 }
Arnaldo Carvalho de Meloe4204992009-10-20 14:25:40 -0200143
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900144 if (use_browser == 2) {
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900145 int ret;
146
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900147 ret = hist_entry__gtk_annotate(he, evsel, NULL);
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900148 if (!ret || !ann->skip_missing)
149 return;
150
151 /* skip missing symbols */
152 nd = rb_next(nd);
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900153 } else if (use_browser == 1) {
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900154 key = hist_entry__tui_annotate(he, evsel, NULL);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300155 switch (key) {
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900156 case -1:
157 if (!ann->skip_missing)
158 return;
159 /* fall through */
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200160 case K_RIGHT:
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300161 next = rb_next(nd);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300162 break;
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200163 case K_LEFT:
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300164 next = rb_prev(nd);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300165 break;
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300166 default:
167 return;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300168 }
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300169
170 if (next != NULL)
171 nd = next;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300172 } else {
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900173 hist_entry__tty_annotate(he, evsel, ann);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300174 nd = rb_next(nd);
175 /*
176 * Since we have a hist_entry per IP for the same
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200177 * symbol, free he->ms.sym->src to signal we already
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300178 * processed this symbol.
179 */
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200180 free(notes->src);
181 notes->src = NULL;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300182 }
Ingo Molnar0b73da32009-06-06 15:48:52 +0200183 }
Ingo Molnar0b73da32009-06-06 15:48:52 +0200184}
185
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200186static int __cmd_annotate(struct perf_annotate *ann)
Ingo Molnar8035e422009-06-06 15:19:13 +0200187{
Li Zefanbab81b62009-12-01 14:04:49 +0800188 int ret;
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200189 struct perf_session *session;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300190 struct perf_evsel *pos;
191 u64 total_nr_samples;
Ingo Molnar8035e422009-06-06 15:19:13 +0200192
Feng Tang70cb4e92012-10-30 11:56:02 +0800193 session = perf_session__new(input_name, O_RDONLY,
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200194 ann->force, false, &ann->tool);
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200195 if (session == NULL)
196 return -ENOMEM;
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)
202 goto out_delete;
203 }
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)
208 goto out_delete;
209 }
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)
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200213 goto out_delete;
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 Melo94c744b2009-12-11 21:24:02 -0200217 goto out_delete;
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200218 }
Ingo Molnar8035e422009-06-06 15:19:13 +0200219
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300220 if (verbose > 3)
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200221 perf_session__fprintf(session, stdout);
Ingo Molnar8035e422009-06-06 15:19:13 +0200222
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300223 if (verbose > 2)
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300224 perf_session__fprintf_dsos(session, stdout);
Ingo Molnar8035e422009-06-06 15:19:13 +0200225
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300226 total_nr_samples = 0;
227 list_for_each_entry(pos, &session->evlist->entries, node) {
228 struct hists *hists = &pos->hists;
229 u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
Ingo Molnar8035e422009-06-06 15:19:13 +0200230
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300231 if (nr_samples > 0) {
232 total_nr_samples += nr_samples;
233 hists__collapse_resort(hists);
234 hists__output_resort(hists);
Namhyung Kimb1dd4432013-03-05 14:53:25 +0900235
236 if (symbol_conf.event_group &&
237 !perf_evsel__is_group_leader(pos))
238 continue;
239
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900240 hists__find_annotations(hists, pos, ann);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300241 }
242 }
243
244 if (total_nr_samples == 0) {
Namhyung Kim3780f482012-05-29 13:22:57 +0900245 ui__error("The %s file has no samples!\n", session->filename);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300246 goto out_delete;
247 }
Namhyung Kim7a60ba92013-02-07 18:02:09 +0900248
249 if (use_browser == 2)
250 perf_gtk__show_annotations();
251
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300252out_delete:
253 /*
254 * Speed up the exit process, for large files this can
255 * take quite a while.
256 *
257 * XXX Enable this when using valgrind or if we ever
258 * librarize this command.
259 *
260 * Also experiment with obstacks to see how much speed
261 * up we'll get here.
262 *
263 * perf_session__delete(session);
264 */
Li Zefanbab81b62009-12-01 14:04:49 +0800265 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200266}
267
268static const char * const annotate_usage[] = {
Namhyung Kim99345252012-01-08 02:25:30 +0900269 "perf annotate [<options>]",
Ingo Molnar8035e422009-06-06 15:19:13 +0200270 NULL
271};
272
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300273int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200274{
275 struct perf_annotate annotate = {
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200276 .tool = {
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200277 .sample = process_sample_event,
278 .mmap = perf_event__process_mmap,
279 .comm = perf_event__process_comm,
Arnaldo Carvalho de Meloec4622f2012-10-06 15:53:41 -0300280 .exit = perf_event__process_exit,
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300281 .fork = perf_event__process_fork,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200282 .ordered_samples = true,
283 .ordering_requires_timestamps = true,
284 },
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200285 };
286 const struct option options[] = {
Feng Tang70cb4e92012-10-30 11:56:02 +0800287 OPT_STRING('i', "input", &input_name, "file",
Ingo Molnar8035e422009-06-06 15:19:13 +0200288 "input file name"),
Arnaldo Carvalho de Meloac73c5a2010-03-24 16:40:16 -0300289 OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
290 "only consider symbols in these dsos"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200291 OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol",
Ingo Molnar0b73da32009-06-06 15:48:52 +0200292 "symbol to annotate"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200293 OPT_BOOLEAN('f', "force", &annotate.force, "don't complain, do it"),
Ian Munsiec0555642010-04-13 18:37:33 +1000294 OPT_INCR('v', "verbose", &verbose,
Ingo Molnar8035e422009-06-06 15:19:13 +0200295 "be more verbose (show symbol address, etc)"),
296 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
297 "dump raw trace in ASCII"),
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900298 OPT_BOOLEAN(0, "gtk", &annotate.use_gtk, "Use the GTK interface"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200299 OPT_BOOLEAN(0, "tui", &annotate.use_tui, "Use the TUI interface"),
300 OPT_BOOLEAN(0, "stdio", &annotate.use_stdio, "Use the stdio interface"),
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200301 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
302 "file", "vmlinux pathname"),
303 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
Mike Galbraith42976482009-07-02 08:09:46 +0200304 "load module symbols - WARNING: use only with -k and LIVE kernel"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200305 OPT_BOOLEAN('l', "print-line", &annotate.print_line,
Frederic Weisbecker301406b2009-06-13 00:11:21 +0200306 "print matching source lines (may be slow)"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200307 OPT_BOOLEAN('P', "full-paths", &annotate.full_paths,
Mike Galbraith42976482009-07-02 08:09:46 +0200308 "Don't shorten the displayed pathnames"),
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900309 OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
310 "Skip symbols that cannot be annotated"),
David Ahernc8e66722011-11-13 11:30:08 -0700311 OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
Stephane Eraniane71a0592011-07-30 01:20:40 +0200312 OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
313 "Look for files with symbols relative to this directory"),
Arnaldo Carvalho de Melo64c6f0c2011-10-06 12:48:31 -0300314 OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +0200315 "Interleave source code with assembly code (default)"),
Arnaldo Carvalho de Melo64c6f0c2011-10-06 12:48:31 -0300316 OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +0200317 "Display raw encoding of assembly instructions (default)"),
Andi Kleenf69b64f2011-09-15 14:31:41 -0700318 OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
319 "Specify disassembler style (e.g. -M intel for intel syntax)"),
Maciek Borzecki7a4ec932012-09-04 12:32:30 +0200320 OPT_STRING(0, "objdump", &objdump_path, "path",
321 "objdump binary to use for disassembly and annotations"),
Namhyung Kimb1dd4432013-03-05 14:53:25 +0900322 OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
323 "Show event group information together"),
Ingo Molnar8035e422009-06-06 15:19:13 +0200324 OPT_END()
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200325 };
Ingo Molnar8035e422009-06-06 15:19:13 +0200326
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -0200327 argc = parse_options(argc, argv, options, annotate_usage, 0);
328
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200329 if (annotate.use_stdio)
Arnaldo Carvalho de Melo8b9e74e2010-08-21 10:38:16 -0300330 use_browser = 0;
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200331 else if (annotate.use_tui)
Arnaldo Carvalho de Melo8b9e74e2010-08-21 10:38:16 -0300332 use_browser = 1;
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900333 else if (annotate.use_gtk)
334 use_browser = 2;
Arnaldo Carvalho de Melo8b9e74e2010-08-21 10:38:16 -0300335
Arnaldo Carvalho de Melo229ade92011-01-31 18:08:39 -0200336 setup_browser(true);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300337
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200338 symbol_conf.priv_size = sizeof(struct annotation);
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200339 symbol_conf.try_vmlinux_path = true;
340
341 if (symbol__init() < 0)
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200342 return -1;
Ingo Molnar8035e422009-06-06 15:19:13 +0200343
Namhyung Kim55309982013-02-06 14:57:16 +0900344 if (setup_sorting() < 0)
345 usage_with_options(annotate_usage, options);
Ingo Molnar8035e422009-06-06 15:19:13 +0200346
Ingo Molnar0b73da32009-06-06 15:48:52 +0200347 if (argc) {
348 /*
349 * Special case: if there's an argument left then assume tha
350 * it's a symbol filter:
351 */
352 if (argc > 1)
353 usage_with_options(annotate_usage, options);
354
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200355 annotate.sym_hist_filter = argv[0];
Ingo Molnar0b73da32009-06-06 15:48:52 +0200356 }
357
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200358 return __cmd_annotate(&annotate);
Ingo Molnar8035e422009-06-06 15:19:13 +0200359}