All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Stephane Eranian <eranian@google.com>,
	David Ahern <dsahern@gmail.com>, Andi Kleen <andi@firstfloor.org>
Subject: [RFC/PATCH 26/38] perf session: Pass struct events stats to event processing functions
Date: Fri,  2 Oct 2015 14:19:07 +0900	[thread overview]
Message-ID: <1443763159-29098-27-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1443763159-29098-1-git-send-email-namhyung@kernel.org>

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

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/session.c | 71 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 45 insertions(+), 26 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7546c4d147b9..8cafc679096b 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -19,6 +19,7 @@
 #include "thread-stack.h"
 
 static 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,
@@ -107,7 +108,8 @@ static int ordered_events__deliver_event(struct ordered_events *oe,
 		return ret;
 	}
 
-	return perf_session__deliver_event(session, event->event, &sample,
+	return perf_session__deliver_event(session, &session->evlist->stats,
+					   event->event, &sample,
 					   session->tool, event->file_offset);
 }
 
@@ -981,6 +983,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,
@@ -996,7 +999,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;
 	}
 
@@ -1004,6 +1007,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,
@@ -1013,7 +1017,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)
@@ -1025,6 +1029,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,
@@ -1041,14 +1046,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);
 }
 
 static int machines__deliver_event(struct machines *machines,
+				   struct events_stats *stats,
 				   struct perf_evlist *evlist,
 				   union perf_event *event,
 				   struct perf_sample *sample,
@@ -1066,15 +1072,16 @@ static int machines__deliver_event(struct machines *machines,
 	switch (event->header.type) {
 	case PERF_RECORD_SAMPLE:
 		if (evsel == NULL) {
-			++evlist->stats.nr_unknown_id;
+			++stats->nr_unknown_id;
 			return 0;
 		}
 		dump_sample(evsel, event, sample);
 		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:
@@ -1089,7 +1096,7 @@ static int machines__deliver_event(struct machines *machines,
 		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_LOST_SAMPLES:
 		if (tool->lost_samples == perf_event__process_lost_samples)
@@ -1112,12 +1119,13 @@ static int machines__deliver_event(struct machines *machines,
 	case PERF_RECORD_SWITCH_CPU_WIDE:
 		return tool->context_switch(tool, event, sample, machine);
 	default:
-		++evlist->stats.nr_unknown_events;
+		++stats->nr_unknown_events;
 		return -1;
 	}
 }
 
 static 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,
@@ -1131,8 +1139,9 @@ static int perf_session__deliver_event(struct perf_session *session,
 	if (ret > 0)
 		return 0;
 
-	return machines__deliver_event(&session->machines, session->evlist,
-				       event, sample, tool, file_offset);
+	return machines__deliver_event(&session->machines, stats,
+				       session->evlist, event, sample,
+				       tool, file_offset);
 }
 
 static s64 perf_session__process_user_event(struct perf_session *session,
@@ -1197,7 +1206,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, 0);
 
-	return machines__deliver_event(&session->machines, evlist, event, sample, tool, 0);
+	return machines__deliver_event(&session->machines, &evlist->stats,
+				       evlist, event, sample, tool, 0);
 }
 
 static void event_swap(union perf_event *event, bool sample_id_all)
@@ -1265,7 +1275,9 @@ out_parse_sample:
 }
 
 static s64 perf_session__process_event(struct perf_session *session,
-				       union perf_event *event, u64 file_offset)
+				       struct events_stats *stats,
+				       union perf_event *event,
+				       u64 file_offset)
 {
 	struct perf_evlist *evlist = session->evlist;
 	struct perf_tool *tool = session->tool;
@@ -1278,7 +1290,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, file_offset);
@@ -1296,8 +1308,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)
@@ -1325,9 +1337,9 @@ struct thread *perf_session__register_idle_thread(struct perf_session *session)
 	return thread;
 }
 
