aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/session.c')
-rw-r--r--tools/perf/util/session.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 8e4f0755d2aa..2437fb0b463a 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -80,14 +80,12 @@ out_close:
80 return -1; 80 return -1;
81} 81}
82 82
83void perf_session__update_sample_type(struct perf_session *self) 83void perf_session__set_id_hdr_size(struct perf_session *session)
84{ 84{
85 self->sample_type = perf_evlist__sample_type(self->evlist); 85 u16 id_hdr_size = perf_evlist__id_hdr_size(session->evlist);
86 self->sample_size = __perf_evsel__sample_size(self->sample_type); 86
87 self->sample_id_all = perf_evlist__sample_id_all(self->evlist); 87 session->host_machine.id_hdr_size = id_hdr_size;
88 self->id_hdr_size = perf_evlist__id_hdr_size(self->evlist); 88 machines__set_id_hdr_size(&session->machines, id_hdr_size);
89 self->host_machine.id_hdr_size = self->id_hdr_size;
90 machines__set_id_hdr_size(&self->machines, self->id_hdr_size);
91} 89}
92 90
93int perf_session__create_kernel_maps(struct perf_session *self) 91int perf_session__create_kernel_maps(struct perf_session *self)
@@ -147,7 +145,7 @@ struct perf_session *perf_session__new(const char *filename, int mode,
147 if (mode == O_RDONLY) { 145 if (mode == O_RDONLY) {
148 if (perf_session__open(self, force) < 0) 146 if (perf_session__open(self, force) < 0)
149 goto out_delete; 147 goto out_delete;
150 perf_session__update_sample_type(self); 148 perf_session__set_id_hdr_size(self);
151 } else if (mode == O_WRONLY) { 149 } else if (mode == O_WRONLY) {
152 /* 150 /*
153 * In O_RDONLY mode this will be performed when reading the 151 * In O_RDONLY mode this will be performed when reading the
@@ -158,7 +156,7 @@ struct perf_session *perf_session__new(const char *filename, int mode,
158 } 156 }
159 157
160 if (tool && tool->ordering_requires_timestamps && 158 if (tool && tool->ordering_requires_timestamps &&
161 tool->ordered_samples && !self->sample_id_all) { 159 tool->ordered_samples && !perf_evlist__sample_id_all(self->evlist)) {
162 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n"); 160 dump_printf("WARNING: No sample_id_all support, falling back to unordered processing\n");
163 tool->ordered_samples = false; 161 tool->ordered_samples = false;
164 } 162 }
@@ -673,7 +671,8 @@ static void flush_sample_queue(struct perf_session *s,
673 if (iter->timestamp > limit) 671 if (iter->timestamp > limit)
674 break; 672 break;
675 673
676 ret = perf_session__parse_sample(s, iter->event, &sample); 674 ret = perf_evlist__parse_sample(s->evlist, iter->event, &sample,
675 s->header.needs_swap);
677 if (ret) 676 if (ret)
678 pr_err("Can't parse sample, err = %d\n", ret); 677 pr_err("Can't parse sample, err = %d\n", ret);
679 else 678 else
@@ -865,16 +864,18 @@ static void perf_session__print_tstamp(struct perf_session *session,
865 union perf_event *event, 864 union perf_event *event,
866 struct perf_sample *sample) 865 struct perf_sample *sample)
867{ 866{
867 u64 sample_type = perf_evlist__sample_type(session->evlist);
868
868 if (event->header.type != PERF_RECORD_SAMPLE && 869 if (event->header.type != PERF_RECORD_SAMPLE &&
869 !session->sample_id_all) { 870 !perf_evlist__sample_id_all(session->evlist)) {
870 fputs("-1 -1 ", stdout); 871 fputs("-1 -1 ", stdout);
871 return; 872 return;
872 } 873 }
873 874
874 if ((session->sample_type & PERF_SAMPLE_CPU)) 875 if ((sample_type & PERF_SAMPLE_CPU))
875 printf("%u ", sample->cpu); 876 printf("%u ", sample->cpu);
876 877
877 if (session->sample_type & PERF_SAMPLE_TIME) 878 if (sample_type & PERF_SAMPLE_TIME)
878 printf("%" PRIu64 " ", sample->time); 879 printf("%" PRIu64 " ", sample->time);
879} 880}
880 881
@@ -899,6 +900,8 @@ static void dump_event(struct perf_session *session, union perf_event *event,
899static void dump_sample(struct perf_session *session, union perf_event *event, 900static void dump_sample(struct perf_session *session, union perf_event *event,
900 struct perf_sample *sample) 901 struct perf_sample *sample)
901{ 902{
903 u64 sample_type;
904
902 if (!dump_trace) 905 if (!dump_trace)
903 return; 906 return;
904 907
@@ -906,10 +909,12 @@ static void dump_sample(struct perf_session *session, union perf_event *event,
906 event->header.misc, sample->pid, sample->tid, sample->ip, 909 event->header.misc, sample->pid, sample->tid, sample->ip,
907 sample->period, sample->addr); 910 sample->period, sample->addr);
908 911
909 if (session->sample_type & PERF_SAMPLE_CALLCHAIN) 912 sample_type = perf_evlist__sample_type(session->evlist);
913
914 if (sample_type & PERF_SAMPLE_CALLCHAIN)
910 callchain__printf(sample); 915 callchain__printf(sample);
911 916
912 if (session->sample_type & PERF_SAMPLE_BRANCH_STACK) 917 if (sample_type & PERF_SAMPLE_BRANCH_STACK)
913 branch_stack__printf(sample); 918 branch_stack__printf(sample);
914} 919}
915 920
@@ -1006,7 +1011,7 @@ static int perf_session__preprocess_sample(struct perf_session *session,
1006 union perf_event *event, struct perf_sample *sample) 1011 union perf_event *event, struct perf_sample *sample)
1007{ 1012{
1008 if (event->header.type != PERF_RECORD_SAMPLE || 1013 if (event->header.type != PERF_RECORD_SAMPLE ||
1009 !(session->sample_type & PERF_SAMPLE_CALLCHAIN)) 1014 !(perf_evlist__sample_type(session->evlist) & PERF_SAMPLE_CALLCHAIN))
1010 return 0; 1015 return 0;
1011 1016
1012 if (!ip_callchain__valid(sample->callchain, event)) { 1017 if (!ip_callchain__valid(sample->callchain, event)) {
@@ -1030,7 +1035,7 @@ static int perf_session__process_user_event(struct perf_session *session, union
1030 case PERF_RECORD_HEADER_ATTR: 1035 case PERF_RECORD_HEADER_ATTR:
1031 err = tool->attr(event, &session->evlist); 1036 err = tool->attr(event, &session->evlist);
1032 if (err == 0) 1037 if (err == 0)
1033 perf_session__update_sample_type(session); 1038 perf_session__set_id_hdr_size(session);
1034 return err; 1039 return err;
1035 case PERF_RECORD_HEADER_EVENT_TYPE: 1040 case PERF_RECORD_HEADER_EVENT_TYPE:
1036 return tool->event_type(tool, event); 1041 return tool->event_type(tool, event);
@@ -1065,7 +1070,7 @@ static int perf_session__process_event(struct perf_session *session,
1065 int ret; 1070 int ret;
1066 1071
1067 if (session->header.needs_swap) 1072 if (session->header.needs_swap)
1068 event_swap(event, session->sample_id_all); 1073 event_swap(event, perf_evlist__sample_id_all(session->evlist));
1069 1074
1070 if (event->header.type >= PERF_RECORD_HEADER_MAX) 1075 if (event->header.type >= PERF_RECORD_HEADER_MAX)
1071 return -EINVAL; 1076 return -EINVAL;
@@ -1078,7 +1083,8 @@ static int perf_session__process_event(struct perf_session *session,
1078 /* 1083 /*
1079 * For all kernel events we get the sample data 1084 * For all kernel events we get the sample data
1080 */ 1085 */
1081 ret = perf_session__parse_sample(session, event, &sample); 1086 ret = perf_evlist__parse_sample(session->evlist, event, &sample,
1087 session->header.needs_swap);
1082 if (ret) 1088 if (ret)
1083 return ret; 1089 return ret;
1084 1090
@@ -1389,9 +1395,9 @@ int perf_session__process_events(struct perf_session *self,
1389 return err; 1395 return err;
1390} 1396}
1391 1397
1392bool perf_session__has_traces(struct perf_session *self, const char *msg) 1398bool perf_session__has_traces(struct perf_session *session, const char *msg)
1393{ 1399{
1394 if (!(self->sample_type & PERF_SAMPLE_RAW)) { 1400 if (!(perf_evlist__sample_type(session->evlist) & PERF_SAMPLE_RAW)) {
1395 pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg); 1401 pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg);
1396 return false; 1402 return false;
1397 } 1403 }