From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: namhyung@kernel.org, adrian.hunter@intel.com,
james.clark@linaro.org, jolsa@kernel.org, leo.yan@arm.com,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
mingo@redhat.com, peterz@infradead.org, thomas.falcon@intel.com,
tmricht@linux.ibm.com
Subject: Re: [PATCH v2 02/12] perf test: Truncate test description to fit terminal width
Date: Tue, 16 Jun 2026 12:25:59 -0300 [thread overview]
Message-ID: <ajFrBwTzZuqpWPd1@x1> (raw)
In-Reply-To: <20260616061404.41929-3-irogers@google.com>
On Mon, Jun 15, 2026 at 11:13:54PM -0700, Ian Rogers wrote:
> The parallel test harness uses the carriage return delete escape sequence
> `PERF_COLOR_DELETE_LINE` ("\033[A\33[2K\r") to erase and update the
> "Running (X active)" progress lines.
>
> However, if a test description is longer than the terminal width, the line
> wraps around. When this happens, the cursor up escape sequence `\033[A` only
> moves the cursor to the last wrapped row, leaving the top half of the description
> printed on the previous line. This leads to name duplication and output corruption
> spilling over multiple rows on consoles narrower than the maximum description length
> (e.g., 101 columns wide).
>
> Fix this by dynamically querying the terminal width using `get_term_dimensions`
> and truncating the printed test descriptions using the `%-*.*s` printf format.
> We reserve 35 characters for prefix, status, and spacing metrics to guarantee
> the progress line never wraps.
>
> Fixes: 0e036dcad4e6 ("perf test: Display number of active running tests")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/tests/builtin-test.c | 110 ++++++++++++++++++++++++--------
> 1 file changed, 85 insertions(+), 25 deletions(-)
>
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index afc06cec4954..65a2dc50ef55 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -10,35 +10,39 @@
> #ifdef HAVE_BACKTRACE_SUPPORT
> #include <execinfo.h>
> #endif
> -#include <poll.h>
> -#include <unistd.h>
> #include <setjmp.h>
> -#include <string.h>
> #include <stdlib.h>
> -#include <sys/types.h>
> +#include <string.h>
> +
> #include <dirent.h>
> -#include <sys/wait.h>
> +#include <linux/kernel.h>
> +#include <linux/string.h>
> +#include <linux/zalloc.h>
> +#include <poll.h>
> +#include <sys/ioctl.h>
> #include <sys/stat.h>
> #include <sys/time.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <unistd.h>
> +
> +#include <subcmd/exec-cmd.h>
> +#include <subcmd/parse-options.h>
> +#include <subcmd/run-command.h>
> +
> #include "builtin.h"
> +#include "color.h"
> #include "config.h"
> +#include "debug.h"
> #include "hist.h"
> #include "intlist.h"
> -#include "tests.h"
> -#include "debug.h"
> -#include "color.h"
> -#include <subcmd/parse-options.h>
> -#include <subcmd/run-command.h>
> #include "string2.h"
> #include "symbol.h"
> +#include "tests-scripts.h"
> +#include "tests.h"
> #include "util/rlimit.h"
> #include "util/strbuf.h"
> -#include <linux/kernel.h>
> -#include <linux/string.h>
> -#include <subcmd/exec-cmd.h>
> -#include <linux/zalloc.h>
> -
> -#include "tests-scripts.h"
> +#include "util/term.h"
>
> static const char *junit_filename;
> static struct strbuf junit_xml_buf = STRBUF_INIT;
> @@ -413,19 +417,64 @@ static char *xml_escape(const char *str)
> return res ? res : strdup("");
> }
>
> +static int get_term_width(void)
> +{
> + struct winsize ws;
> + int cols = 80;
> + int term_width;
> +
A comment here to explain this 10000 magic number?
> + if (!isatty(1))
> + return 10000;
> +
> + get_term_dimensions(&ws);
> + if (ws.ws_col > 0)
> + cols = ws.ws_col;
> +
> + /*
> + * Limit description width to fit on a single line. We subtract 35
> + * columns of headroom to allocate space for:
> + * - The suite index prefix: e.g. " 10.100:" (9 characters).
> + * - The colon separator and spaces: " : " (3 characters).
> + * - The longest status results: e.g. "Skip (some metrics failed)" (26 characters)
> + * or "Running (XX active)" (20 characters).
> + *
> + * A minimum description width of 10 is enforced to ensure names are
> + * legible even on very narrow consoles.
> + */
> + term_width = cols - 35;
> + if (term_width < 10)
> + term_width = 10;
> +
> + return term_width;
> +}
> +
> +static int get_max_desc_width(int width)
> +{
> + int term_width = get_term_width();
> +
> + return width > term_width ? term_width : width;
> +}
> +
> static int print_test_result(struct test_suite *t, int curr_suite, int curr_test_case,
> int result, int width, int running,
> const char *err_output, double elapsed)
> {
> + int pad_width = get_max_desc_width(width);
> + int term_width = get_term_width();
> +
> if (test_suite__num_test_cases(t) > 1) {
> char prefix[32];
> int len = snprintf(prefix, sizeof(prefix), "%3d.%1d:",
> curr_suite + 1, curr_test_case + 1);
> - int subw = len >= 4 ? width + 4 - len : width;
> + int pad = len >= 4 ? pad_width + 4 - len : pad_width;
> + int trunc = len >= 4 ? term_width + 4 - len : term_width;
>
> - pr_info("%s %-*s:", prefix, subw, test_description(t, curr_test_case));
> - } else
> - pr_info("%3d: %-*s:", curr_suite + 1, width, test_description(t, curr_test_case));
> + pr_info("%s %-*.*s:", prefix, pad, trunc,
> + test_description(t, curr_test_case));
> + } else {
> + pr_info("%3d: %-*.*s:", curr_suite + 1, pad_width, term_width,
> + test_description(t, curr_test_case));
> + }
>
> switch (result) {
> case TEST_RUNNING:
> @@ -695,6 +744,7 @@ static void finish_test(struct child_test **child_tests, int running_test, int c
> int ret;
> struct timespec end_time;
> double elapsed;
> + width = get_max_desc_width(width);
>
> if (child_test == NULL) {
> /* Test wasn't started. */
> @@ -709,7 +759,8 @@ static void finish_test(struct child_test **child_tests, int running_test, int c
> * sub test names.
> */
> if (test_suite__num_test_cases(t) > 1 && curr_test_case == 0)
> - pr_info("%3d: %-*s:\n", curr_suite + 1, width, test_description(t, -1));
> + pr_info("%3d: %-*.*s:\n", curr_suite + 1, width, width,
> + test_description(t, -1));
>
> /*
> * Busy loop reading from the child's stdout/stderr that are set to be
> @@ -917,6 +968,8 @@ static int finish_tests_parallel(struct child_test **child_tests, size_t num_tes
> int last_suite_printed = -1;
> sigset_t set, oldset;
>
> + width = get_max_desc_width(width);
> +
> sigemptyset(&set);
> sigaddset(&set, SIGINT);
> sigaddset(&set, SIGTERM);
> @@ -985,8 +1038,11 @@ static int finish_tests_parallel(struct child_test **child_tests, size_t num_tes
> if (next_child) {
> if (test_suite__num_test_cases(next_child->test) > 1 &&
> last_suite_printed != next_child->suite_num) {
> - pr_info("%3d: %-*s:\n", next_child->suite_num + 1, width,
> - test_description(next_child->test, -1));
> + pr_info("%3d: %-*.*s:\n",
> + next_child->suite_num + 1,
> + width, width,
> + test_description(
> + next_child->test, -1));
> last_suite_printed = next_child->suite_num;
> }
> print_test_result(next_child->test, next_child->suite_num,
> @@ -1049,7 +1105,8 @@ static int finish_tests_parallel(struct child_test **child_tests, size_t num_tes
>
> if (test_suite__num_test_cases(child->test) > 1 &&
> last_suite_printed != child->suite_num) {
> - pr_info("%3d: %-*s:\n", child->suite_num + 1, width,
> + pr_info("%3d: %-*.*s:\n", child->suite_num + 1,
> + width, width,
> test_description(child->test, -1));
> last_suite_printed = child->suite_num;
> }
> @@ -1296,7 +1353,10 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
>
> if (intlist__find(skiplist, curr_suite + 1)) {
> if (pass == 1) {
> - pr_info("%3d: %-*s:", curr_suite + 1, width,
> + int pad_width = get_max_desc_width(width);
> + int term_width = get_term_width();
> +
> + pr_info("%3d: %-*.*s:", curr_suite + 1, pad_width, term_width,
> test_description(*t, -1));
> color_fprintf(stderr, PERF_COLOR_YELLOW,
> " Skip (user override)\n");
> --
> 2.54.0.1136.gdb2ca164c4-goog
next prev parent reply other threads:[~2026-06-16 15:26 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 1:27 [PATCH v1 00/12] perf tests: Enhancements, speedups, and flakiness fixes Ian Rogers
2026-06-16 1:27 ` [PATCH v1 01/12] perf parse-events: Restrict core PMU bypass to --cputype option Ian Rogers
2026-06-16 1:44 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 02/12] perf test: Truncate test description to fit terminal width Ian Rogers
2026-06-16 1:38 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 03/12] perf tests workloads: Support sub-second durations in noploop and thloop Ian Rogers
2026-06-16 1:35 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 04/12] perf tests: Add robust record retry helper and use subsecond workloads Ian Rogers
2026-06-16 1:38 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 05/12] perf tests: Skip metrics validation if system-wide recording lacks permission Ian Rogers
2026-06-16 1:41 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 06/12] perf tests: Fix Python JIT dump profiling test failure Ian Rogers
2026-06-16 1:39 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 07/12] perf tests: Fix flakiness in trace record and replay test Ian Rogers
2026-06-16 1:42 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 08/12] perf tests: Fix flakiness in BPF counters test on hybrid systems Ian Rogers
2026-06-16 1:35 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 09/12] perf tests: Fix flakiness in branch stack sampling tests Ian Rogers
2026-06-16 1:27 ` [PATCH v1 10/12] perf tests: Speed up off-cpu profiling tests Ian Rogers
2026-06-16 1:41 ` sashiko-bot
2026-06-16 1:27 ` [PATCH v1 11/12] perf tests: Speed up lock contention analysis shell test Ian Rogers
2026-06-16 1:27 ` [PATCH v1 12/12] perf tests: Speed up metrics checking shell tests Ian Rogers
2026-06-16 6:13 ` [PATCH v2 00/12] perf tests: Enhance robustness, speed up execution, and fix flakiness Ian Rogers
2026-06-16 6:13 ` [PATCH v2 01/12] perf parse-events: Restrict core PMU bypass to --cputype option Ian Rogers
2026-06-16 6:31 ` sashiko-bot
2026-06-16 15:14 ` Arnaldo Carvalho de Melo
2026-06-16 15:17 ` Arnaldo Carvalho de Melo
2026-06-16 6:13 ` [PATCH v2 02/12] perf test: Truncate test description to fit terminal width Ian Rogers
2026-06-16 6:24 ` sashiko-bot
2026-06-16 15:25 ` Arnaldo Carvalho de Melo [this message]
2026-06-16 6:13 ` [PATCH v2 03/12] perf tests workloads: Support sub-second durations in noploop and thloop Ian Rogers
2026-06-16 6:22 ` sashiko-bot
2026-06-16 6:13 ` [PATCH v2 04/12] perf tests: Add robust record retry helper and use subsecond workloads Ian Rogers
2026-06-16 6:27 ` sashiko-bot
2026-06-16 6:13 ` [PATCH v2 05/12] perf tests: Skip metrics validation if system-wide recording lacks permission Ian Rogers
2026-06-16 6:13 ` [PATCH v2 06/12] perf tests: Fix Python JIT dump profiling test failure Ian Rogers
2026-06-16 6:27 ` sashiko-bot
2026-06-16 6:13 ` [PATCH v2 07/12] perf tests: Fix flakiness in trace record and replay test Ian Rogers
2026-06-16 6:27 ` sashiko-bot
2026-06-16 6:14 ` [PATCH v2 08/12] perf tests: Fix flakiness in BPF counters test on hybrid systems Ian Rogers
2026-06-16 6:14 ` [PATCH v2 09/12] perf tests: Fix flakiness in branch stack sampling tests Ian Rogers
2026-06-16 6:14 ` [PATCH v2 10/12] perf tests: Speed up off-cpu profiling tests Ian Rogers
2026-06-16 6:25 ` sashiko-bot
2026-06-16 6:14 ` [PATCH v2 11/12] perf tests: Speed up lock contention analysis shell test Ian Rogers
2026-06-16 6:14 ` [PATCH v2 12/12] perf tests: Speed up metrics checking shell tests Ian Rogers
2026-06-16 16:48 ` [PATCH v3 00/13] perf tests: Robustness and performance improvements Ian Rogers
2026-06-16 16:48 ` [PATCH v3 01/13] perf parse-events: Restrict core PMU bypass to --cputype option Ian Rogers
2026-06-16 16:48 ` [PATCH v3 02/13] perf test: Truncate test description to fit terminal width Ian Rogers
2026-06-16 16:48 ` [PATCH v3 03/13] perf tests workloads: Support sub-second durations in noploop and thloop Ian Rogers
2026-06-16 16:48 ` [PATCH v3 04/13] perf tests: Add robust record retry helper and use subsecond workloads Ian Rogers
2026-06-16 16:48 ` [PATCH v3 05/13] perf tests: Skip metrics validation if system-wide recording lacks permission Ian Rogers
2026-06-16 16:48 ` [PATCH v3 06/13] perf tests: Fix Python JIT dump profiling test failure Ian Rogers
2026-06-16 16:48 ` [PATCH v3 07/13] perf tests: Fix flakiness in trace record and replay test Ian Rogers
2026-06-16 16:48 ` [PATCH v3 08/13] perf tests: Fix flakiness in BPF counters test on hybrid systems Ian Rogers
2026-06-16 16:48 ` [PATCH v3 09/13] perf tests: Fix flakiness in branch stack sampling tests Ian Rogers
2026-06-16 16:48 ` [PATCH v3 10/13] perf tests: Speed up off-cpu profiling tests Ian Rogers
2026-06-16 16:48 ` [PATCH v3 11/13] perf tests: Speed up lock contention analysis shell test Ian Rogers
2026-06-16 16:48 ` [PATCH v3 12/13] perf tests: Speed up metrics checking shell tests Ian Rogers
2026-06-16 16:48 ` [PATCH v3 13/13] perf tests: Include error output for skipped tests in JUnit XML Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ajFrBwTzZuqpWPd1@x1 \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=thomas.falcon@intel.com \
--cc=tmricht@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox