hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/tools/perf/builtin-annotate.c
....@@ -8,11 +8,11 @@
88 */
99 #include "builtin.h"
1010
11
-#include "util/util.h"
1211 #include "util/color.h"
1312 #include <linux/list.h>
1413 #include "util/cache.h"
1514 #include <linux/rbtree.h>
15
+#include <linux/zalloc.h>
1616 #include "util/symbol.h"
1717
1818 #include "perf.h"
....@@ -24,18 +24,23 @@
2424 #include "util/event.h"
2525 #include <subcmd/parse-options.h>
2626 #include "util/parse-events.h"
27
-#include "util/thread.h"
2827 #include "util/sort.h"
2928 #include "util/hist.h"
29
+#include "util/dso.h"
30
+#include "util/machine.h"
31
+#include "util/map.h"
3032 #include "util/session.h"
3133 #include "util/tool.h"
3234 #include "util/data.h"
3335 #include "arch/common.h"
3436 #include "util/block-range.h"
37
+#include "util/map_symbol.h"
38
+#include "util/branch.h"
3539
3640 #include <dlfcn.h>
3741 #include <errno.h>
3842 #include <linux/bitmap.h>
43
+#include <linux/err.h>
3944
4045 struct perf_annotate {
4146 struct perf_tool tool;
....@@ -78,7 +83,7 @@
7883 struct addr_map_symbol *end,
7984 struct branch_flags *flags)
8085 {
81
- struct symbol *sym = start->sym;
86
+ struct symbol *sym = start->ms.sym;
8287 struct annotation *notes = sym ? symbol__annotation(sym) : NULL;
8388 struct block_range_iter iter;
8489 struct block_range *entry;
....@@ -155,10 +160,8 @@
155160 struct hist_entry *he = iter->he;
156161 struct branch_info *bi;
157162 struct perf_sample *sample = iter->sample;
158
- struct perf_evsel *evsel = iter->evsel;
163
+ struct evsel *evsel = iter->evsel;
159164 int err;
160
-
161
- hist__account_cycles(sample->branch_stack, al, sample, false);
162165
163166 bi = he->branch_info;
164167 err = addr_map_symbol__inc_samples(&bi->from, sample, evsel);
....@@ -172,7 +175,7 @@
172175 return err;
173176 }
174177
175
-static int process_branch_callback(struct perf_evsel *evsel,
178
+static int process_branch_callback(struct evsel *evsel,
176179 struct perf_sample *sample,
177180 struct addr_location *al __maybe_unused,
178181 struct perf_annotate *ann,
....@@ -198,6 +201,8 @@
198201 if (a.map != NULL)
199202 a.map->dso->hit = 1;
200203
204
+ hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
205
+
201206 ret = hist_entry_iter__add(&iter, &a, PERF_MAX_STACK_DEPTH, ann);
202207 return ret;
203208 }
....@@ -207,11 +212,9 @@
207212 return ui__has_annotation() || ann->use_stdio2;
208213 }
209214
210
-static int perf_evsel__add_sample(struct perf_evsel *evsel,
211
- struct perf_sample *sample,
212
- struct addr_location *al,
213
- struct perf_annotate *ann,
214
- struct machine *machine)
215
+static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample,
216
+ struct addr_location *al, struct perf_annotate *ann,
217
+ struct machine *machine)
215218 {
216219 struct hists *hists = evsel__hists(evsel);
217220 struct hist_entry *he;
....@@ -227,7 +230,7 @@
227230 * the DSO?
228231 */
229232 if (al->sym != NULL) {
230
- rb_erase(&al->sym->rb_node,
233
+ rb_erase_cached(&al->sym->rb_node,
231234 &al->map->dso->symbols);
232235 symbol__delete(al->sym);
233236 dso__reset_find_symbol_cache(al->map->dso);
....@@ -256,7 +259,7 @@
256259 static int process_sample_event(struct perf_tool *tool,
257260 union perf_event *event,
258261 struct perf_sample *sample,
259
- struct perf_evsel *evsel,
262
+ struct evsel *evsel,
260263 struct machine *machine)
261264 {
262265 struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool);
....@@ -273,7 +276,7 @@
273276 goto out_put;
274277
275278 if (!al.filtered &&
276
- perf_evsel__add_sample(evsel, sample, &al, ann, machine)) {
279
+ evsel__add_sample(evsel, sample, &al, ann, machine)) {
277280 pr_warning("problem incrementing symbol count, "
278281 "skipping event\n");
279282 ret = -1;
....@@ -283,30 +286,29 @@
283286 return ret;
284287 }
285288
286
-static int process_feature_event(struct perf_tool *tool,
287
- union perf_event *event,
288
- struct perf_session *session)
289
+static int process_feature_event(struct perf_session *session,
290
+ union perf_event *event)
289291 {
290292 if (event->feat.feat_id < HEADER_LAST_FEATURE)
291
- return perf_event__process_feature(tool, event, session);
293
+ return perf_event__process_feature(session, event);
292294 return 0;
293295 }
294296
295297 static int hist_entry__tty_annotate(struct hist_entry *he,
296
- struct perf_evsel *evsel,
298
+ struct evsel *evsel,
297299 struct perf_annotate *ann)
298300 {
299301 if (!ann->use_stdio2)
300
- return symbol__tty_annotate(he->ms.sym, he->ms.map, evsel, &ann->opts);
302
+ return symbol__tty_annotate(&he->ms, evsel, &ann->opts);
301303
302
- return symbol__tty_annotate2(he->ms.sym, he->ms.map, evsel, &ann->opts);
304
+ return symbol__tty_annotate2(&he->ms, evsel, &ann->opts);
303305 }
304306
305307 static void hists__find_annotations(struct hists *hists,
306
- struct perf_evsel *evsel,
308
+ struct evsel *evsel,
307309 struct perf_annotate *ann)
308310 {
309
- struct rb_node *nd = rb_first(&hists->entries), *next;
311
+ struct rb_node *nd = rb_first_cached(&hists->entries), *next;
310312 int key = K_RIGHT;
311313
312314 while (nd) {
....@@ -333,7 +335,7 @@
333335 if (use_browser == 2) {
334336 int ret;
335337 int (*annotate)(struct hist_entry *he,
336
- struct perf_evsel *evsel,
338
+ struct evsel *evsel,
337339 struct hist_browser_timer *hbt);
338340
339341 annotate = dlsym(perf_gtk_handle,
....@@ -387,7 +389,7 @@
387389 {
388390 int ret;
389391 struct perf_session *session = ann->session;
390
- struct perf_evsel *pos;
392
+ struct evsel *pos;
391393 u64 total_nr_samples;
392394
393395 if (ann->cpu_list) {
....@@ -429,11 +431,10 @@
429431 total_nr_samples += nr_samples;
430432 hists__collapse_resort(hists, NULL);
431433 /* Don't sort callchain */
432
- perf_evsel__reset_sample_bit(pos, CALLCHAIN);
433
- perf_evsel__output_resort(pos, NULL);
434
+ evsel__reset_sample_bit(pos, CALLCHAIN);
435
+ evsel__output_resort(pos, NULL);
434436
435
- if (symbol_conf.event_group &&
436
- !perf_evsel__is_group_leader(pos))
437
+ if (symbol_conf.event_group && !evsel__is_group_leader(pos))
437438 continue;
438439
439440 hists__find_annotations(hists, pos, ann);
....@@ -441,7 +442,7 @@
441442 }
442443
443444 if (total_nr_samples == 0) {
444
- ui__error("The %s file has no samples!\n", session->data->file.path);
445
+ ui__error("The %s data has no samples!\n", session->data->path);
445446 goto out;
446447 }
447448
....@@ -531,6 +532,10 @@
531532 "Display raw encoding of assembly instructions (default)"),
532533 OPT_STRING('M', "disassembler-style", &annotate.opts.disassembler_style, "disassembler style",
533534 "Specify disassembler style (e.g. -M intel for intel syntax)"),
535
+ OPT_STRING(0, "prefix", &annotate.opts.prefix, "prefix",
536
+ "Add prefix to source file path names in programs (with --prefix-strip)"),
537
+ OPT_STRING(0, "prefix-strip", &annotate.opts.prefix_strip, "N",
538
+ "Strip first N entries of source file path name in programs (with --prefix)"),
534539 OPT_STRING(0, "objdump", &annotate.opts.objdump_path, "path",
535540 "objdump binary to use for disassembly and annotations"),
536541 OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
....@@ -558,6 +563,8 @@
558563 if (ret < 0)
559564 return ret;
560565
566
+ annotation_config__init(&annotate.opts);
567
+
561568 argc = parse_options(argc, argv, options, annotate_usage, 0);
562569 if (argc) {
563570 /*
....@@ -570,6 +577,9 @@
570577 annotate.sym_hist_filter = argv[0];
571578 }
572579
580
+ if (annotate_check_args(&annotate.opts) < 0)
581
+ return -EINVAL;
582
+
573583 if (symbol_conf.show_nr_samples && annotate.use_gtk) {
574584 pr_err("--show-nr-samples is not available in --gtk mode at this time\n");
575585 return ret;
....@@ -578,11 +588,11 @@
578588 if (quiet)
579589 perf_quiet_option();
580590
581
- data.file.path = input_name;
591
+ data.path = input_name;
582592
583593 annotate.session = perf_session__new(&data, false, &annotate.tool);
584
- if (annotate.session == NULL)
585
- return -1;
594
+ if (IS_ERR(annotate.session))
595
+ return PTR_ERR(annotate.session);
586596
587597 annotate.has_br_stack = perf_header__has_feat(&annotate.session->header,
588598 HEADER_BRANCH_STACK);
....@@ -593,8 +603,6 @@
593603 ret = symbol__annotation_init();
594604 if (ret < 0)
595605 goto out_delete;
596
-
597
- annotation_config__init();
598606
599607 symbol_conf.try_vmlinux_path = true;
600608