perf intel-pt: Factor out intel_pt_get_buffer()
authorAdrian Hunter <adrian.hunter@intel.com>
Tue, 4 Jun 2019 13:00:07 +0000 (16:00 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 10 Jun 2019 19:20:12 +0000 (16:20 -0300)
Factor out intel_pt_get_buffer() so it can be reused.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190604130017.31207-10-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/intel-pt.c

index 3cff8fe2eaa0e9412f9ee2fecc15626012c9488f..4a61c73c97113ea36ea2fe269777f363f2de661a 100644 (file)
@@ -239,32 +239,13 @@ static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *
        return 0;
 }
 
-/* This function assumes data is processed sequentially only */
-static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data)
+static int intel_pt_get_buffer(struct intel_pt_queue *ptq,
+                              struct auxtrace_buffer *buffer,
+                              struct auxtrace_buffer *old_buffer,
+                              struct intel_pt_buffer *b)
 {
-       struct intel_pt_queue *ptq = data;
-       struct auxtrace_buffer *buffer = ptq->buffer;
-       struct auxtrace_buffer *old_buffer = ptq->old_buffer;
-       struct auxtrace_queue *queue;
        bool might_overlap;
 
-       if (ptq->stop) {
-               b->len = 0;
-               return 0;
-       }
-
-       queue = &ptq->pt->queues.queue_array[ptq->queue_nr];
-
-       buffer = auxtrace_buffer__next(queue, buffer);
-       if (!buffer) {
-               if (old_buffer)
-                       auxtrace_buffer__drop_data(old_buffer);
-               b->len = 0;
-               return 0;
-       }
-
-       ptq->buffer = buffer;
-
        if (!buffer->data) {
                int fd = perf_data__fd(ptq->pt->session->data);
 
@@ -294,6 +275,39 @@ static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data)
                b->consecutive = true;
        }
 
+       return 0;
+}
+
+/* This function assumes data is processed sequentially only */
+static int intel_pt_get_trace(struct intel_pt_buffer *b, void *data)
+{
+       struct intel_pt_queue *ptq = data;
+       struct auxtrace_buffer *buffer = ptq->buffer;
+       struct auxtrace_buffer *old_buffer = ptq->old_buffer;
+       struct auxtrace_queue *queue;
+       int err;
+
+       if (ptq->stop) {
+               b->len = 0;
+               return 0;
+       }
+
+       queue = &ptq->pt->queues.queue_array[ptq->queue_nr];
+
+       buffer = auxtrace_buffer__next(queue, buffer);
+       if (!buffer) {
+               if (old_buffer)
+                       auxtrace_buffer__drop_data(old_buffer);
+               b->len = 0;
+               return 0;
+       }
+
+       ptq->buffer = buffer;
+
+       err = intel_pt_get_buffer(ptq, buffer, old_buffer, b);
+       if (err)
+               return err;
+
        if (ptq->step_through_buffers)
                ptq->stop = true;