Skip to content

Commit

Permalink
perf session: Pass the perf_session to the event handling operations
Browse files Browse the repository at this point in the history
They will need it to get the right threads list, etc.

Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Frédéric Weisbecker <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Paul Mackerras <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
acmel authored and Ingo Molnar committed Dec 14, 2009
1 parent 2cd9046 commit d8f6624
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 79 deletions.
2 changes: 1 addition & 1 deletion tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static int hist_entry__add(struct addr_location *al, u64 count)
return 0;
}

static int process_sample_event(event_t *event)
static int process_sample_event(event_t *event, struct perf_session *session __used)
{
struct addr_location al;

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ process_raw_event(event_t *raw_event __used, void *data,
}
}

static int process_sample_event(event_t *event)
static int process_sample_event(event_t *event, struct perf_session *session __used)
{
struct sample_data data;
struct thread *thread;
Expand Down
11 changes: 7 additions & 4 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ static void write_event(event_t *buf, size_t size)
write_output(buf, size);
}

static int process_synthesized_event(event_t *event)
static int process_synthesized_event(event_t *event,
struct perf_session *self __used)
{
write_event(event, event->header.size);
return 0;
Expand Down Expand Up @@ -488,9 +489,10 @@ static int __cmd_record(int argc, const char **argv)
}

if (!system_wide)
event__synthesize_thread(pid, process_synthesized_event);
event__synthesize_thread(pid, process_synthesized_event,
session);
else
event__synthesize_threads(process_synthesized_event);
event__synthesize_threads(process_synthesized_event, session);

if (target_pid == -1 && argc) {
pid = fork();
Expand All @@ -510,7 +512,8 @@ static int __cmd_record(int argc, const char **argv)
*/
usleep(1000);
event__synthesize_thread(pid,
process_synthesized_event);
process_synthesized_event,
session);
}

child_pid = pid;
Expand Down
9 changes: 4 additions & 5 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ static int exclude_other = 1;

static char callchain_default_opt[] = "fractal,0.5";

static struct perf_session *session;

static u64 sample_type;

struct symbol_conf symbol_conf;
Expand Down Expand Up @@ -604,7 +602,7 @@ static int validate_chain(struct ip_callchain *chain, event_t *event)
return 0;
}

static int process_sample_event(event_t *event)
static int process_sample_event(event_t *event, struct perf_session *session __used)
{
struct sample_data data;
int cpumode;
Expand Down Expand Up @@ -683,7 +681,7 @@ static int process_sample_event(event_t *event)
return 0;
}

static int process_comm_event(event_t *event)
static int process_comm_event(event_t *event, struct perf_session *session __used)
{
struct thread *thread = threads__findnew(event->comm.pid);

Expand All @@ -698,7 +696,7 @@ static int process_comm_event(event_t *event)
return 0;
}

