Skip to content

Commit 6cff0e8

Browse files
navytuxIngo Molnar
authored andcommitted
perf top: Teach it to autolocate vmlinux
By relying on logic in dso__load_kernel_sym(), we can automatically load vmlinux. The only thing which needs to be adjusted, is how --sym-annotate option is handled - now we can't rely on vmlinux been loaded until full successful pass of dso__load_vmlinux(), but that's not the case if we'll do sym_filter_entry setup in symbol_filter(). So move this step right after event__process_sample() where we know the whole dso__load_kernel_sym() pass is done. By the way, though conceptually similar `perf top` still can't annotate userspace - see next patches with fixes. Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Mike Galbraith <efault@gmx.de> LKML-Reference: <1265223128-11786-9-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 7a2b620 commit 6cff0e8

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

tools/perf/Documentation/perf-top.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ OPTIONS
7474

7575
-s <symbol>::
7676
--sym-annotate=<symbol>::
77-
Annotate this symbol. Requires -k option.
77+
Annotate this symbol.
7878

7979
-v::
8080
--verbose::

tools/perf/builtin-top.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct source_line {
9494

9595
static char *sym_filter = NULL;
9696
struct sym_entry *sym_filter_entry = NULL;
97+
struct sym_entry *sym_filter_entry_sched = NULL;
9798
static int sym_pcnt_filter = 5;
9899
static int sym_counter = 0;
99100
static int display_weighted = -1;
@@ -695,11 +696,9 @@ static void print_mapped_keys(void)
695696

696697
fprintf(stdout, "\t[f] profile display filter (count). \t(%d)\n", count_filter);
697698

698-
if (symbol_conf.vmlinux_name) {
699-
fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter);
700-
fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL");
701-
fprintf(stdout, "\t[S] stop annotation.\n");
702-
}
699+
fprintf(stdout, "\t[F] annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter);
700+
fprintf(stdout, "\t[s] annotate symbol. \t(%s)\n", name?: "NULL");
701+
fprintf(stdout, "\t[S] stop annotation.\n");
703702

704703
if (nr_counters > 1)
705704
fprintf(stdout, "\t[w] toggle display weighted/count[E]r. \t(%d)\n", display_weighted ? 1 : 0);
@@ -725,14 +724,13 @@ static int key_mapped(int c)
725724
case 'Q':
726725
case 'K':
727726
case 'U':
727+
case 'F':
728+
case 's':
729+
case 'S':
728730
return 1;
729731
case 'E':
730732
case 'w':
731733
return nr_counters > 1 ? 1 : 0;
732-
case 'F':
733-
case 's':
734-
case 'S':
735-
return symbol_conf.vmlinux_name ? 1 : 0;
736734
default:
737735
break;
738736
}
@@ -910,8 +908,12 @@ static int symbol_filter(struct map *map, struct symbol *sym)
910908
syme = symbol__priv(sym);
911909
syme->map = map;
912910
syme->src = NULL;
913-
if (!sym_filter_entry && sym_filter && !strcmp(name, sym_filter))
914-
sym_filter_entry = syme;
911+
912+
if (!sym_filter_entry && sym_filter && !strcmp(name, sym_filter)) {
913+
/* schedule initial sym_filter_entry setup */
914+
sym_filter_entry_sched = syme;
915+
sym_filter = NULL;
916+
}
915917

916918
for (i = 0; skip_symbols[i]; i++) {
917919
if (!strcmp(skip_symbols[i], name)) {
@@ -976,6 +978,13 @@ static void event__process_sample(const event_t *self,
976978
return;
977979
}
978980

981+
/* let's see, whether we need to install initial sym_filter_entry */
982+
if (sym_filter_entry_sched) {
983+
sym_filter_entry = sym_filter_entry_sched;
984+
sym_filter_entry_sched = NULL;
985+
parse_source(sym_filter_entry);
986+
}
987+
979988
syme = symbol__priv(al.sym);
980989
if (!syme->skip) {
981990
syme->count[counter]++;
@@ -1270,7 +1279,7 @@ static const struct option options[] = {
12701279
OPT_BOOLEAN('i', "inherit", &inherit,
12711280
"child tasks inherit counters"),
12721281
OPT_STRING('s', "sym-annotate", &sym_filter, "symbol name",
1273-
"symbol to annotate - requires -k option"),
1282+
"symbol to annotate"),
12741283
OPT_BOOLEAN('z', "zero", &zero,
12751284
"zero history across updates"),
12761285
OPT_INTEGER('F', "freq", &freq,
@@ -1306,16 +1315,14 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
13061315

13071316
symbol_conf.priv_size = (sizeof(struct sym_entry) +
13081317
(nr_counters + 1) * sizeof(unsigned long));
1309-
if (symbol_conf.vmlinux_name == NULL)
1310-
symbol_conf.try_vmlinux_path = true;
1318+
1319+
symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
13111320
if (symbol__init() < 0)
13121321
return -1;
13131322

13141323
if (delay_secs < 1)
13151324
delay_secs = 1;
13161325

1317-
parse_source(sym_filter_entry);
1318-
13191326
/*
13201327
* User specified count overrides default frequency.
13211328
*/

0 commit comments

Comments
 (0)