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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 7009cc34
......@@ -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...]",
......@@ -275,10 +283,8 @@ static const struct option options[] = {
OPT_STRING('M', "disassembler-style", &disassembler_style, "disassembler style",
"Specify disassembler style (e.g. -M intel for intel syntax)"),
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);
}
......@@ -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)
......
......@@ -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,
};
......
......@@ -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)
......
......@@ -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)
......
This diff is collapsed.
......@@ -35,7 +35,9 @@
#include <linux/bitmap.h>
static struct perf_report {
struct perf_report {
struct perf_event_ops ops;
struct perf_session *session;
char const *input_name;
bool force, use_tui, use_stdio;
bool hide_unresolved;
......@@ -48,12 +50,7 @@ static struct perf_report {
symbol_filter_t annotate_init;
const char *cpu_list;
DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
} report = {
.input_name = "perf.data",
.pretty_printing_style = "normal",
}, *rep = &report;
static char callchain_default_opt[] = "fractal,0.5,callee";
};
static int perf_session__add_hist_entry(struct perf_session *session,
struct addr_location *al,
......@@ -106,11 +103,13 @@ static int perf_session__add_hist_entry(struct perf_session *session,
}
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_report *rep = container_of(ops, struct perf_report, ops);
struct addr_location al;
if (perf_event__preprocess_sample(event, session, &al, sample,
......@@ -137,10 +136,12 @@ static int process_sample_event(union perf_event *event,
return 0;
}
static int process_read_event(union perf_event *event,
static int process_read_event(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session)
{
struct perf_report *rep = container_of(ops, struct perf_report, ops);
struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist,
event->read.id);
if (rep->show_threads) {
......@@ -159,8 +160,10 @@ static int process_read_event(union perf_event *event,
return 0;
}
static int perf_session__setup_sample_type(struct perf_session *self)
static int perf_report__setup_sample_type(struct perf_report *rep)
{
struct perf_session *self = rep->session;
if (!(self->sample_type & PERF_SAMPLE_CALLCHAIN)) {
if (sort__has_parent) {
ui__warning("Selected --sort parent, but no "
......@@ -187,22 +190,6 @@ static int perf_session__setup_sample_type(struct perf_session *self)
return 0;
}
static struct perf_event_ops event_ops = {
.sample = process_sample_event,
.mmap = perf_event__process_mmap,
.comm = perf_event__process_comm,
.exit = perf_event__process_task,
.fork = perf_event__process_task,
.lost = perf_event__process_lost,
.read = process_read_event,
.attr = perf_event__process_attr,
.event_type = perf_event__process_event_type,
.tracing_data = perf_event__process_tracing_data,
.build_id = perf_event__process_build_id,
.ordered_samples = true,
.ordering_requires_timestamps = true,
};
extern volatile int session_done;
static void sig_handler(int sig __used)
......@@ -225,6 +212,7 @@ static size_t hists__fprintf_nr_sample_events(struct hists *self,
}
static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
struct perf_report *rep,
const char *help)
{
struct perf_evsel *pos;
......@@ -253,7 +241,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist,
return 0;
}
static int __cmd_report(void)
static int __cmd_report(struct perf_report *rep)
{
int ret = -EINVAL;
u64 nr_samples;
......@@ -266,10 +254,12 @@ static int __cmd_report(void)
signal(SIGINT, sig_handler);
session = perf_session__new(rep->input_name, O_RDONLY,
rep->force, false, &event_ops);
rep->force, false, &rep->ops);
if (session == NULL)
return -ENOMEM;
rep->session = session;
if (rep->cpu_list) {
ret = perf_session__cpu_bitmap(session, rep->cpu_list,
rep->cpu_bitmap);
......@@ -283,11 +273,11 @@ static int __cmd_report(void)
if (rep->show_threads)
perf_read_values_init(&rep->show_threads_values);
ret = perf_session__setup_sample_type(session);
ret = perf_report__setup_sample_type(rep);
if (ret)
goto out_delete;
ret = perf_session__process_events(session, &event_ops);
ret = perf_session__process_events(session, &rep->ops);
if (ret)
goto out_delete;
......@@ -339,7 +329,7 @@ static int __cmd_report(void)
perf_evlist__tui_browse_hists(session->evlist, help,
NULL, NULL, 0);
} else
perf_evlist__tty_browse_hists(session->evlist, help);
perf_evlist__tty_browse_hists(session->evlist, rep, help);
out_delete:
/*
......@@ -358,9 +348,9 @@ static int __cmd_report(void)
}
static int
parse_callchain_opt(const struct option *opt __used, const char *arg,
int unset)
parse_callchain_opt(const struct option *opt, const char *arg, int unset)
{
struct perf_report *rep = (struct perf_report *)opt->value;
char *tok, *tok2;
char *endptr;
......@@ -437,12 +427,33 @@ parse_callchain_opt(const struct option *opt __used, const char *arg,
return 0;
}
static const char * const report_usage[] = {
int cmd_report(int argc, const char **argv, const char *prefix __used)
{
char callchain_default_opt[] = "fractal,0.5,callee";
const char * const report_usage[] = {
"perf report [<options>] <command>",
NULL
};
static const struct option options[] = {
};
struct perf_report report = {
.ops = {
.sample = process_sample_event,
.mmap = perf_event__process_mmap,
.comm = perf_event__process_comm,
.exit = perf_event__process_task,
.fork = perf_event__process_task,
.lost = perf_event__process_lost,
.read = process_read_event,
.attr = perf_event__process_attr,
.event_type = perf_event__process_event_type,
.tracing_data = perf_event__process_tracing_data,
.build_id = perf_event__process_build_id,
.ordered_samples = true,
.ordering_requires_timestamps = true,
},
.input_name = "perf.data",
.pretty_printing_style = "normal",
};
const struct option options[] = {
OPT_STRING('i', "input", &report.input_name, "file",
"input file name"),
OPT_INCR('v', "verbose", &verbose,
......@@ -473,7 +484,7 @@ static const struct option options[] = {
"regex filter to identify parent, see: '--sort parent'"),
OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
"Only display entries with parent-match"),
OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent, call_order",
OPT_CALLBACK_DEFAULT('g', "call-graph", &report, "output_type,min_percent, call_order",
"Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold and callchain order. "
"Default: fractal,0.5,callee", &parse_callchain_opt, callchain_default_opt),
OPT_BOOLEAN('G', "inverted", &report.inverted_callchain,
......@@ -507,10 +518,8 @@ static const struct option options[] = {
OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
"Show a column with the sum of periods"),
OPT_END()
};
};
int cmd_report(int argc, const char **argv, const char *prefix __used)
{
argc = parse_options(argc, argv, options, report_usage, 0);
if (report.use_stdio)
......@@ -579,5 +588,5 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
sort_entry__setup_elide(&sort_comm, symbol_conf.comm_list, "comm", stdout);
sort_entry__setup_elide(&sort_sym, symbol_conf.sym_list, "symbol", stdout);
return __cmd_report();
return __cmd_report(&report);
}
......@@ -1602,7 +1602,8 @@ static void process_raw_event(union perf_event *raw_event __used,
process_sched_migrate_task_event(data, session, event, cpu, timestamp, thread);
}
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,
struct perf_session *session)
......
......@@ -434,7 +434,8 @@ static int cleanup_scripting(void)
static char const *input_name = "perf.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,
struct perf_session *session)
......
......@@ -274,7 +274,8 @@ static int cpus_cstate_state[MAX_CPUS];
static u64 cpus_pstate_start_times[MAX_CPUS];
static u64 cpus_pstate_state[MAX_CPUS];
static int process_comm_event(union perf_event *event,
static int process_comm_event(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session __used)
{
......@@ -282,7 +283,8 @@ static int process_comm_event(union perf_event *event,
return 0;
}
static int process_fork_event(union perf_event *event,
static int process_fork_event(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session __used)
{
......@@ -290,7 +292,8 @@ static int process_fork_event(union perf_event *event,
return 0;
}
static int process_exit_event(union perf_event *event,
static int process_exit_event(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session __used)
{
......@@ -487,7 +490,8 @@ static void sched_switch(int cpu, u64 timestamp, struct trace_entry *te)
}
static int process_sample_event(union perf_event *event __used,
static int process_sample_event(struct perf_event_ops *ops __used,
union perf_event *event __used,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct perf_session *session __used)
......
......@@ -824,7 +824,7 @@ static void perf_session__mmap_read_idx(struct perf_session *self, int idx)
perf_event__process_sample(event, evsel, &sample, self);
else if (event->header.type < PERF_RECORD_MAX) {
hists__inc_nr_events(&evsel->hists, event->header.type);
perf_event__process(event, &sample, self);
perf_event__process(&top.ops, event, &sample, self);
} else
++self->hists.stats.nr_unknown_events;
}
......@@ -966,10 +966,10 @@ static int __cmd_top(void)
goto out_delete;
if (top.target_tid != -1)
perf_event__synthesize_thread_map(top.evlist->threads,
perf_event__synthesize_thread_map(&top.ops, top.evlist->threads,
perf_event__process, top.session);
else
perf_event__synthesize_threads(perf_event__process, top.session);
perf_event__synthesize_threads(&top.ops, perf_event__process, top.session);
start_counters(top.evlist);
top.session->evlist = top.evlist;
......
......@@ -13,8 +13,10 @@
#include "symbol.h"
#include <linux/kernel.h>
#include "debug.h"
#include "session.h"
static int build_id__mark_dso_hit(union perf_event *event,
static int build_id__mark_dso_hit(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_evsel *evsel __used,
struct perf_session *session)
......@@ -38,7 +40,8 @@ static int build_id__mark_dso_hit(union perf_event *event,
return 0;
}
static int perf_event__exit_del_thread(union perf_event *event,
static int perf_event__exit_del_thread(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session)
{
......
......@@ -101,6 +101,9 @@ int callchain_append(struct callchain_root *root,
int callchain_merge(struct callchain_cursor *cursor,
struct callchain_root *dst, struct callchain_root *src);
struct ip_callchain;
union perf_event;
bool ip_callchain__valid(struct ip_callchain *chain,
const union perf_event *event);
/*
......
......@@ -44,7 +44,8 @@ static struct perf_sample synth_sample = {
.period = 1,
};
static pid_t perf_event__synthesize_comm(union perf_event *event, pid_t pid,
static pid_t perf_event__synthesize_comm(struct perf_event_ops *ops,
union perf_event *event, pid_t pid,
int full, perf_event__handler_t process,
struct perf_session *session)
{
......@@ -99,7 +100,7 @@ static pid_t perf_event__synthesize_comm(union perf_event *event, pid_t pid,
if (!full) {
event->comm.tid = pid;
process(event, &synth_sample, session);
process(ops, event, &synth_sample, session);
goto out;
}
......@@ -117,7 +118,7 @@ static pid_t perf_event__synthesize_comm(union perf_event *event, pid_t pid,
event->comm.tid = pid;
process(event, &synth_sample, session);
process(ops, event, &synth_sample, session);
}
closedir(tasks);
......@@ -127,7 +128,8 @@ static pid_t perf_event__synthesize_comm(union perf_event *event, pid_t pid,
return tgid;
}
static int perf_event__synthesize_mmap_events(union perf_event *event,
static int perf_event__synthesize_mmap_events(struct perf_event_ops *ops,
union perf_event *event,
pid_t pid, pid_t tgid,
perf_event__handler_t process,
struct perf_session *session)
......@@ -198,7 +200,7 @@ static int perf_event__synthesize_mmap_events(union perf_event *event,
event->mmap.pid = tgid;
event->mmap.tid = pid;
process(event, &synth_sample, session);
process(ops, event, &synth_sample, session);
}
}
......@@ -206,7 +208,8 @@ static int perf_event__synthesize_mmap_events(union perf_event *event,
return 0;
}
int perf_event__synthesize_modules(perf_event__handler_t process,
int perf_event__synthesize_modules(struct perf_event_ops *ops,
perf_event__handler_t process,
struct perf_session *session,
struct machine *machine)
{
......@@ -251,7 +254,7 @@ int perf_event__synthesize_modules(perf_event__handler_t process,
memcpy(event->mmap.filename, pos->dso->long_name,
pos->dso->long_name_len + 1);
process(event, &synth_sample, session);
process(ops, event, &synth_sample, session);
}
free(event);
......@@ -261,17 +264,19 @@ int perf_event__synthesize_modules(perf_event__handler_t process,
static int __event__synthesize_thread(union perf_event *comm_event,
union perf_event *mmap_event,
pid_t pid, perf_event__handler_t process,
struct perf_event_ops *ops,
struct perf_session *session)
{
pid_t tgid = perf_event__synthesize_comm(comm_event, pid, 1, process,
pid_t tgid = perf_event__synthesize_comm(ops, comm_event, pid, 1, process,
session);
if (tgid == -1)
return -1;
return perf_event__synthesize_mmap_events(mmap_event, pid, tgid,
return perf_event__synthesize_mmap_events(ops, mmap_event, pid, tgid,
process, session);
}
int perf_event__synthesize_thread_map(struct thread_map *threads,
int perf_event__synthesize_thread_map(struct perf_event_ops *ops,
struct thread_map *threads,
perf_event__handler_t process,
struct perf_session *session)
{
......@@ -290,7 +295,7 @@ int perf_event__synthesize_thread_map(struct thread_map *threads,
for (thread = 0; thread < threads->nr; ++thread) {
if (__event__synthesize_thread(comm_event, mmap_event,
threads->map[thread],
process, session)) {
process, ops, session)) {
err = -1;
break;
}
......@@ -302,7 +307,8 @@ int perf_event__synthesize_thread_map(struct thread_map *threads,
return err;
}
int perf_event__synthesize_threads(perf_event__handler_t process,
int perf_event__synthesize_threads(struct perf_event_ops *ops,
perf_event__handler_t process,
struct perf_session *session)
{
DIR *proc;
......@@ -330,7 +336,7 @@ int perf_event__synthesize_threads(perf_event__handler_t process,
continue;
__event__synthesize_thread(comm_event, mmap_event, pid,
process, session);
process, ops, session);
}
closedir(proc);
......@@ -365,7 +371,8 @@ static int find_symbol_cb(void *arg, const char *name, char type,
return 1;
}
int perf_event__synthesize_kernel_mmap(perf_event__handler_t process,
int perf_event__synthesize_kernel_mmap(struct perf_event_ops *ops,
perf_event__handler_t process,
struct perf_session *session,
struct machine *machine,
const char *symbol_name)
......@@ -423,13 +430,14 @@ int perf_event__synthesize_kernel_mmap(perf_event__handler_t process,
event->mmap.len = map->end - event->mmap.start;
event->mmap.pid = machine->pid;
err = process(event, &synth_sample, session);
err = process(ops, event, &synth_sample, session);
free(event);
return err;
}
int perf_event__process_comm(union perf_event *event,
int perf_event__process_comm(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session)
{
......@@ -445,7 +453,8 @@ int perf_event__process_comm(union perf_event *event,
return 0;
}
int perf_event__process_lost(union perf_event *event,
int perf_event__process_lost(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session)
{
......@@ -468,7 +477,8 @@ static void perf_event__set_kernel_mmap_len(union perf_event *event,
maps[MAP__FUNCTION]->end = ~0ULL;
}
static int perf_event__process_kernel_mmap(union perf_event *event,
static int perf_event__process_kernel_mmap(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_session *session)
{
struct map *map;
......@@ -567,7 +577,8 @@ static int perf_event__process_kernel_mmap(union perf_event *event,
return -1;
}
int perf_event__process_mmap(union perf_event *event,
int perf_event__process_mmap(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session)
{
......@@ -583,7 +594,7 @@ int perf_event__process_mmap(union perf_event *event,
if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
cpumode == PERF_RECORD_MISC_KERNEL) {
ret = perf_event__process_kernel_mmap(event, session);
ret = perf_event__process_kernel_mmap(ops, event, session);
if (ret < 0)
goto out_problem;
return 0;
......@@ -610,7 +621,8 @@ int perf_event__process_mmap(union perf_event *event,
return 0;
}
int perf_event__process_task(union perf_event *event,
int perf_event__process_task(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_sample *sample __used,
struct perf_session *session)
{
......@@ -634,22 +646,22 @@ int perf_event__process_task(union perf_event *event,
return 0;
}
int perf_event__process(union perf_event *event, struct perf_sample *sample,
struct perf_session *session)
int perf_event__process(struct perf_event_ops *ops, union perf_event *event,
struct perf_sample *sample, struct perf_session *session)
{
switch (event->header.type) {
case PERF_RECORD_COMM:
perf_event__process_comm(event, sample, session);
perf_event__process_comm(ops, event, sample, session);
break;
case PERF_RECORD_MMAP:
perf_event__process_mmap(event, sample, session);
perf_event__process_mmap(ops, event, sample, session);
break;
case PERF_RECORD_FORK:
case PERF_RECORD_EXIT:
perf_event__process_task(event, sample, session);
perf_event__process_task(ops, event, sample, session);
break;
case PERF_RECORD_LOST:
perf_event__process_lost(event, sample, session);
perf_event__process_lost(ops, event, sample, session);
default:
break;
}
......
......@@ -141,38 +141,52 @@ union perf_event {
void perf_event__print_totals(void);
struct perf_event_ops;
struct perf_session;
struct thread_map;
typedef int (*perf_event__handler_synth_t)(union perf_event *event,
struct perf_session *session);
typedef int (*perf_event__handler_t)(union perf_event *event,
typedef int (*perf_event__handler_t)(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_session *session);
int perf_event__synthesize_thread_map(struct thread_map *threads,
int perf_event__synthesize_thread_map(struct perf_event_ops *ops,
struct thread_map *threads,
perf_event__handler_t process,
struct perf_session *session);
int perf_event__synthesize_threads(perf_event__handler_t process,
int perf_event__synthesize_threads(struct perf_event_ops *ops,
perf_event__handler_t process,
struct perf_session *session);
int perf_event__synthesize_kernel_mmap(perf_event__handler_t process,
int perf_event__synthesize_kernel_mmap(struct perf_event_ops *ops,
perf_event__handler_t process,
struct perf_session *session,
struct machine *machine,
const char *symbol_name);
int perf_event__synthesize_modules(perf_event__handler_t process,
int perf_event__synthesize_modules(struct perf_event_ops *ops,
perf_event__handler_t process,
struct perf_session *session,
struct machine *machine);
int perf_event__process_comm(union perf_event *event, struct perf_sample *sample,
int perf_event__process_comm(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_session *session);
int perf_event__process_lost(union perf_event *event, struct perf_sample *sample,
int perf_event__process_lost(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_session *session);
int perf_event__process_mmap(union perf_event *event, struct perf_sample *sample,
int perf_event__process_mmap(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_session *session);
int perf_event__process_task(union perf_event *event, struct perf_sample *sample,
int perf_event__process_task(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_session *session);
int perf_event__process(union perf_event *event, struct perf_sample *sample,
int perf_event__process(struct perf_event_ops *ops,
union perf_event *event,
struct perf_sample *sample,
struct perf_session *session);
struct addr_location;
......
......@@ -2070,7 +2070,8 @@ int perf_session__read_header(struct perf_session *session, int fd)
return -ENOMEM;
}
int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
int perf_event__synthesize_attr(struct perf_event_ops *ops,
struct perf_event_attr *attr, u16 ids, u64 *id,
perf_event__handler_t process,
struct perf_session *session)
{
......@@ -2094,21 +2095,22 @@ int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
ev->attr.header.type = PERF_RECORD_HEADER_ATTR;
ev->attr.header.size = size;
err = process(ev, NULL, session);
err = process(ops, ev, NULL, session);
free(ev);
return err;
}
int perf_session__synthesize_attrs(struct perf_session *session,
int perf_event__synthesize_attrs(struct perf_event_ops *ops,
struct perf_session *session,
perf_event__handler_t process)
{
struct perf_evsel *attr;
int err = 0;
list_for_each_entry(attr, &session->evlist->entries, node) {
err = perf_event__synthesize_attr(&attr->attr, attr->ids,
err = perf_event__synthesize_attr(ops, &attr->attr, attr->ids,
attr->id, process, session);
if (err) {
pr_debug("failed to create perf header attribute\n");
......@@ -2156,7 +2158,8 @@ int perf_event__process_attr(union perf_event *event,
return 0;
}
int perf_event__synthesize_event_type(u64 event_id, char *name,
int perf_event__synthesize_event_type(struct perf_event_ops *ops,
u64 event_id, char *name,
perf_event__handler_t process,
struct perf_session *session)
{
......@@ -2176,12 +2179,13 @@ int perf_event__synthesize_event_type(u64 event_id, char *name,
ev.event_type.header.size = sizeof(ev.event_type) -
(sizeof(ev.event_type.event_type.name) - size);
err = process(&ev, NULL, session);
err = process(ops, &ev, NULL, session);
return err;
}
int perf_event__synthesize_event_types(perf_event__handler_t process,
int perf_event__synthesize_event_types(struct perf_event_ops *ops,
perf_event__handler_t process,
struct perf_session *session)
{
struct perf_trace_event_type *type;
......@@ -2190,7 +2194,7 @@ int perf_event__synthesize_event_types(perf_event__handler_t process,
for (i = 0; i < event_count; i++) {
type = &events[i];
err = perf_event__synthesize_event_type(type->event_id,
err = perf_event__synthesize_event_type(ops, type->event_id,
type->name, process,
session);
if (err) {
......@@ -2202,7 +2206,8 @@ int perf_event__synthesize_event_types(perf_event__handler_t process,
return err;
}
int perf_event__process_event_type(union perf_event *event,
int perf_event__process_event_type(struct perf_event_ops *ops __unused,
union perf_event *event,
struct perf_session *session __unused)
{
if (perf_header__push_event(event->event_type.event_type.event_id,
......@@ -2212,7 +2217,8 @@ int perf_event__process_event_type(union perf_event *event,
return 0;
}
int perf_event__synthesize_tracing_data(int fd, struct perf_evlist *evlist,
int perf_event__synthesize_tracing_data(struct perf_event_ops *ops, int fd,
struct perf_evlist *evlist,
perf_event__handler_t process,
struct perf_session *session __unused)
{
......@@ -2245,7 +2251,7 @@ int perf_event__synthesize_tracing_data(int fd, struct perf_evlist *evlist,
ev.tracing_data.header.size = sizeof(ev.tracing_data);
ev.tracing_data.size = aligned_size;
process(&ev, NULL, session);
process(ops, &ev, NULL, session);
/*
* The put function will copy all the tracing data
......@@ -2287,7 +2293,8 @@ int perf_event__process_tracing_data(union perf_event *event,
return size_read + padding;
}
int perf_event__synthesize_build_id(struct dso *pos, u16 misc,
int perf_event__synthesize_build_id(struct perf_event_ops *ops,
struct dso *pos, u16 misc,
perf_event__handler_t process,
struct machine *machine,
struct perf_session *session)
......@@ -2310,12 +2317,13 @@ int perf_event__synthesize_build_id(struct dso *pos, u16 misc,
ev.build_id.header.size = sizeof(ev.build_id) + len;
memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len);
err = process(&ev, NULL, session);
err = process(ops, &ev, NULL, session);
return err;
}
int perf_event__process_build_id(union perf_event *event,
int perf_event__process_build_id(struct perf_event_ops *ops __used,
union perf_event *event,
struct perf_session *session)
{
__event_process_build_id(&event->build_id,
......
......@@ -68,6 +68,7 @@ struct perf_header {
};
struct perf_evlist;
struct perf_session;
int perf_session__read_header(struct perf_session *session, int fd);
int perf_session__write_header(struct perf_session *session,
......@@ -96,32 +97,40 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
const char *name, bool is_kallsyms);
int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir);
int perf_event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
int perf_event__synthesize_attr(struct perf_event_ops *ops,
struct perf_event_attr *attr, u16 ids, u64 *id,
perf_event__handler_t process,
struct perf_session *session);
int perf_session__synthesize_attrs(struct perf_session *session,
int perf_event__synthesize_attrs(struct perf_event_ops *ops,
struct perf_session *session,
perf_event__handler_t process);
int perf_event__process_attr(union perf_event *event, struct perf_evlist **pevlist);
int perf_event__synthesize_event_type(u64 event_id, char *name,
int perf_event__synthesize_event_type(struct perf_event_ops *ops,
u64 event_id, char *name,
perf_event__handler_t process,
struct perf_session *session);
int perf_event__synthesize_event_types(perf_event__handler_t process,
int perf_event__synthesize_event_types(struct perf_event_ops *ops,
perf_event__handler_t process,
struct perf_session *session);
int perf_event__process_event_type(union perf_event *event,
int perf_event__process_event_type(struct perf_event_ops *ops,
union perf_event *event,
struct perf_session *session);
int perf_event__synthesize_tracing_data(int fd, struct perf_evlist *evlist,
int perf_event__synthesize_tracing_data(struct perf_event_ops *ops,
int fd, struct perf_evlist *evlist,
perf_event__handler_t process,
struct perf_session *session);
int perf_event__process_tracing_data(union perf_event *event,
struct perf_session *session);
int perf_event__synthesize_build_id(struct dso *pos, u16 misc,
int perf_event__synthesize_build_id(struct perf_event_ops *ops,
struct dso *pos, u16 misc,
perf_event__handler_t process,
struct machine *machine,
struct perf_session *session);
int perf_event__process_build_id(union perf_event *event,
int perf_event__process_build_id(struct perf_event_ops *ops,
union perf_event *event,
struct perf_session *session);
/*
......
......@@ -270,7 +270,15 @@ int perf_session__resolve_callchain(struct perf_session *self, struct perf_evsel
return 0;
}
static int process_event_synth_stub(union perf_event *event __used,
static int process_event_synth_stub(struct perf_event_ops *ops __used,
union perf_event *event __used,
struct perf_session *session __used)
{
dump_printf(": unhandled!\n");
return 0;
}
static int process_event_synth_tracing_data_stub(union perf_event *event __used,
struct perf_session *session __used)
{
dump_printf(": unhandled!\n");
......@@ -284,7 +292,8 @@ static int process_event_synth_attr_stub(union perf_event *event __used,
return 0;
}
static int process_event_sample_stub(union perf_event *event __used,
static int process_event_sample_stub(struct perf_event_ops *ops __used,
union perf_event *event __used,
struct perf_sample *sample __used,
struct perf_evsel *evsel __used,
struct perf_session *session __used)
......@@ -293,7 +302,8 @@ static int process_event_sample_stub(union perf_event *event __used,
return 0;
}
static int process_event_stub(union perf_event *event __used,
static int process_event_stub(struct perf_event_ops *ops __used,
union perf_event *event __used,
struct perf_sample *sample __used,
struct perf_session *session __used)
{
......@@ -301,17 +311,17 @@ static int process_event_stub(union perf_event *event __used,
return 0;
}
static int process_finished_round_stub(union perf_event *event __used,
struct perf_session *session __used,
struct perf_event_ops *ops __used)
static int process_finished_round_stub(struct perf_event_ops *ops __used,
union perf_event *event __used,
struct perf_session *session __used)
{
dump_printf(": unhandled!\n");
return 0;
}
static int process_finished_round(union perf_event *event,
struct perf_session *session,
struct perf_event_ops *ops);
static int process_finished_round(struct perf_event_ops *ops,
union perf_event *event,
struct perf_session *session);
static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
{
......@@ -338,7 +348,7 @@ static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
if (handler->event_type == NULL)
handler->event_type = process_event_synth_stub;
if (handler->tracing_data == NULL)
handler->tracing_data = process_event_synth_stub;
handler->tracing_data = process_event_synth_tracing_data_stub;
if (handler->build_id == NULL)
handler->build_id = process_event_synth_stub;
if (handler->finished_round == NULL) {
......@@ -565,9 +575,9 @@ static void flush_sample_queue(struct perf_session *s,
* Flush every events below timestamp 7
* etc...
*/
static int process_finished_round(union perf_event *event __used,
struct perf_session *session,
struct perf_event_ops *ops)
static int process_finished_round(struct perf_event_ops *ops,
union perf_event *event __used,
struct perf_session *session)
{
flush_sample_queue(session, ops);
session->ordered_samples.next_flush = session->ordered_samples.max_timestamp;
......@@ -759,23 +769,23 @@ static int perf_session_deliver_event(struct perf_session *session,
++session->hists.stats.nr_unknown_id;
return -1;
}
return ops->sample(event, sample, evsel, session);
return ops->sample(ops, event, sample, evsel, session);
case PERF_RECORD_MMAP:
return ops->mmap(event, sample, session);
return ops->mmap(ops, event, sample, session);
case PERF_RECORD_COMM:
return ops->comm(event, sample, session);
return ops->comm(ops, event, sample, session);
case PERF_RECORD_FORK:
return ops->fork(event, sample, session);
return ops->fork(ops, event, sample, session);
case PERF_RECORD_EXIT:
return ops->exit(event, sample, session);
return ops->exit(ops, event, sample, session);
case PERF_RECORD_LOST:
return ops->lost(event, sample, session);
return ops->lost(ops, event, sample, session);
case PERF_RECORD_READ:
return ops->read(event, sample, session);
return ops->read(ops, event, sample, session);
case PERF_RECORD_THROTTLE:
return ops->throttle(event, sample, session);
return ops->throttle(ops, event, sample, session);
case PERF_RECORD_UNTHROTTLE:
return ops->unthrottle(event, sample, session);
return ops->unthrottle(ops, event, sample, session);
default:
++session->hists.stats.nr_unknown_events;
return -1;
......@@ -813,15 +823,15 @@ static int perf_session__process_user_event(struct perf_session *session, union
perf_session__update_sample_type(session);
return err;
case PERF_RECORD_HEADER_EVENT_TYPE:
return ops->event_type(event, session);
return ops->event_type(ops, event, session);
case PERF_RECORD_HEADER_TRACING_DATA:
/* setup for reading amidst mmap */
lseek(session->fd, file_offset, SEEK_SET);
return ops->tracing_data(event, session);
case PERF_RECORD_HEADER_BUILD_ID:
return ops->build_id(event, session);
return ops->build_id(ops, event, session);
case PERF_RECORD_FINISHED_ROUND:
return ops->finished_round(event, session, ops);
return ops->finished_round(ops, event, session);
default:
return -EINVAL;
}
......
......@@ -56,16 +56,18 @@ struct perf_session {
struct perf_evsel;
struct perf_event_ops;
typedef int (*event_sample)(union perf_event *event, struct perf_sample *sample,
typedef int (*event_sample)(struct perf_event_ops *ops,
union perf_event *event, struct perf_sample *sample,
struct perf_evsel *evsel, struct perf_session *session);
typedef int (*event_op)(union perf_event *self, struct perf_sample *sample,
typedef int (*event_op)(struct perf_event_ops *ops, union perf_event *event,
struct perf_sample *sample,
struct perf_session *session);
typedef int (*event_synth_op)(union perf_event *self,
struct perf_session *session);
typedef int (*event_attr_op)(union perf_event *event,
struct perf_evlist **pevlist);
typedef int (*event_op2)(union perf_event *self, struct perf_session *session,
struct perf_event_ops *ops);
typedef int (*event_op2)(struct perf_event_ops *ops, union perf_event *event,
struct perf_session *session);
struct perf_event_ops {
event_sample sample;
......@@ -78,10 +80,10 @@ struct perf_event_ops {
throttle,
unthrottle;
event_attr_op attr;
event_synth_op event_type,
tracing_data,
build_id;
event_op2 finished_round;
event_synth_op tracing_data;
event_op2 event_type,
build_id,
finished_round;
bool ordered_samples;
bool ordering_requires_timestamps;
};
......@@ -142,10 +144,11 @@ struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t p
static inline
void perf_session__process_machines(struct perf_session *self,
struct perf_event_ops *ops,
machine__process_t process)
{
process(&self->host_machine, self);
return machines__process(&self->machines, process, self);
process(&self->host_machine, ops);
return machines__process(&self->machines, process, ops);
}
size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
......
......@@ -2,14 +2,15 @@
#define __PERF_TOP_H 1
#include "types.h"
#include "session.h"
#include "../perf.h"
#include <stddef.h>
struct perf_evlist;
struct perf_evsel;
struct perf_session;
struct perf_top {
struct perf_event_ops ops;
struct perf_evlist *evlist;
/*
* Symbols will be added here in perf_event__process_sample and will
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment