The HEADER_DATA_INDEX feature is to record index table for sample data
so that they can be processed by multiple thread concurrently.  Each
item is a struct perf_file_section which consists of an offset and size.

Signed-off-by: Namhyung Kim <namhy...@kernel.org>
---
 tools/perf/builtin-record.c |  2 ++
 tools/perf/util/header.c    | 64 +++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/header.h    |  3 +++
 3 files changed, 69 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 90b1237d2525..623984c81478 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -451,6 +451,8 @@ static void record__init_features(struct record *rec)
 
        if (!rec->opts.full_auxtrace)
                perf_header__clear_feat(&session->header, HEADER_AUXTRACE);
+
+       perf_header__clear_feat(&session->header, HEADER_DATA_INDEX);
 }
 
 static volatile int workload_exec_errno;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 43838003c1a1..c357f7f47d32 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -868,6 +868,24 @@ static int write_auxtrace(int fd, struct perf_header *h,
        return err;
 }
 
+static int write_data_index(int fd, struct perf_header *h,
+                           struct perf_evlist *evlist __maybe_unused)
+{
+       int ret;
+       unsigned i;
+
+       ret = do_write(fd, &h->nr_index, sizeof(h->nr_index));
+       if (ret < 0)
+               return ret;
+
+       for (i = 0; i < h->nr_index; i++) {
+               ret = do_write(fd, &h->index[i], sizeof(*h->index));
+               if (ret < 0)
+                       return ret;
+       }
+       return 0;
+}
+
 static void print_hostname(struct perf_header *ph, int fd __maybe_unused,
                           FILE *fp)
 {
@@ -1221,6 +1239,12 @@ static void print_group_desc(struct perf_header *ph, int 
fd __maybe_unused,
        }
 }
 
+static void print_data_index(struct perf_header *ph __maybe_unused,
+                            int fd __maybe_unused, FILE *fp)
+{
+       fprintf(fp, "# contains data index for parallel processing\n");
+}
+
 static int __event_process_build_id(struct build_id_event *bev,
                                    char *filename,
                                    struct perf_session *session)
@@ -1891,6 +1915,7 @@ out_free:
        return ret;
 }
 
+
 static int process_auxtrace(struct perf_file_section *section,
                            struct perf_header *ph, int fd,
                            void *data __maybe_unused)
@@ -1907,6 +1932,44 @@ static int process_auxtrace(struct perf_file_section 
*section,
        return err;
 }
 
+static int process_data_index(struct perf_file_section *section __maybe_unused,
+                             struct perf_header *ph, int fd,
+                             void *data __maybe_unused)
+{
+       ssize_t ret;
+       u64 nr_idx;
+       unsigned i;
+       struct perf_file_section *idx;
+
+       ret = readn(fd, &nr_idx, sizeof(nr_idx));
+       if (ret != sizeof(nr_idx))
+               return -1;
+
+       if (ph->needs_swap)
+               nr_idx = bswap_64(nr_idx);
+
+       idx = calloc(nr_idx, sizeof(*idx));
+       if (idx == NULL)
+               return -1;
+
+       for (i = 0; i < nr_idx; i++) {
+               ret = readn(fd, &idx[i], sizeof(*idx));
+               if (ret != sizeof(*idx)) {
+                       free(idx);
+                       return -1;
+               }
+
+               if (ph->needs_swap) {
+                       idx[i].offset = bswap_64(idx[i].offset);
+                       idx[i].size   = bswap_64(idx[i].size);
+               }
+       }
+
+       ph->index = idx;
+       ph->nr_index = nr_idx;
+       return 0;
+}
+
 struct feature_ops {
        int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist);
        void (*print)(struct perf_header *h, int fd, FILE *fp);
@@ -1948,6 +2011,7 @@ static const struct feature_ops 
feat_ops[HEADER_LAST_FEATURE] = {
        FEAT_OPP(HEADER_PMU_MAPPINGS,   pmu_mappings),
        FEAT_OPP(HEADER_GROUP_DESC,     group_desc),
        FEAT_OPP(HEADER_AUXTRACE,       auxtrace),
+       FEAT_OPP(HEADER_DATA_INDEX,     data_index),
 };
 
 struct header_print_data {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 05f27cb6b7e3..add455a7abff 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -31,6 +31,7 @@ enum {
        HEADER_PMU_MAPPINGS,
        HEADER_GROUP_DESC,
        HEADER_AUXTRACE,
+       HEADER_DATA_INDEX,
        HEADER_LAST_FEATURE,
        HEADER_FEAT_BITS        = 256,
 };
@@ -71,6 +72,8 @@ struct perf_header {
        bool                            needs_swap;
        u64                             data_offset;
        u64                             data_size;
+       struct perf_file_section        *index;
+       u64                             nr_index;
        u64                             feat_offset;
        DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
        struct perf_env         env;
-- 
2.6.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to