[PATCH v7 2/5] perf tools: pass session to mmap processing code

From: Stephane Eranian
Date: Thu Oct 01 2015 - 02:48:34 EST


This patch passes the perf_session to the mmap processing callbacks.
This is needed in a later patch to get to the event list and sample_type.

A consequence of the patch is that the number of argument to
machine_deliver_event() is reduced.

Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
---
tools/perf/builtin-inject.c | 14 ++++++++------
tools/perf/builtin-script.c | 14 ++++++--------
tools/perf/util/event.c | 6 ++++--
tools/perf/util/event.h | 6 ++++--
tools/perf/util/session.c | 43 +++++++++++++++++++++++++------------------
tools/perf/util/tool.h | 11 ++++++++---
6 files changed, 55 insertions(+), 39 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 0a945d2..db5393e 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -224,11 +224,12 @@ static int perf_event__repipe_sample(struct perf_tool *tool,
static int perf_event__repipe_mmap(struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
- struct machine *machine)
+ struct machine *machine,
+ struct perf_session *session)
{
int err;

- err = perf_event__process_mmap(tool, event, sample, machine);
+ err = perf_event__process_mmap(tool, event, sample, machine, session);
perf_event__repipe(tool, event, sample, machine);

return err;
@@ -237,11 +238,12 @@ static int perf_event__repipe_mmap(struct perf_tool *tool,
static int perf_event__repipe_mmap2(struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
- struct machine *machine)
+ struct machine *machine,
+ struct perf_session *session)
{
int err;

- err = perf_event__process_mmap2(tool, event, sample, machine);
+ err = perf_event__process_mmap2(tool, event, sample, machine, session);
perf_event__repipe(tool, event, sample, machine);

return err;
@@ -669,8 +671,8 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused)
struct perf_inject inject = {
.tool = {
.sample = perf_event__repipe_sample,
- .mmap = perf_event__repipe,
- .mmap2 = perf_event__repipe,
+ .mmap = perf_event__repipe_mmap,
+ .mmap2 = perf_event__repipe_mmap,
.comm = perf_event__repipe,
.fork = perf_event__repipe,
.exit = perf_event__repipe,
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 8ce1c6b..93d09f2 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -790,14 +790,13 @@ static int process_exit_event(struct perf_tool *tool,
static int process_mmap_event(struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
- struct machine *machine)
+ struct machine *machine,
+ struct perf_session *session)
{
struct thread *thread;
- struct perf_script *script = container_of(tool, struct perf_script, tool);
- struct perf_session *session = script->session;
struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);

- if (perf_event__process_mmap(tool, event, sample, machine) < 0)
+ if (perf_event__process_mmap(tool, event, sample, machine, session) < 0)
return -1;

thread = machine__findnew_thread(machine, event->mmap.pid, event->mmap.tid);
@@ -821,14 +820,13 @@ static int process_mmap_event(struct perf_tool *tool,
static int process_mmap2_event(struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
- struct machine *machine)
+ struct machine *machine,
+ struct perf_session *session)
{
struct thread *thread;
- struct perf_script *script = container_of(tool, struct perf_script, tool);
- struct perf_session *session = script->session;
struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);

- if (perf_event__process_mmap2(tool, event, sample, machine) < 0)
+ if (perf_event__process_mmap2(tool, event, sample, machine, session) < 0)
return -1;

thread = machine__findnew_thread(machine, event->mmap2.pid, event->mmap2.tid);
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index b1bb348..555f876 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -786,7 +786,8 @@ size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp)
int perf_event__process_mmap(struct perf_tool *tool __maybe_unused,
union perf_event *event,
struct perf_sample *sample,
- struct machine *machine)
+ struct machine *machine,
+ struct perf_session *session __maybe_unused)
{
return machine__process_mmap_event(machine, event, sample);
}
@@ -794,7 +795,8 @@ int perf_event__process_mmap(struct perf_tool *tool __maybe_unused,
int perf_event__process_mmap2(struct perf_tool *tool __maybe_unused,
union perf_event *event,
struct perf_sample *sample,
- struct machine *machine)
+ struct machine *machine,
+ struct perf_session *session __maybe_unused)
{
return machine__process_mmap2_event(machine, event, sample);
}
diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h
index a0dbcbd..a33d50d 100644
--- a/tools/perf/util/event.h
+++ b/tools/perf/util/event.h
@@ -434,11 +434,13 @@ int perf_event__process_switch(struct perf_tool *tool,
int perf_event__process_mmap(struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
- struct machine *machine);
+ struct machine *machine,
+ struct perf_session *session);
int perf_event__process_mmap2(struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
- struct machine *machine);
+ struct machine *machine,
+ struct perf_session *session);
int perf_event__process_fork(struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 84a02eae..fcbf1a0 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -21,7 +21,6 @@
static int perf_session__deliver_event(struct perf_session *session,
union perf_event *event,
struct perf_sample *sample,
- struct perf_tool *tool,
u64 file_offset);

static int perf_session__open(struct perf_session *session)
@@ -108,7 +107,7 @@ static int ordered_events__deliver_event(struct ordered_events *oe,
}

return perf_session__deliver_event(session, event->event, &sample,
- session->tool, event->file_offset);
+ event->file_offset);
}

