perf session: Ditch register_perf_file_handler
Pass the event_ops to perf_session__process_events instead. Also move the event_ops definition to session.h, starting to move things around to their right place, trimming the many unneeded headers we have. Signed-off-by: Arnaldo 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: <1260741029-4430-2-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
d8f66248d6
commit
301a0b0202
|
@ -370,7 +370,6 @@ LIB_H += util/values.h
|
|||
LIB_H += util/sort.h
|
||||
LIB_H += util/hist.h
|
||||
LIB_H += util/thread.h
|
||||
LIB_H += util/data_map.h
|
||||
LIB_H += util/probe-finder.h
|
||||
LIB_H += util/probe-event.h
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "util/sort.h"
|
||||
#include "util/hist.h"
|
||||
#include "util/session.h"
|
||||
#include "util/data_map.h"
|
||||
|
||||
static char const *input_name = "perf.data";
|
||||
|
||||
|
@ -454,7 +453,7 @@ static void find_annotations(void)
|
|||
}
|
||||
}
|
||||
|
||||
static struct perf_file_handler file_handler = {
|
||||
static struct perf_event_ops event_ops = {
|
||||
.process_sample_event = process_sample_event,
|
||||
.process_mmap_event = event__process_mmap,
|
||||
.process_comm_event = event__process_comm,
|
||||
|
@ -463,7 +462,8 @@ static struct perf_file_handler file_handler = {
|
|||
|
||||
static int __cmd_annotate(void)
|
||||
{
|
||||
struct perf_session *session = perf_session__new(input_name, O_RDONLY, force);
|
||||
struct perf_session *session = perf_session__new(input_name, O_RDONLY,
|
||||
force);
|
||||
struct thread *idle;
|
||||
int ret;
|
||||
|
||||
|
@ -471,9 +471,9 @@ static int __cmd_annotate(void)
|
|||
return -ENOMEM;
|
||||
|
||||
idle = register_idle_thread();
|
||||
register_perf_file_handler(&file_handler);
|
||||
|
||||
ret = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
|
||||
ret = perf_session__process_events(session, &event_ops, 0,
|
||||
&event__cwdlen, &event__cwd);
|
||||
if (ret)
|
||||
goto out_delete;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include "builtin.h"
|
||||
#include "perf.h"
|
||||
#include "util/cache.h"
|
||||
#include "util/data_map.h"
|
||||
#include "util/debug.h"
|
||||
#include "util/parse-options.h"
|
||||
#include "util/session.h"
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "util/trace-event.h"
|
||||
|
||||
#include "util/debug.h"
|
||||
#include "util/data_map.h"
|
||||
|
||||
#include <linux/rbtree.h>
|
||||
|
||||
|
@ -359,7 +358,7 @@ static int sample_type_check(u64 type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static struct perf_file_handler file_handler = {
|
||||
static struct perf_event_ops event_ops = {
|
||||
.process_sample_event = process_sample_event,
|
||||
.process_comm_event = event__process_comm,
|
||||
.sample_type_check = sample_type_check,
|
||||
|
@ -374,9 +373,8 @@ static int read_events(void)
|
|||
return -ENOMEM;
|
||||
|
||||
register_idle_thread();
|
||||
register_perf_file_handler(&file_handler);
|
||||
|
||||
err = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
|
||||
err = perf_session__process_events(session, &event_ops, 0,
|
||||
&event__cwdlen, &event__cwd);
|
||||
perf_session__delete(session);
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "util/parse-options.h"
|
||||
#include "util/parse-events.h"
|
||||
|
||||
#include "util/data_map.h"
|
||||
#include "util/thread.h"
|
||||
#include "util/sort.h"
|
||||
#include "util/hist.h"
|
||||
|
@ -748,7 +747,7 @@ static int sample_type_check(u64 type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static struct perf_file_handler file_handler = {
|
||||
static struct perf_event_ops event_ops = {
|
||||
.process_sample_event = process_sample_event,
|
||||
.process_mmap_event = event__process_mmap,
|
||||
.process_comm_event = process_comm_event,
|
||||
|
@ -776,9 +775,7 @@ static int __cmd_report(void)
|
|||
if (show_threads)
|
||||
perf_read_values_init(&show_threads_values);
|
||||
|
||||
register_perf_file_handler(&file_handler);
|
||||
|
||||
ret = perf_session__process_events(session, full_paths,
|
||||
ret = perf_session__process_events(session, &event_ops, full_paths,
|
||||
&event__cwdlen, &event__cwd);
|
||||
if (ret)
|
||||
goto out_delete;
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "util/trace-event.h"
|
||||
|
||||
#include "util/debug.h"
|
||||
#include "util/data_map.h"
|
||||
|
||||
#include <sys/prctl.h>
|
||||
|
||||
|
@ -1656,7 +1655,7 @@ static int sample_type_check(u64 type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static struct perf_file_handler file_handler = {
|
||||
static struct perf_event_ops event_ops = {
|
||||
.process_sample_event = process_sample_event,
|
||||
.process_comm_event = event__process_comm,
|
||||
.process_lost_event = process_lost_event,
|
||||
|
@ -1672,9 +1671,9 @@ static int read_events(void)
|
|||
return -ENOMEM;
|
||||
|
||||
register_idle_thread();
|
||||
register_perf_file_handler(&file_handler);
|
||||
|
||||
err = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
|
||||
err = perf_session__process_events(session, &event_ops, 0,
|
||||
&event__cwdlen, &event__cwd);
|
||||
perf_session__delete(session);
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "util/parse-options.h"
|
||||
#include "util/parse-events.h"
|
||||
#include "util/event.h"
|
||||
#include "util/data_map.h"
|
||||
#include "util/session.h"
|
||||
#include "util/svghelper.h"
|
||||
|
||||
static char const *input_name = "perf.data";
|
||||
|
@ -1046,7 +1046,7 @@ static int sample_type_check(u64 type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static struct perf_file_handler file_handler = {
|
||||
static struct perf_event_ops event_ops = {
|
||||
.process_comm_event = process_comm_event,
|
||||
.process_fork_event = process_fork_event,
|
||||
.process_exit_event = process_exit_event,
|
||||
|
@ -1062,9 +1062,8 @@ static int __cmd_timechart(void)
|
|||
if (session == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
register_perf_file_handler(&file_handler);
|
||||
|
||||
ret = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
|
||||
ret = perf_session__process_events(session, &event_ops, 0,
|
||||
&event__cwdlen, &event__cwd);
|
||||
if (ret)
|
||||
goto out_delete;
|
||||
|
||||
|
|
|
@ -57,7 +57,6 @@ static int cleanup_scripting(void)
|
|||
#include "util/debug.h"
|
||||
|
||||
#include "util/trace-event.h"
|
||||
#include "util/data_map.h"
|
||||
#include "util/exec_cmd.h"
|
||||
|
||||
static char const *input_name = "perf.data";
|
||||
|
@ -118,7 +117,7 @@ static int sample_type_check(u64 type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static struct perf_file_handler file_handler = {
|
||||
static struct perf_event_ops event_ops = {
|
||||
.process_sample_event = process_sample_event,
|
||||
.process_comm_event = event__process_comm,
|
||||
.sample_type_check = sample_type_check,
|
||||
|
@ -127,9 +126,8 @@ static struct perf_file_handler file_handler = {
|
|||
static int __cmd_trace(struct perf_session *session)
|
||||
{
|
||||
register_idle_thread();
|
||||
register_perf_file_handler(&file_handler);
|
||||
|
||||
return perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
|
||||
return perf_session__process_events(session, &event_ops, 0,
|
||||
&event__cwdlen, &event__cwd);
|
||||
}
|
||||
|
||||
struct script_spec {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
#include "data_map.h"
|
||||
#include "symbol.h"
|
||||
#include "util.h"
|
||||
#include "debug.h"
|
||||
#include "session.h"
|
||||
|
||||
|
||||
static struct perf_file_handler *curr_handler;
|
||||
static unsigned long mmap_window = 32;
|
||||
static char __cwd[PATH_MAX];
|
||||
|
||||
|
@ -15,7 +13,7 @@ static int process_event_stub(event_t *event __used,
|
|||
return 0;
|
||||
}
|
||||
|
||||
void register_perf_file_handler(struct perf_file_handler *handler)
|
||||
static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
|
||||
{
|
||||
if (!handler->process_sample_event)
|
||||
handler->process_sample_event = process_event_stub;
|
||||
|
@ -35,8 +33,6 @@ void register_perf_file_handler(struct perf_file_handler *handler)
|
|||
handler->process_throttle_event = process_event_stub;
|
||||
if (!handler->process_unthrottle_event)
|
||||
handler->process_unthrottle_event = process_event_stub;
|
||||
|
||||
curr_handler = handler;
|
||||
}
|
||||
|
||||
static const char *event__name[] = {
|
||||
|
@ -63,6 +59,7 @@ void event__print_totals(void)
|
|||
}
|
||||
|
||||
static int process_event(event_t *event, struct perf_session *session,
|
||||
struct perf_event_ops *ops,
|
||||
unsigned long offset, unsigned long head)
|
||||
{
|
||||
trace_event(event);
|
||||
|
@ -78,25 +75,25 @@ static int process_event(event_t *event, struct perf_session *session,
|
|||
|
||||
switch (event->header.type) {
|
||||
case PERF_RECORD_SAMPLE:
|
||||
return curr_handler->process_sample_event(event, session);
|
||||
return ops->process_sample_event(event, session);
|
||||
case PERF_RECORD_MMAP:
|
||||
return curr_handler->process_mmap_event(event, session);
|
||||
return ops->process_mmap_event(event, session);
|
||||
case PERF_RECORD_COMM:
|
||||
return curr_handler->process_comm_event(event, session);
|
||||
return ops->process_comm_event(event, session);
|
||||
case PERF_RECORD_FORK:
|
||||
return curr_handler->process_fork_event(event, session);
|
||||
return ops->process_fork_event(event, session);
|
||||
case PERF_RECORD_EXIT:
|
||||
return curr_handler->process_exit_event(event, session);
|
||||
return ops->process_exit_event(event, session);
|
||||
case PERF_RECORD_LOST:
|
||||
return curr_handler->process_lost_event(event, session);
|
||||
return ops->process_lost_event(event, session);
|
||||
case PERF_RECORD_READ:
|
||||
return curr_handler->process_read_event(event, session);
|
||||
return ops->process_read_event(event, session);
|
||||
case PERF_RECORD_THROTTLE:
|
||||
return curr_handler->process_throttle_event(event, session);
|
||||
return ops->process_throttle_event(event, session);
|
||||
case PERF_RECORD_UNTHROTTLE:
|
||||
return curr_handler->process_unthrottle_event(event, session);
|
||||
return ops->process_unthrottle_event(event, session);
|
||||
default:
|
||||
curr_handler->total_unknown++;
|
||||
ops->total_unknown++;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -131,6 +128,7 @@ out:
|
|||
}
|
||||
|
||||
int perf_session__process_events(struct perf_session *self,
|
||||
struct perf_event_ops *ops,
|
||||
int full_paths, int *cwdlen, char **cwd)
|
||||
{
|
||||
int err;
|
||||
|
@ -142,10 +140,7 @@ int perf_session__process_events(struct perf_session *self,
|
|||
uint32_t size;
|
||||
char *buf;
|
||||
|
||||
if (curr_handler == NULL) {
|
||||
pr_debug("Forgot to register perf file handler\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
perf_event_ops__fill_defaults(ops);
|
||||
|
||||
page_size = getpagesize();
|
||||
|
||||
|
@ -153,8 +148,8 @@ int perf_session__process_events(struct perf_session *self,
|
|||
sample_type = perf_header__sample_type(&self->header);
|
||||
|
||||
err = -EINVAL;
|
||||
if (curr_handler->sample_type_check &&
|
||||
curr_handler->sample_type_check(sample_type) < 0)
|
||||
if (ops->sample_type_check &&
|
||||
ops->sample_type_check(sample_type) < 0)
|
||||
goto out_err;
|
||||
|
||||
if (!full_paths) {
|
||||
|
@ -210,7 +205,7 @@ more:
|
|||
(void *)(long)event->header.size,
|
||||
event->header.type);
|
||||
|
||||
if (!size || process_event(event, self, offset, head) < 0) {
|
||||
if (!size || process_event(event, self, ops, offset, head) < 0) {
|
||||
|
||||
dump_printf("%p [%p]: skipping unknown header type: %d\n",
|
||||
(void *)(offset + head),
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
#ifndef __PERF_DATAMAP_H
|
||||
#define __PERF_DATAMAP_H
|
||||
|
||||
#include "event.h"
|
||||
#include "header.h"
|
||||
#include "session.h"
|
||||
|
||||
struct perf_session;
|
||||
|
||||
typedef int (*event_type_handler_t)(event_t *self,
|
||||
struct perf_session *session);
|
||||
|
||||
struct perf_file_handler {
|
||||
event_type_handler_t process_sample_event;
|
||||
event_type_handler_t process_mmap_event;
|
||||
event_type_handler_t process_comm_event;
|
||||
event_type_handler_t process_fork_event;
|
||||
event_type_handler_t process_exit_event;
|
||||
event_type_handler_t process_lost_event;
|
||||
event_type_handler_t process_read_event;
|
||||
event_type_handler_t process_throttle_event;
|
||||
event_type_handler_t process_unthrottle_event;
|
||||
int (*sample_type_check)(u64 sample_type);
|
||||
unsigned long total_unknown;
|
||||
};
|
||||
|
||||
void register_perf_file_handler(struct perf_file_handler *handler);
|
||||
int perf_session__process_events(struct perf_session *self,
|
||||
int full_paths, int *cwdlen, char **cwd);
|
||||
int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
|
||||
|
||||
#endif
|
|
@ -8,8 +8,8 @@
|
|||
#include "header.h"
|
||||
#include "../perf.h"
|
||||
#include "trace-event.h"
|
||||
#include "session.h"
|
||||
#include "symbol.h"
|
||||
#include "data_map.h"
|
||||
#include "debug.h"
|
||||
|
||||
/*
|
||||
|
|
|
@ -48,7 +48,8 @@ out_close:
|
|||
return -1;
|
||||
}
|
||||
|
||||
struct perf_session *perf_session__new(const char *filename, int mode, bool force)
|
||||
struct perf_session *perf_session__new(const char *filename, int mode,
|
||||
bool force)
|
||||
{
|
||||
size_t len = strlen(filename) + 1;
|
||||
struct perf_session *self = zalloc(sizeof(*self) + len);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __PERF_SESSION_H
|
||||
#define __PERF_SESSION_H
|
||||
|
||||
#include "event.h"
|
||||
#include "header.h"
|
||||
|
||||
struct perf_session {
|
||||
|
@ -10,7 +11,30 @@ struct perf_session {
|
|||
char filename[0];
|
||||
};
|
||||
|
||||
struct perf_session *perf_session__new(const char *filename, int mode, bool force);
|
||||
typedef int (*event_op)(event_t *self, struct perf_session *session);
|
||||
|
||||
struct perf_event_ops {
|
||||
event_op process_sample_event;
|
||||
event_op process_mmap_event;
|
||||
event_op process_comm_event;
|
||||
event_op process_fork_event;
|
||||
event_op process_exit_event;
|
||||
event_op process_lost_event;
|
||||
event_op process_read_event;
|
||||
event_op process_throttle_event;
|
||||
event_op process_unthrottle_event;
|
||||
int (*sample_type_check)(u64 sample_type);
|
||||
unsigned long total_unknown;
|
||||
};
|
||||
|
||||
struct perf_session *perf_session__new(const char *filename, int mode,
|
||||
bool force);
|
||||
void perf_session__delete(struct perf_session *self);
|
||||
|
||||
int perf_session__process_events(struct perf_session *self,
|
||||
struct perf_event_ops *event_ops,
|
||||
int full_paths, int *cwdlen, char **cwd);
|
||||
|
||||
int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
|
||||
|
||||
#endif /* __PERF_SESSION_H */
|
||||
|
|
Loading…
Reference in New Issue