blob: 2c1bec39c30ea191fecb46654df14dc6229d27d5 [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 */
Arnaldo Carvalho de Melofacf3f02015-05-25 15:30:09 -030062 /*
63 * FIXME: why isn't this done in the symbol_filter when loading
64 * the DSO?
65 */
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030066 if (al->sym != NULL) {
67 rb_erase(&al->sym->rb_node,
68 &al->map->dso->symbols[al->map->type]);
69 symbol__delete(al->sym);
70 }
71 return 0;
72 }
73
Arnaldo Carvalho de Melo4ea062ed2014-10-09 13:13:41 -030074 he = __hists__add_entry(hists, al, NULL, NULL, NULL, 1, 1, 0, true);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -030075 if (he == NULL)
Ingo Molnar8035e422009-06-06 15:19:13 +020076 return -ENOMEM;
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030077
Arnaldo Carvalho de Melo00e55212013-12-18 15:46:32 -030078 ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
Arnaldo Carvalho de Melo4ea062ed2014-10-09 13:13:41 -030079 hists__inc_nr_samples(hists, true);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030080 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +020081}
82
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020083static int process_sample_event(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020084 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020085 struct perf_sample *sample,
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -030086 struct perf_evsel *evsel,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020087 struct machine *machine)
Ingo Molnar8035e422009-06-06 15:19:13 +020088{
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020089 struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020090 struct addr_location al;
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -030091 int ret = 0;
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020092
Adrian Huntere44baa32013-08-08 14:32:25 +030093 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
Arnaldo Carvalho de Melo29a9f662010-02-03 16:52:06 -020094 pr_warning("problem processing %d event, skipping it.\n",
95 event->header.type);
Ingo Molnar8035e422009-06-06 15:19:13 +020096 return -1;
97 }
98
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -020099 if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300100 goto out_put;
Anton Blanchard5d67be92011-07-04 21:57:50 +1000101
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200102 if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al, ann)) {
Arnaldo Carvalho de Melo29a9f662010-02-03 16:52:06 -0200103 pr_warning("problem incrementing symbol count, "
104 "skipping event\n");
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300105 ret = -1;
Ingo Molnar8035e422009-06-06 15:19:13 +0200106 }
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300107out_put:
108 addr_location__put(&al);
109 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200110}
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
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300120static void hists__find_annotations(struct hists *hists,
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900121 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 Meloc824c432013-10-22 19:01:31 -0300124 struct rb_node *nd = rb_first(&hists->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;
Namhyung Kimfc672972013-09-13 15:27:43 +0900146 int (*annotate)(struct hist_entry *he,
147 struct perf_evsel *evsel,
148 struct hist_browser_timer *hbt);
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900149
Namhyung Kimfc672972013-09-13 15:27:43 +0900150 annotate = dlsym(perf_gtk_handle,
151 "hist_entry__gtk_annotate");
152 if (annotate == NULL) {
153 ui__error("GTK browser not found!\n");
154 return;
155 }
156
157 ret = annotate(he, evsel, NULL);
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900158 if (!ret || !ann->skip_missing)
159 return;
160
161 /* skip missing symbols */
162 nd = rb_next(nd);
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900163 } else if (use_browser == 1) {
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900164 key = hist_entry__tui_annotate(he, evsel, NULL);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300165 switch (key) {
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900166 case -1:
167 if (!ann->skip_missing)
168 return;
169 /* fall through */
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200170 case K_RIGHT:
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300171 next = rb_next(nd);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300172 break;
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200173 case K_LEFT:
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300174 next = rb_prev(nd);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300175 break;
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300176 default:
177 return;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300178 }
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300179
180 if (next != NULL)
181 nd = next;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300182 } else {
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900183 hist_entry__tty_annotate(he, evsel, ann);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300184 nd = rb_next(nd);
185 /*
186 * Since we have a hist_entry per IP for the same
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200187 * symbol, free he->ms.sym->src to signal we already
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300188 * processed this symbol.
189 */
Arnaldo Carvalho de Melo04662522013-12-26 17:41:15 -0300190 zfree(&notes->src);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300191 }
Ingo Molnar0b73da32009-06-06 15:48:52 +0200192 }
Ingo Molnar0b73da32009-06-06 15:48:52 +0200193}
194
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200195static int __cmd_annotate(struct perf_annotate *ann)
Ingo Molnar8035e422009-06-06 15:19:13 +0200196{
Li Zefanbab81b62009-12-01 14:04:49 +0800197 int ret;
Namhyung Kimfa10f312014-08-12 15:40:35 +0900198 struct perf_session *session = ann->session;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300199 struct perf_evsel *pos;
200 u64 total_nr_samples;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200201
Adrian Hunter476d35c2013-08-08 14:32:24 +0300202 machines__set_symbol_filter(&session->machines, symbol__annotate_init);
203
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200204 if (ann->cpu_list) {
205 ret = perf_session__cpu_bitmap(session, ann->cpu_list,
206 ann->cpu_bitmap);
Anton Blanchard5d67be92011-07-04 21:57:50 +1000207 if (ret)
Namhyung Kimfa10f312014-08-12 15:40:35 +0900208 goto out;
Anton Blanchard5d67be92011-07-04 21:57:50 +1000209 }
210
Irina Tirdea68e94f42012-10-16 02:33:38 +0300211 if (!objdump_path) {
212 ret = perf_session_env__lookup_objdump(&session->header.env);
213 if (ret)
Namhyung Kimfa10f312014-08-12 15:40:35 +0900214 goto out;
Irina Tirdea68e94f42012-10-16 02:33:38 +0300215 }
216
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -0300217 ret = perf_session__process_events(session);
Li Zefanbab81b62009-12-01 14:04:49 +0800218 if (ret)
Namhyung Kimfa10f312014-08-12 15:40:35 +0900219 goto out;
Ingo Molnar8035e422009-06-06 15:19:13 +0200220
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200221 if (dump_trace) {
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300222 perf_session__fprintf_nr_events(session, stdout);
Arnaldo Carvalho de Melo2a1731f2014-10-10 15:49:21 -0300223 perf_evlist__fprintf_nr_events(session->evlist, stdout);
Namhyung Kimfa10f312014-08-12 15:40:35 +0900224 goto out;
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200225 }
Ingo Molnar8035e422009-06-06 15:19:13 +0200226
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300227 if (verbose > 3)
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200228 perf_session__fprintf(session, stdout);
Ingo Molnar8035e422009-06-06 15:19:13 +0200229
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300230 if (verbose > 2)
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300231 perf_session__fprintf_dsos(session, stdout);
Ingo Molnar8035e422009-06-06 15:19:13 +0200232
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300233 total_nr_samples = 0;
Arnaldo Carvalho de Melo0050f7a2014-01-10 10:37:27 -0300234 evlist__for_each(session->evlist, pos) {
Arnaldo Carvalho de Melo4ea062ed2014-10-09 13:13:41 -0300235 struct hists *hists = evsel__hists(pos);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300236 u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
Ingo Molnar8035e422009-06-06 15:19:13 +0200237
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300238 if (nr_samples > 0) {
239 total_nr_samples += nr_samples;
Namhyung Kimc1fb5652013-10-11 14:15:38 +0900240 hists__collapse_resort(hists, NULL);
Namhyung Kim740b97f2014-12-22 13:44:10 +0900241 hists__output_resort(hists, NULL);
Namhyung Kimb1dd4432013-03-05 14:53:25 +0900242
243 if (symbol_conf.event_group &&
244 !perf_evsel__is_group_leader(pos))
245 continue;
246
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900247 hists__find_annotations(hists, pos, ann);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300248 }
249 }
250
251 if (total_nr_samples == 0) {
Namhyung Kimfa10f312014-08-12 15:40:35 +0900252 ui__error("The %s file has no samples!\n", session->file->path);
253 goto out;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300254 }
Namhyung Kim7a60ba92013-02-07 18:02:09 +0900255
Namhyung Kimfc672972013-09-13 15:27:43 +0900256 if (use_browser == 2) {
257 void (*show_annotations)(void);
258
259 show_annotations = dlsym(perf_gtk_handle,
260 "perf_gtk__show_annotations");
261 if (show_annotations == NULL) {
262 ui__error("GTK browser not found!\n");
Namhyung Kimfa10f312014-08-12 15:40:35 +0900263 goto out;
Namhyung Kimfc672972013-09-13 15:27:43 +0900264 }
265 show_annotations();
266 }
Namhyung Kim7a60ba92013-02-07 18:02:09 +0900267
Namhyung Kimfa10f312014-08-12 15:40:35 +0900268out:
Li Zefanbab81b62009-12-01 14:04:49 +0800269 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200270}
271
272static const char * const annotate_usage[] = {
Namhyung Kim99345252012-01-08 02:25:30 +0900273 "perf annotate [<options>]",
Ingo Molnar8035e422009-06-06 15:19:13 +0200274 NULL
275};
276
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300277int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200278{
279 struct perf_annotate annotate = {
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200280 .tool = {
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200281 .sample = process_sample_event,
282 .mmap = perf_event__process_mmap,
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200283 .mmap2 = perf_event__process_mmap2,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200284 .comm = perf_event__process_comm,
Arnaldo Carvalho de Meloec4622f2012-10-06 15:53:41 -0300285 .exit = perf_event__process_exit,
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300286 .fork = perf_event__process_fork,
Jiri Olsa0a8cb852014-07-06 14:18:21 +0200287 .ordered_events = true,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200288 .ordering_requires_timestamps = true,
289 },
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200290 };
Namhyung Kimfa10f312014-08-12 15:40:35 +0900291 struct perf_data_file file = {
Namhyung Kimfa10f312014-08-12 15:40:35 +0900292 .mode = PERF_DATA_MODE_READ,
293 };
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200294 const struct option options[] = {
Feng Tang70cb4e92012-10-30 11:56:02 +0800295 OPT_STRING('i', "input", &input_name, "file",
Ingo Molnar8035e422009-06-06 15:19:13 +0200296 "input file name"),
Arnaldo Carvalho de Meloac73c5a2010-03-24 16:40:16 -0300297 OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
298 "only consider symbols in these dsos"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200299 OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol",
Ingo Molnar0b73da32009-06-06 15:48:52 +0200300 "symbol to annotate"),
Namhyung Kimfa10f312014-08-12 15:40:35 +0900301 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
Ian Munsiec0555642010-04-13 18:37:33 +1000302 OPT_INCR('v', "verbose", &verbose,
Ingo Molnar8035e422009-06-06 15:19:13 +0200303 "be more verbose (show symbol address, etc)"),
304 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
305 "dump raw trace in ASCII"),
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900306 OPT_BOOLEAN(0, "gtk", &annotate.use_gtk, "Use the GTK interface"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200307 OPT_BOOLEAN(0, "tui", &annotate.use_tui, "Use the TUI interface"),
308 OPT_BOOLEAN(0, "stdio", &annotate.use_stdio, "Use the stdio interface"),
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200309 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
310 "file", "vmlinux pathname"),
311 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
Mike Galbraith42976482009-07-02 08:09:46 +0200312 "load module symbols - WARNING: use only with -k and LIVE kernel"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200313 OPT_BOOLEAN('l', "print-line", &annotate.print_line,
Frederic Weisbecker301406b2009-06-13 00:11:21 +0200314 "print matching source lines (may be slow)"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200315 OPT_BOOLEAN('P', "full-paths", &annotate.full_paths,
Mike Galbraith42976482009-07-02 08:09:46 +0200316 "Don't shorten the displayed pathnames"),
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900317 OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
318 "Skip symbols that cannot be annotated"),
David Ahernc8e66722011-11-13 11:30:08 -0700319 OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
Stephane Eraniane71a0592011-07-30 01:20:40 +0200320 OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
321 "Look for files with symbols relative to this directory"),
Arnaldo Carvalho de Melo64c6f0c2011-10-06 12:48:31 -0300322 OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +0200323 "Interleave source code with assembly code (default)"),
Arnaldo Carvalho de Melo64c6f0c2011-10-06 12:48:31 -0300324 OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +0200325 "Display raw encoding of assembly instructions (default)"),
Andi Kleenf69b64f2011-09-15 14:31:41 -0700326 OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
327 "Specify disassembler style (e.g. -M intel for intel syntax)"),
Maciek Borzecki7a4ec932012-09-04 12:32:30 +0200328 OPT_STRING(0, "objdump", &objdump_path, "path",
329 "objdump binary to use for disassembly and annotations"),
Namhyung Kimb1dd4432013-03-05 14:53:25 +0900330 OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
331 "Show event group information together"),
Martin Liška0c4a5bc2015-06-19 16:10:43 -0300332 OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
333 "Show a column with the sum of periods"),
Ingo Molnar8035e422009-06-06 15:19:13 +0200334 OPT_END()
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200335 };
Arnaldo Carvalho de Meloa635fc52014-10-09 16:16:00 -0300336 int ret = hists__init();
337
338 if (ret < 0)
339 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200340
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -0200341 argc = parse_options(argc, argv, options, annotate_usage, 0);
342
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200343 if (annotate.use_stdio)
Arnaldo Carvalho de Melo8b9e74e2010-08-21 10:38:16 -0300344 use_browser = 0;
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200345 else if (annotate.use_tui)
Arnaldo Carvalho de Melo8b9e74e2010-08-21 10:38:16 -0300346 use_browser = 1;
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900347 else if (annotate.use_gtk)
348 use_browser = 2;
Arnaldo Carvalho de Melo8b9e74e2010-08-21 10:38:16 -0300349
Martin Liška44848cd2015-05-29 14:06:44 +0200350 file.path = input_name;
351
Arnaldo Carvalho de Melo229ade92011-01-31 18:08:39 -0200352 setup_browser(true);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300353
Namhyung Kimfa10f312014-08-12 15:40:35 +0900354 annotate.session = perf_session__new(&file, false, &annotate.tool);
355 if (annotate.session == NULL)
Taeung Song52e028342014-09-24 10:33:37 +0900356 return -1;
Namhyung Kimfa10f312014-08-12 15:40:35 +0900357
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200358 symbol_conf.priv_size = sizeof(struct annotation);
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200359 symbol_conf.try_vmlinux_path = true;
360
Namhyung Kim0a7e6d12014-08-12 15:40:45 +0900361 ret = symbol__init(&annotate.session->header.env);
Namhyung Kimfa10f312014-08-12 15:40:35 +0900362 if (ret < 0)
363 goto out_delete;
Ingo Molnar8035e422009-06-06 15:19:13 +0200364
Namhyung Kim55309982013-02-06 14:57:16 +0900365 if (setup_sorting() < 0)
366 usage_with_options(annotate_usage, options);
Ingo Molnar8035e422009-06-06 15:19:13 +0200367
Ingo Molnar0b73da32009-06-06 15:48:52 +0200368 if (argc) {
369 /*
Dongsheng Yang6f1d0c82013-12-09 17:47:48 -0500370 * Special case: if there's an argument left then assume that
Ingo Molnar0b73da32009-06-06 15:48:52 +0200371 * it's a symbol filter:
372 */
373 if (argc > 1)
374 usage_with_options(annotate_usage, options);
375
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200376 annotate.sym_hist_filter = argv[0];
Ingo Molnar0b73da32009-06-06 15:48:52 +0200377 }
378
Namhyung Kimfa10f312014-08-12 15:40:35 +0900379 ret = __cmd_annotate(&annotate);
380
381out_delete:
382 /*
383 * Speed up the exit process, for large files this can
384 * take quite a while.
385 *
386 * XXX Enable this when using valgrind or if we ever
387 * librarize this command.
388 *
389 * Also experiment with obstacks to see how much speed
390 * up we'll get here.
391 *
392 * perf_session__delete(session);
393 */
394 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200395}