[PATCH 39/49] perf record: Read record thread's mmaps

From: Jiri Olsa
Date: Tue Jan 09 2018 - 10:41:09 EST


Switch the maps source from evlist into thread data.

Link: http://lkml.kernel.org/n/tip-2r6hn6shl185j66b4vl1k4pr@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/builtin-record.c | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 2c8500163d24..4d08f81a3bfe 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -96,6 +96,8 @@ struct record {
int threads_cnt;
};

+static __thread struct record_thread *thread;
+
static volatile int auxtrace_record__snapshot_started;
static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
static DEFINE_TRIGGER(switch_output_trigger);
@@ -538,24 +540,24 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli
bool overwrite)
{
u64 bytes_written = rec->bytes_written;
- int i;
+ int i, nr;
int rc = 0;
- struct perf_mmap *maps;
+ struct perf_mmap **maps;

if (!evlist)
return 0;

- maps = overwrite ? evlist->overwrite_mmap : evlist->mmap;
+ maps = overwrite ? thread->ovw_mmap : thread->mmap;
if (!maps)
return 0;

if (overwrite && evlist->bkw_mmap_state != BKW_MMAP_DATA_PENDING)
return 0;

- for (i = 0; i < evlist->nr_mmaps; i++) {
- struct perf_mmap *map = &maps[i];
- struct perf_mmap *track_map = evlist->track_mmap ?
- &evlist->track_mmap[i] : NULL;
+ nr = overwrite ? thread->ovw_mmap_nr : thread->mmap_nr;
+
+ for (i = 0; i < nr; i++) {
+ struct perf_mmap *map = maps[i];

if (map->base) {
if (perf_mmap__push(map, overwrite, rec, record__pushfn) != 0) {
@@ -569,21 +571,20 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli
rc = -1;
goto out;
}
-
- if (track_map && track_map->base) {
- if (perf_mmap__push(track_map, overwrite, rec, record__pushfn) != 0) {
- rc = -1;
- goto out;
- }
- }
}

/*
* Mark the round finished in case we wrote
* at least one event.
*/
- if (bytes_written != rec->bytes_written)
- rc = record__write(rec, NULL, &finished_round_event, sizeof(finished_round_event));
+ if (bytes_written != rec->bytes_written) {
+ /*
+ * All maps of the threads point to a single file,
+ * so we can just pick first one.
+ */
+ rc = record__write(rec, thread->mmap[0], &finished_round_event,
+ sizeof(finished_round_event));
+ }

if (overwrite)
perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_EMPTY);
@@ -1189,6 +1190,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
goto out_child;
}

+ thread = &rec->threads[0];
+
err = bpf__apply_obj_config();
if (err) {
char errbuf[BUFSIZ];
@@ -1383,7 +1386,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
if (hits == rec->samples) {
if (done || draining)
break;
- err = perf_evlist__poll(rec->evlist, -1);
+ err = fdarray__poll(&thread->pollfd, -1);
/*
* Propagate error, only if there's any. Ignore positive
* number of returned events and interrupt error.
--
2.13.6