perf tools: Pass tool context in the the perf_event_ops functions
Commit-ID: d20deb64e0490ee9442b5181bc08a62d2cadcb90 Gitweb: http://git.kernel.org/tip/d20deb64e0490ee9442b5181bc08a62d2cadcb90 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Fri, 25 Nov 2011 08:19:45 -0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 28 Nov 2011 10:38:56 -0200
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 <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/builtin-annotate.c | 62 ++++--- tools/perf/builtin-diff.c | 3 +- tools/perf/builtin-inject.c | 55 ++++--- tools/perf/builtin-kmem.c | 3 +- tools/perf/builtin-lock.c | 3 +- tools/perf/builtin-record.c | 383 ++++++++++++++++++++++------------------ tools/perf/builtin-report.c | 97 ++++++----- tools/perf/builtin-sched.c | 3 +- tools/perf/builtin-script.c | 3 +- tools/perf/builtin-timechart.c | 12 +- tools/perf/builtin-top.c | 6 +- tools/perf/util/build-id.c | 7 +- tools/perf/util/callchain.h | 3 + tools/perf/util/event.c | 66 ++++--- tools/perf/util/event.h | 38 +++-- tools/perf/util/header.c | 36 +++-- tools/perf/util/header.h | 27 ++- tools/perf/util/session.c | 60 ++++--- tools/perf/util/session.h | 23 ++- tools/perf/util/top.h | 3 +- 20 files changed, 520 insertions(+), 373 deletions(-)
tools/perf/builtin-annotate.c +34 -28
@@ -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 @@ find_next: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 @@ find_next: } } -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); }
tools/perf/builtin-diff.c +2 -1
@@ -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)
tools/perf/builtin-inject.c +34 -21
139 lines not on this page · raw message
tools/perf/builtin-kmem.c +2 -1
@@ -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)
tools/perf/builtin-lock.c +2 -1
@@ -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)
tools/perf/builtin-record.c +215 -168
750 lines not on this page · raw message
tools/perf/builtin-report.c +53 -44
207 lines not on this page · raw message
tools/perf/builtin-sched.c +2 -1
@@ -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)
tools/perf/builtin-script.c +2 -1
@@ -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)
tools/perf/builtin-timechart.c +8 -4
@@ -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 )
tools/perf/builtin-top.c +3 -3
@@ -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;
tools/perf/util/build-id.c +5 -2
@@ -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) {
tools/perf/util/callchain.h +3 -0
@@ -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);/*
tools/perf/util/event.c +39 -27
203 lines not on this page · raw message
tools/perf/util/event.h +26 -12
@@ -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 ;
tools/perf/util/header.c +22 -14
@@ -2070,7 +2070,8 @@ out_delete_evlist: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,
tools/perf/util/header.h +18 -9
@@ -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, -perf_event__handler_t process); +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);/*
tools/perf/util/session.c +35 -25
133 lines not on this page · raw message
tools/perf/util/session.h +13 -10
@@ -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 pstatic 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);
tools/perf/util/top.h +2 -1
@@ -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