From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752724AbeAIPrt (ORCPT + 1 other); Tue, 9 Jan 2018 10:47:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35660 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758850AbeAIPfs (ORCPT ); Tue, 9 Jan 2018 10:35:48 -0500 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , David Ahern , Andi Kleen , Alexander Shishkin , Peter Zijlstra Subject: [PATCH 10/49] perf tools: Add HEADER_DATA_INDEX feature Date: Tue, 9 Jan 2018 16:34:43 +0100 Message-Id: <20180109153522.14116-11-jolsa@kernel.org> In-Reply-To: <20180109153522.14116-1-jolsa@kernel.org> References: <20180109153522.14116-1-jolsa@kernel.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 09 Jan 2018 15:35:48 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: From: Namhyung Kim 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. Link: http://lkml.kernel.org/n/tip-q5rh23fs1qlenc2s9fj0ug7u@git.kernel.org Signed-off-by: Namhyung Kim Signed-off-by: Jiri Olsa --- tools/perf/builtin-record.c | 1 + tools/perf/util/header.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/header.h | 3 ++ 3 files changed, 80 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 385aa9fba282..e52be5593b2f 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -579,6 +579,7 @@ static void record__init_features(struct record *rec) perf_header__clear_feat(&session->header, HEADER_AUXTRACE); perf_header__clear_feat(&session->header, HEADER_STAT); + perf_header__clear_feat(&session->header, HEADER_DATA_INDEX); } static void diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 418608a7c91a..e947a380eddb 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -33,6 +33,7 @@ #include "strbuf.h" #include "build-id.h" #include "data.h" +#include "units.h" #include #include "asm/bug.h" #include "tool.h" @@ -1196,6 +1197,25 @@ static int write_sample_time(struct feat_fd *ff, sizeof(evlist->last_sample_time)); } +static int write_data_index(struct feat_fd *ff, + struct perf_evlist *evlist __maybe_unused) +{ + struct perf_header *ph = ff->ph; + int ret; + unsigned int i; + + ret = do_write(ff, &ph->nr_index, sizeof(ph->nr_index)); + if (ret < 0) + return ret; + + for (i = 0; i < ph->nr_index; i++) { + ret = do_write(ff, &ph->index[i], sizeof(*ph->index)); + if (ret < 0) + return ret; + } + return 0; +} + static void print_hostname(struct feat_fd *ff, FILE *fp) { fprintf(fp, "# hostname : %s\n", ff->ph->env.hostname); @@ -1543,6 +1563,23 @@ static void print_sample_time(struct feat_fd *ff, FILE *fp) fprintf(fp, "# sample duration : %10.3f ms\n", d); } +static void print_data_index(struct feat_fd *ff, FILE *fp) +{ + struct perf_header *ph = ff->ph; + unsigned int i; + + fprintf(fp, "# contains data index (%lu) for parallel processing\n", + ph->nr_index); + + for (i = 0; i < ph->nr_index; i++) { + struct perf_file_section *s = &ph->index[i]; + char buf[20]; + + unit_number__scnprintf(buf, sizeof(buf), s->size); + fprintf(fp, "# %u: %s @ %lu\n", i, buf, s->offset); + } +} + static int __event_process_build_id(struct build_id_event *bev, char *filename, struct perf_session *session) @@ -2205,6 +2242,44 @@ static int process_sample_time(struct feat_fd *ff, void *data __maybe_unused) return 0; } +static int process_data_index(struct feat_fd *ff, void *data __maybe_unused) +{ + struct perf_header *ph = ff->ph; + int fd = ff->fd; + ssize_t ret; + u64 nr_idx; + unsigned int 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)(struct feat_fd *ff, struct perf_evlist *evlist); void (*print)(struct feat_fd *ff, FILE *fp); @@ -2263,6 +2338,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = { FEAT_OPN(STAT, stat, false), FEAT_OPN(CACHE, cache, true), FEAT_OPR(SAMPLE_TIME, sample_time, false), + FEAT_OPN(DATA_INDEX, data_index, true), }; struct header_print_data { diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index fa8025fbe90d..cc8b651e779a 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -36,6 +36,7 @@ enum { HEADER_STAT, HEADER_CACHE, HEADER_SAMPLE_TIME, + HEADER_DATA_INDEX, HEADER_LAST_FEATURE, HEADER_FEAT_BITS = 256, }; @@ -76,6 +77,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.13.6