static int process_read_event(event_t *event)
static int process_read_event(event_t *event, struct perf_session *session __used)
{
struct perf_event_attr *attr;

Expand Down Expand Up @@ -766,6 +764,7 @@ static int __cmd_report(void)
{
struct thread *idle;
int ret;
struct perf_session *session;

session = perf_session__new(input_name, O_RDONLY, force);
if (session == NULL)
Expand Down
6 changes: 4 additions & 2 deletions tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,8 @@ process_raw_event(event_t *raw_event __used, void *data,
process_sched_migrate_task_event(data, event, cpu, timestamp, thread);
}

static int process_sample_event(event_t *event)
static int process_sample_event(event_t *event,
struct perf_session *session __used)
{
struct sample_data data;
struct thread *thread;
Expand Down Expand Up @@ -1632,7 +1633,8 @@ static int process_sample_event(event_t *event)
return 0;
}

static int process_lost_event(event_t *event __used)
static int process_lost_event(event_t *event __used,
struct perf_session *session __used)
{
nr_lost_chunks++;
nr_lost_events += event->lost.lost;
Expand Down
13 changes: 5 additions & 8 deletions tools/perf/builtin-timechart.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,19 @@ 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(event_t *event)
static int process_comm_event(event_t *event, struct perf_session *session __used)
{
pid_set_comm(event->comm.pid, event->comm.comm);
return 0;
}
static int
process_fork_event(event_t *event)

static int process_fork_event(event_t *event, struct perf_session *session __used)
{
pid_fork(event->fork.pid, event->fork.ppid, event->fork.time);
return 0;
}

static int
process_exit_event(event_t *event)
static int process_exit_event(event_t *event, struct perf_session *session __used)
{
pid_exit(event->fork.pid, event->fork.time);
return 0;
Expand Down Expand Up @@ -594,8 +592,7 @@ static u64 sample_time(event_t *event)
* We first queue all events, sorted backwards by insertion.
* The order will get flipped later.
*/
static int
queue_sample_event(event_t *event)
static int queue_sample_event(event_t *event, struct perf_session *session __used)
{
struct sample_wrapper *copy, *prev;
int size;
Expand Down
28 changes: 17 additions & 11 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,14 +965,14 @@ static void event__process_sample(const event_t *self, int counter)
}
}

static int event__process(event_t *event)
static int event__process(event_t *event, struct perf_session *session)
{
switch (event->header.type) {
case PERF_RECORD_COMM:
event__process_comm(event);
event__process_comm(event, session);
break;
case PERF_RECORD_MMAP:
event__process_mmap(event);
event__process_mmap(event, session);
break;
default:
break;
Expand All @@ -999,7 +999,8 @@ static unsigned int mmap_read_head(struct mmap_data *md)
return head;
}

static void mmap_read_counter(struct mmap_data *md)
static void perf_session__mmap_read_counter(struct perf_session *self,
struct mmap_data *md)
{
unsigned int head = mmap_read_head(md);
unsigned int old = md->prev;
Expand Down Expand Up @@ -1054,7 +1055,7 @@ static void mmap_read_counter(struct mmap_data *md)
if (event->header.type == PERF_RECORD_SAMPLE)
event__process_sample(event, md->counter);
else
event__process(event);
event__process(event, self);
old += size;
}

Expand All @@ -1064,13 +1065,13 @@ static void mmap_read_counter(struct mmap_data *md)
static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS];
static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS];

static void mmap_read(void)
static void perf_session__mmap_read(struct perf_session *self)
{
int i, counter;

for (i = 0; i < nr_cpus; i++) {
for (counter = 0; counter < nr_counters; counter++)
mmap_read_counter(&mmap_array[i][counter]);
perf_session__mmap_read_counter(self, &mmap_array[i][counter]);
}
}

Expand Down Expand Up @@ -1155,11 +1156,16 @@ static int __cmd_top(void)
pthread_t thread;
int i, counter;
int ret;
/*
* XXX perf_session__new should allow passing a O_MMAP, so that all this
* mmap reading, etc is encapsulated in it.
*/
struct perf_session *session = NULL;

if (target_pid != -1)
event__synthesize_thread(target_pid, event__process);
event__synthesize_thread(target_pid, event__process, session);
else
event__synthesize_threads(event__process);
event__synthesize_threads(event__process, session);

for (i = 0; i < nr_cpus; i++) {
group_fd = -1;
Expand All @@ -1170,7 +1176,7 @@ static int __cmd_top(void)
/* Wait for a minimal set of events before starting the snapshot */
poll(event_array, nr_poll, 100);

mmap_read();
perf_session__mmap_read(session);

if (pthread_create(&thread, NULL, display_thread, NULL)) {
printf("Could not create display thread.\n");
Expand All @@ -1190,7 +1196,7 @@ static int __cmd_top(void)
while (1) {
int hits = samples;

mmap_read();
perf_session__mmap_read(session);

if (hits == samples)
ret = poll(event_array, nr_poll, 100);
Expand Down
23 changes: 10 additions & 13 deletions tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ static int cleanup_scripting(void)

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

static struct perf_session *session;
static u64 sample_type;

static int process_sample_event(event_t *event)
static int process_sample_event(event_t *event, struct perf_session *session __used)
{
struct sample_data data;
struct thread *thread;
Expand Down Expand Up @@ -125,20 +124,12 @@ static struct perf_file_handler file_handler = {
.sample_type_check = sample_type_check,
};

static int __cmd_trace(void)
static int __cmd_trace(struct perf_session *session)
{
int err;

session = perf_session__new(input_name, O_RDONLY, 0);
if (session == NULL)
return -ENOMEM;

register_idle_thread();
register_perf_file_handler(&file_handler);

err = perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
perf_session__delete(session);
return err;
return perf_session__process_events(session, 0, &event__cwdlen, &event__cwd);
}

struct script_spec {
Expand Down Expand Up @@ -313,6 +304,7 @@ static const struct option options[] = {
int cmd_trace(int argc, const char **argv, const char *prefix __used)
{
int err;
struct perf_session *session;

symbol__init(0);

Expand All @@ -330,6 +322,10 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)

setup_pager();

session = perf_session__new(input_name, O_RDONLY, 0);
if (session == NULL)
return -ENOMEM;

if (generate_script_lang) {
struct stat perf_stat;

Expand Down Expand Up @@ -367,8 +363,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
goto out;
}

err = __cmd_trace();
err = __cmd_trace(session);

perf_session__delete(session);
cleanup_scripting();
out:
return err;
Expand Down
27 changes: 14 additions & 13 deletions tools/perf/util/data_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ static struct perf_file_handler *curr_handler;
static unsigned long mmap_window = 32;
static char __cwd[PATH_MAX];

static int process_event_stub(event_t *event __used)
static int process_event_stub(event_t *event __used,
struct perf_session *session __used)
{
dump_printf(": unhandled!\n");
return 0;
Expand Down Expand Up @@ -61,8 +62,8 @@ void event__print_totals(void)
event__name[i], event__total[i]);
}

static int
process_event(event_t *event, unsigned long offset, unsigned long head)
static int process_event(event_t *event, struct perf_session *session,
unsigned long offset, unsigned long head)
{
trace_event(event);

Expand All @@ -77,23 +78,23 @@ process_event(event_t *event, unsigned long offset, unsigned long head)

switch (event->header.type) {
case PERF_RECORD_SAMPLE:
return curr_handler->process_sample_event(event);
return curr_handler->process_sample_event(event, session);
case PERF_RECORD_MMAP:
return curr_handler->process_mmap_event(event);
return curr_handler->process_mmap_event(event, session);
case PERF_RECORD_COMM:
return curr_handler->process_comm_event(event);
return curr_handler->process_comm_event(event, session);
case PERF_RECORD_FORK:
return curr_handler->process_fork_event(event);
return curr_handler->process_fork_event(event, session);
case PERF_RECORD_EXIT:
return curr_handler->process_exit_event(event);
return curr_handler->process_exit_event(event, session);
case PERF_RECORD_LOST:
return curr_handler->process_lost_event(event);
return curr_handler->process_lost_event(event, session);
case PERF_RECORD_READ:
return curr_handler->process_read_event(event);
return curr_handler->process_read_event(event, session);
case PERF_RECORD_THROTTLE:
return curr_handler->process_throttle_event(event);
return curr_handler->process_throttle_event(event, session);
case PERF_RECORD_UNTHROTTLE:
return curr_handler->process_unthrottle_event(event);
return curr_handler->process_unthrottle_event(event, session);
default:
curr_handler->total_unknown++;
return -1;
Expand Down Expand Up @@ -209,7 +210,7 @@ int perf_session__process_events(struct perf_session *self,
(void *)(long)event->header.size,
event->header.type);

if (!size || process_event(event, offset, head) < 0) {
if (!size || process_event(event, self, offset, head) < 0) {

dump_printf("%p [%p]: skipping unknown header type: %d\n",
(void *)(offset + head),
Expand Down
5 changes: 4 additions & 1 deletion tools/perf/util/data_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include "header.h"
#include "session.h"

typedef int (*event_type_handler_t)(event_t *);
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;
Expand Down
Loading

0 comments on commit d8f6624

Please sign in to comment.