[PATCH v3 01/12] perf script: Make printing flags reliable

Adrian Hunter adrian.hunter at intel.com
Mon Mar 3 08:56:42 PST 2025


On 3/03/25 20:11, Leo Yan wrote:
> On Mon, Mar 03, 2025 at 05:05:13PM +0200, Adrian Hunter wrote:
> 
> [...]
> 
>>>>> +	ret = max(ret, SAMPLE_FLAGS_STR_ALIGNED_SIZE);
>>>>> +	return fprintf(fp, "  %-*s ", ret, str);
>>>>
>>>> -21 means the field width is 21 and left-justified.  It should not
>>>> truncate the string.
>>>
>>> No, it does not truncate the string.
>>>
>>> It calculates a maximum value between the returned length and 21 (
>>> defined in SAMPLE_FLAGS_STR_ALIGNED_SIZE).  It keeps left-justified and
>>> can printing a complete string if the string length is bigger than 21.
>>
>> Maybe I am missing something, but that isn't that what
>>
>> 	return fprintf(fp, "  %-21s ", str);
>>
>> does anyway?  Why change it to something more complicated.
> 
> You are right.  I should have done an experiment for this.
> 
> I will remove the max() sentence and update the last line:
> 
>         return fprintf(fp, "  %-*s ", SAMPLE_FLAGS_STR_ALIGNED_SIZE, str);
> 
> Another option is to drop this patch.  But I prefer to keep it, the
> reason is except the benefit for the debugging log, an extra reason is
> the SAMPLE_FLAGS_STR_ALIGNED_SIZE macro is used to replace the opened
> value '21'.  The macro also will be used by a later patch for
> right-alignment printing.  How about you think?

Sure




More information about the linux-arm-kernel mailing list