Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf annotate: Introduce global annotation_options

The annotation options are to control the behavior of objdump and the
output. It's basically used by 'perf annotate' but 'perf report' and
'perf top' can call it on TUI dynamically.

But it doesn't need to have a copy of annotation options in many places.

As most of the work is done in the util/annotate.c file, add a global
variable and set/use it instead of having their own copies.

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20231128175441.721579-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
9d03194a 0713ab3b

+26 -22
+21 -22
tools/perf/builtin-annotate.c
··· 45 45 struct perf_annotate { 46 46 struct perf_tool tool; 47 47 struct perf_session *session; 48 - struct annotation_options opts; 49 48 #ifdef HAVE_SLANG_SUPPORT 50 49 bool use_tui; 51 50 #endif ··· 317 318 struct perf_annotate *ann) 318 319 { 319 320 if (!ann->use_stdio2) 320 - return symbol__tty_annotate(&he->ms, evsel, &ann->opts); 321 + return symbol__tty_annotate(&he->ms, evsel, &annotate_opts); 321 322 322 - return symbol__tty_annotate2(&he->ms, evsel, &ann->opts); 323 + return symbol__tty_annotate2(&he->ms, evsel, &annotate_opts); 323 324 } 324 325 325 326 static void hists__find_annotations(struct hists *hists, ··· 375 376 return; 376 377 } 377 378 378 - ret = annotate(he, evsel, &ann->opts, NULL); 379 + ret = annotate(he, evsel, &annotate_opts, NULL); 379 380 if (!ret || !ann->skip_missing) 380 381 return; 381 382 382 383 /* skip missing symbols */ 383 384 nd = rb_next(nd); 384 385 } else if (use_browser == 1) { 385 - key = hist_entry__tui_annotate(he, evsel, NULL, &ann->opts); 386 + key = hist_entry__tui_annotate(he, evsel, NULL, &annotate_opts); 386 387 387 388 switch (key) { 388 389 case -1: ··· 424 425 goto out; 425 426 } 426 427 427 - if (!ann->opts.objdump_path) { 428 + if (!annotate_opts.objdump_path) { 428 429 ret = perf_env__lookup_objdump(&session->header.env, 429 - &ann->opts.objdump_path); 430 + &annotate_opts.objdump_path); 430 431 if (ret) 431 432 goto out; 432 433 } ··· 560 561 "file", "vmlinux pathname"), 561 562 OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, 562 563 "load module symbols - WARNING: use only with -k and LIVE kernel"), 563 - OPT_BOOLEAN('l', "print-line", &annotate.opts.print_lines, 564 + OPT_BOOLEAN('l', "print-line", &annotate_opts.print_lines, 564 565 "print matching source lines (may be slow)"), 565 - OPT_BOOLEAN('P', "full-paths", &annotate.opts.full_path, 566 + OPT_BOOLEAN('P', "full-paths", &annotate_opts.full_path, 566 567 "Don't shorten the displayed pathnames"), 567 568 OPT_BOOLEAN(0, "skip-missing", &annotate.skip_missing, 568 569 "Skip symbols that cannot be annotated"), ··· 573 574 OPT_CALLBACK(0, "symfs", NULL, "directory", 574 575 "Look for files with symbols relative to this directory", 575 576 symbol__config_symfs), 576 - OPT_BOOLEAN(0, "source", &annotate.opts.annotate_src, 577 + OPT_BOOLEAN(0, "source", &annotate_opts.annotate_src, 577 578 "Interleave source code with assembly code (default)"), 578 - OPT_BOOLEAN(0, "asm-raw", &annotate.opts.show_asm_raw, 579 + OPT_BOOLEAN(0, "asm-raw", &annotate_opts.show_asm_raw, 579 580 "Display raw encoding of assembly instructions (default)"), 580 581 OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style", 581 582 "Specify disassembler style (e.g. -M intel for intel syntax)"), 582 - OPT_STRING(0, "prefix", &annotate.opts.prefix, "prefix", 583 + OPT_STRING(0, "prefix", &annotate_opts.prefix, "prefix", 583 584 "Add prefix to source file path names in programs (with --prefix-strip)"), 584 - OPT_STRING(0, "prefix-strip", &annotate.opts.prefix_strip, "N", 585 + OPT_STRING(0, "prefix-strip", &annotate_opts.prefix_strip, "N", 585 586 "Strip first N entries of source file path name in programs (with --prefix)"), 586 587 OPT_STRING(0, "objdump", &objdump_path, "path", 587 588 "objdump binary to use for disassembly and annotations"), ··· 600 601 OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode", 601 602 "'always' (default), 'never' or 'auto' only applicable to --stdio mode", 602 603 stdio__config_color, "always"), 603 - OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period", 604 + OPT_CALLBACK(0, "percent-type", &annotate_opts, "local-period", 604 605 "Set percent type local/global-period/hits", 605 606 annotate_parse_percent_type), 606 607 OPT_CALLBACK(0, "percent-limit", &annotate, "percent", ··· 616 617 set_option_flag(options, 0, "show-total-period", PARSE_OPT_EXCLUSIVE); 617 618 set_option_flag(options, 0, "show-nr-samples", PARSE_OPT_EXCLUSIVE); 618 619 619 - annotation_options__init(&annotate.opts); 620 + annotation_options__init(&annotate_opts); 620 621 621 622 ret = hists__init(); 622 623 if (ret < 0) 623 624 return ret; 624 625 625 - annotation_config__init(&annotate.opts); 626 + annotation_config__init(&annotate_opts); 626 627 627 628 argc = parse_options(argc, argv, options, annotate_usage, 0); 628 629 if (argc) { ··· 637 638 } 638 639 639 640 if (disassembler_style) { 640 - annotate.opts.disassembler_style = strdup(disassembler_style); 641 - if (!annotate.opts.disassembler_style) 641 + annotate_opts.disassembler_style = strdup(disassembler_style); 642 + if (!annotate_opts.disassembler_style) 642 643 return -ENOMEM; 643 644 } 644 645 if (objdump_path) { 645 - annotate.opts.objdump_path = strdup(objdump_path); 646 - if (!annotate.opts.objdump_path) 646 + annotate_opts.objdump_path = strdup(objdump_path); 647 + if (!annotate_opts.objdump_path) 647 648 return -ENOMEM; 648 649 } 649 650 if (addr2line_path) { ··· 652 653 return -ENOMEM; 653 654 } 654 655 655 - if (annotate_check_args(&annotate.opts) < 0) 656 + if (annotate_check_args(&annotate_opts) < 0) 656 657 return -EINVAL; 657 658 658 659 #ifdef HAVE_GTK2_SUPPORT ··· 733 734 #ifndef NDEBUG 734 735 perf_session__delete(annotate.session); 735 736 #endif 736 - annotation_options__exit(&annotate.opts); 737 + annotation_options__exit(&annotate_opts); 737 738 738 739 return ret; 739 740 }
+3
tools/perf/util/annotate.c
··· 57 57 58 58 #include <linux/ctype.h> 59 59 60 + /* global annotation options */ 61 + struct annotation_options annotate_opts; 62 + 60 63 static regex_t file_lineno; 61 64 62 65 static struct ins_ops *ins__find(struct arch *arch, const char *name);
+2
tools/perf/util/annotate.h
··· 105 105 unsigned int percent_type; 106 106 }; 107 107 108 + extern struct annotation_options annotate_opts; 109 + 108 110 enum { 109 111 ANNOTATION__OFFSET_JUMP_TARGETS = 1, 110 112 ANNOTATION__OFFSET_CALL,