Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1280651pxb; Sun, 12 Sep 2021 13:47:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYgNLfsb+MwhBXczSwRuB7olzp2XlLyFRRNFQRv5n43MXf30oo5B8+NAPyFLtqrdfbZJ33 X-Received: by 2002:a05:6e02:1e03:: with SMTP id g3mr5567946ila.320.1631479670582; Sun, 12 Sep 2021 13:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631479670; cv=none; d=google.com; s=arc-20160816; b=oi09N1j6rn88VkEfyhtculW9Dm4mccT4/Ahf8E7yr/Lnd+sj4pH+uOp7/Pek87BHPS R2pcwHZTGR+iODd1I/8yC3vXLqBeMvDVZFxFLpDJyu2FNlir8kfsA0liFzc3Qe0H/8xp 6s3tjJUE3BUWGf5+OKxDpRGpiP4mY1cekqtR+iChw5TRHT5bovq0GaAv68R5FOd6RJKN IQsngFDyWaZuwJ9cs/9IkxxLpmTqiNuigz7Pu2pU52UN2tIyeS7fgN2EFq+MH/IZE6/h Zocm8UndvDufEM5vjdDCVyQt3FxXURVbkaEl3bE1Ow4kiptu7Y1mGALrDn/Yi4mDk4Cj w+yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hD5mu2L0rSn6NJ0lYDv6IN5TJCoxQGbrMjRvgkRfR3Q=; b=NzQ5XeKo4c66RJ2oZ53eff2MhZfFVa46QsEYQuifgItXe7RHyEwZ6NymZctGyug/ch SwOf7uMsl6sWGBrGQH3jI1kJvxoF97qYrBJIjluHYUpsNn21rvAyCBpdX+u8Qy3taakz U6AJJXxaFLw9IgjUpL6dkonUD4jUUxucJLwh5GP7uJj19QR52MUx0WD0gQYr1uQYe9IJ PcyMYaDSULx1BY4cCetkEyZfSoLbcd3dPPKkffw8SqijmsLE8HT1l5egwlydYNXE03zR 7y7C1oHcl4Tn8N2MkH0Onufaiw5QuFCV3b4MiNKK9yuvOfiQquoQT99+QwnpiJaC9TxE c+Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gEW6UVr7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r17si4835153ilj.23.2021.09.12.13.47.37; Sun, 12 Sep 2021 13:47:50 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gEW6UVr7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236430AbhILUsE (ORCPT + 99 others); Sun, 12 Sep 2021 16:48:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50526 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236226AbhILUsD (ORCPT ); Sun, 12 Sep 2021 16:48:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631479608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hD5mu2L0rSn6NJ0lYDv6IN5TJCoxQGbrMjRvgkRfR3Q=; b=gEW6UVr7x7XsT2S0FBvEEBx+PhxHV2ihamCJ1OcfedpZVEiRFZqJ3bDdr0A/IGOlwmRtiO 431ckDYBqP54KRt1uudabVfw7BBPs5VGEUYyC5ePozYrzITPT0kbzV6sKSrTMV4DyJeidP vl16GZ8B+FDoPV1I3AsxjOTJYrw8zCc= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-472-N88aZidYNxirmF0qoQ0kzQ-1; Sun, 12 Sep 2021 16:46:47 -0400 X-MC-Unique: N88aZidYNxirmF0qoQ0kzQ-1 Received: by mail-ed1-f71.google.com with SMTP id bf22-20020a0564021a5600b003c86b59e291so3853370edb.18 for ; Sun, 12 Sep 2021 13:46:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=hD5mu2L0rSn6NJ0lYDv6IN5TJCoxQGbrMjRvgkRfR3Q=; b=1mTfzmiZriX+XzTDkHAmdlpOfuslrpZDHAxV5epL8OE7T1noQU0vtiN5P5891itYTf NBwfiKw9KUxw8Kk2aEQpFOoc3yd4ou7jC0s7FAX31hb2ltitm1Z1vuAdi8qRZ/J/CoDQ 2Xvbvhq40oTUJ6V37uTTL3upGw26OO2z7JDZCC2FKVGzqw2/qsZzf4f9hrJSkzkPbpAM mq0zB7T4scBG5FFhbuZI7neyy9MJrsKQZXrF+G4sxTrmdSB6e4ns2V7u9h92nRbjWZau 0RRLMxALp6/mKIlqlXvEXkTr8RUHLQgi/R8SMbKrOC5IDza0RAg+y4JTvo2NLY2k1RHR UMFw== X-Gm-Message-State: AOAM532o6gpxqBuH0Q/QkqK73s3kQRGxWsLoNE459FpcCAjeW7wTosZo f78NpkeniFSqjb3c7gR6jDzJa3CYcLS9I8hKozH2f5yTZ5w+oL4yk8wWJS6kshANnxn64+/FOPp O+cSnEvcXJDfd1Zv/iBPXwJfT X-Received: by 2002:a17:906:6943:: with SMTP id c3mr9063606ejs.550.1631479606136; Sun, 12 Sep 2021 13:46:46 -0700 (PDT) X-Received: by 2002:a17:906:6943:: with SMTP id c3mr9063592ejs.550.1631479605943; Sun, 12 Sep 2021 13:46:45 -0700 (PDT) Received: from krava ([83.240.60.52]) by smtp.gmail.com with ESMTPSA id z12sm2823128edi.44.2021.09.12.13.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Sep 2021 13:46:45 -0700 (PDT) Date: Sun, 12 Sep 2021 22:46:43 +0200 From: Jiri Olsa To: Alexey Bayduraev Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Ingo Molnar , linux-kernel , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexei Budankov , Riccardo Mancini Subject: Re: [PATCH v11 09/24] perf record: Introduce bytes written stats to support --max-size option Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 17, 2021 at 11:23:12AM +0300, Alexey Bayduraev wrote: > Adding a function to calculate the total amount of data written > and using it to support the --max-size option. > > Acked-by: Namhyung Kim > Reviewed-by: Riccardo Mancini > Tested-by: Riccardo Mancini > 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 eff6f8db60b2..cb155f1ba979 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) { also instead of slowing down each write with calling record__output_max_size_exceeded and risking the race with done, I think this should be called as part of trigger framework we could call this check periodically every second or such, we don't mind the size overhead.. IMO it's still better than caling this each time we write to the file jirka > 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 >