Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2830571pxv; Mon, 12 Jul 2021 03:01:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwW/hrttC6mBmRmGnm/RhMg+Ogcyx1Y3eN7ydVnupUlF9L4JwUslE/TLtAZnUwLM7tJuCEP X-Received: by 2002:a6b:f81a:: with SMTP id o26mr40053913ioh.68.1626084079930; Mon, 12 Jul 2021 03:01:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626084079; cv=none; d=google.com; s=arc-20160816; b=f98ccE9XfEGHzy6h0hItErX/RQF73NWVihFqtxrssWaw1qbad7PIgc06zbbQfCU2bv SEDOw9SaEsvoBsbf5bwnuz0KFyDgQ4SAqYDsA787SskExTc6sI6IRLyfHQ5XxQX22Zex HyAhyy68Ef/DsYXAqPzk9J2EV7np8pmTnXQDB2joaNvGi0jkt3mCuJ+xFgHUeolFZZmR cziGVAmhuxF6neMXIh26ypWo59ZG3Z/jZVwPiM/RhpDyD65obW9fj+K55Cfs2RPQwvbl +nmNKxn4n/zUUYrZtywf4GkKHdpYnxVwHKwZ6wD0bSrXU6g0sLuEKofT/gSdlXyjaw49 x91Q== 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=w4WVLxEs3Dw16KKs0N/c+PaZqgE52iS78oFRLcCHeN8=; b=ts7MiQqKmwEDuIA0TZTCJz+N2V7bbC9esKcaM4f2oehNVjXzd2RFUHwkePE0RQPxON Gty3Ycfpopel9UyBVBUbN9hASrHR/0JA4a5XUZOdbDwvsKVwsoxNQlcvmibTyl6GBzKR Je5WDKZjHY3c0E6oN0Ikf0b+5Lmikh26OcwNiEUfHiHhyzYRv1xXg3mPfgAK34uUbOLY gSkTzrcl4NdQ9pyVL8CfyAUvTojmlVpSA38eHmFxtHqsI1CCOHr9fGvwGw7bgHOGsaxQ 1DqwPyx3sC8aR3MeWYSlkpOnYtLLS5eOwN9V10WQM0zq9nd0RMm8I9hyPWbr7VtVTmkM qRAQ== 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 i13si18554108ilm.156.2021.07.12.03.01.03; Mon, 12 Jul 2021 03:01:19 -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 S244928AbhGLHO1 (ORCPT + 99 others); Mon, 12 Jul 2021 03:14:27 -0400 Received: from mga14.intel.com ([192.55.52.115]:45774 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239464AbhGLGtt (ORCPT ); Mon, 12 Jul 2021 02:49:49 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10042"; a="209748948" X-IronPort-AV: E=Sophos;i="5.84,232,1620716400"; d="scan'208";a="209748948" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2021 23:47:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,232,1620716400"; d="scan'208";a="491916182" Received: from nntpat99-84.inn.intel.com ([10.125.99.84]) by FMSMGA003.fm.intel.com with ESMTP; 11 Jul 2021 23:46:54 -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 v10 09/24] perf record: Introduce bytes written stats to support --max-size option Date: Mon, 12 Jul 2021 09:46:09 +0300 Message-Id: <2c52dc828026cfdccb302294223102775a77605b.1626072009.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 Adding a function to calculate the total amount of data written and using it to support the --max-size option. Acked-by: Namhyung Kim 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 d67a09e26792..50cfe6869027 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