Re: [PATCH v4] perf record: Add support for limit perf output file size

From: Jiri Olsa
Date: Mon Oct 21 2019 - 09:41:58 EST


On Wed, Sep 25, 2019 at 03:06:37PM +0800, Jiwei Sun wrote:

SNIP

> SEE ALSO
> --------
> linkperf:perf-stat[1], linkperf:perf-list[1]
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index 48600c90cc7e..30904d2a3407 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -91,6 +91,7 @@ struct record {
> struct switch_output switch_output;
> unsigned long long samples;
> cpu_set_t affinity_mask;
> + unsigned long output_max_size; /* = 0: unlimited */
> };
>
> static volatile int auxtrace_record__snapshot_started;
> @@ -120,6 +121,12 @@ static bool switch_output_time(struct record *rec)
> trigger_is_ready(&switch_output_trigger);
> }
>
> +static bool record__output_max_size_exceeded(struct record *rec)
> +{
> + return rec->output_max_size &&
> + (rec->bytes_written >= rec->output_max_size);
> +}
> +
> static int record__write(struct record *rec, struct mmap *map __maybe_unused,
> void *bf, size_t size)
> {
> @@ -132,6 +139,12 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused,
>
> rec->bytes_written += size;
>
> + if (record__output_max_size_exceeded(rec)) {
> + WARN_ONCE(1, "WARNING: The perf data has already reached "
> + "the limit, stop recording!\n");

I think the message whouldn't be a warning, the user asked for
that, maybe something more like:

[ perf record: perf size limit reached (XXMB), stopping session ]

> + raise(SIGTERM);

could we just set 'done = 1' what's the benefit in killing perf?

thanks,
jirka