mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Mike Galbraith <efault@gmx.de>,
	Namhyung Kim <namhyung@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 04/18] perf evsel: Precalculate the sample size
Date: Fri,  3 Aug 2012 11:00:56 -0300	[thread overview]
Message-ID: <1344002470-5965-5-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1344002470-5965-1-git-send-email-acme@infradead.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

So that we don't have to store it in the perf_session instance, because
in the future perf_session instances may have multiple evlists, each
with different sample_type/sizes.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-ptod86fxkpgq3h62m9refkv4@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-test.c |    9 ++++-----
 tools/perf/util/evsel.c   |    3 ++-
 tools/perf/util/evsel.h   |    8 +-------
 tools/perf/util/python.c  |    2 +-
 tools/perf/util/session.c |   14 +++++++++++++-
 tools/perf/util/session.h |   13 +++----------
 6 files changed, 24 insertions(+), 25 deletions(-)

diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index d909eb7..2ea5fe4 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -478,7 +478,6 @@ static int test__basic_mmap(void)
 	unsigned int nr_events[nsyscalls],
 		     expected_nr_events[nsyscalls], i, j;
 	struct perf_evsel *evsels[nsyscalls], *evsel;
-	int sample_size = __perf_evsel__sample_size(attr.sample_type);
 
 	for (i = 0; i < nsyscalls; ++i) {
 		char name[64];
@@ -563,7 +562,8 @@ static int test__basic_mmap(void)
 			goto out_munmap;
 		}
 
