[PATCH 06/40] perf tools: Add HEADER_DATA_INDEX feature

From: Namhyung Kim
Date: Sun May 17 2015 - 20:41:28 EST


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 <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-record.c | 2 ++
tools/perf/util/header.c | 62 +++++++++++++++++++++++++++++++++++++++++++++
tools/perf/util/header.h | 3 +++
3 files changed, 67 insertions(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 21f7edb23370..303116c9a38a 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -459,6 +459,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 3f0d809d853a..1e10f4bc664d 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -883,6 +883,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)
{
@@ -1233,6 +1251,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)
@@ -1841,6 +1865,7 @@ static int process_group_desc(struct perf_file_section *section __maybe_unused,
return ret;
}

+
static int process_auxtrace(struct perf_file_section *section,
struct perf_header *ph, int fd,
void *data __maybe_unused)
@@ -1857,6 +1882,42 @@ 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))
+ return ret;
+
+ 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);
@@ -1898,6 +1959,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 d4d57962c591..746e27763fab 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,
};
@@ -95,6 +96,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_session_env env;
--
2.4.0

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