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

Commit d20deb64 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf tools: Pass tool context in the the perf_event_ops functions

So that we don't need to have that many globals.

Next steps will remove the 'session' pointer, that in most cases is
not needed.

Then we can rename perf_event_ops to 'perf_tool' that better describes
this class hierarchy.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-wp4djox7x6w1i2bab1pt4xxp@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7009cc34
Loading
Loading
Loading
Loading
+34 −28
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@

#include <linux/bitmap.h>

static struct perf_annotate {
struct perf_annotate {
	struct perf_event_ops ops;
	char const *input_name;
	bool	   force, use_tui, use_stdio;
	bool	   full_paths;
@@ -38,13 +39,12 @@ static struct perf_annotate {
	const char *sym_hist_filter;
	const char *cpu_list;
	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
} annotate = {
	.input_name = "perf.data",
}, *ann = &annotate;
};

static int perf_evsel__add_sample(struct perf_evsel *evsel,
				  struct perf_sample *sample,
				  struct addr_location *al)
				  struct addr_location *al,
				  struct perf_annotate *ann)
{
	struct hist_entry *he;
	int ret;
@@ -79,11 +79,13 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
	return ret;
}

static int process_sample_event(union perf_event *event,
static int process_sample_event(struct perf_event_ops *ops,
				union perf_event *event,
				struct perf_sample *sample,
				struct perf_evsel *evsel,
				struct perf_session *session)
{
	struct perf_annotate *ann = container_of(ops, struct perf_annotate, ops);
	struct addr_location al;

	if (perf_event__preprocess_sample(event, session, &al, sample,
@@ -96,7 +98,7 @@ static int process_sample_event(union perf_event *event,
	if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
		return 0;

	if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al)) {
	if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al, ann)) {
		pr_warning("problem incrementing symbol count, "
			   "skipping event\n");
		return -1;
@@ -105,13 +107,15 @@ static int process_sample_event(union perf_event *event,
	return 0;
}

static int hist_entry__tty_annotate(struct hist_entry *he, int evidx)
static int hist_entry__tty_annotate(struct hist_entry *he, int evidx,
				    struct perf_annotate *ann)
{
	return symbol__tty_annotate(he->ms.sym, he->ms.map, evidx,
				    ann->print_line, ann->full_paths, 0, 0);
}

static void hists__find_annotations(struct hists *self, int evidx)
static void hists__find_annotations(struct hists *self, int evidx,
				    struct perf_annotate *ann)
{
	struct rb_node *nd = rb_first(&self->entries), *next;
	int key = K_RIGHT;
@@ -149,7 +153,7 @@ static void hists__find_annotations(struct hists *self, int evidx)
			if (next != NULL)
				nd = next;
		} else {
			hist_entry__tty_annotate(he, evidx);
			hist_entry__tty_annotate(he, evidx, ann);
			nd = rb_next(nd);
			/*
			 * Since we have a hist_entry per IP for the same
@@ -162,16 +166,7 @@ static void hists__find_annotations(struct hists *self, int evidx)
	}
}

static struct perf_event_ops event_ops = {
	.sample	= process_sample_event,
	.mmap	= perf_event__process_mmap,
	.comm	= perf_event__process_comm,
	.fork	= perf_event__process_task,
	.ordered_samples = true,
	.ordering_requires_timestamps = true,
};

static int __cmd_annotate(void)
static int __cmd_annotate(struct perf_annotate *ann)
{
	int ret;
	struct perf_session *session;
@@ -179,7 +174,7 @@ static int __cmd_annotate(void)
	u64 total_nr_samples;

	session = perf_session__new(ann->input_name, O_RDONLY,
				    ann->force, false, &event_ops);
				    ann->force, false, &ann->ops);
	if (session == NULL)
		return -ENOMEM;

@@ -190,7 +185,7 @@ static int __cmd_annotate(void)
			goto out_delete;
	}

	ret = perf_session__process_events(session, &event_ops);
	ret = perf_session__process_events(session, &ann->ops);
	if (ret)
		goto out_delete;

@@ -214,7 +209,7 @@ static int __cmd_annotate(void)
			total_nr_samples += nr_samples;
			hists__collapse_resort(hists);
			hists__output_resort(hists);
			hists__find_annotations(hists, pos->idx);
			hists__find_annotations(hists, pos->idx, ann);
		}
	}

@@ -243,7 +238,20 @@ static const char * const annotate_usage[] = {
	NULL
};

static const struct option options[] = {
int cmd_annotate(int argc, const char **argv, const char *prefix __used)
{
	struct perf_annotate annotate = {
		.ops = {
			.sample	= process_sample_event,
			.mmap	= perf_event__process_mmap,
			.comm	= perf_event__process_comm,
			.fork	= perf_event__process_task,
			.ordered_samples = true,
			.ordering_requires_timestamps = true,
		},
		.input_name = "perf.data",
	};
	const struct option options[] = {
	OPT_STRING('i', "input", &annotate.input_name, "file",
		    "input file name"),
	OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
@@ -277,8 +285,6 @@ static const struct option options[] = {
	OPT_END()
	};

int cmd_annotate(int argc, const char **argv, const char *prefix __used)
{
	argc = parse_options(argc, argv, options, annotate_usage, 0);

	if (annotate.use_stdio)
@@ -312,5 +318,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used)
		return -1;
	}

	return __cmd_annotate();
	return __cmd_annotate(&annotate);
}
+2 −1
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@ static int hists__add_entry(struct hists *self,
	return -ENOMEM;
}

static int diff__process_sample_event(union perf_event *event,
static int diff__process_sample_event(struct perf_event_ops *ops __used,
				      union perf_event *event,
				      struct perf_sample *sample,
				      struct perf_evsel *evsel __used,
				      struct perf_session *session)
+34 −21
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@
static char		const *input_name = "-";
static bool		inject_build_ids;

static int perf_event__repipe_synth(union perf_event *event,
static int perf_event__repipe_synth(struct perf_event_ops *ops __used,
				    union perf_event *event,
				    struct perf_session *session __used)
{
	uint32_t size;
@@ -36,47 +37,57 @@ static int perf_event__repipe_synth(union perf_event *event,
	return 0;
}

static int perf_event__repipe_tracing_data_synth(union perf_event *event,
						 struct perf_session *session)
{
	return perf_event__repipe_synth(NULL, event, session);
}

static int perf_event__repipe_attr(union perf_event *event,
				   struct perf_evlist **pevlist __used)
{
	return perf_event__repipe_synth(event, NULL);
	return perf_event__repipe_synth(NULL, event, NULL);
}

static int perf_event__repipe(union perf_event *event,
static int perf_event__repipe(struct perf_event_ops *ops,
			      union perf_event *event,
			      struct perf_sample *sample __used,
			      struct perf_session *session)
{
	return perf_event__repipe_synth(event, session);
	return perf_event__repipe_synth(ops, event, session);
}

static int perf_event__repipe_sample(union perf_event *event,
static int perf_event__repipe_sample(struct perf_event_ops *ops,
				     union perf_event *event,
			      struct perf_sample *sample __used,
			      struct perf_evsel *evsel __used,
			      struct perf_session *session)
{
	return perf_event__repipe_synth(event, session);
	return perf_event__repipe_synth(ops, event, session);
}

static int perf_event__repipe_mmap(union perf_event *event,
static int perf_event__repipe_mmap(struct perf_event_ops *ops,
				   union perf_event *event,
				   struct perf_sample *sample,
				   struct perf_session *session)
{
	int err;

	err = perf_event__process_mmap(event, sample, session);
	perf_event__repipe(event, sample, session);
	err = perf_event__process_mmap(ops, event, sample, session);
	perf_event__repipe(ops, event, sample, session);

	return err;
}

static int perf_event__repipe_task(union perf_event *event,
static int perf_event__repipe_task(struct perf_event_ops *ops,
				   union perf_event *event,
				   struct perf_sample *sample,
				   struct perf_session *session)
{
	int err;

	err = perf_event__process_task(event, sample, session);
	perf_event__repipe(event, sample, session);
	err = perf_event__process_task(ops, event, sample, session);
	perf_event__repipe(ops, event, sample, session);

	return err;
}
@@ -86,7 +97,7 @@ static int perf_event__repipe_tracing_data(union perf_event *event,
{
	int err;

	perf_event__repipe_synth(event, session);
	perf_event__repipe_synth(NULL, event, session);
	err = perf_event__process_tracing_data(event, session);

	return err;
@@ -106,7 +117,8 @@ static int dso__read_build_id(struct dso *self)
	return -1;
}

static int dso__inject_build_id(struct dso *self, struct perf_session *session)
static int dso__inject_build_id(struct dso *self, struct perf_event_ops *ops,
				struct perf_session *session)
{
	u16 misc = PERF_RECORD_MISC_USER;
	struct machine *machine;
@@ -126,7 +138,7 @@ static int dso__inject_build_id(struct dso *self, struct perf_session *session)
	if (self->kernel)
		misc = PERF_RECORD_MISC_KERNEL;

	err = perf_event__synthesize_build_id(self, misc, perf_event__repipe,
	err = perf_event__synthesize_build_id(ops, self, misc, perf_event__repipe,
					      machine, session);
	if (err) {
		pr_err("Can't synthesize build_id event for %s\n", self->long_name);
@@ -136,7 +148,8 @@ static int dso__inject_build_id(struct dso *self, struct perf_session *session)
	return 0;
}

static int perf_event__inject_buildid(union perf_event *event,
static int perf_event__inject_buildid(struct perf_event_ops *ops,
				      union perf_event *event,
				      struct perf_sample *sample,
				      struct perf_evsel *evsel __used,
				      struct perf_session *session)
@@ -161,7 +174,7 @@ static int perf_event__inject_buildid(union perf_event *event,
		if (!al.map->dso->hit) {
			al.map->dso->hit = 1;
			if (map__load(al.map, NULL) >= 0) {
				dso__inject_build_id(al.map->dso, session);
				dso__inject_build_id(al.map->dso, ops, session);
				/*
				 * If this fails, too bad, let the other side
				 * account this as unresolved.
@@ -174,7 +187,7 @@ static int perf_event__inject_buildid(union perf_event *event,
	}

repipe:
	perf_event__repipe(event, sample, session);
	perf_event__repipe(ops, event, sample, session);
	return 0;
}

@@ -190,7 +203,7 @@ struct perf_event_ops inject_ops = {
	.unthrottle	= perf_event__repipe,
	.attr		= perf_event__repipe_attr,
	.event_type	= perf_event__repipe_synth,
	.tracing_data 	= perf_event__repipe_synth,
	.tracing_data	= perf_event__repipe_tracing_data_synth,
	.build_id	= perf_event__repipe_synth,
};

+2 −1
Original line number Diff line number Diff line
@@ -303,7 +303,8 @@ static void process_raw_event(union perf_event *raw_event __used, void *data,
	}
}

static int process_sample_event(union perf_event *event,
static int process_sample_event(struct perf_event_ops *ops __used,
				union perf_event *event,
				struct perf_sample *sample,
				struct perf_evsel *evsel __used,
				struct perf_session *session)
+2 −1
Original line number Diff line number Diff line
@@ -845,7 +845,8 @@ static void dump_info(void)
		die("Unknown type of information\n");
}

static int process_sample_event(union perf_event *event,
static int process_sample_event(struct perf_event_ops *ops __used,
				union perf_event *event,
				struct perf_sample *sample,
				struct perf_evsel *evsel __used,
				struct perf_session *s)
Loading