[PATCH 29/38] perf session: Pass struct events stats to event processing functions

From: Namhyung Kim
Date: Mon Mar 02 2015 - 22:14:27 EST


Pass stats structure so that it can point separate object when used in
multi-thread environment.

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/ordered-events.c | 4 ++-
tools/perf/util/session.c | 53 ++++++++++++++++++++++++----------------
tools/perf/util/session.h | 1 +
3 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index 077ddd25189f..35b7c0fd103b 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -183,7 +183,9 @@ static int __ordered_events__flush(struct perf_session *s,
if (ret)
pr_err("Can't parse sample, err = %d\n", ret);
else {
- ret = perf_session__deliver_event(s, iter->event, &sample, tool,
+ ret = perf_session__deliver_event(s, &s->evlist->stats,
+ iter->event,
+ &sample, tool,
iter->file_offset);
if (ret)
return ret;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index d89dfa8592a9..0090eb8c6974 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -826,6 +826,7 @@ static struct machine *machines__find_for_cpumode(struct machines *machines,
}

static int deliver_sample_value(struct perf_evlist *evlist,
+ struct events_stats *stats,
struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
@@ -841,7 +842,7 @@ static int deliver_sample_value(struct perf_evlist *evlist,
}

if (!sid || sid->evsel == NULL) {
- ++evlist->stats.nr_unknown_id;
+ ++stats->nr_unknown_id;
return 0;
}

@@ -849,6 +850,7 @@ static int deliver_sample_value(struct perf_evlist *evlist,
}

static int deliver_sample_group(struct perf_evlist *evlist,
+ struct events_stats *stats,
struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
@@ -858,7 +860,7 @@ static int deliver_sample_group(struct perf_evlist *evlist,
u64 i;

for (i = 0; i < sample->read.group.nr; i++) {
- ret = deliver_sample_value(evlist, tool, event, sample,
+ ret = deliver_sample_value(evlist, stats, tool, event, sample,
&sample->read.group.values[i],
machine);
if (ret)
@@ -870,6 +872,7 @@ static int deliver_sample_group(struct perf_evlist *evlist,

static int
perf_evlist__deliver_sample(struct perf_evlist *evlist,
+ struct events_stats *stats,
struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
@@ -886,14 +889,15 @@ static int

/* For PERF_SAMPLE_READ we have either single or group mode. */
if (read_format & PERF_FORMAT_GROUP)
- return deliver_sample_group(evlist, tool, event, sample,
+ return deliver_sample_group(evlist, stats, tool, event, sample,
machine);
else
- return deliver_sample_value(evlist, tool, event, sample,
+ return deliver_sample_value(evlist, stats, tool, event, sample,
&sample->read.one, machine);
}

int perf_session__deliver_event(struct perf_session *session,
+ struct events_stats *stats,
union perf_event *event,
struct perf_sample *sample,
struct perf_tool *tool, u64 file_offset)
@@ -912,14 +916,15 @@ int perf_session__deliver_event(struct perf_session *session,
case PERF_RECORD_SAMPLE:
dump_sample(evsel, event, sample);
if (evsel == NULL) {
- ++evlist->stats.nr_unknown_id;
+ ++stats->nr_unknown_id;
return 0;
}
if (machine == NULL) {
- ++evlist->stats.nr_unprocessable_samples;
+ ++stats->nr_unprocessable_samples;
return 0;
}
- return perf_evlist__deliver_sample(evlist, tool, event, sample, evsel, machine);
+ return perf_evlist__deliver_sample(evlist, stats, tool, event,
+ sample, evsel, machine);
case PERF_RECORD_MMAP:
return tool->mmap(tool, event, sample, machine);
case PERF_RECORD_MMAP2:
@@ -932,7 +937,7 @@ int perf_session__deliver_event(struct perf_session *session,
return tool->exit(tool, event, sample, machine);
case PERF_RECORD_LOST:
if (tool->lost == perf_event__process_lost)
- evlist->stats.total_lost += event->lost.lost;
+ stats->total_lost += event->lost.lost;
return tool->lost(tool, event, sample, machine);
case PERF_RECORD_READ:
return tool->read(tool, event, sample, evsel, machine);
@@ -941,7 +946,7 @@ int perf_session__deliver_event(struct perf_session *session,
case PERF_RECORD_UNTHROTTLE:
return tool->unthrottle(tool, event, sample, machine);
default:
- ++evlist->stats.nr_unknown_events;
+ ++stats->nr_unknown_events;
return -1;
}
}
@@ -996,7 +1001,8 @@ int perf_session__deliver_synth_event(struct perf_session *session,
if (event->header.type >= PERF_RECORD_USER_TYPE_START)
return perf_session__process_user_event(session, event, tool, 0);

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

static void event_swap(union perf_event *event, bool sample_id_all)
@@ -1064,6 +1070,7 @@ int perf_session__peek_event(struct perf_session *session, off_t file_offset,
}

static s64 perf_session__process_event(struct perf_session *session,
+ struct events_stats *stats,
union perf_event *event,
struct perf_tool *tool,
u64 file_offset)
@@ -1078,7 +1085,7 @@ static s64 perf_session__process_event(struct perf_session *session,
if (event->header.type >= PERF_RECORD_HEADER_MAX)
return -EINVAL;

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

if (event->header.type >= PERF_RECORD_USER_TYPE_START)
return perf_session__process_user_event(session, event, tool, file_offset);
@@ -1097,8 +1104,8 @@ 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, stats, event, &sample,
+ tool, file_offset);
}

void perf_event_header__bswap(struct perf_event_header *hdr)
@@ -1237,7 +1244,8 @@ static int __perf_session__process_pipe_events(struct perf_session *session,
}
}

- if ((skip = perf_session__process_event(session, event, tool, head)) < 0) {
+ if ((skip = perf_session__process_event(session, &session->evlist->stats,
+ event, tool, head)) < 0) {
pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n",
head, event->header.size, event->header.type);
err = -EINVAL;
@@ -1301,7 +1309,8 @@ fetch_mmaped_event(struct perf_session *session,
#define NUM_MMAPS 128
#endif

-static int __perf_session__process_events(struct perf_session *session, int fd,
+static int __perf_session__process_events(struct perf_session *session,
+ struct events_stats *stats, int fd,
u64 data_offset, u64 data_size,
u64 file_size, struct perf_tool *tool)
{
@@ -1374,8 +1383,8 @@ static int __perf_session__process_events(struct perf_session *session, int fd,
size = event->header.size;

if (size < sizeof(struct perf_event_header) ||
- (skip = perf_session__process_event(session, event, tool, file_pos))
- < 0) {
+ (skip = perf_session__process_event(session, stats, event,
+ tool, file_pos)) < 0) {
pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n",
file_offset + head, event->header.size,
event->header.type);
@@ -1412,6 +1421,7 @@ static int __perf_session__process_indexed_events(struct perf_session *session,
{
struct perf_data_file *file = session->file;
u64 size = perf_data_file__size(file);
+ struct events_stats *stats = &session->evlist->stats;
int err = 0, i;

for (i = 0; i < (int)session->header.nr_index; i++) {
@@ -1428,7 +1438,7 @@ static int __perf_session__process_indexed_events(struct perf_session *session,
if (i > 0)
tool->ordered_events = false;

- err = __perf_session__process_events(session,
+ err = __perf_session__process_events(session, stats,
perf_data_file__fd(file),
index->offset, index->size,
size, tool);
@@ -1436,7 +1446,7 @@ static int __perf_session__process_indexed_events(struct perf_session *session,
break;
}

- perf_tool__warn_about_errors(tool, &session->evlist->stats);
+ perf_tool__warn_about_errors(tool, stats);
return err;
}

@@ -1445,6 +1455,7 @@ int perf_session__process_events(struct perf_session *session,
{
struct perf_data_file *file = session->file;
u64 size = perf_data_file__size(file);
+ struct events_stats *stats = &session->evlist->stats;
int err;

if (perf_session__register_idle_thread(session) == NULL)
@@ -1455,13 +1466,13 @@ int perf_session__process_events(struct perf_session *session,
if (perf_session__has_index(session))
return __perf_session__process_indexed_events(session, tool);

- err = __perf_session__process_events(session,
+ err = __perf_session__process_events(session, stats,
perf_data_file__fd(file),
session->header.data_offset,
session->header.data_size,
size, tool);

- perf_tool__warn_about_errors(tool, &session->evlist->stats);
+ perf_tool__warn_about_errors(tool, stats);
return err;
}

diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 4d264fef8968..c9a53ecf658d 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -58,6 +58,7 @@ int perf_session_queue_event(struct perf_session *s, union perf_event *event,
void perf_tool__fill_defaults(struct perf_tool *tool);

int perf_session__deliver_event(struct perf_session *session,
+ struct events_stats *stats,
union perf_event *event,
struct perf_sample *sample,
struct perf_tool *tool, u64 file_offset);
--
2.2.2

--
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/