diff options
author | Kan Liang <kan.liang@intel.com> | 2018-01-18 16:26:23 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-02-15 07:53:40 -0500 |
commit | 7bb45972952db9298fe5cc440160dcad1a66bfbc (patch) | |
tree | c7642dbb2f3e4c5a9be33ac4c891c102b3424928 /tools/perf | |
parent | ee023de05f35484691f7d9e5c1f92195ac4d64d2 (diff) |
perf mmap: Introduce perf_mmap__read_event()
Except for 'perf record', the other perf tools read events one by one
from the ring buffer using perf_mmap__read_forward(). But it only
supports non-overwrite mode.
Introduce perf_mmap__read_event() to support both non-overwrite and
overwrite mode.
Usage:
perf_mmap__read_init()
while(event = perf_mmap__read_event()) {
//process the event
perf_mmap__consume()
}
perf_mmap__read_done()
It cannot use perf_mmap__read_backward(). Because it always reads the
stale buffer which is already processed. Furthermore, the forward and
backward concepts have been removed. The perf_mmap__read_backward() will
be replaced and discarded later.
Signed-off-by: Kan Liang <kan.liang@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1516310792-208685-9-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/mmap.c | 39 | ||||
-rw-r--r-- | tools/perf/util/mmap.h | 4 |
2 files changed, 43 insertions, 0 deletions
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 4f59eaefc706..f804926778b7 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c | |||
@@ -113,6 +113,45 @@ union perf_event *perf_mmap__read_backward(struct perf_mmap *map) | |||
113 | return perf_mmap__read(map, &map->prev, end); | 113 | return perf_mmap__read(map, &map->prev, end); |
114 | } | 114 | } |
115 | 115 | ||
116 | /* | ||
117 | * Read event from ring buffer one by one. | ||
118 | * Return one event for each call. | ||
119 | * | ||
120 | * Usage: | ||
121 | * perf_mmap__read_init() | ||
122 | * while(event = perf_mmap__read_event()) { | ||
123 | * //process the event | ||
124 | * perf_mmap__consume() | ||
125 | * } | ||
126 | * perf_mmap__read_done() | ||
127 | */ | ||
128 | union perf_event *perf_mmap__read_event(struct perf_mmap *map, | ||
129 | bool overwrite, | ||
130 | u64 *startp, u64 end) | ||
131 | { | ||
132 | union perf_event *event; | ||
133 | |||
134 | /* | ||
135 | * Check if event was unmapped due to a POLLHUP/POLLERR. | ||
136 | */ | ||
137 | if (!refcount_read(&map->refcnt)) | ||
138 | return NULL; | ||
139 | |||
140 | if (startp == NULL) | ||
141 | return NULL; | ||
142 | |||
143 | /* non-overwirte doesn't pause the ringbuffer */ | ||
144 | if (!overwrite) | ||
145 | end = perf_mmap__read_head(map); | ||
146 | |||
147 | event = perf_mmap__read(map, startp, end); | ||
148 | |||
149 | if (!overwrite) | ||
150 | map->prev = *startp; | ||
151 | |||
152 | return event; | ||
153 | } | ||
154 | |||
116 | void perf_mmap__read_catchup(struct perf_mmap *map) | 155 | void perf_mmap__read_catchup(struct perf_mmap *map) |
117 | { | 156 | { |
118 | u64 head; | 157 | u64 head; |
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index 95549d4af943..28718543dd42 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h | |||
@@ -89,6 +89,10 @@ static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail) | |||
89 | union perf_event *perf_mmap__read_forward(struct perf_mmap *map); | 89 | union perf_event *perf_mmap__read_forward(struct perf_mmap *map); |
90 | union perf_event *perf_mmap__read_backward(struct perf_mmap *map); | 90 | union perf_event *perf_mmap__read_backward(struct perf_mmap *map); |
91 | 91 | ||
92 | union perf_event *perf_mmap__read_event(struct perf_mmap *map, | ||
93 | bool overwrite, | ||
94 | u64 *startp, u64 end); | ||
95 | |||
92 | int perf_mmap__push(struct perf_mmap *md, bool backward, | 96 | int perf_mmap__push(struct perf_mmap *md, bool backward, |
93 | void *to, int push(void *to, void *buf, size_t size)); | 97 | void *to, int push(void *to, void *buf, size_t size)); |
94 | 98 | ||