aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-08-01 18:15:52 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-08-01 18:15:52 -0400
commit7f3be652c1a8866251bfba9ea8b02067328f5db9 (patch)
tree27bd48d04f7db733b6c980afb55eed0719ac3725 /tools/perf
parentbde09467b56c5a3cfe2a29d58edc5f7172c15184 (diff)
perf session: Use perf_evlist__sample_type more extensively
Removing perf_session->sample_type, as it can be obtained from the evsel/evlist. 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-mnt1zwlik7sp7z6ljc9kyefg@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-report.c5
-rw-r--r--tools/perf/builtin-test.c10
-rw-r--r--tools/perf/util/session.c31
-rw-r--r--tools/perf/util/session.h11
4 files changed, 30 insertions, 27 deletions
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 69b1c1185159..7c88a243b5db 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -249,8 +249,9 @@ static int process_read_event(struct perf_tool *tool,
249static int perf_report__setup_sample_type(struct perf_report *rep) 249static int perf_report__setup_sample_type(struct perf_report *rep)
250{ 250{
251 struct perf_session *self = rep->session; 251 struct perf_session *self = rep->session;
252 u64 sample_type = perf_evlist__sample_type(self->evlist);
252 253
253 if (!self->fd_pipe && !(self->sample_type & PERF_SAMPLE_CALLCHAIN)) { 254 if (!self->fd_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
254 if (sort__has_parent) { 255 if (sort__has_parent) {
255 ui__error("Selected --sort parent, but no " 256 ui__error("Selected --sort parent, but no "
256 "callchain data. Did you call " 257 "callchain data. Did you call "
@@ -274,7 +275,7 @@ static int perf_report__setup_sample_type(struct perf_report *rep)
274 275
275 if (sort__branch_mode == 1) { 276 if (sort__branch_mode == 1) {
276 if (!self->fd_pipe && 277 if (!self->fd_pipe &&
277 !(self->sample_type & PERF_SAMPLE_BRANCH_STACK)) { 278 !(sample_type & PERF_SAMPLE_BRANCH_STACK)) {
278 ui__error("Selected -b but no branch data. " 279 ui__error("Selected -b but no branch data. "
279 "Did you call perf record without -b?\n"); 280 "Did you call perf record without -b?\n");
280 return -1; 281 return -1;
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 2ea5fe4cc940..e5032ed2f259 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -661,7 +661,7 @@ static int test__PERF_RECORD(void)
661 const char *cmd = "sleep"; 661 const char *cmd = "sleep";
662 const char *argv[] = { cmd, "1", NULL, }; 662 const char *argv[] = { cmd, "1", NULL, };
663 char *bname; 663 char *bname;
664 u64 sample_type, prev_time = 0; 664 u64 prev_time = 0;
665 bool found_cmd_mmap = false, 665 bool found_cmd_mmap = false,
666 found_libc_mmap = false, 666 found_libc_mmap = false,
667 found_vdso_mmap = false, 667 found_vdso_mmap = false,
@@ -757,12 +757,6 @@ static int test__PERF_RECORD(void)
757 } 757 }
758 758
759 /* 759 /*
760 * We'll need these two to parse the PERF_SAMPLE_* fields in each
761 * event.
762 */
763 sample_type = perf_evlist__sample_type(evlist);
764
765 /*
766 * Now that all is properly set up, enable the events, they will 760 * Now that all is properly set up, enable the events, they will
767 * count just on workload.pid, which will start... 761 * count just on workload.pid, which will start...
768 */ 762 */
@@ -787,7 +781,7 @@ static int test__PERF_RECORD(void)
787 if (type < PERF_RECORD_MAX) 781 if (type < PERF_RECORD_MAX)
788 nr_events[type]++; 782 nr_events[type]++;
789 783
790 err = perf_event__parse_sample(event, sample_type, 784 err = perf_event__parse_sample(event, evsel->attr.sample_type,
791 evsel->sample_size, true, 785 evsel->sample_size, true,
792 &sample, false); 786 &sample, false);
793 if (err < 0) { 787 if (err < 0) {
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index b8da60d1ecb5..00e180e116e7 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -23,12 +23,20 @@ int perf_session__parse_sample(struct perf_session *session,
23 struct perf_evsel *first; 23 struct perf_evsel *first;
24 first = list_entry(session->evlist->entries.next, struct perf_evsel, node); 24 first = list_entry(session->evlist->entries.next, struct perf_evsel, node);
25 25
26 return perf_event__parse_sample(event, session->sample_type, 26 return perf_event__parse_sample(event, first->attr.sample_type,
27 first->sample_size, 27 first->sample_size,
28 session->sample_id_all, sample, 28 session->sample_id_all, sample,
29 session->header.needs_swap); 29 session->header.needs_swap);
30} 30}
31 31
32int perf_session__synthesize_sample(struct perf_session *session,
33 union perf_event *event,
34 const struct perf_sample *sample)
35{
36 return perf_event__synthesize_sample(event, perf_evlist__sample_type(session->evlist),
37 sample, session->header.needs_swap);
38}
39
32static int perf_session__open(struct perf_session *self, bool force) 40static int perf_session__open(struct perf_session *self, bool force)
33{ 41{
34 struct stat input_stat; 42 struct stat input_stat;
@@ -95,7 +103,6 @@ out_close:
95 103
96void perf_session__update_sample_type(struct perf_session *self) 104void perf_session__update_sample_type(struct perf_session *self)
97{ 105{
98 self->sample_type = perf_evlist__sample_type(self->evlist);
99 self->sample_id_all = perf_evlist__sample_id_all(self->evlist); 106 self->sample_id_all = perf_evlist__sample_id_all(self->evlist);
100 self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist); 107 self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist);
101 self->host_machine.id_hdr_size = self->id_hdr_size; 108 self->host_machine.id_hdr_size = self->id_hdr_size;
@@ -877,16 +884,18 @@ static void perf_session__print_tstamp(struct perf_session *session,
877 union perf_event *event, 884 union perf_event *event,
878 struct perf_sample *sample) 885 struct perf_sample *sample)
879{ 886{
887 u64 sample_type = perf_evlist__sample_type(session->evlist);
888
880 if (event->header.type != PERF_RECORD_SAMPLE && 889 if (event->header.type != PERF_RECORD_SAMPLE &&
881 !session->sample_id_all) { 890 !session->sample_id_all) {
882 fputs("-1 -1 ", stdout); 891 fputs("-1 -1 ", stdout);
883 return; 892 return;
884 } 893 }
885 894
886 if ((session->sample_type & PERF_SAMPLE_CPU)) 895 if ((sample_type & PERF_SAMPLE_CPU))
887 printf("%u ", sample->cpu); 896 printf("%u ", sample->cpu);
888 897
889 if (session->sample_type & PERF_SAMPLE_TIME) 898 if (sample_type & PERF_SAMPLE_TIME)
890 printf("%" PRIu64 " ", sample->time); 899 printf("%" PRIu64 " ", sample->time);
891} 900}
892 901
@@ -911,6 +920,8 @@ static void dump_event(struct perf_session *session, union perf_event *event,
911static void dump_sample(struct perf_session *session, union perf_event *event, 920static void dump_sample(struct perf_session *session, union perf_event *event,
912 struct perf_sample *sample) 921 struct perf_sample *sample)
913{ 922{
923 u64 sample_type;
924
914 if (!dump_trace) 925 if (!dump_trace)
915 return; 926 return;
916 927
@@ -918,10 +929,12 @@ static void dump_sample(struct perf_session *session, union perf_event *event,
918 event->header.misc, sample->pid, sample->tid, sample->ip, 929 event->header.misc, sample->pid, sample->tid, sample->ip,
919 sample->period, sample->addr); 930 sample->period, sample->addr);
920 931
921 if (session->sample_type & PERF_SAMPLE_CALLCHAIN) 932 sample_type = perf_evlist__sample_type(session->evlist);
933
934 if (sample_type & PERF_SAMPLE_CALLCHAIN)
922 callchain__printf(sample); 935 callchain__printf(sample);
923 936
924 if (session->sample_type & PERF_SAMPLE_BRANCH_STACK) 937 if (sample_type & PERF_SAMPLE_BRANCH_STACK)
925 branch_stack__printf(sample); 938 branch_stack__printf(sample);
926} 939}
927 940
@@ -1018,7 +1031,7 @@ static int perf_session__preprocess_sample(struct perf_session *session,
1018 union perf_event *event, struct perf_sample *sample) 1031 union perf_event *event, struct perf_sample *sample)
1019{ 1032{
1020 if (event->header.type != PERF_RECORD_SAMPLE || 1033 if (event->header.type != PERF_RECORD_SAMPLE ||
1021 !(session->sample_type & PERF_SAMPLE_CALLCHAIN)) 1034 !(perf_evlist__sample_type(session->evlist) & PERF_SAMPLE_CALLCHAIN))
1022 return 0; 1035 return 0;
1023 1036
1024 if (!ip_callchain__valid(sample->callchain, event)) { 1037 if (!ip_callchain__valid(sample->callchain, event)) {
@@ -1401,9 +1414,9 @@ int perf_session__process_events(struct perf_session *self,
1401 return err; 1414 return err;
1402} 1415}
1403 1416
1404bool perf_session__has_traces(struct perf_session *self, const char *msg) 1417bool perf_session__has_traces(struct perf_session *session, const char *msg)
1405{ 1418{
1406 if (!(self->sample_type & PERF_SAMPLE_RAW)) { 1419 if (!(perf_evlist__sample_type(session->evlist) & PERF_SAMPLE_RAW)) {
1407 pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg); 1420 pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg);
1408 return false; 1421 return false;
1409 } 1422 }
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 4d549e28248f..c45ce4348b83 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -41,7 +41,6 @@ struct perf_session {
41 * perf.data file. 41 * perf.data file.
42 */ 42 */
43 struct hists hists; 43 struct hists hists;
44 u64 sample_type;
45 int fd; 44 int fd;
46 bool fd_pipe; 45 bool fd_pipe;
47 bool repipe; 46 bool repipe;
@@ -133,13 +132,9 @@ int perf_session__parse_sample(struct perf_session *session,
133 const union perf_event *event, 132 const union perf_event *event,
134 struct perf_sample *sample); 133 struct perf_sample *sample);
135 134
136static inline int perf_session__synthesize_sample(struct perf_session *session, 135int perf_session__synthesize_sample(struct perf_session *session,
137 union perf_event *event, 136 union perf_event *event,
138 const struct perf_sample *sample) 137 const struct perf_sample *sample);
139{
140 return perf_event__synthesize_sample(event, session->sample_type,
141 sample, session->header.needs_swap);
142}
143 138
144struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session, 139struct perf_evsel *perf_session__find_first_evtype(struct perf_session *session,
145 unsigned int type); 140 unsigned int type);