blob: 9c1034d81b4fe3cc72d4b3b09ac8d527d07b0da0 [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 Weisbecker8f288272009-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"
Josh Poimboeuf4b6ab942015-12-15 09:39:39 -060024#include <subcmd/parse-options.h>
Ingo Molnar8035e422009-06-06 15:19:13 +020025#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 Kimfd36f3d2015-12-23 02:06:58 +090050 struct perf_sample *sample,
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);
Arnaldo Carvalho de Meloc0b4dff2015-08-24 13:33:14 -030070 dso__reset_find_symbol_cache(al->map->dso);
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030071 }
72 return 0;
73 }
74
Namhyung Kimfd36f3d2015-12-23 02:06:58 +090075 sample->period = 1;
76 sample->weight = 1;
77
Jiri Olsa0102ef32016-06-14 20:19:21 +020078 he = hists__add_entry(hists, al, NULL, NULL, NULL, sample, true);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -030079 if (he == NULL)
Ingo Molnar8035e422009-06-06 15:19:13 +020080 return -ENOMEM;
Arnaldo Carvalho de Melo628ada02010-02-25 12:57:40 -030081
Arnaldo Carvalho de Melo00e55212013-12-18 15:46:32 -030082 ret = hist_entry__inc_addr_samples(he, evsel->idx, al->addr);
Arnaldo Carvalho de Melo4ea062ed2014-10-09 13:13:41 -030083 hists__inc_nr_samples(hists, true);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -030084 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +020085}
86
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020087static int process_sample_event(struct perf_tool *tool,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -020088 union perf_event *event,
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020089 struct perf_sample *sample,
Arnaldo Carvalho de Melo9e69c212011-03-15 15:44:01 -030090 struct perf_evsel *evsel,
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020091 struct machine *machine)
Ingo Molnar8035e422009-06-06 15:19:13 +020092{
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -020093 struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool);
Arnaldo Carvalho de Melo1ed091c2009-11-27 16:29:23 -020094 struct addr_location al;
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -030095 int ret = 0;
Frederic Weisbecker6baa0a52009-08-14 12:21:53 +020096
Arnaldo Carvalho de Melobb3eb562016-03-22 18:39:09 -030097 if (machine__resolve(machine, &al, sample) < 0) {
Arnaldo Carvalho de Melo29a9f662010-02-03 16:52:06 -020098 pr_warning("problem processing %d event, skipping it.\n",
99 event->header.type);
Ingo Molnar8035e422009-06-06 15:19:13 +0200100 return -1;
101 }
102
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200103 if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300104 goto out_put;
Anton Blanchard5d67be92011-07-04 21:57:50 +1000105
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200106 if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al, ann)) {
Arnaldo Carvalho de Melo29a9f662010-02-03 16:52:06 -0200107 pr_warning("problem incrementing symbol count, "
108 "skipping event\n");
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300109 ret = -1;
Ingo Molnar8035e422009-06-06 15:19:13 +0200110 }
Arnaldo Carvalho de Melob91fc392015-04-06 20:43:22 -0300111out_put:
112 addr_location__put(&al);
113 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200114}
115
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900116static int hist_entry__tty_annotate(struct hist_entry *he,
117 struct perf_evsel *evsel,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200118 struct perf_annotate *ann)
Ingo Molnar0b73da32009-06-06 15:48:52 +0200119{
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900120 return symbol__tty_annotate(he->ms.sym, he->ms.map, evsel,
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200121 ann->print_line, ann->full_paths, 0, 0);
Ingo Molnar0b73da32009-06-06 15:48:52 +0200122}
123
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300124static void hists__find_annotations(struct hists *hists,
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900125 struct perf_evsel *evsel,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200126 struct perf_annotate *ann)
Ingo Molnar0b73da32009-06-06 15:48:52 +0200127{
Arnaldo Carvalho de Meloc824c432013-10-22 19:01:31 -0300128 struct rb_node *nd = rb_first(&hists->entries), *next;
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200129 int key = K_RIGHT;
Ingo Molnar0b73da32009-06-06 15:48:52 +0200130
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300131 while (nd) {
Arnaldo Carvalho de Meloed52ce22009-10-19 17:17:57 -0200132 struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200133 struct annotation *notes;
Ingo Molnar0b73da32009-06-06 15:48:52 +0200134
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300135 if (he->ms.sym == NULL || he->ms.map->dso->annotate_warned)
136 goto find_next;
Ingo Molnar0b73da32009-06-06 15:48:52 +0200137
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200138 notes = symbol__annotation(he->ms.sym);
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200139 if (notes->src == NULL) {
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300140find_next:
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200141 if (key == K_LEFT)
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300142 nd = rb_prev(nd);
143 else
144 nd = rb_next(nd);
Arnaldo Carvalho de Meloe4204992009-10-20 14:25:40 -0200145 continue;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300146 }
Arnaldo Carvalho de Meloe4204992009-10-20 14:25:40 -0200147
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900148 if (use_browser == 2) {
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900149 int ret;
Namhyung Kimfc672972013-09-13 15:27:43 +0900150 int (*annotate)(struct hist_entry *he,
151 struct perf_evsel *evsel,
152 struct hist_browser_timer *hbt);
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900153
Namhyung Kimfc672972013-09-13 15:27:43 +0900154 annotate = dlsym(perf_gtk_handle,
155 "hist_entry__gtk_annotate");
156 if (annotate == NULL) {
157 ui__error("GTK browser not found!\n");
158 return;
159 }
160
161 ret = annotate(he, evsel, NULL);
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900162 if (!ret || !ann->skip_missing)
163 return;
164
165 /* skip missing symbols */
166 nd = rb_next(nd);
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900167 } else if (use_browser == 1) {
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900168 key = hist_entry__tui_annotate(he, evsel, NULL);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300169 switch (key) {
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900170 case -1:
171 if (!ann->skip_missing)
172 return;
173 /* fall through */
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200174 case K_RIGHT:
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300175 next = rb_next(nd);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300176 break;
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -0200177 case K_LEFT:
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300178 next = rb_prev(nd);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300179 break;
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300180 default:
181 return;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300182 }
Arnaldo Carvalho de Melob50e0032010-08-11 10:07:43 -0300183
184 if (next != NULL)
185 nd = next;
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300186 } else {
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900187 hist_entry__tty_annotate(he, evsel, ann);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300188 nd = rb_next(nd);
189 /*
190 * Since we have a hist_entry per IP for the same
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200191 * symbol, free he->ms.sym->src to signal we already
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300192 * processed this symbol.
193 */
Andi Kleend4957632015-07-18 08:24:48 -0700194 zfree(&notes->src->cycles_hist);
Arnaldo Carvalho de Melo04662522013-12-26 17:41:15 -0300195 zfree(&notes->src);
Arnaldo Carvalho de Melo46e3e052010-05-22 11:25:40 -0300196 }
Ingo Molnar0b73da32009-06-06 15:48:52 +0200197 }
Ingo Molnar0b73da32009-06-06 15:48:52 +0200198}
199
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200200static int __cmd_annotate(struct perf_annotate *ann)
Ingo Molnar8035e422009-06-06 15:19:13 +0200201{
Li Zefanbab81b62009-12-01 14:04:49 +0800202 int ret;
Namhyung Kimfa10f312014-08-12 15:40:35 +0900203 struct perf_session *session = ann->session;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300204 struct perf_evsel *pos;
205 u64 total_nr_samples;
Arnaldo Carvalho de Melo94c744b2009-12-11 21:24:02 -0200206
Adrian Hunter476d35c2013-08-08 14:32:24 +0300207 machines__set_symbol_filter(&session->machines, symbol__annotate_init);
208
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200209 if (ann->cpu_list) {
210 ret = perf_session__cpu_bitmap(session, ann->cpu_list,
211 ann->cpu_bitmap);
Anton Blanchard5d67be92011-07-04 21:57:50 +1000212 if (ret)
Namhyung Kimfa10f312014-08-12 15:40:35 +0900213 goto out;
Anton Blanchard5d67be92011-07-04 21:57:50 +1000214 }
215
Irina Tirdea68e94f42012-10-16 02:33:38 +0300216 if (!objdump_path) {
Arnaldo Carvalho de Meloeebd0bf2015-09-08 15:52:20 -0300217 ret = perf_env__lookup_objdump(&session->header.env);
Irina Tirdea68e94f42012-10-16 02:33:38 +0300218 if (ret)
Namhyung Kimfa10f312014-08-12 15:40:35 +0900219 goto out;
Irina Tirdea68e94f42012-10-16 02:33:38 +0300220 }
221
Arnaldo Carvalho de Melob7b61cb2015-03-03 11:58:45 -0300222 ret = perf_session__process_events(session);
Li Zefanbab81b62009-12-01 14:04:49 +0800223 if (ret)
Namhyung Kimfa10f312014-08-12 15:40:35 +0900224 goto out;
Ingo Molnar8035e422009-06-06 15:19:13 +0200225
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200226 if (dump_trace) {
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300227 perf_session__fprintf_nr_events(session, stdout);
Arnaldo Carvalho de Melo2a1731f2014-10-10 15:49:21 -0300228 perf_evlist__fprintf_nr_events(session->evlist, stdout);
Namhyung Kimfa10f312014-08-12 15:40:35 +0900229 goto out;
Arnaldo Carvalho de Melo62daacb2009-11-27 16:29:22 -0200230 }
Ingo Molnar8035e422009-06-06 15:19:13 +0200231
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300232 if (verbose > 3)
Arnaldo Carvalho de Melob3165f42009-12-13 19:50:28 -0200233 perf_session__fprintf(session, stdout);
Ingo Molnar8035e422009-06-06 15:19:13 +0200234
Arnaldo Carvalho de Meloda21d1b2009-10-07 10:49:00 -0300235 if (verbose > 2)
Arnaldo Carvalho de Melocbf69682010-04-27 21:22:44 -0300236 perf_session__fprintf_dsos(session, stdout);
Ingo Molnar8035e422009-06-06 15:19:13 +0200237
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300238 total_nr_samples = 0;
Arnaldo Carvalho de Meloe5cadb92016-06-23 11:26:15 -0300239 evlist__for_each_entry(session->evlist, pos) {
Arnaldo Carvalho de Melo4ea062ed2014-10-09 13:13:41 -0300240 struct hists *hists = evsel__hists(pos);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300241 u32 nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
Ingo Molnar8035e422009-06-06 15:19:13 +0200242
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300243 if (nr_samples > 0) {
244 total_nr_samples += nr_samples;
Namhyung Kimc1fb5652013-10-11 14:15:38 +0900245 hists__collapse_resort(hists, NULL);
Kan Liangf9db0d02015-08-11 06:30:48 -0400246 /* Don't sort callchain */
247 perf_evsel__reset_sample_bit(pos, CALLCHAIN);
Jiri Olsa452ce032016-01-18 10:24:00 +0100248 perf_evsel__output_resort(pos, NULL);
Namhyung Kimb1dd4432013-03-05 14:53:25 +0900249
250 if (symbol_conf.event_group &&
251 !perf_evsel__is_group_leader(pos))
252 continue;
253
Namhyung Kimdb8fd072013-03-05 14:53:21 +0900254 hists__find_annotations(hists, pos, ann);
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300255 }
256 }
257
258 if (total_nr_samples == 0) {
Namhyung Kimfa10f312014-08-12 15:40:35 +0900259 ui__error("The %s file has no samples!\n", session->file->path);
260 goto out;
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -0300261 }
Namhyung Kim7a60ba92013-02-07 18:02:09 +0900262
Namhyung Kimfc672972013-09-13 15:27:43 +0900263 if (use_browser == 2) {
264 void (*show_annotations)(void);
265
266 show_annotations = dlsym(perf_gtk_handle,
267 "perf_gtk__show_annotations");
268 if (show_annotations == NULL) {
269 ui__error("GTK browser not found!\n");
Namhyung Kimfa10f312014-08-12 15:40:35 +0900270 goto out;
Namhyung Kimfc672972013-09-13 15:27:43 +0900271 }
272 show_annotations();
273 }
Namhyung Kim7a60ba92013-02-07 18:02:09 +0900274
Namhyung Kimfa10f312014-08-12 15:40:35 +0900275out:
Li Zefanbab81b62009-12-01 14:04:49 +0800276 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200277}
278
279static const char * const annotate_usage[] = {
Namhyung Kim99345252012-01-08 02:25:30 +0900280 "perf annotate [<options>]",
Ingo Molnar8035e422009-06-06 15:19:13 +0200281 NULL
282};
283
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300284int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200285{
286 struct perf_annotate annotate = {
Arnaldo Carvalho de Melo45694aa2011-11-28 08:30:20 -0200287 .tool = {
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200288 .sample = process_sample_event,
289 .mmap = perf_event__process_mmap,
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200290 .mmap2 = perf_event__process_mmap2,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200291 .comm = perf_event__process_comm,
Arnaldo Carvalho de Meloec4622f2012-10-06 15:53:41 -0300292 .exit = perf_event__process_exit,
Arnaldo Carvalho de Melof62d3f02012-10-06 15:44:59 -0300293 .fork = perf_event__process_fork,
Jiri Olsa0a8cb852014-07-06 14:18:21 +0200294 .ordered_events = true,
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200295 .ordering_requires_timestamps = true,
296 },
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200297 };
Namhyung Kimfa10f312014-08-12 15:40:35 +0900298 struct perf_data_file file = {
Namhyung Kimfa10f312014-08-12 15:40:35 +0900299 .mode = PERF_DATA_MODE_READ,
300 };
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200301 const struct option options[] = {
Feng Tang70cb4e92012-10-30 11:56:02 +0800302 OPT_STRING('i', "input", &input_name, "file",
Ingo Molnar8035e422009-06-06 15:19:13 +0200303 "input file name"),
Arnaldo Carvalho de Meloac73c5a2010-03-24 16:40:16 -0300304 OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
305 "only consider symbols in these dsos"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200306 OPT_STRING('s', "symbol", &annotate.sym_hist_filter, "symbol",
Ingo Molnar0b73da32009-06-06 15:48:52 +0200307 "symbol to annotate"),
Namhyung Kimfa10f312014-08-12 15:40:35 +0900308 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
Ian Munsiec0555642010-04-13 18:37:33 +1000309 OPT_INCR('v', "verbose", &verbose,
Ingo Molnar8035e422009-06-06 15:19:13 +0200310 "be more verbose (show symbol address, etc)"),
311 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
312 "dump raw trace in ASCII"),
Namhyung Kim2b676bf2013-02-07 18:02:08 +0900313 OPT_BOOLEAN(0, "gtk", &annotate.use_gtk, "Use the GTK interface"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200314 OPT_BOOLEAN(0, "tui", &annotate.use_tui, "Use the TUI interface"),
315 OPT_BOOLEAN(0, "stdio", &annotate.use_stdio, "Use the stdio interface"),
Arnaldo Carvalho de Melob32d1332009-11-24 12:05:15 -0200316 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
317 "file", "vmlinux pathname"),
318 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
Mike Galbraith42976482009-07-02 08:09:46 +0200319 "load module symbols - WARNING: use only with -k and LIVE kernel"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200320 OPT_BOOLEAN('l', "print-line", &annotate.print_line,
Frederic Weisbecker301406b2009-06-13 00:11:21 +0200321 "print matching source lines (may be slow)"),
Arnaldo Carvalho de Melo7009cc32011-11-17 12:33:21 -0200322 OPT_BOOLEAN('P', "full-paths", &annotate.full_paths,
Mike Galbraith42976482009-07-02 08:09:46 +0200323 "Don't shorten the displayed pathnames"),
Namhyung Kim18c9e5c2013-02-07 18:02:14 +0900324 OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing,
325 "Skip symbols that cannot be annotated"),
David Ahernc8e66722011-11-13 11:30:08 -0700326 OPT_STRING('C', "cpu", &annotate.cpu_list, "cpu", "list of cpus to profile"),
He Kuanga7066702016-05-19 11:47:37 +0000327 OPT_CALLBACK(0, "symfs", NULL, "directory",
328 "Look for files with symbols relative to this directory",
329 symbol__config_symfs),
Arnaldo Carvalho de Melo64c6f0c2011-10-06 12:48:31 -0300330 OPT_BOOLEAN(0, "source", &symbol_conf.annotate_src,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +0200331 "Interleave source code with assembly code (default)"),
Arnaldo Carvalho de Melo64c6f0c2011-10-06 12:48:31 -0300332 OPT_BOOLEAN(0, "asm-raw", &symbol_conf.annotate_asm_raw,
Stephane Eranian3e6a2a72011-05-17 17:32:07 +0200333 "Display raw encoding of assembly instructions (default)"),
Andi Kleenf69b64f2011-09-15 14:31:41 -0700334 OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
335 "Specify disassembler style (e.g. -M intel for intel syntax)"),
Maciek Borzecki7a4ec932012-09-04 12:32:30 +0200336 OPT_STRING(0, "objdump", &objdump_path, "path",
337 "objdump binary to use for disassembly and annotations"),
Namhyung Kimb1dd4432013-03-05 14:53:25 +0900338 OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
339 "Show event group information together"),
Martin Liška0c4a5bc2015-06-19 16:10:43 -0300340 OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
341 "Show a column with the sum of periods"),
Arnaldo Carvalho de Melo53fe4ba2016-07-05 11:08:17 -0300342 OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
343 "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
344 stdio__config_color, "always"),
Ingo Molnar8035e422009-06-06 15:19:13 +0200345 OPT_END()
Arnaldo Carvalho de Melod20deb62011-11-25 08:19:45 -0200346 };
Arnaldo Carvalho de Meloa635fc52014-10-09 16:16:00 -0300347 int ret = hists__init();
348
349 if (ret < 0)
350 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200351
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -0200352 argc = parse_options(argc, argv, options, annotate_usage, 0);
Namhyung Kim50e19ef2015-12-10 12:00:53 +0900353 if (argc) {
354 /*
355 * Special case: if there's an argument left then assume that
356 * it's a symbol filter:
357 */
358 if (argc > 1)
359 usage_with_options(annotate_usage, options);
360
361 annotate.sym_hist_filter = argv[0];
362 }
Arnaldo Carvalho de Melo655000e2009-12-15 20:04:40 -0200363
Martin Liška44848cd2015-05-29 14:06:44 +0200364 file.path = input_name;
365
Namhyung Kimfa10f312014-08-12 15:40:35 +0900366 annotate.session = perf_session__new(&file, false, &annotate.tool);
367 if (annotate.session == NULL)
Taeung Song52e028342014-09-24 10:33:37 +0900368 return -1;
Namhyung Kimfa10f312014-08-12 15:40:35 +0900369
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -0200370 symbol_conf.priv_size = sizeof(struct annotation);
Arnaldo Carvalho de Melo75be6cf2009-12-15 20:04:39 -0200371 symbol_conf.try_vmlinux_path = true;
372
Namhyung Kim0a7e6d12014-08-12 15:40:45 +0900373 ret = symbol__init(&annotate.session->header.env);
Namhyung Kimfa10f312014-08-12 15:40:35 +0900374 if (ret < 0)
375 goto out_delete;
Ingo Molnar8035e422009-06-06 15:19:13 +0200376
Namhyung Kim40184c42015-12-23 02:07:01 +0900377 if (setup_sorting(NULL) < 0)
Namhyung Kim55309982013-02-06 14:57:16 +0900378 usage_with_options(annotate_usage, options);
Ingo Molnar8035e422009-06-06 15:19:13 +0200379
Namhyung Kim3df668e72015-12-10 12:00:54 +0900380 if (annotate.use_stdio)
381 use_browser = 0;
382 else if (annotate.use_tui)
383 use_browser = 1;
384 else if (annotate.use_gtk)
385 use_browser = 2;
386
387 setup_browser(true);
388
Namhyung Kimfa10f312014-08-12 15:40:35 +0900389 ret = __cmd_annotate(&annotate);
390
391out_delete:
392 /*
393 * Speed up the exit process, for large files this can
394 * take quite a while.
395 *
396 * XXX Enable this when using valgrind or if we ever
397 * librarize this command.
398 *
399 * Also experiment with obstacks to see how much speed
400 * up we'll get here.
401 *
402 * perf_session__delete(session);
403 */
404 return ret;
Ingo Molnar8035e422009-06-06 15:19:13 +0200405}