aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2014-07-31 02:00:57 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-08-13 18:21:44 -0400
commit5a52f33adf02a3e5eafdc1e597a3fe172e620bec (patch)
treed12ea34f3f193acc6a1005b884aab388df5ef6c1 /tools/perf
parent60b0896cc35243f515eda2085f9897e296177e45 (diff)
perf session: Add perf_session__peek_event()
Add a function to peek at other events in the event stream. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> 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/r/1406786474-9306-15-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/session.c55
-rw-r--r--tools/perf/util/session.h5
2 files changed, 60 insertions, 0 deletions
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7e27f1eb260c..1b383bd93af6 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -897,6 +897,61 @@ static void event_swap(union perf_event *event, bool sample_id_all)
897 swap(event, sample_id_all); 897 swap(event, sample_id_all);
898} 898}
899 899
900int perf_session__peek_event(struct perf_session *session, off_t file_offset,
901 void *buf, size_t buf_sz,
902 union perf_event **event_ptr,
903 struct perf_sample *sample)
904{
905 union perf_event *event;
906 size_t hdr_sz, rest;
907 int fd;
908
909 if (session->one_mmap && !session->header.needs_swap) {
910 event = file_offset - session->one_mmap_offset +
911 session->one_mmap_addr;
912 goto out_parse_sample;
913 }
914
915 if (perf_data_file__is_pipe(session->file))
916 return -1;
917
918 fd = perf_data_file__fd(session->file);
919 hdr_sz = sizeof(struct perf_event_header);
920
921 if (buf_sz < hdr_sz)
922 return -1;
923
924 if (lseek(fd, file_offset, SEEK_SET) == (off_t)-1 ||
925 readn(fd, &buf, hdr_sz) != (ssize_t)hdr_sz)
926 return -1;
927
928 event = (union perf_event *)buf;
929
930 if (session->header.needs_swap)
931 perf_event_header__bswap(&event->header);
932
933 if (event->header.size < hdr_sz)
934 return -1;
935
936 rest = event->header.size - hdr_sz;
937
938 if (readn(fd, &buf, rest) != (ssize_t)rest)
939 return -1;
940
941 if (session->header.needs_swap)
942 event_swap(event, perf_evlist__sample_id_all(session->evlist));
943
944out_parse_sample:
945
946 if (sample && event->header.type < PERF_RECORD_USER_TYPE_START &&
947 perf_evlist__parse_sample(session->evlist, event, sample))
948 return -1;
949
950 *event_ptr = event;
951
952 return 0;
953}
954
900static s64 perf_session__process_event(struct perf_session *session, 955static s64 perf_session__process_event(struct perf_session *session,
901 union perf_event *event, 956 union perf_event *event,
902 struct perf_tool *tool, 957 struct perf_tool *tool,
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index 0630e658f8be..8dd41cad2d59 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -45,6 +45,11 @@ void perf_session__delete(struct perf_session *session);
45 45
46void perf_event_header__bswap(struct perf_event_header *hdr); 46void perf_event_header__bswap(struct perf_event_header *hdr);
47 47
48int perf_session__peek_event(struct perf_session *session, off_t file_offset,
49 void *buf, size_t buf_sz,
50 union perf_event **event_ptr,
51 struct perf_sample *sample);
52
48int __perf_session__process_events(struct perf_session *session, 53int __perf_session__process_events(struct perf_session *session,
49 u64 data_offset, u64 data_size, u64 size, 54 u64 data_offset, u64 data_size, u64 size,
50 struct perf_tool *tool); 55 struct perf_tool *tool);