perf session: Share the common trace sample_check routine as perf_session__has_traces
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 27 Dec 2009 23:37:01 +0000 (21:37 -0200)
committerIngo Molnar <mingo@elte.hu>
Mon, 28 Dec 2009 08:03:33 +0000 (09:03 +0100)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1261957026-15580-5-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/builtin-kmem.c
tools/perf/builtin-sched.c
tools/perf/builtin-timechart.c
tools/perf/builtin-trace.c
tools/perf/util/session.c
tools/perf/util/session.h

index fc21ad79dd83e25a7520f00e6d3611587650ee79..a85936f09f3e46d9fbbafce96ab650ddba2c314f 100644 (file)
@@ -342,22 +342,10 @@ static int process_sample_event(event_t *event, struct perf_session *session)
        return 0;
 }
 
-static int sample_type_check(struct perf_session *session)
-{
-       if (!(session->sample_type & PERF_SAMPLE_RAW)) {
-               fprintf(stderr,
-                       "No trace sample to read. Did you call perf record "
-                       "without -R?");
-               return -1;
-       }
-
-       return 0;
-}
-
 static struct perf_event_ops event_ops = {
        .process_sample_event   = process_sample_event,
        .process_comm_event     = event__process_comm,
-       .sample_type_check      = sample_type_check,
+       .sample_type_check      = perf_session__has_traces,
 };
 
 static double fragmentation(unsigned long n_req, unsigned long n_alloc)
index 80209df6cfe8df3267050c8bb64f5974748a8ce7..d65098c4299086acf043e8347042351c37ed0320 100644 (file)
@@ -1653,23 +1653,11 @@ static int process_lost_event(event_t *event __used,
        return 0;
 }
 
-static int sample_type_check(struct perf_session *session __used)
-{
-       if (!(session->sample_type & PERF_SAMPLE_RAW)) {
-               fprintf(stderr,
-                       "No trace sample to read. Did you call perf record "
-                       "without -R?");
-               return -1;
-       }
-
-       return 0;
-}
-
 static struct perf_event_ops event_ops = {
        .process_sample_event   = process_sample_event,
        .process_comm_event     = event__process_comm,
        .process_lost_event     = process_lost_event,
-       .sample_type_check      = sample_type_check,
+       .sample_type_check      = perf_session__has_traces,
 };
 
 static int read_events(void)
index a589a43112d67f7b764ae02365a1b53e2e8119a7..b42f337c17d978a4fb9e783a70fb20346a37105f 100644 (file)
@@ -1029,23 +1029,12 @@ static void process_samples(struct perf_session *session)
        }
 }
 
-static int sample_type_check(struct perf_session *session)
-{
-       if (!(session->sample_type & PERF_SAMPLE_RAW)) {
-               fprintf(stderr, "No trace samples found in the file.\n"
-                               "Have you used 'perf timechart record' to record it?\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 static struct perf_event_ops event_ops = {
        .process_comm_event     = process_comm_event,
        .process_fork_event     = process_fork_event,
        .process_exit_event     = process_exit_event,
        .process_sample_event   = queue_sample_event,
-       .sample_type_check      = sample_type_check,
+       .sample_type_check      = perf_session__has_traces,
 };
 
 static int __cmd_timechart(void)
index 574a215e800b502abeb05fa9e874421db8e3f79a..b0ba2ac37e2c1446ecf5da8374f7207853f37f1c 100644 (file)
@@ -103,22 +103,10 @@ static int process_sample_event(event_t *event, struct perf_session *session)
        return 0;
 }
 
-static int sample_type_check(struct perf_session *session)
-{
-       if (!(session->sample_type & PERF_SAMPLE_RAW)) {
-               fprintf(stderr,
-                       "No trace sample to read. Did you call perf record "
-                       "without -R?");
-               return -1;
-       }
-
-       return 0;
-}
-
 static struct perf_event_ops event_ops = {
        .process_sample_event   = process_sample_event,
        .process_comm_event     = event__process_comm,
-       .sample_type_check      = sample_type_check,
+       .sample_type_check      = perf_session__has_traces,
 };
 
 static int __cmd_trace(struct perf_session *session)
index 736d4fda9272a552bcc29a798b82f3933228845a..60eab8b3ff34ea256b527eb59cd437c952a4aa69 100644 (file)
@@ -393,3 +393,14 @@ done:
 out_err:
        return err;
 }
+
+int perf_session__has_traces(struct perf_session *self)
+{
+       if (!(self->sample_type & PERF_SAMPLE_RAW)) {
+               pr_err("No trace sample to read. Did you call perf record "
+                      "without -R?");
+               return -1;
+       }
+
+       return 0;
+}
index 32eaa1bada062a108ddaebed928489b5bf3d5da6..a6951d2f700f91bb0ede7529904601aad7810408 100644 (file)
@@ -56,6 +56,8 @@ struct symbol **perf_session__resolve_callchain(struct perf_session *self,
                                                struct ip_callchain *chain,
                                                struct symbol **parent);
 
+int perf_session__has_traces(struct perf_session *self);
+
 int perf_header__read_build_ids(int input, u64 offset, u64 file_size);
 
 #endif /* __PERF_SESSION_H */