-static void perf_session__warn_about_errors(const struct perf_session *session)
+static void perf_session__warn_about_errors(const struct perf_session *session,
+					    const struct events_stats *stats)
 {
-	const struct events_stats *stats = &session->evlist->stats;
 	const struct ordered_events *oe = &session->ordered_events;
 
 	if (session->tool->lost == perf_event__process_lost &&
@@ -1420,6 +1432,7 @@ volatile int session_done;
 static int __perf_session__process_pipe_events(struct perf_session *session)
 {
 	struct ordered_events *oe = &session->ordered_events;
+	struct events_stats *stats = &session->evlist->stats;
 	struct perf_tool *tool = session->tool;
 	int fd = perf_data_file__fd(session->file);
 	union perf_event *event;
@@ -1484,7 +1497,8 @@ more:
 		}
 	}
 
-	if ((skip = perf_session__process_event(session, event, head)) < 0) {
+	if ((skip = perf_session__process_event(session, stats, event,
+						head)) < 0) {
 		pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n",
 		       head, event->header.size, event->header.type);
 		err = -EINVAL;
@@ -1509,7 +1523,7 @@ done:
 	err = perf_session__flush_thread_stacks(session);
 out_err:
 	free(buf);
-	perf_session__warn_about_errors(session);
+	perf_session__warn_about_errors(session, stats);
 	ordered_events__free(&session->ordered_events);
 	auxtrace__free_events(session);
 	return err;
@@ -1556,6 +1570,7 @@ fetch_mmaped_event(struct perf_session *session,
 #endif
 
 static int __perf_session__process_events(struct perf_session *session,
+					  struct events_stats *stats,
 					  u64 data_offset, u64 data_size,
 					  u64 file_size)
 {
@@ -1634,7 +1649,8 @@ more:
 	size = event->header.size;
 
 	if (size < sizeof(struct perf_event_header) ||
-	    (skip = perf_session__process_event(session, event, file_pos)) < 0) {
+	    (skip = perf_session__process_event(session, stats, event,
+						file_pos)) < 0) {
 		pr_err("%#" PRIx64 " [%#x]: failed to process type: %d\n",
 		       file_offset + head, event->header.size,
 		       event->header.type);
@@ -1678,6 +1694,7 @@ static int __perf_session__process_indexed_events(struct perf_session *session)
 	struct perf_data_file *file = session->file;
 	struct perf_tool *tool = session->tool;
 	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++) {
@@ -1694,13 +1711,14 @@ static int __perf_session__process_indexed_events(struct perf_session *session)
 		if (i > 0)
 			tool->ordered_events = false;
 
-		err = __perf_session__process_events(session, idx->offset,
+		err = __perf_session__process_events(session, stats,
+						     idx->offset,
 						     idx->size, size);
 		if (err < 0)
 			break;
 	}
 
-	perf_session__warn_about_errors(session);
+	perf_session__warn_about_errors(session, stats);
 	return err;
 }
 
@@ -1708,6 +1726,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)
@@ -1718,12 +1737,12 @@ int perf_session__process_events(struct perf_session *session)
 	if (perf_has_index)
 		return __perf_session__process_indexed_events(session);
 
-	err = __perf_session__process_events(session,
+	err = __perf_session__process_events(session, stats,
 					     session->header.data_offset,
 					     session->header.data_size,
 					     size);
 
-	perf_session__warn_about_errors(session);
+	perf_session__warn_about_errors(session, stats);
 	return err;
 }
 
-- 
2.6.0


  parent reply	other threads:[~2015-10-02  5:25 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-02  5:18 [RFC/PATCH 00/38] perf tools: Speed-up perf report by using multi thread (v5) Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 01/38] perf tools: Use a software dummy event to track task/mmap events Namhyung Kim
2015-10-05 12:51   ` Jiri Olsa
2015-10-06  8:31     ` Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 02/38] perf tools: Save mmap_param.len instead of mask Namhyung Kim
2015-10-02 18:44   ` Arnaldo Carvalho de Melo
2015-10-06  8:34     ` Namhyung Kim
2015-10-08 10:17   ` Jiri Olsa
2015-10-09  6:03     ` Namhyung Kim
2015-10-12 12:42       ` Jiri Olsa
2015-10-02  5:18 ` [RFC/PATCH 03/38] perf tools: Move auxtrace_mmap field to struct perf_evlist Namhyung Kim
2015-10-02 18:45   ` Arnaldo Carvalho de Melo
2015-10-05 11:29     ` Adrian Hunter
2015-10-06  9:03       ` Namhyung Kim
2015-10-06  9:26         ` Adrian Hunter
2015-10-07  9:06           ` Namhyung Kim
2015-10-08 16:07             ` Adrian Hunter
2015-10-09  7:54               ` Namhyung Kim
2015-10-06  8:56     ` Namhyung Kim
2015-10-05 13:14   ` Jiri Olsa
2015-10-06  8:40     ` Namhyung Kim
2015-10-08 10:18   ` Jiri Olsa
2015-10-02  5:18 ` [RFC/PATCH 04/38] perf tools: pass perf_mmap desc directly Namhyung Kim
2015-10-02 18:47   ` Arnaldo Carvalho de Melo
2015-10-02  5:18 ` [RFC/PATCH 05/38] perf tools: Create separate mmap for dummy tracking event Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 06/38] perf tools: Extend perf_evlist__mmap_ex() to use track mmap Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 07/38] perf tools: Add HEADER_DATA_INDEX feature Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 08/38] perf tools: Handle indexed data file properly Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 09/38] perf record: Add --index option for building index table Namhyung Kim
2015-10-02 18:58   ` Arnaldo Carvalho de Melo
2015-10-05 13:46   ` Jiri Olsa
2015-10-07  8:21     ` Namhyung Kim
2015-10-07 12:10       ` Jiri Olsa
2015-10-02  5:18 ` [RFC/PATCH 10/38] perf report: Skip dummy tracking event Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 11/38] perf tools: Introduce thread__comm(_str)_by_time() helpers Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 12/38] perf tools: Add a test case for thread comm handling Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 13/38] perf tools: Use thread__comm_by_time() when adding hist entries Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 14/38] perf tools: Convert dead thread list into rbtree Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 15/38] perf tools: Introduce machine__find*_thread_by_time() Namhyung Kim
2015-10-08 12:20   ` Jiri Olsa
2015-10-09  6:04     ` Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 16/38] perf tools: Add a test case for timed thread handling Namhyung Kim
2015-10-02  5:18 ` [RFC/PATCH 17/38] perf tools: Maintain map groups list in a leader thread Namhyung Kim
2015-10-08 12:51   ` Jiri Olsa
2015-10-09  6:24     ` Namhyung Kim
2015-10-08 12:58   ` Jiri Olsa
2015-10-09  6:58     ` Namhyung Kim
2015-10-12 12:43       ` Jiri Olsa
2015-10-02  5:18 ` [RFC/PATCH 18/38] perf tools: Introduce thread__find_addr_location_by_time() and friends Namhyung Kim
2015-10-12 13:35   ` Jiri Olsa
2015-10-02  5:19 ` [RFC/PATCH 19/38] perf callchain: Use " Namhyung Kim
2015-10-02  5:19 ` [RFC/PATCH 20/38] perf tools: Add a test case for timed map groups handling Namhyung Kim
2015-10-02  5:19 ` [RFC/PATCH 21/38] perf tools: Save timestamp of a map creation Namhyung Kim
2015-10-02  5:19 ` [RFC/PATCH 22/38] perf tools: Introduce map_groups__{insert,find}_by_time() Namhyung Kim
2015-10-02  5:19 ` [RFC/PATCH 23/38] perf tools: Use map_groups__find_addr_by_time() Namhyung Kim
2015-10-02  5:19 ` [RFC/PATCH 24/38] perf tools: Add testcase for managing maps with time Namhyung Kim
2015-10-02  5:19 ` [RFC/PATCH 25/38] perf callchain: Maintain libunwind's address space in map_groups Namhyung Kim
2015-10-02  5:19 ` Namhyung Kim [this message]
2015-10-02  5:19 ` [RFC/PATCH 27/38] perf hists: Pass hists struct to hist_entry_iter struct Namhyung Kim
2015-10-02  5:19 ` [RFC/PATCH 28/38] perf tools: Move BUILD_ID_SIZE definition to perf.h Namhyung Kim
2015-10-02  5:22 ` Namhyung Kim
2015-10-02  6:58 ` Namhyung Kim
2015-10-12 14:32   ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443763159-29098-27-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=andi@firstfloor.org \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.