aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-08-01 17:53:11 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-08-01 17:53:11 -0400
commitbde09467b56c5a3cfe2a29d58edc5f7172c15184 (patch)
tree5a5bfcdd800a7fbe2a750b86f153e83e866f99c5 /tools/perf/util
parent0ecf4f0c02b7802de5d1251e03e6eab360f158e1 (diff)
perf evsel: Precalculate the sample size
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>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/evsel.c3
-rw-r--r--tools/perf/util/evsel.h8
-rw-r--r--tools/perf/util/python.c2
-rw-r--r--tools/perf/util/session.c14
-rw-r--r--tools/perf/util/session.h13
5 files changed, 20 insertions, 20 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index e81771364867..8feec4011356 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -20,7 +20,7 @@
20#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) 20#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
21#define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) 21#define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0))
22 22
23int __perf_evsel__sample_size(u64 sample_type) 23static int __perf_evsel__sample_size(u64 sample_type)
24{ 24{
25 u64 mask = sample_type & PERF_SAMPLE_MASK; 25 u64 mask = sample_type & PERF_SAMPLE_MASK;
26 int size = 0; 26 int size = 0;
@@ -53,6 +53,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
53 evsel->attr = *attr; 53 evsel->attr = *attr;
54 INIT_LIST_HEAD(&evsel->node); 54 INIT_LIST_HEAD(&evsel->node);
55 hists__init(&evsel->hists); 55 hists__init(&evsel->hists);
56 evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
56} 57}
57 58
58struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx) 59struct 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 67cc5033d192..894bd77d90cc 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -65,6 +65,7 @@ struct perf_evsel {
65 void *func; 65 void *func;
66 void *data; 66 void *data;
67 } handler; 67 } handler;
68 unsigned int sample_size;
68 bool supported; 69 bool supported;
69}; 70};
70 71
@@ -177,13 +178,6 @@ static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
177 return __perf_evsel__read(evsel, ncpus, nthreads, true); 178 return __perf_evsel__read(evsel, ncpus, nthreads, true);
178} 179}
179 180
180int __perf_evsel__sample_size(u64 sample_type);
181
182static inline int perf_evsel__sample_size(struct perf_evsel *evsel)
183{
184 return __perf_evsel__sample_size(evsel->attr.sample_type);
185}
186
187void hists__init(struct hists *hists); 181void hists__init(struct hists *hists);
188 182
189#endif /* __PERF_EVSEL_H */ 183#endif /* __PERF_EVSEL_H */
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index e03b58a48424..b0d6f85e30f1 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,
806 806
807 first = list_entry(evlist->entries.next, struct perf_evsel, node); 807 first = list_entry(evlist->entries.next, struct perf_evsel, node);
808 err = perf_event__parse_sample(event, first->attr.sample_type, 808 err = perf_event__parse_sample(event, first->attr.sample_type,
809 perf_evsel__sample_size(first), 809 first->sample_size,
810 sample_id_all, &pevent->sample, false); 810 sample_id_all, &pevent->sample, false);
811 if (err) 811 if (err)
812 return PyErr_Format(PyExc_OSError, 812 return PyErr_Format(PyExc_OSError,
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 8e4f0755d2aa..b8da60d1ecb5 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -16,6 +16,19 @@
16#include "cpumap.h" 16#include "cpumap.h"
17#include "event-parse.h" 17#include "event-parse.h"
18 18
19int perf_session__parse_sample(struct perf_session *session,
20 const union perf_event *event,
21 struct perf_sample *sample)
22{
23 struct perf_evsel *first;
24 first = list_entry(session->evlist->entries.next, struct perf_evsel, node);
25
26 return perf_event__parse_sample(event, session->sample_type,
27 first->sample_size,
28 session->sample_id_all, sample,
29 session->header.needs_swap);
30}
31
19static int perf_session__open(struct perf_session *self, bool force) 32static int perf_session__open(struct perf_session *self, bool force)
20{ 33{
21 struct stat input_stat; 34 struct stat input_stat;
@@ -83,7 +96,6 @@ out_close:
83void perf_session__update_sample_type(struct perf_session *self) 96void perf_session__update_sample_type(struct perf_session *self)
84{ 97{
85 self->sample_type = perf_evlist__sample_type(self->evlist); 98 self->sample_type = perf_evlist__sample_type(self->evlist);
86 self->sample_size = __perf_evsel__sample_size(self->sample_type);
87 self->sample_id_all = perf_evlist__sample_id_all(self->evlist); 99 self->sample_id_all = perf_evlist__sample_id_all(self->evlist);
88 self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist); 100 self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist);
89 self->host_machine.id_hdr_size = self->id_hdr_size; 101 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 7c435bde6eb0..4d549e28248f 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -42,7 +42,6 @@ struct perf_session {
42 */ 42 */
43 struct hists hists; 43 struct hists hists;
44 u64 sample_type; 44 u64 sample_type;
45 int sample_size;
46 int fd; 45 int fd;
47 bool fd_pipe; 46 bool fd_pipe;
48 bool repipe; 47 bool repipe;
@@ -130,15 +129,9 @@ size_t perf_session__fprintf_dsos_buildid(struct perf_session *self,
130 129
131size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp); 130size_t perf_session__fprintf_nr_events(struct perf_session *session, FILE *fp);
132 131
133static inline int perf_session__parse_sample(struct perf_session *session, 132int perf_session__parse_sample(struct perf_session *session,
134 const union perf_event *event, 133 const union perf_event *event,
135 struct perf_sample *sample) 134 struct perf_sample *sample);
136{
137 return perf_event__parse_sample(event, session->sample_type,
138 session->sample_size,
139 session->sample_id_all, sample,
140 session->header.needs_swap);
141}
142 135
143static inline int perf_session__synthesize_sample(struct perf_session *session, 136static inline int perf_session__synthesize_sample(struct perf_session *session,
144 union perf_event *event, 137 union perf_event *event,