Initialize data files located at mmap buffer objects so trace data
can be written into several data file located at data directory.

Signed-off-by: Alexey Bayduraev <alexey.v.baydur...@linux.intel.com>
---
 tools/perf/builtin-record.c | 41 ++++++++++++++++++++++++++++++-------
 tools/perf/util/record.h    |  1 +
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3947c60d905b..c1416d28ac6d 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -158,6 +158,11 @@ static const char *affinity_tags[PERF_AFFINITY_MAX] = {
        "SYS", "NODE", "CPU"
 };
 
+static int record__threads_enabled(struct record *rec)
+{
+       return rec->opts.threads_spec;
+}
+
 static bool switch_output_signal(struct record *rec)
 {
        return rec->switch_output.signal &&
@@ -1066,7 +1071,7 @@ static void record__free_thread_data(struct record *rec)
 static int record__mmap_evlist(struct record *rec,
                               struct evlist *evlist)
 {
-       int ret;
+       int i, ret;
        struct record_opts *opts = &rec->opts;
        bool auxtrace_overwrite = opts->auxtrace_snapshot_mode ||
                                  opts->auxtrace_sample_mode;
@@ -1105,6 +1110,18 @@ static int record__mmap_evlist(struct record *rec,
        if (ret)
                return ret;
 
+       if (record__threads_enabled(rec)) {
+               ret = perf_data__create_dir(&rec->data, evlist->core.nr_mmaps);
+               if (ret)
+                       return ret;
+               for (i = 0; i < evlist->core.nr_mmaps; i++) {
+                       if (evlist->mmap)
+                               evlist->mmap[i].file = &rec->data.dir.files[i];
+                       if (evlist->overwrite_mmap)
+                               evlist->overwrite_mmap[i].file = 
&rec->data.dir.files[i];
+               }
+       }
+
        return 0;
 }
 
@@ -1405,8 +1422,12 @@ static int record__mmap_read_evlist(struct record *rec, 
struct evlist *evlist,
        /*
         * Mark the round finished in case we wrote
         * at least one event.
+        *
+        * No need for round events in directory mode,
+        * because per-cpu maps and files have data
+        * sorted by kernel.
         */
-       if (bytes_written != rec->bytes_written)
+       if (!record__threads_enabled(rec) && bytes_written != 
rec->bytes_written)
                rc = record__write(rec, NULL, &finished_round_event, 
sizeof(finished_round_event));
 
        if (overwrite)
@@ -1519,7 +1540,9 @@ static void record__init_features(struct record *rec)
        if (!rec->opts.use_clockid)
                perf_header__clear_feat(&session->header, HEADER_CLOCK_DATA);
 
-       perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT);
+       if (!record__threads_enabled(rec))
+               perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT);
+
        if (!record__comp_enabled(rec))
                perf_header__clear_feat(&session->header, HEADER_COMPRESSED);
 
@@ -1530,15 +1553,21 @@ static void
 record__finish_output(struct record *rec)
 {
        struct perf_data *data = &rec->data;
-       int fd = perf_data__fd(data);
+       int i, fd = perf_data__fd(data);
 
        if (data->is_pipe)
                return;
 
        rec->session->header.data_size += rec->bytes_written;
        data->file.size = lseek(perf_data__fd(data), 0, SEEK_CUR);
+       if (record__threads_enabled(rec)) {
+               for (i = 0; i < data->dir.nr; i++)
+                       data->dir.files[i].size = lseek(data->dir.files[i].fd, 
0, SEEK_CUR);
+       }
 
        if (!rec->no_buildid) {
+               /* this will be recalculated during process_buildids() */
+               rec->samples = 0;
                process_buildids(rec);
 
                if (rec->buildid_all)
@@ -2438,8 +2467,6 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
                status = err;
 
        record__synthesize(rec, true);
-       /* this will be recalculated during process_buildids() */
-       rec->samples = 0;
 
        if (!err) {
                if (!rec->timestamp_filename) {
@@ -3203,7 +3230,7 @@ int cmd_record(int argc, const char **argv)
                rec->no_buildid = true;
        }
 
-       if (rec->opts.kcore)
+       if (rec->opts.kcore || record__threads_enabled(rec))
                rec->data.is_dir = true;
 
        if (rec->opts.comp_level != 0) {
diff --git a/tools/perf/util/record.h b/tools/perf/util/record.h
index 68f471d9a88b..4d68b7e27272 100644
--- a/tools/perf/util/record.h
+++ b/tools/perf/util/record.h
@@ -77,6 +77,7 @@ struct record_opts {
        int           ctl_fd;
        int           ctl_fd_ack;
        bool          ctl_fd_close;
+       int           threads_spec;
 };
 
 extern const char * const *record_usage;
-- 
2.19.0


Reply via email to