Skip to content

Commit 7384083

Browse files
Ravi Bangoriaacmel
authored andcommitted
perf annotate: Make perf config effective
perf default config set by user in [annotate] section is totally ignored by annotate code. Fix it. Before: $ ./perf config annotate.hide_src_code=true annotate.show_nr_jumps=true annotate.show_nr_samples=true $ ./perf annotate shash │ unsigned h = 0; │ movl $0x0,-0xc(%rbp) │ while (*s) │ ↓ jmp 44 │ h = 65599 * h + *s++; 11.33 │24: mov -0xc(%rbp),%eax 43.50 │ imul $0x1003f,%eax,%ecx │ mov -0x18(%rbp),%rax After: │ movl $0x0,-0xc(%rbp) │ ↓ jmp 44 1 │1 24: mov -0xc(%rbp),%eax 4 │ imul $0x1003f,%eax,%ecx │ mov -0x18(%rbp),%rax Note that we have removed show_nr_samples and show_total_period from annotation_options because they are not used. Instead of them we use symbol_conf.show_nr_samples and symbol_conf.show_total_period. Committer testing: Using 'perf annotate --stdio2' to use the TUI rendering but emitting the output to stdio: # perf config # # perf config annotate.hide_src_code=true # perf config annotate.hide_src_code=true # # perf config annotate.show_nr_jumps=true # perf config annotate.show_nr_samples=true # perf config annotate.hide_src_code=true annotate.show_nr_jumps=true annotate.show_nr_samples=true # # Before: # perf annotate --stdio2 ObjectInstance::weak_pointer_was_finalized Samples: 1 of event 'cycles', 4000 Hz, Event count (approx.): 830873, [percent: local period] ObjectInstance::weak_pointer_was_finalized() /usr/lib64/libgjs.so.0.0.0 Percent 00000000000609f0 <ObjectInstance::weak_pointer_was_finalized()@@base>: endbr64 cmpq $0x0,0x20(%rdi) ↓ je 10 xor %eax,%eax ← retq xchg %ax,%ax 100.00 10: push %rbp cmpq $0x0,0x18(%rdi) mov %rdi,%rbp ↓ jne 20 1b: xor %eax,%eax pop %rbp ← retq nop 20: lea 0x18(%rdi),%rdi → callq JS_UpdateWeakPointerAfterGC(JS::Heap<JSObject* cmpq $0x0,0x18(%rbp) ↑ jne 1b mov %rbp,%rdi → callq ObjectBase::jsobj_addr() const@plt mov $0x1,%eax pop %rbp ← retq # After: # perf annotate --stdio2 ObjectInstance::weak_pointer_was_finalized 2> /dev/null Samples: 1 of event 'cycles', 4000 Hz, Event count (approx.): 830873, [percent: local period] ObjectInstance::weak_pointer_was_finalized() /usr/lib64/libgjs.so.0.0.0 Samples endbr64 cmpq $0x0,0x20(%rdi) ↓ je 10 xor %eax,%eax ← retq xchg %ax,%ax 1 1 10: push %rbp cmpq $0x0,0x18(%rdi) mov %rdi,%rbp ↓ jne 20 1 1b: xor %eax,%eax pop %rbp ← retq nop 1 20: lea 0x18(%rdi),%rdi → callq JS_UpdateWeakPointerAfterGC(JS::Heap<JSObject* cmpq $0x0,0x18(%rbp) ↑ jne 1b mov %rbp,%rdi → callq ObjectBase::jsobj_addr() const@plt mov $0x1,%eax pop %rbp ← retq # # perf config annotate.show_nr_jumps annotate.show_nr_jumps=true # perf config annotate.show_nr_jumps=false # perf config annotate.show_nr_jumps annotate.show_nr_jumps=false # # perf annotate --stdio2 ObjectInstance::weak_pointer_was_finalized 2> /dev/null Samples: 1 of event 'cycles', 4000 Hz, Event count (approx.): 830873, [percent: local period] ObjectInstance::weak_pointer_was_finalized() /usr/lib64/libgjs.so.0.0.0 Samples endbr64 cmpq $0x0,0x20(%rdi) ↓ je 10 xor %eax,%eax ← retq xchg %ax,%ax 1 10: push %rbp cmpq $0x0,0x18(%rdi) mov %rdi,%rbp ↓ jne 20 1b: xor %eax,%eax pop %rbp ← retq nop 20: lea 0x18(%rdi),%rdi → callq JS_UpdateWeakPointerAfterGC(JS::Heap<JSObject* cmpq $0x0,0x18(%rbp) ↑ jne 1b mov %rbp,%rdi → callq ObjectBase::jsobj_addr() const@plt mov $0x1,%eax pop %rbp ← retq # Signed-off-by: Ravi Bangoria <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexey Budankov <[email protected]> Cc: Changbin Du <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jin Yao <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Leo Yan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Song Liu <[email protected]> Cc: Taeung Song <[email protected]> Cc: Thomas Richter <[email protected]> Cc: Yisheng Xie <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7b43b69 commit 7384083

