Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1505427pxv; Fri, 2 Jul 2021 05:34:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwN9oRbGI/m3oK6mIs6VtWKdPCGiJoWerico/Cny7tfU4UTT9p5xhtZouMvGvH2m9eN+d2c X-Received: by 2002:a17:906:384c:: with SMTP id w12mr5015036ejc.445.1625229297947; Fri, 02 Jul 2021 05:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625229297; cv=none; d=google.com; s=arc-20160816; b=j0Q59niA7KBtAYoGeao081JdKEdslehLL5CNsj/4cxMDPrmaixgZt6tFZa97m9GyZ2 n9PjapDKm2ACInPg/1qjSi2KjqL4/nJbXrSm2HR1UjJwa61IuWBwWDnXIWQlf6qYqyj3 AerjmBlXj8qE2zJ1ECNhza7BGHRAHFerPWVb0/kg382Rv8+aJzoFvPYWSjTnE5b1TNpa EnuqvnORwRGLPEz89baRyk5DxjodEZo7g4SlBjQaRRShnqY6a/i4IHMC98OVVWBUWwwk 0cSSHiBLdmLCN2wxae7ecYfJuOKGy48nwI6ERP4Li+oZYnHew/aLH9Vp8RX3mzpmWzo8 Dd0w== 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=0OSNYq3/3+n8FeY7LDkrgc1ifHw2vkdP4ginvAvD94s=; b=pIT65e8iwGBFr77uqVfa2a6DKdlpHuoBekbhTtQvefTpKmAgenYmUA4xomnapwiP3g azW1wCdrjh4e+yNdlt5HSTZxo6yKXdyIEV/TRxYJG8+Gt17AgqYg+5wOV/mp0td3qzpG Ln+yZpHFPFVYoFGdpz1YTe5u5bi0KeertqJnAEQbf8UZ6mQPT7UORWfcCvIxAEH40GW1 7ihZxNaR0n91mGBanOLJ1tGgM6488f4vOb78c1FYElr3+9pcTWhh/4ZyzUFlCU/yiToc rWMXvq/s9swuzstxVQAgfXUCeUO6sDEFmBXQ4cGbRBOXeQo2aJTcM2i6EZfK633cw12D +bhw== 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 q14si3099177eds.205.2021.07.02.05.34.34; Fri, 02 Jul 2021 05:34:57 -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 S232378AbhGBMfj (ORCPT + 99 others); Fri, 2 Jul 2021 08:35:39 -0400 Received: from mga01.intel.com ([192.55.52.88]:3514 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232351AbhGBMfg (ORCPT ); Fri, 2 Jul 2021 08:35:36 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10032"; a="230397118" X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="230397118" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 05:33:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,317,1616482800"; d="scan'208";a="642660250" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by fmsmga006.fm.intel.com with ESMTP; 02 Jul 2021 05:33:01 -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 09/24] perf record: Introduce bytes written stats to support --max-size option Date: Fri, 2 Jul 2021 15:32:17 +0300 Message-Id: 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 Adding a function to calculate the total amount of data written and using it to support the --max-size option. Signed-off-by: Alexey Bayduraev --- tools/perf/builtin-record.c | 30 +++++++++++++++++++++++++++--- tools/perf/util/mmap.h | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ac9bc1bbdff4..6419b7974435 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -186,10 +186,28 @@ static bool switch_output_time(struct record *rec) trigger_is_ready(&switch_output_trigger); } +static u64 record__bytes_written(struct record *rec) +{ + int t, tm; + struct record_thread *thread_data = rec->thread_data; + u64 bytes_written = rec->bytes_written; + + for (t = 0; t < rec->nr_threads; t++) { + for (tm = 0; tm < thread_data[t].nr_mmaps; tm++) { + if (thread_data[t].maps) + bytes_written += thread_data[t].maps[tm]->bytes_written; + if (thread_data[t].overwrite_maps) + bytes_written += thread_data[t].overwrite_maps[tm]->bytes_written; + } + } + + return bytes_written; +} + static bool record__output_max_size_exceeded(struct record *rec) { return rec->output_max_size && - (rec->bytes_written >= rec->output_max_size); + (record__bytes_written(rec) >= rec->output_max_size); } static int record__write(struct record *rec, struct mmap *map __maybe_unused, @@ -205,15 +223,21 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused, return -1; } - rec->bytes_written += size; + if (map && map->file) + map->bytes_written += size; + else + rec->bytes_written += size; if (record__output_max_size_exceeded(rec) && !done) { fprintf(stderr, "[ perf record: perf size limit reached (%" PRIu64 " KB)," " stopping session ]\n", - rec->bytes_written >> 10); + record__bytes_written(rec) >> 10); done = 1; } + if (map && map->file) + return 0; + if (switch_output_size(rec)) trigger_hit(&switch_output_trigger); diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index c4aed6e89549..67d41003d82e 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -46,6 +46,7 @@ struct mmap { int comp_level; struct perf_data_file *file; struct zstd_data zstd_data; + u64 bytes_written; }; struct mmap_params { -- 2.19.0