Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b32d133a authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Ingo Molnar
Browse files

perf symbols: Simplify symbol machinery setup



And also express its configuration toggles via a struct.

Now all one has to do is to call symbol__init(NULL) if the
defaults are OK, or pass a struct symbol_conf pointer with the
desired configuration.

If a tool uses kernel_maps__find_symbol() to look at the kernel
and modules mappings for a symbol but didn't call symbol__init()
first, that will generate a one time warning too, alerting the
subcommand developer that symbol__init() must be called.

Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1259071517-3242-2-git-send-email-acme@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 7cc017ed
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -34,11 +34,9 @@ static int input;
static int		full_paths;

static int		print_line;
static bool		use_modules;

static unsigned long	page_size;
static unsigned long	mmap_window = 32;
const char		*vmlinux_name;

struct sym_hist {
	u64		sum;
@@ -56,6 +54,11 @@ struct sym_priv {
	struct sym_ext	*ext;
};

static struct symbol_conf symbol_conf = {
	.priv_size	  = sizeof(struct sym_priv),
	.try_vmlinux_path = true,
};

static const char *sym_hist_filter;

static int symbol_filter(struct map *map __used, struct symbol *sym)
@@ -586,11 +589,6 @@ static int __cmd_annotate(void)
		exit(0);
	}

	if (kernel_maps__init(vmlinux_name, true, use_modules) < 0) {
		pr_err("failed to create kernel maps for symbol resolution\b");
		return -1;
	}

remap:
	buf = (char *)mmap(NULL, page_size * mmap_window, PROT_READ,
			   MAP_SHARED, input, offset);
@@ -691,8 +689,9 @@ static const struct option options[] = {
		    "be more verbose (show symbol address, etc)"),
	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
		    "dump raw trace in ASCII"),
	OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
	OPT_BOOLEAN('m', "modules", &use_modules,
	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
		   "file", "vmlinux pathname"),
	OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
		    "load module symbols - WARNING: use only with -k and LIVE kernel"),
	OPT_BOOLEAN('l', "print-line", &print_line,
		    "print matching source lines (may be slow)"),
@@ -718,7 +717,8 @@ static void setup_sorting(void)

int cmd_annotate(int argc, const char **argv, const char *prefix __used)
{
	symbol__init(sizeof(struct sym_priv));
	if (symbol__init(&symbol_conf) < 0)
		return -1;

	page_size = getpagesize();

+1 −1
Original line number Diff line number Diff line
@@ -412,7 +412,7 @@ static int read_events(void)
	register_idle_thread();
	register_perf_file_handler(&file_handler);

	return mmap_dispatch_perf_file(&header, input_name, NULL, false, 0, 0,
	return mmap_dispatch_perf_file(&header, input_name, 0, 0,
				       &cwdlen, &cwd);
}

+8 −7
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ static char *dso_list_str, *comm_list_str, *sym_list_str,
static struct strlist	*dso_list, *comm_list, *sym_list;

static int		force;
static bool		use_modules;

static int		full_paths;
static int		show_nr_samples;
@@ -53,12 +52,13 @@ static char *pretty_printing_style = default_pretty_printing_style;
static int		exclude_other = 1;

static char		callchain_default_opt[] = "fractal,0.5";
const char		*vmlinux_name;

static struct perf_header *header;

static u64		sample_type;

struct symbol_conf	symbol_conf;


static size_t
callchain__fprintf_left_margin(FILE *fp, int left_margin)
@@ -865,8 +865,7 @@ static int __cmd_report(void)

	register_perf_file_handler(&file_handler);

	ret = mmap_dispatch_perf_file(&header, input_name, vmlinux_name,
				      !vmlinux_name, force,
	ret = mmap_dispatch_perf_file(&header, input_name, force,
				      full_paths, &cwdlen, &cwd);
	if (ret)
		return ret;
@@ -963,9 +962,10 @@ static const struct option options[] = {
		    "be more verbose (show symbol address, etc)"),
	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
		    "dump raw trace in ASCII"),
	OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
		   "file", "vmlinux pathname"),
	OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
	OPT_BOOLEAN('m', "modules", &use_modules,
	OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules,
		    "load module symbols - WARNING: use only with -k and LIVE kernel"),
	OPT_BOOLEAN('n', "show-nr-samples", &show_nr_samples,
		    "Show a column with the number of samples"),
