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

From: Jiwei Sun
Date: Tue Oct 22 2019 - 01:57:07 EST


Hi Jirka,

On 2019e9410f21f% 21:41, Jiri Olsa wrote:
> 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 for your suggestions. Yes, if just set "done == 1" is more efficient and more concise.
And I will modify it and the output format, and then send a v5 patch.
Thanks again.

Regards,
Jiwei

>
> thanks,
> jirka
>
>