-		err = perf_event__parse_sample(event, attr.sample_type, sample_size,
+		err = perf_event__parse_sample(event, attr.sample_type,
+					       evsels[0]->sample_size,
 					       false, &sample, false);
 		if (err) {
 			pr_err("Can't parse sample, err = %d\n", err);
@@ -666,7 +666,7 @@ static int test__PERF_RECORD(void)
 	     found_libc_mmap = false,
 	     found_vdso_mmap = false,
 	     found_ld_mmap = false;
-	int err = -1, errs = 0, i, wakeups = 0, sample_size;
+	int err = -1, errs = 0, i, wakeups = 0;
 	u32 cpu;
 	int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, };
 
@@ -761,7 +761,6 @@ static int test__PERF_RECORD(void)
 	 * event.
 	 */
 	sample_type = perf_evlist__sample_type(evlist);
-	sample_size = __perf_evsel__sample_size(sample_type);
 
 	/*
 	 * Now that all is properly set up, enable the events, they will
@@ -789,7 +788,7 @@ static int test__PERF_RECORD(void)
 					nr_events[type]++;
 
 				err = perf_event__parse_sample(event, sample_type,
-							       sample_size, true,
+							       evsel->sample_size, true,
 							       &sample, false);
 				if (err < 0) {
 					if (verbose)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index e817713..8feec40 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -20,7 +20,7 @@
 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
 #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0))
 
-int __perf_evsel__sample_size(u64 sample_type)
+static int __perf_evsel__sample_size(u64 sample_type)
 {
 	u64 mask = sample_type & PERF_SAMPLE_MASK;
 	int size = 0;
@@ -53,6 +53,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
 	evsel->attr	   = *attr;
 	INIT_LIST_HEAD(&evsel->node);
 	hists__init(&evsel->hists);
+	evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
 }
 
 struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx)
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 67cc503..894bd77 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -65,6 +65,7 @@ struct perf_evsel {
 		void		*func;
 		void		*data;
 	} handler;
+	unsigned int		sample_size;
 	bool 			supported;
 };
 
@@ -177,13 +178,6 @@ static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
 	return __perf_evsel__read(evsel, ncpus, nthreads, true);
 }
 
-int __perf_evsel__sample_size(u64 sample_type);
-
-static inline int perf_evsel__sample_size(struct perf_evsel *evsel)
-{
-	return __perf_evsel__sample_size(evsel->attr.sample_type);
-}
-
 void hists__init(struct hists *hists);
 
 #endif /* __PERF_EVSEL_H */
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index e03b58a..b0d6f85 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -806,7 +806,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist,
 
 		first = list_entry(evlist->entries.next, struct perf_evsel, node);
 		err = perf_event__parse_sample(event, first->attr.sample_type,
-					       perf_evsel__sample_size(first),
+					       first->sample_size,
 					       sample_id_all, &pevent->sample, false);
 		if (err)
 			return PyErr_Format(PyExc_OSError,
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 8e4f075..b8da60d 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -16,6 +16,19 @@
 #include "cpumap.h"
 #include "event-parse.h"
 
+int perf_session__parse_sample(struct perf_session *session,
+			       const union perf_event *event,
+			       struct perf_sample *sample)
+{
+	struct perf_evsel *first;
+	first = list_entry(session->evlist->entries.next, struct perf_evsel, node);
+
+	return perf_event__parse_sample(event, session->sample_type,
+					first->sample_size,
+					session->sample_id_all, sample,
+					session->header.needs_swap);
+}
+
 static int perf_session__open(struct perf_session *self, bool force)
 {
 	struct stat input_stat;
@@ -83,7 +96,6 @@ out_close:
 void perf_session__update_sample_type(struct perf_session *self)
 {
 	self->sample_type = perf_evlist__sample_type(self->evlist);
-	self->sample_size = __perf_evsel__sample_size(self->sample_type);
 	self->sample_id_all = perf_evlist__sample_id_all(self->evlist);
 	self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist);
 	self->host_machine.id_hdr_size = self->id_hdr_size;
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 7c435bd..4d549e2 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -42,7 +42,6 @@ struct perf_session {
 	 */
 	struct hists		hists;
 	u64			sample_type;
-	int			sample_size;
 	int			fd;
 	bool			fd_pipe;
 	bool			repipe;
@@ -130,15 +129,9 @@ size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
 
 size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
 
-static inline int perf_session__parse_sample(struct perf_session *session,
-					     const union perf_event *event,
-					     struct perf_sample *sample)
-{
-	return perf_event__parse_sample(event, session->sample_type,
-					session->sample_size,
-					session->sample_id_all, sample,
-					session->header.needs_swap);
-}
+int perf_session__parse_sample(struct perf_session *session,
+			       const union perf_event *event,
+			       struct perf_sample *sample);
 
 static inline int perf_session__synthesize_sample(struct perf_session *session,
 						  union perf_event *event,
-- 
1.7.1


  parent reply	other threads:[~2012-08-03 14:02 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-03 14:00 [GIT PULL 00/18] perf/core fixes and improvements Arnaldo Carvalho de Melo
2012-08-03 14:00 ` [PATCH 01/18] perf test: Fix parse events automated tests Arnaldo Carvalho de Melo
2012-08-03 14:00 ` [PATCH 02/18] perf symbols: Fix array sizes for binary types arrays Arnaldo Carvalho de Melo
2012-08-03 14:00 ` [PATCH 03/18] perf target: Fix check on buffer size Arnaldo Carvalho de Melo
2012-08-03 14:17   ` Kirill A. Shutemov
2012-08-06  3:53     ` Namhyung Kim
2012-08-06  4:14       ` David Ahern
2012-08-06  4:15         ` Namhyung Kim
2012-08-03 14:00 ` Arnaldo Carvalho de Melo [this message]
2012-08-03 14:00 ` [PATCH 05/18] perf session: Use perf_evlist__sample_type more extensively Arnaldo Carvalho de Melo
2012-08-03 14:00 ` [PATCH 06/18] perf session: Use perf_evlist__sample_id_all " Arnaldo Carvalho de Melo
2012-08-03 14:00 ` [PATCH 07/18] perf session: Use perf_evlist__id_hdr_size " Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 08/18] perf evlist: Introduce perf_evlist__parse_sample Arnaldo Carvalho de Melo
2012-08-03 15:24   ` David Ahern
2012-08-03 17:28     ` Stephane Eranian
2012-08-03 14:01 ` [PATCH 09/18] perf evsel: Adopt parse_sample method from perf_event Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 10/18] perf session: Remove no longer used synthesize_sample method Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 11/18] perf top: Error handling for counter creation should parallel perf-record Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 12/18] perf tool: Save cmdline from user in file header vs what is passed to record Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 13/18] perf kvm: Use strtol for walking guestmount directory Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 14/18] perf tools: Introducing rblist Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 15/18] perf tools: Change strlist to use the new rblist Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 16/18] perf tools: Introduce intlist Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 17/18] perf kvm top: Limit guest kernel info message to once Arnaldo Carvalho de Melo
2012-08-03 14:01 ` [PATCH 18/18] perf tools: Remove brace expansion from clean target Arnaldo Carvalho de Melo
2012-08-05 10:40 ` [GIT PULL 00/18] perf/core fixes and improvements Ingo Molnar

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=1344002470-5965-5-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=efault@gmx.de \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®