@@ -1035,7 +1035,8 @@ static void setup_list(struct strlist **list, const char *list_str,

int cmd_report(int argc, const char **argv, const char *prefix __used)
{
	symbol__init(0);
	if (symbol__init(&symbol_conf) < 0)
		return -1;

	argc = parse_options(argc, argv, options, report_usage, 0);

+1 −1
Original line number Diff line number Diff line
@@ -1718,7 +1718,7 @@ static int read_events(void)
	register_idle_thread();
	register_perf_file_handler(&file_handler);

	return mmap_dispatch_perf_file(&header, input_name, NULL, false, 0, 0,
	return mmap_dispatch_perf_file(&header, input_name, 0, 0,
				       &cwdlen, &cwd);
}

+13 −11
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ static int dump_symtab = 0;
static bool			hide_kernel_symbols		=  false;
static bool			hide_user_symbols		=  false;
static struct winsize		winsize;
const char 			*vmlinux_name;
struct symbol_conf		symbol_conf;

/*
 * Source
@@ -128,7 +128,7 @@ struct sym_entry {

static inline struct symbol *sym_entry__symbol(struct sym_entry *self)
{
       return ((void *)self) + symbol__priv_size;
       return ((void *)self) + symbol_conf.priv_size;
}

static void get_term_dimensions(struct winsize *ws)
@@ -695,7 +695,7 @@ static void print_mapped_keys(void)

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

	if (vmlinux_name) {
	if (symbol_conf.vmlinux_name) {
		fprintf(stdout, "\t[F]     annotate display filter (percent). \t(%d%%)\n", sym_pcnt_filter);
		fprintf(stdout, "\t[s]     annotate symbol.                   \t(%s)\n", name?: "NULL");
		fprintf(stdout, "\t[S]     stop annotation.\n");
@@ -732,7 +732,7 @@ static int key_mapped(int c)
		case 'F':
		case 's':
		case 'S':
			return vmlinux_name ? 1 : 0;
			return symbol_conf.vmlinux_name ? 1 : 0;
		default:
			break;
	}
@@ -1261,7 +1261,8 @@ static const struct option options[] = {
			    "system-wide collection from all CPUs"),
	OPT_INTEGER('C', "CPU", &profile_cpu,
		    "CPU to profile on"),
	OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"),
	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
		   "file", "vmlinux pathname"),
	OPT_BOOLEAN('K', "hide_kernel_symbols", &hide_kernel_symbols,
		    "hide kernel symbols"),
	OPT_INTEGER('m', "mmap-pages", &mmap_pages,
@@ -1295,7 +1296,7 @@ static const struct option options[] = {

int cmd_top(int argc, const char **argv, const char *prefix __used)
{
	int counter, err;
	int counter;

	page_size = sysconf(_SC_PAGE_SIZE);

@@ -1313,15 +1314,16 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
	if (!nr_counters)
		nr_counters = 1;

	symbol__init(sizeof(struct sym_entry) +
	symbol_conf.priv_size = (sizeof(struct sym_entry) +
				 (nr_counters + 1) * sizeof(unsigned long));
	if (symbol_conf.vmlinux_name == NULL)
		symbol_conf.try_vmlinux_path = true;
	if (symbol__init(&symbol_conf) < 0)
		return -1;

	if (delay_secs < 1)
		delay_secs = 1;

	err = kernel_maps__init(vmlinux_name, !vmlinux_name, true);
	if (err < 0)
		return err;
	parse_source(sym_filter_entry);

	/*
Loading