From nobody Tue Nov 26 12:31:30 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0178183CA9 for ; Fri, 18 Oct 2024 05:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729230455; cv=none; b=LgIPXF4QxmJ5CgoKWzzuhxf6v0J8xHgiO6Oqw5SEvd+VYb1aAXmPPhJYAvY9t531THKT9wVe+yHAdFZy3qDeXD8V8wJE6Q5y4BtgB1UWUP9j+UGrQ6QSdnOpf/8YIT6It0o3Mmnimjuqu0ROBqwlIOBslgdwSpUWoJUzTD0umiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729230455; c=relaxed/simple; bh=fFas7LyqSjmG5V26rD2/CFaF2XrJIT7gW3QIZSxUtUU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=SiGOiYDQ88d1eGZD1xvWXKriZo4/yQnViVT8iRnoQMjsdksef7UlVjIv45xRm9cBjQVsQhkCKBzlqwdrbfrAghMbmovKelkw0OVr7jOdhPPcDNZGiflAohB4oYqwr1l7i/vne6WMSEQxatxJms168UFpOTfTpmSv2pifuPzuyTs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Iz/SkRpt; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Iz/SkRpt" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-690404fd230so36751667b3.3 for ; Thu, 17 Oct 2024 22:47:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729230453; x=1729835253; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7H4716CUp7wRIu/vgNl/76x7htTbrKtb+Q2pljLbUoA=; b=Iz/SkRpt+y9leMN/kflJf+5cBQd0solzwWHd6EnoR8YWI2s6EB8kkd8CXD9dwj7Ty1 KKMMGPDMp9k7SKXk5iHduGU0OjQVUhUDTzP7OihpVEvTUk4Ik60ooKWDvZJBx9By4mfC 9++J/LA2IJRVQPqPsrhObDI4xNH7ICTsoNobtjl0SBVSiVnmHoF5iQJbFlCTkGN8ZnXO 5YgNubzyqoWIhxMVvKRiLI7+GitZq2FMHjdKluvF7XBWN3wUWuET8pLuIsRnxJPfq7Vf 1ipKv31w+Zbkqf7OwUl77oxonjGLGiD9L4XNtL7vBorZkOlnYDz+PKo4dsyTuepQVLVC 7NHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729230453; x=1729835253; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7H4716CUp7wRIu/vgNl/76x7htTbrKtb+Q2pljLbUoA=; b=jpzfdJwPAiQaXFThAsa379ouP2cPo4tOZPRSPYcKuze9IB60obNCDwjfyAkNCN98/0 Z+yTg1dIBQfm5N+sExP1ICqSeAlEQ1rGmNxFJnPmYUu17Z8si5w3M+qxBPbKkLtOUvli oXJRJnrtHyDJKVfbjZUoVrDSQe8HZqLdTyk3YfYt9EIm7UtxKFJYaCeDcajsFAToWILy bWZLuo9Aso70Y0eIXeQppyEkIil6zqEwX6Yq3tpOCZZFPsT73sHghZWDFx6u6DmLFmAW 7lqjOCKRBANhfgF5may4PQ9MtRGRGhJGd8j/6LoT1g3Q/mgosMgbRntk43uAQPGGoSUk ZzIA== X-Forwarded-Encrypted: i=1; AJvYcCUUBACx+O27G4dT4BPSYohac5c+8wohHYfTsXr7rjpNSE9ZGXjeRF1KIiaEbpBIyJoqHzqku/KbUrh7hto=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1pj7Pm5rHVHaeh05KlS4+qs6fcoYzC7nUerFHEnnS9UQlMYx9 cdwvN+fX8d8EosSGWOflIivThefTgOFNaEE5Xm6vte2AHbVLfuySGIRthbdvSNFdLbmOwMX+DAn 3uKFGvw== X-Google-Smtp-Source: AGHT+IHrNwGQ65miZ1DrqGdwnyD++/1tfu2IOs+mARqDoQe1p6KCckIDzEp1Tmy2Msvr1EzURm1awJvJOTxP X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:30c5:9d92:bcd:7977]) (user=irogers job=sendgmr) by 2002:a05:690c:618a:b0:6e2:1713:bdb5 with SMTP id 00721157ae682-6e5bfd20ea6mr90897b3.5.1729230452936; Thu, 17 Oct 2024 22:47:32 -0700 (PDT) Date: Thu, 17 Oct 2024 22:47:12 -0700 In-Reply-To: <20241018054719.1004128-1-irogers@google.com> Message-Id: <20241018054719.1004128-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241018054719.1004128-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v3 2/9] perf test: Display number of active running tests From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Before polling or sleeping to wait for a test to complete, print out ": Running ( active)" where the number of active tests is determined by iterating over the tests and seeing which return false for check_if_command_finished. The line erasing and printing out only occur if the number of runnings tests changes to avoid the line flickering excessively. Knowing tests are running allows a user to know a test is running and in parallel mode how many of the tests are waiting to complete. If color mode is disabled then avoid displaying the "Running" message as deleting the line isn't reliable. Tested-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 93 ++++++++++++++++++++++----------- tools/perf/util/color.h | 1 + 2 files changed, 63 insertions(+), 31 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index 3b30f258c395..381363fc766a 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -243,7 +243,10 @@ static int run_test_child(struct child_process *proces= s) return -err; } =20 -static int print_test_result(struct test_suite *t, int i, int subtest, int= result, int width) +#define TEST_RUNNING -3 + +static int print_test_result(struct test_suite *t, int i, int subtest, int= result, int width, + int running) { if (has_subtests(t)) { int subw =3D width > 2 ? width - 2 : width; @@ -253,6 +256,9 @@ static int print_test_result(struct test_suite *t, int = i, int subtest, int resul pr_info("%3d: %-*s:", i + 1, width, test_description(t, subtest)); =20 switch (result) { + case TEST_RUNNING: + color_fprintf(stderr, PERF_COLOR_YELLOW, " Running (%d active)\n", runni= ng); + break; case TEST_OK: pr_info(" Ok\n"); break; @@ -274,14 +280,17 @@ static int print_test_result(struct test_suite *t, in= t i, int subtest, int resul return 0; } =20 -static int finish_test(struct child_test *child_test, int width) +static int finish_test(struct child_test **child_tests, int running_test, = int child_test_num, + int width) { + struct child_test *child_test =3D child_tests[running_test]; struct test_suite *t =3D child_test->test; int i =3D child_test->test_num; int subi =3D child_test->subtest; int err =3D child_test->process.err; - bool err_done =3D err <=3D 0; + bool err_done =3D false; struct strbuf err_output =3D STRBUF_INIT; + int last_running =3D -1; int ret; =20 /* @@ -295,7 +304,7 @@ static int finish_test(struct child_test *child_test, i= nt width) * Busy loop reading from the child's stdout/stderr that are set to be * non-blocking until EOF. */ - if (!err_done) + if (err > 0) fcntl(err, F_SETFL, O_NONBLOCK); if (verbose > 1) { if (has_subtests(t)) @@ -309,38 +318,60 @@ static int finish_test(struct child_test *child_test,= int width) .events =3D POLLIN | POLLERR | POLLHUP | POLLNVAL, }, }; - char buf[512]; - ssize_t len; - - /* Poll to avoid excessive spinning, timeout set for 100ms. */ - poll(pfds, ARRAY_SIZE(pfds), /*timeout=3D*/100); - if (!err_done && pfds[0].revents) { - errno =3D 0; - len =3D read(err, buf, sizeof(buf) - 1); - - if (len <=3D 0) { - err_done =3D errno !=3D EAGAIN; - } else { - buf[len] =3D '\0'; - if (verbose > 1) - fprintf(stdout, "%s", buf); - else + if (perf_use_color_default) { + int running =3D 0; + + for (int y =3D running_test; y < child_test_num; y++) { + if (check_if_command_finished(&child_tests[y]->process) =3D=3D 0) + running++; + } + if (running !=3D last_running) { + if (last_running !=3D -1) { + /* + * Erase "Running (.. active)" line + * printed before poll/sleep. + */ + fprintf(debug_file(), PERF_COLOR_DELETE_LINE); + } + print_test_result(t, i, subi, TEST_RUNNING, width, running); + last_running =3D running; + } + } + + err_done =3D true; + if (err <=3D 0) { + /* No child stderr to poll, sleep for 10ms for child to complete. */ + usleep(10 * 1000); + } else { + /* Poll to avoid excessive spinning, timeout set for 100ms. */ + poll(pfds, ARRAY_SIZE(pfds), /*timeout=3D*/100); + if (pfds[0].revents) { + char buf[512]; + ssize_t len; + + len =3D read(err, buf, sizeof(buf) - 1); + + if (len > 0) { + err_done =3D false; + buf[len] =3D '\0'; strbuf_addstr(&err_output, buf); + } } } + if (err_done) + err_done =3D check_if_command_finished(&child_test->process); + } + if (perf_use_color_default && last_running !=3D -1) { + /* Erase "Running (.. active)" line printed before poll/sleep. */ + fprintf(debug_file(), PERF_COLOR_DELETE_LINE); } /* Clean up child process. */ ret =3D finish_command(&child_test->process); - if (verbose =3D=3D 1 && ret =3D=3D TEST_FAIL) { - /* Add header for test that was skipped above. */ - if (has_subtests(t)) - pr_info("%3d.%1d: %s:\n", i + 1, subi + 1, test_description(t, subi)); - else - pr_info("%3d: %s:\n", i + 1, test_description(t, -1)); + if (verbose > 1 || (verbose =3D=3D 1 && ret =3D=3D TEST_FAIL)) fprintf(stderr, "%s", err_output.buf); - } + strbuf_release(&err_output); - print_test_result(t, i, subi, ret, width); + print_test_result(t, i, subi, ret, width, /*running=3D*/0); if (err > 0) close(err); return 0; @@ -356,7 +387,7 @@ static int start_test(struct test_suite *test, int i, i= nt subi, struct child_tes pr_debug("--- start ---\n"); err =3D test_function(test, subi)(test, subi); pr_debug("---- end ----\n"); - print_test_result(test, i, subi, err, width); + print_test_result(test, i, subi, err, width, /*running=3D*/0); return 0; } =20 @@ -381,7 +412,7 @@ static int start_test(struct test_suite *test, int i, i= nt subi, struct child_tes err =3D start_command(&(*child)->process); if (err || !sequential) return err; - return finish_test(*child, width); + return finish_test(child, /*running_test=3D*/0, /*child_test_num=3D*/1, w= idth); } =20 #define for_each_test(j, k, t) \ @@ -466,7 +497,7 @@ static int __cmd_test(int argc, const char *argv[], str= uct intlist *skiplist) } for (i =3D 0; i < child_test_num; i++) { if (!sequential) { - int ret =3D finish_test(child_tests[i], width); + int ret =3D finish_test(child_tests, i, child_test_num, width); =20 if (ret) return ret; diff --git a/tools/perf/util/color.h b/tools/perf/util/color.h index aecf56dae73f..dfc897a6fa20 100644 --- a/tools/perf/util/color.h +++ b/tools/perf/util/color.h @@ -22,6 +22,7 @@ #define MIN_GREEN 0.5 #define MIN_RED 5.0 =20 +#define PERF_COLOR_DELETE_LINE "\033[A\33[2K\r" /* * This variable stores the value of color.ui */ --=20 2.47.0.105.g07ac214952-goog