Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1505695pxv; Fri, 2 Jul 2021 05:35:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhZspgVh0YKSuo0uND3QfAeDphbk8c74UUUFUw2pryfjE2XjrR0Nk5EwCbfA85YlX6dD6R X-Received: by 2002:a05:6402:31bc:: with SMTP id dj28mr6432893edb.382.1625229318204; Fri, 02 Jul 2021 05:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625229318; cv=none; d=google.com; s=arc-20160816; b=V3dSE/+16SFqVio2z2eQEBZg3vr8Bq57PmU4LJa8wjzpa3BQ4ylZ0llyTDMWW1QSP4 GVwRQ/TWLUkzzG+8tH7ns/JPZ//IxVGga5/C1aH/H24Cvz3JbpfaIXlLN1BQzZeuLqGu EIIywmyC5gvamYBAt8oViCv+frQmG+Bo7jf8eT63GFTWr0HnJAiZnIj3x4FSMGmknz+Y 57IDkDqmcc/bhMdkANJSF2ls/eHSO3U4lSbvwvOZgvwJTDxqZzUhdWQJ/GEMyv5mvsh9 Jvx4bNvbA6IcG+EmM0n/gL7hfLK05EL0oRelorEp6bd70uxSAaKqA+nU8tB86Il0/gDD mjrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7NVt4OVTkp1V8zzFxfsHd7yzq5zNtxYDWeHF28jKl0o=; b=hED5oYBwok4hyDJ/CTqdqZNAHWwV+UVKSfHFSJ+sVVWjefYz+mUKWTyRUpx80tZxoJ XX89yYX8TUOufeISQWmt601wbGd1o6s/kTQGgeM2czBoJ0k5N6lEs1RM4sSzz2uJgPem ZEP+1Q3BGWq39z+FeUH3U9qHTRcw1mY09S514jOjGPN9VhDQ6uNMNuRJzp5RPkPpm6Wi lab6SgZXlg1ivc8vaDcpPzXj1Xmi7XcEIAEpXwPHfoStDxEJwlcclNyyDYTOND1ccjjK 6wHoPLIWz7FhVE80A9HBTl0YmPo+sSosEIlwHkYixG0yxOq0Wk7GZxYoGf/4aN9ylhaK qzJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yh1si3014415ejb.216.2021.07.02.05.34.47; Fri, 02 Jul 2021 05:35:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232351AbhGBMfp (ORCPT + 99 others); Fri, 2 Jul 2021 08:35:45 -0400 Received: from mga17.intel.com ([192.55.52.151]:32627 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232416AbhGBMfm (ORCPT ); Fri, 2 Jul 2021 08:35:42 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10032"; a="189107261" X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="189107261" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 05:33:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="642660268" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga006.fm.intel.com with ESMTP; 02 Jul 2021 05:33:07 -0700 From: Alexey Bayduraev To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: [PATCH v9 11/24] perf record: Init data file at mmap buffer object Date: Fri, 2 Jul 2021 15:32:19 +0300 Message-Id: <370ca676350c4cc41a38bc6b1179a8811e86fa7c.1625227739.git.alexey.v.bayduraev@linux.intel.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Initialize data files located at mmap buffer objects so trace data can be written into several data file located at data directory. Acked-by: Andi Kleen Acked-by: Namhyung Kim Signed-off-by: Alexey Bayduraev --- 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 4d1571234ba2..ba3f60f7882a 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -167,6 +167,11 @@ static inline pid_t gettid(void) } #endif +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 && @@ -1146,7 +1151,7 @@ static int record__alloc_thread_data(struct record *rec, struct evlist *evlist) 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; @@ -1185,6 +1190,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; } @@ -1494,8 +1511,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) @@ -1611,7 +1632,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); @@ -1622,15 +1645,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) @@ -2576,8 +2605,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) { @@ -3378,7 +3405,7 @@ int cmd_record(int argc, const char **argv) goto out_opts; } - 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