File tree

5 files changed

+33
-55
lines changed

5 files changed

+33
-55
lines changed

tools/perf/builtin-annotate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ int cmd_annotate(int argc, const char **argv)
605605
if (ret < 0)
606606
goto out_delete;
607607

608-
annotation_config__init();
608+
annotation_config__init(&annotate.opts);
609609

610610
symbol_conf.try_vmlinux_path = true;
611611

tools/perf/builtin-report.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1507,7 +1507,7 @@ int cmd_report(int argc, const char **argv)
15071507
symbol_conf.priv_size += sizeof(u32);
15081508
symbol_conf.sort_by_name = true;
15091509
}
1510-
annotation_config__init();
1510+
annotation_config__init(&report.annotation_opts);
15111511
}
15121512

15131513
if (symbol__init(&session->header.env) < 0)

tools/perf/builtin-top.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ int cmd_top(int argc, const char **argv)
16831683
if (status < 0)
16841684
goto out_delete_evlist;
16851685

1686-
annotation_config__init();
1686+
annotation_config__init(&top.annotation_opts);
16871687

16881688
symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
16891689
status = symbol__init(NULL);

tools/perf/util/annotate.c

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,66 +3094,46 @@ int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel,
30943094
return err;
30953095
}
30963096

3097-
#define ANNOTATION__CFG(n) \
3098-
{ .name = #n, .value = &annotation__default_options.n, }
3099-
3100-
/*
3101-
* Keep the entries sorted, they are bsearch'ed
3102-
*/
3103-
static struct annotation_config {
3104-
const char *name;
3105-
void *value;
3106-
} annotation__configs[] = {
3107-
ANNOTATION__CFG(hide_src_code),
3108-
ANNOTATION__CFG(jump_arrows),
3109-
ANNOTATION__CFG(offset_level),
3110-
ANNOTATION__CFG(show_linenr),
3111-
ANNOTATION__CFG(show_nr_jumps),
3112-
ANNOTATION__CFG(show_nr_samples),
3113-
ANNOTATION__CFG(show_total_period),
3114-
ANNOTATION__CFG(use_offset),
3115-
};
3116-
3117-
#undef ANNOTATION__CFG
3118-
3119-
static int annotation_config__cmp(const void *name, const void *cfgp)
3097+
static int annotation__config(const char *var, const char *value, void *data)
31203098
{
3121-
const struct annotation_config *cfg = cfgp;
3122-
3123-
return strcmp(name, cfg->name);
3124-
}
3125-
3126-
static int annotation__config(const char *var, const char *value,
3127-
void *data __maybe_unused)
3128-
{
3129-
struct annotation_config *cfg;
3130-
const char *name;
3099+
struct annotation_options *opt = data;
31313100

31323101
if (!strstarts(var, "annotate."))
31333102
return 0;
31343103

3135-
name = var + 9;
3136-
cfg = bsearch(name, annotation__configs, ARRAY_SIZE(annotation__configs),
3137-
sizeof(struct annotation_config), annotation_config__cmp);
3138-
3139-
if (cfg == NULL)
3140-
pr_debug("%s variable unknown, ignoring...", var);
3141-
else if (strcmp(var, "annotate.offset_level") == 0) {
3142-
perf_config_int(cfg->value, name, value);
3143-
3144-
if (*(int *)cfg->value > ANNOTATION__MAX_OFFSET_LEVEL)
3145-
*(int *)cfg->value = ANNOTATION__MAX_OFFSET_LEVEL;
3146-
else if (*(int *)cfg->value < ANNOTATION__MIN_OFFSET_LEVEL)
3147-
*(int *)cfg->value = ANNOTATION__MIN_OFFSET_LEVEL;
3104+
if (!strcmp(var, "annotate.offset_level")) {
3105+
perf_config_u8(&opt->offset_level, "offset_level", value);
3106+
3107+
if (opt->offset_level > ANNOTATION__MAX_OFFSET_LEVEL)
3108+
opt->offset_level = ANNOTATION__MAX_OFFSET_LEVEL;
3109+
else if (opt->offset_level < ANNOTATION__MIN_OFFSET_LEVEL)
3110+
opt->offset_level = ANNOTATION__MIN_OFFSET_LEVEL;
3111+
} else if (!strcmp(var, "annotate.hide_src_code")) {
3112+
opt->hide_src_code = perf_config_bool("hide_src_code", value);
3113+
} else if (!strcmp(var, "annotate.jump_arrows")) {
3114+
opt->jump_arrows = perf_config_bool("jump_arrows", value);
3115+
} else if (!strcmp(var, "annotate.show_linenr")) {
3116+
opt->show_linenr = perf_config_bool("show_linenr", value);
3117+
} else if (!strcmp(var, "annotate.show_nr_jumps")) {
3118+
opt->show_nr_jumps = perf_config_bool("show_nr_jumps", value);
3119+
} else if (!strcmp(var, "annotate.show_nr_samples")) {
3120+
symbol_conf.show_nr_samples = perf_config_bool("show_nr_samples",
3121+
value);
3122+
} else if (!strcmp(var, "annotate.show_total_period")) {
3123+
symbol_conf.show_total_period = perf_config_bool("show_total_period",
3124+
value);
3125+
} else if (!strcmp(var, "annotate.use_offset")) {
3126+
opt->use_offset = perf_config_bool("use_offset", value);
31483127
} else {
3149-
*(bool *)cfg->value = perf_config_bool(name, value);
3128+
pr_debug("%s variable unknown, ignoring...", var);
31503129
}
3130+
31513131
return 0;
31523132
}
31533133

3154-
void annotation_config__init(void)
3134+
void annotation_config__init(struct annotation_options *opt)
31553135
{
3156-
perf_config(annotation__config, NULL);
3136+
perf_config(annotation__config, opt);
31573137
}
31583138

31593139
static unsigned int parse_percent_type(char *str1, char *str2)

tools/perf/util/annotate.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ struct annotation_options {
8383
full_path,
8484
show_linenr,
8585
show_nr_jumps,
86-
show_nr_samples,
87-
show_total_period,
8886
show_minmax_cycle,
8987
show_asm_raw,
9088
annotate_src;
@@ -413,7 +411,7 @@ static inline int symbol__tui_annotate(struct map_symbol *ms __maybe_unused,
413411
}
414412
#endif
415413

416-
void annotation_config__init(void);
414+
void annotation_config__init(struct annotation_options *opt);
417415

418416
int annotate_parse_percent_type(const struct option *opt, const char *_str,
419417
int unset);

0 commit comments

Comments
 (0)