struct perf_session *perf_session__new(struct perf_data_file *file,
@@ -214,7 +213,6 @@ static int process_event_sample_stub(struct perf_tool *tool __maybe_unused,
dump_printf(": unhandled!\n");
return 0;
}
-
static int process_event_stub(struct perf_tool *tool __maybe_unused,
union perf_event *event __maybe_unused,
struct perf_sample *sample __maybe_unused,
@@ -224,6 +222,17 @@ static int process_event_stub(struct perf_tool *tool __maybe_unused,
return 0;
}

+
+static int process_event_mmap_stub(struct perf_tool *tool __maybe_unused,
+ union perf_event *event __maybe_unused,
+ struct perf_sample *sample __maybe_unused,
+ struct machine *machine __maybe_unused,
+ struct perf_session *session __maybe_unused)
+{
+ dump_printf(": unhandled!\n");
+ return 0;
+}
+
static int process_build_id_stub(struct perf_tool *tool __maybe_unused,
union perf_event *event __maybe_unused,
struct perf_session *session __maybe_unused)
@@ -301,9 +310,9 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
if (tool->sample == NULL)
tool->sample = process_event_sample_stub;
if (tool->mmap == NULL)
- tool->mmap = process_event_stub;
+ tool->mmap = process_event_mmap_stub;
if (tool->mmap2 == NULL)
- tool->mmap2 = process_event_stub;
+ tool->mmap2 = process_event_mmap_stub;
if (tool->comm == NULL)
tool->comm = process_event_stub;
if (tool->fork == NULL)
@@ -1047,12 +1056,14 @@ static int
&sample->read.one, machine);
}

-static int machines__deliver_event(struct machines *machines,
- struct perf_evlist *evlist,
+static int machines__deliver_event(struct perf_session *session,
union perf_event *event,
struct perf_sample *sample,
- struct perf_tool *tool, u64 file_offset)
+ u64 file_offset)
{
+ struct machines *machines = &session->machines;
+ struct perf_evlist *evlist = session->evlist;
+ struct perf_tool *tool = session->tool;
struct perf_evsel *evsel;
struct machine *machine;

@@ -1075,11 +1086,11 @@ static int machines__deliver_event(struct machines *machines,
}
return perf_evlist__deliver_sample(evlist, tool, event, sample, evsel, machine);
case PERF_RECORD_MMAP:
- return tool->mmap(tool, event, sample, machine);
+ return tool->mmap(tool, event, sample, machine, session);
case PERF_RECORD_MMAP2:
if (event->header.misc & PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT)
++evlist->stats.nr_proc_map_timeout;
- return tool->mmap2(tool, event, sample, machine);
+ return tool->mmap2(tool, event, sample, machine, session);
case PERF_RECORD_COMM:
return tool->comm(tool, event, sample, machine);
case PERF_RECORD_FORK:
@@ -1119,19 +1130,17 @@ static int machines__deliver_event(struct machines *machines,
static int perf_session__deliver_event(struct perf_session *session,
union perf_event *event,
struct perf_sample *sample,
- struct perf_tool *tool,
u64 file_offset)
{
int ret;

- ret = auxtrace__process_event(session, event, sample, tool);
+ ret = auxtrace__process_event(session, event, sample, session->tool);
if (ret < 0)
return ret;
if (ret > 0)
return 0;

- return machines__deliver_event(&session->machines, session->evlist,
- event, sample, tool, file_offset);
+ return machines__deliver_event(session, event, sample, file_offset);
}

static s64 perf_session__process_user_event(struct perf_session *session,
@@ -1189,14 +1198,13 @@ int perf_session__deliver_synth_event(struct perf_session *session,
struct perf_sample *sample)
{
struct perf_evlist *evlist = session->evlist;
- struct perf_tool *tool = session->tool;

events_stats__inc(&evlist->stats, event->header.type);

if (event->header.type >= PERF_RECORD_USER_TYPE_START)
return perf_session__process_user_event(session, event, 0);

- return machines__deliver_event(&session->machines, evlist, event, sample, tool, 0);
+ return machines__deliver_event(session, event, sample, 0);
}

static void event_swap(union perf_event *event, bool sample_id_all)
@@ -1295,8 +1303,7 @@ static s64 perf_session__process_event(struct perf_session *session,
return ret;
}

- return perf_session__deliver_event(session, event, &sample, tool,
- file_offset);
+ return perf_session__deliver_event(session, event, &sample, file_offset);
}

void perf_event_header__bswap(struct perf_event_header *hdr)
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index cab8cc2..b4f94fe 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -34,12 +34,15 @@ typedef int (*event_oe)(struct perf_tool *tool, union perf_event *event,
typedef s64 (*event_op3)(struct perf_tool *tool, union perf_event *event,
struct perf_session *session);

+
+typedef int (*event_op4)(struct perf_tool *tool, union perf_event *event,
+ struct perf_sample *sample, struct machine *machine,
+ struct perf_session *session);
+
struct perf_tool {
event_sample sample,
read;
- event_op mmap,
- mmap2,
- comm,
+ event_op comm,
fork,
exit,
lost,
@@ -57,6 +60,8 @@ struct perf_tool {
auxtrace_info,
auxtrace_error;
event_op3 auxtrace;
+ event_op4 mmap,
+ mmap2;
bool ordered_events;
bool ordering_requires_timestamps;
};
--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/