* [PATCH] perf hist: Fix width calculation in hpp__fmt()
@ 2025-01-08 6:59 Dmitry Vyukov
2025-01-08 17:26 ` James Clark
2025-01-17 17:54 ` Namhyung Kim
0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Vyukov @ 2025-01-08 6:59 UTC (permalink / raw)
To: namhyung, irogers; +Cc: Dmitry Vyukov, linux-perf-users, linux-kernel
hpp__width_fn() round up width to length of the field name,
hpp__fmt() should do it too. Otherwise, the numbers may
end up unaligned if the field name is long.
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
tools/perf/ui/hist.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index e5491995adf08..34fda1d5eccb4 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -121,7 +121,7 @@ int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
const char *fmtstr, hpp_snprint_fn print_fn,
enum perf_hpp_fmt_type fmtype)
{
- int len = fmt->user_len ?: fmt->len;
+ int len = max(fmt->user_len ?: fmt->len, (int)strlen(fmt->name));
if (symbol_conf.field_sep) {
return __hpp__fmt(hpp, he, get_field, fmtstr, 1,
base-commit: 09a0fa92e5b45e99cf435b2fbf5ebcf889cf8780
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf hist: Fix width calculation in hpp__fmt()
2025-01-08 6:59 [PATCH] perf hist: Fix width calculation in hpp__fmt() Dmitry Vyukov
@ 2025-01-08 17:26 ` James Clark
2025-01-08 17:41 ` James Clark
2025-01-17 17:54 ` Namhyung Kim
1 sibling, 1 reply; 4+ messages in thread
From: James Clark @ 2025-01-08 17:26 UTC (permalink / raw)
To: Dmitry Vyukov; +Cc: linux-perf-users, linux-kernel, namhyung, irogers
On 08/01/2025 6:59 am, Dmitry Vyukov wrote:
> hpp__width_fn() round up width to length of the field name,
> hpp__fmt() should do it too. Otherwise, the numbers may
> end up unaligned if the field name is long.
>
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Ian Rogers <irogers@google.com>
> Cc: linux-perf-users@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
> tools/perf/ui/hist.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
> index e5491995adf08..34fda1d5eccb4 100644
> --- a/tools/perf/ui/hist.c
> +++ b/tools/perf/ui/hist.c
> @@ -121,7 +121,7 @@ int hpp__fmt(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
> const char *fmtstr, hpp_snprint_fn print_fn,
> enum perf_hpp_fmt_type fmtype)
> {
> - int len = fmt->user_len ?: fmt->len;
> + int len = max(fmt->user_len ?: fmt->len, (int)strlen(fmt->name));
>
> if (symbol_conf.field_sep) {
> return __hpp__fmt(hpp, he, get_field, fmtstr, 1,
>
> base-commit: 09a0fa92e5b45e99cf435b2fbf5ebcf889cf8780
This seems to right align the field correctly with a long name. Although
it's worth noting I had to add a long name to make it obvious.
Reviewed-by: James Clark <james.clark@linaro.org>
I saw some other existing issue with small column-width arguments which
is changed slightly by this patch. But I don't think it's worse:
$ perf report --fields
overhead,overhead_sys,overhead_us,overhead_guest_us,dso
--column-widths=3,3,3,3,3
After:
------
Overhead sys usr guest usr long name Shared Object
63.78% 0.00% 63.78% 0.00% ld-linux-x86-64.so
After, width=3:
--------------
Overhead sys usr guest usr long name Sha
63.78% 0.00% 63.78% 0.00% ld-
Before:
---------------
Overhead sys usr guest usr long name Shared Object
63.78% 0.00% 63.78% 0.00% ld-linux-x86-64.so
Before, width=3:
---------------
Overhead sys usr guest usr long name Sha
63.78% 0.00% 63.78% 0.00% ld-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf hist: Fix width calculation in hpp__fmt()
2025-01-08 17:26 ` James Clark
@ 2025-01-08 17:41 ` James Clark
0 siblings, 0 replies; 4+ messages in thread
From: James Clark @ 2025-01-08 17:41 UTC (permalink / raw)
To: Dmitry Vyukov; +Cc: linux-perf-users, linux-kernel, namhyung, irogers
On 08/01/2025 5:26 pm, James Clark wrote:
>
>
> On 08/01/2025 6:59 am, Dmitry Vyukov wrote:
>> hpp__width_fn() round up width to length of the field name,
>> hpp__fmt() should do it too. Otherwise, the numbers may
>> end up unaligned if the field name is long.
>>
>> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
>> Cc: Namhyung Kim <namhyung@kernel.org>
>> Cc: Ian Rogers <irogers@google.com>
>> Cc: linux-perf-users@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> ---
>> tools/perf/ui/hist.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
>> index e5491995adf08..34fda1d5eccb4 100644
>> --- a/tools/perf/ui/hist.c
>> +++ b/tools/perf/ui/hist.c
>> @@ -121,7 +121,7 @@ int hpp__fmt(struct perf_hpp_fmt *fmt, struct
>> perf_hpp *hpp,
>> const char *fmtstr, hpp_snprint_fn print_fn,
>> enum perf_hpp_fmt_type fmtype)
>> {
>> - int len = fmt->user_len ?: fmt->len;
>> + int len = max(fmt->user_len ?: fmt->len, (int)strlen(fmt->name));
>> if (symbol_conf.field_sep) {
>> return __hpp__fmt(hpp, he, get_field, fmtstr, 1,
>>
>> base-commit: 09a0fa92e5b45e99cf435b2fbf5ebcf889cf8780
>
> This seems to right align the field correctly with a long name. Although
> it's worth noting I had to add a long name to make it obvious.
>
> Reviewed-by: James Clark <james.clark@linaro.org>
>
> I saw some other existing issue with small column-width arguments which
> is changed slightly by this patch. But I don't think it's worse:
>
Ah maybe I was looking at it wrong, before and after are the same with
width=3, apart from the intended fix. False alarm.
>
> $ perf report --fields
> overhead,overhead_sys,overhead_us,overhead_guest_us,dso --column-
> widths=3,3,3,3,3
>
> After:
> ------
> Overhead sys usr guest usr long name Shared Object
> 63.78% 0.00% 63.78% 0.00% ld-linux-x86-64.so
>
> After, width=3:
> --------------
> Overhead sys usr guest usr long name Sha
> 63.78% 0.00% 63.78% 0.00% ld-
>
> Before:
> ---------------
> Overhead sys usr guest usr long name Shared Object
> 63.78% 0.00% 63.78% 0.00% ld-linux-x86-64.so
>
> Before, width=3:
> ---------------
> Overhead sys usr guest usr long name Sha
> 63.78% 0.00% 63.78% 0.00% ld-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf hist: Fix width calculation in hpp__fmt()
2025-01-08 6:59 [PATCH] perf hist: Fix width calculation in hpp__fmt() Dmitry Vyukov
2025-01-08 17:26 ` James Clark
@ 2025-01-17 17:54 ` Namhyung Kim
1 sibling, 0 replies; 4+ messages in thread
From: Namhyung Kim @ 2025-01-17 17:54 UTC (permalink / raw)
To: irogers, Dmitry Vyukov; +Cc: linux-perf-users, linux-kernel
On Wed, 08 Jan 2025 07:59:34 +0100, Dmitry Vyukov wrote:
> hpp__width_fn() round up width to length of the field name,
> hpp__fmt() should do it too. Otherwise, the numbers may
> end up unaligned if the field name is long.
>
>
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-17 17:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-08 6:59 [PATCH] perf hist: Fix width calculation in hpp__fmt() Dmitry Vyukov
2025-01-08 17:26 ` James Clark
2025-01-08 17:41 ` James Clark
2025-01-17 17:54 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®