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

Commit cd84c2ac authored by Frederic Weisbecker's avatar Frederic Weisbecker
Browse files

perf tools: Factorize high level dso helpers



Factorize multiple definitions of high level dso helpers into the
symbol source file.

The side effect is a general export of the verbose and eprintf
debugging helpers into a new file dedicated to debugging purposes.

Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Brice Goglin <Brice.Goglin@inria.fr>
parent 9f866697
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -339,6 +339,7 @@ LIB_OBJS += util/pager.o
LIB_OBJS += util/header.o
LIB_OBJS += util/callchain.o
LIB_OBJS += util/values.o
LIB_OBJS += util/debug.o

BUILTIN_OBJS += builtin-annotate.o
BUILTIN_OBJS += builtin-help.o
+0 −96
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@
#define SHOW_HV		4

static char		const *input_name = "perf.data";
static char		*vmlinux = "vmlinux";

static char		default_sort_order[] = "comm,symbol";
static char		*sort_order = default_sort_order;
@@ -37,9 +36,6 @@ static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;
static int		dump_trace = 0;
#define dprintf(x...)	do { if (dump_trace) printf(x); } while (0)

static int		verbose;

static int		modules;

static int		full_paths;

@@ -89,98 +85,6 @@ struct sym_ext {
	char		*path;
};

static LIST_HEAD(dsos);
static struct dso *kernel_dso;
static struct dso *vdso;


static void dsos__add(struct dso *dso)
{
	list_add_tail(&dso->node, &dsos);
}

static struct dso *dsos__find(const char *name)
{
	struct dso *pos;

	list_for_each_entry(pos, &dsos, node)
		if (strcmp(pos->name, name) == 0)
			return pos;
	return NULL;
}

static struct dso *dsos__findnew(const char *name)
{
	struct dso *dso = dsos__find(name);
	int nr;

	if (dso)
		return dso;

	dso = dso__new(name, 0);
	if (!dso)
		goto out_delete_dso;

	nr = dso__load(dso, NULL, verbose);
	if (nr < 0) {
		if (verbose)
			fprintf(stderr, "Failed to open: %s\n", name);
		goto out_delete_dso;
	}
	if (!nr && verbose) {
		fprintf(stderr,
		"No symbols found in: %s, maybe install a debug package?\n",
				name);
	}

	dsos__add(dso);

	return dso;

out_delete_dso:
	dso__delete(dso);
	return NULL;
}

static void dsos__fprintf(FILE *fp)
{
	struct dso *pos;

	list_for_each_entry(pos, &dsos, node)
		dso__fprintf(pos, fp);
}

static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip)
{
	return dso__find_symbol(dso, ip);
}

static int load_kernel(void)
{
	int err;

	kernel_dso = dso__new("[kernel]", 0);
	if (!kernel_dso)
		return -1;

	err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules);
	if (err <= 0) {
		dso__delete(kernel_dso);
		kernel_dso = NULL;
	} else
		dsos__add(kernel_dso);

	vdso = dso__new("[vdso]", 0);
	if (!vdso)
		return -1;

	vdso->find_symbol = vdso__find_symbol;

	dsos__add(vdso);

	return err;
}

struct map {
	struct list_head node;
	u64	 start;
+0 −1
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ static int inherit = 1;
static int			force				= 0;
static int			append_file			= 0;
static int			call_graph			= 0;
static int			verbose				= 0;
static int			inherit_stat			= 0;
static int			no_samples			= 0;
static int			sample_address			= 0;
+0 −97
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@
#define SHOW_HV		4

static char		const *input_name = "perf.data";
static char		*vmlinux = NULL;

static char		default_sort_order[] = "comm,dso,symbol";
static char		*sort_order = default_sort_order;
@@ -46,11 +45,6 @@ static int dump_trace = 0;
#define dprintf(x...)	do { if (dump_trace) printf(x); } while (0)
#define cdprintf(x...)	do { if (dump_trace) color_fprintf(stdout, color, x); } while (0)

static int		verbose;
#define eprintf(x...)	do { if (verbose) fprintf(stderr, x); } while (0)

static int		modules;

static int		full_paths;
static int		show_nr_samples;

@@ -161,98 +155,7 @@ static int repsep_fprintf(FILE *fp, const char *fmt, ...)
	return n;
}

static LIST_HEAD(dsos);
static struct dso *kernel_dso;
static struct dso *vdso;
static struct dso *hypervisor_dso;

static void dsos__add(struct dso *dso)
{
	list_add_tail(&dso->node, &dsos);
}

static struct dso *dsos__find(const char *name)
{
	struct dso *pos;

	list_for_each_entry(pos, &dsos, node)
		if (strcmp(pos->name, name) == 0)
			return pos;
	return NULL;
}

static struct dso *dsos__findnew(const char *name)
{
	struct dso *dso = dsos__find(name);
	int nr;

	if (dso)
		return dso;

	dso = dso__new(name, 0);
	if (!dso)
		goto out_delete_dso;

	nr = dso__load(dso, NULL, verbose);
	if (nr < 0) {
		eprintf("Failed to open: %s\n", name);
		goto out_delete_dso;
	}
	if (!nr)
		eprintf("No symbols found in: %s, maybe install a debug package?\n", name);

	dsos__add(dso);

	return dso;

out_delete_dso:
	dso__delete(dso);
	return NULL;
}

static void dsos__fprintf(FILE *fp)
{
	struct dso *pos;

	list_for_each_entry(pos, &dsos, node)
		dso__fprintf(pos, fp);
}

static struct symbol *vdso__find_symbol(struct dso *dso, u64 ip)
{
	return dso__find_symbol(dso, ip);
}

static int load_kernel(void)
{
	int err;

	kernel_dso = dso__new("[kernel]", 0);
	if (!kernel_dso)
		return -1;

	err = dso__load_kernel(kernel_dso, vmlinux, NULL, verbose, modules);
	if (err <= 0) {
		dso__delete(kernel_dso);
		kernel_dso = NULL;
	} else
		dsos__add(kernel_dso);

	vdso = dso__new("[vdso]", 0);
	if (!vdso)
		return -1;

	vdso->find_symbol = vdso__find_symbol;

	dsos__add(vdso);

	hypervisor_dso = dso__new("[hypervisor]", 0);
	if (!hypervisor_dso)
		return -1;
	dsos__add(hypervisor_dso);

	return err;
}

static char __cwd[PATH_MAX];
static char *cwd = __cwd;
+0 −1
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ static struct perf_counter_attr default_attrs[] = {
#define MAX_RUN			100

static int			system_wide			=  0;
static int			verbose				=  0;
static unsigned int		nr_cpus				=  0;
static int			run_idx				=  0;

Loading