aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-kmem.c6
-rw-r--r--tools/perf/builtin-report.c16
-rw-r--r--tools/perf/builtin-sched.c7
-rw-r--r--tools/perf/builtin-timechart.c6
-rw-r--r--tools/perf/builtin-trace.c4
-rw-r--r--tools/perf/util/session.c16
-rw-r--r--tools/perf/util/session.h3
7 files changed, 31 insertions, 27 deletions
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index a85936f09f3e..73b065022e27 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -345,7 +345,6 @@ static int process_sample_event(event_t *event, struct perf_session *session)
345static struct perf_event_ops event_ops = { 345static struct perf_event_ops event_ops = {
346 .process_sample_event = process_sample_event, 346 .process_sample_event = process_sample_event,
347 .process_comm_event = event__process_comm, 347 .process_comm_event = event__process_comm,
348 .sample_type_check = perf_session__has_traces,
349}; 348};
350 349
351static double fragmentation(unsigned long n_req, unsigned long n_alloc) 350static double fragmentation(unsigned long n_req, unsigned long n_alloc)
@@ -492,11 +491,14 @@ static void sort_result(void)
492 491
493static int __cmd_kmem(void) 492static int __cmd_kmem(void)
494{ 493{
495 int err; 494 int err = -EINVAL;
496 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); 495 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
497 if (session == NULL) 496 if (session == NULL)
498 return -ENOMEM; 497 return -ENOMEM;
499 498
499 if (!perf_session__has_traces(session, "kmem record"))
500 goto out_delete;
501
500 setup_pager(); 502 setup_pager();
501 err = perf_session__process_events(session, &event_ops); 503 err = perf_session__process_events(session, &event_ops);
502 if (err != 0) 504 if (err != 0)
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index db10c0e8ecae..08259184cedb 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -156,14 +156,14 @@ static int process_read_event(event_t *event, struct perf_session *session __use
156 return 0; 156 return 0;
157} 157}
158 158
159static int sample_type_check(struct perf_session *session) 159static int perf_session__setup_sample_type(struct perf_session *self)
160{ 160{
161 if (!(session->sample_type & PERF_SAMPLE_CALLCHAIN)) { 161 if (!(self->sample_type & PERF_SAMPLE_CALLCHAIN)) {
162 if (sort__has_parent) { 162 if (sort__has_parent) {
163 fprintf(stderr, "selected --sort parent, but no" 163 fprintf(stderr, "selected --sort parent, but no"
164 " callchain data. Did you call" 164 " callchain data. Did you call"
165 " perf record without -g?\n"); 165 " perf record without -g?\n");
166 return -1; 166 return -EINVAL;
167 } 167 }
168 if (symbol_conf.use_callchain) { 168 if (symbol_conf.use_callchain) {
169 fprintf(stderr, "selected -g but no callchain data." 169 fprintf(stderr, "selected -g but no callchain data."
@@ -176,7 +176,7 @@ static int sample_type_check(struct perf_session *session)
176 if (register_callchain_param(&callchain_param) < 0) { 176 if (register_callchain_param(&callchain_param) < 0) {
177 fprintf(stderr, "Can't register callchain" 177 fprintf(stderr, "Can't register callchain"
178 " params\n"); 178 " params\n");
179 return -1; 179 return -EINVAL;
180 } 180 }
181 } 181 }
182 182
@@ -191,13 +191,11 @@ static struct perf_event_ops event_ops = {
191 .process_fork_event = event__process_task, 191 .process_fork_event = event__process_task,
192 .process_lost_event = event__process_lost, 192 .process_lost_event = event__process_lost,
193 .process_read_event = process_read_event, 193 .process_read_event = process_read_event,
194 .sample_type_check = sample_type_check,
195}; 194};
196 195
197
198static int __cmd_report(void) 196static int __cmd_report(void)
199{ 197{
200 int ret; 198 int ret = -EINVAL;
201 struct perf_session *session; 199 struct perf_session *session;
202 200
203 session = perf_session__new(input_name, O_RDONLY, force); 201 session = perf_session__new(input_name, O_RDONLY, force);
@@ -207,6 +205,10 @@ static int __cmd_report(void)
207 if (show_threads) 205 if (show_threads)
208 perf_read_values_init(&show_threads_values); 206 perf_read_values_init(&show_threads_values);
209 207
208 ret = perf_session__setup_sample_type(session);
209 if (ret)
210 goto out_delete;
211
210 ret = perf_session__process_events(session, &event_ops); 212 ret = perf_session__process_events(session, &event_ops);
211 if (ret) 213 if (ret)
212 goto out_delete; 214 goto out_delete;
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index d65098c42990..e862e71f4e68 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -1657,17 +1657,18 @@ static struct perf_event_ops event_ops = {
1657 .process_sample_event = process_sample_event, 1657 .process_sample_event = process_sample_event,
1658 .process_comm_event = event__process_comm, 1658 .process_comm_event = event__process_comm,
1659 .process_lost_event = process_lost_event, 1659 .process_lost_event = process_lost_event,
1660 .sample_type_check = perf_session__has_traces,
1661}; 1660};
1662 1661
1663static int read_events(void) 1662static int read_events(void)
1664{ 1663{
1665 int err; 1664 int err = -EINVAL;
1666 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); 1665 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
1667 if (session == NULL) 1666 if (session == NULL)
1668 return -ENOMEM; 1667 return -ENOMEM;
1669 1668
1670 err = perf_session__process_events(session, &event_ops); 1669 if (perf_session__has_traces(session, "record -R"))
1670 err = perf_session__process_events(session, &event_ops);
1671
1671 perf_session__delete(session); 1672 perf_session__delete(session);
1672 return err; 1673 return err;
1673} 1674}
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index b42f337c17d9..825283794985 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1034,17 +1034,19 @@ static struct perf_event_ops event_ops = {
1034 .process_fork_event = process_fork_event, 1034 .process_fork_event = process_fork_event,
1035 .process_exit_event = process_exit_event, 1035 .process_exit_event = process_exit_event,
1036 .process_sample_event = queue_sample_event, 1036 .process_sample_event = queue_sample_event,
1037 .sample_type_check = perf_session__has_traces,
1038}; 1037};
1039 1038
1040static int __cmd_timechart(void) 1039static int __cmd_timechart(void)
1041{ 1040{
1042 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0); 1041 struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
1043 int ret; 1042 int ret = -EINVAL;
1044 1043
1045 if (session == NULL) 1044 if (session == NULL)
1046 return -ENOMEM; 1045 return -ENOMEM;
1047 1046
1047 if (!perf_session__has_traces(session, "timechart record"))
1048 goto out_delete;
1049
1048 ret = perf_session__process_events(session, &event_ops); 1050 ret = perf_session__process_events(session, &event_ops);
1049 if (ret) 1051 if (ret)
1050 goto out_delete; 1052 goto out_delete;
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index b0ba2ac37e2c..e94f34631585 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -106,7 +106,6 @@ static int process_sample_event(event_t *event, struct perf_session *session)
106static struct perf_event_ops event_ops = { 106static struct perf_event_ops event_ops = {
107 .process_sample_event = process_sample_event, 107 .process_sample_event = process_sample_event,
108 .process_comm_event = event__process_comm, 108 .process_comm_event = event__process_comm,
109 .sample_type_check = perf_session__has_traces,
110}; 109};
111 110
112static int __cmd_trace(struct perf_session *session) 111static int __cmd_trace(struct perf_session *session)
@@ -580,6 +579,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
580 if (session == NULL) 579 if (session == NULL)
581 return -ENOMEM; 580 return -ENOMEM;
582 581
582 if (!perf_session__has_traces(session, "record -R"))
583 return -EINVAL;
584
583 if (generate_script_lang) { 585 if (generate_script_lang) {
584 struct stat perf_stat; 586 struct stat perf_stat;
585 587
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 60eab8b3ff34..bc84a5217955 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -73,6 +73,8 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
73 73
74 if (mode == O_RDONLY && perf_session__open(self, force) < 0) 74 if (mode == O_RDONLY && perf_session__open(self, force) < 0)
75 goto out_delete; 75 goto out_delete;
76
77 self->sample_type = perf_header__sample_type(&self->header);
76out: 78out:
77 return self; 79 return self;
78out_free: 80out_free:
@@ -302,11 +304,6 @@ int perf_session__process_events(struct perf_session *self,
302 page_size = getpagesize(); 304 page_size = getpagesize();
303 305
304 head = self->header.data_offset; 306 head = self->header.data_offset;
305 self->sample_type = perf_header__sample_type(&self->header);
306
307 err = -EINVAL;
308 if (ops->sample_type_check && ops->sample_type_check(self) < 0)
309 goto out_err;
310 307
311 if (!ops->full_paths) { 308 if (!ops->full_paths) {
312 char bf[PATH_MAX]; 309 char bf[PATH_MAX];
@@ -394,13 +391,12 @@ out_err:
394 return err; 391 return err;
395} 392}
396 393
397int perf_session__has_traces(struct perf_session *self) 394bool perf_session__has_traces(struct perf_session *self, const char *msg)
398{ 395{
399 if (!(self->sample_type & PERF_SAMPLE_RAW)) { 396 if (!(self->sample_type & PERF_SAMPLE_RAW)) {
400 pr_err("No trace sample to read. Did you call perf record " 397 pr_err("No trace sample to read. Did you call 'perf %s'?\n", msg);
401 "without -R?"); 398 return false;
402 return -1;
403 } 399 }
404 400
405 return 0; 401 return true;
406} 402}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index a6951d2f700f..5771ccb3fe03 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -40,7 +40,6 @@ struct perf_event_ops {
40 event_op process_read_event; 40 event_op process_read_event;
41 event_op process_throttle_event; 41 event_op process_throttle_event;
42 event_op process_unthrottle_event; 42 event_op process_unthrottle_event;
43 int (*sample_type_check)(struct perf_session *session);
44 unsigned long total_unknown; 43 unsigned long total_unknown;
45 bool full_paths; 44 bool full_paths;
46}; 45};
@@ -56,7 +55,7 @@ struct symbol **perf_session__resolve_callchain(struct perf_session *self,
56 struct ip_callchain *chain, 55 struct ip_callchain *chain,
57 struct symbol **parent); 56 struct symbol **parent);
58 57
59int perf_session__has_traces(struct perf_session *self); 58bool perf_session__has_traces(struct perf_session *self, const char *msg);
60 59
61int perf_header__read_build_ids(int input, u64 offset, u64 file_size); 60int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
62 61