From nobody Sun Feb 8 07:17:14 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 C1D1737169 for ; Mon, 1 Jul 2024 04:42:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719808964; cv=none; b=IM1DJLweHpBENSVi5w8/075P1Qiyy10dGzhkEnQcqWjzZ6TnB8yNu6S5z39UP0noYeDKpQei9RDpamAQbrq9Ah0Idu+iLHB3MHk0X3hedRhG94/sC1YWWAkBQWnbU3FdmQRew9yr6syrodmUSnwnSHDC5Je146vD4soDt/DUpc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719808964; c=relaxed/simple; bh=3WSw+LzwDfsuTLO07J/Gfgu67U+bggq7nxlP2SFbdkc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=grj8SrB8DhtLG/sAPjegjes5O3JipgrBAK4cLPenMVq78ItS3zPFp0QuZyEBArvAScrRnL/UKbngvGBO7xC8/dIy+S+SsIGXU77n+nDv1tCVj1AldowAf0Acnm3VgTuD7Gi+r2PT4M/Eol/YeksYd/Y567uMsxe/OyWzsUlRAcY= 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=cWQpvF4T; arc=none smtp.client-ip=209.85.215.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="cWQpvF4T" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-6507e2f0615so1545438a12.1 for ; Sun, 30 Jun 2024 21:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719808962; x=1720413762; 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=hJaevJbd0eQTHDa7xn1OIMkQuKnrhSd1AMXiSY5R5Xk=; b=cWQpvF4TR0LQ91aZUrUG80AKl+7sQa9kdkGKiAH9uI16gpjdBczaRLIsJ9rSJgkDzx KEckuB61p3wpyuCfIms4QVx7MOsHmey8LfY53Vc2aMEhPlNxaHJldMgcIML0RrELdHtb qlli5PELIJbUWRviMItJREKEIRgrfMqXjABSMTECSHbPWjvDUW5Pldeio641SielBE+l cmYtdAZGELWhdSKVNxq64wiNfIesX7/KjcbnBopigwYEeEkqhGPtP8y42pio4KKvtc6n eZLwBte1a5zsAUqmKDA/xzEF/G8qtwEZsnOkxxZatNAk+V3VjwTMxujfsTcEHGUaXR6J fpDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719808962; x=1720413762; 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=hJaevJbd0eQTHDa7xn1OIMkQuKnrhSd1AMXiSY5R5Xk=; b=xNUCXwTlMOuzdwVGzthkPVRy/G5bZzhovYQwKpe+LWrwiBiula0+lHbsNv9daKN4Gw eErgr7kRBzYkKlWbY7axH1wVbEHyeOM1SC21y6I1oJ/mbu5+u3Aua1651VxwfpHL+jwH V7BfQBjs3UAu5yTPYzlcGrYzDgzDqzVU5mYMwUk/b3NzRuRcd9qBYSI9MEsYFipLXhYo wi3dqzZhanhFeYvfJGTuGeqP2GU6Kfx54DaaZ3+OkJXMrEMtkeH4TbCoLWO0osWtF3Om 4Za+fNGexhJ9IM80h63kbRZbcjulcHJG/r2b/FxhuHP9ucP7Z0LlwgR/eGi8WYb8rhFu zE0Q== X-Forwarded-Encrypted: i=1; AJvYcCU2sH+fPnCp8bhmV2AbAlzHoszku46mVLBOOIYp7SIzR1emgduzdEP4Ln4Un5TubhpmocSe89a5iufSY8o4n2gARMi/tPuqH5NXvhAm X-Gm-Message-State: AOJu0YzwoxyMmutVYpnvvPPKuVIsAHNgYPqLum4Ny96RxZGfbkQqI5D8 wj2VPc8WyVOyC6Y9//PfsQKlTu2SFuHf6VgLToeTKW06AeOVbVltXHxdngVJwUf1eII7bcKePWH O1shyeg== X-Google-Smtp-Source: AGHT+IEIzUWDNM21Dmwx3C1YCGQLf5z9VbV+vSSee8+oDr/p/4o0NWDbt/9UqSMxCfs86165f3MQN29AeBtQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7bcd:6ae9:263e:82ff]) (user=irogers job=sendgmr) by 2002:a63:77cc:0:b0:6e4:d411:7c64 with SMTP id 41be03b00d2f7-73cf238df43mr12182a12.3.1719808961796; Sun, 30 Jun 2024 21:42:41 -0700 (PDT) Date: Sun, 30 Jun 2024 21:42:35 -0700 In-Reply-To: <20240701044236.475098-1-irogers@google.com> Message-Id: <20240701044236.475098-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240701044236.475098-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Subject: [PATCH v2 1/2] tools subcmd: Add non-waitpid check_if_command_finished() 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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Using waitpid can cause stdout/stderr of the child process to be lost. Use Linux's /prod//status file to determine if the process has reached the zombie state. Use the 'status' file rather than 'stat' to avoid issues around skipping the process name. Signed-off-by: Ian Rogers --- tools/lib/subcmd/run-command.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/lib/subcmd/run-command.c b/tools/lib/subcmd/run-command.c index 4e3a557a2f37..ec06683e77a0 100644 --- a/tools/lib/subcmd/run-command.c +++ b/tools/lib/subcmd/run-command.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -217,8 +218,40 @@ static int wait_or_whine(struct child_process *cmd, bo= ol block) =20 int check_if_command_finished(struct child_process *cmd) { +#ifdef __linux__ + char filename[FILENAME_MAX + 12]; + char status_line[256]; + FILE *status_file; + + /* + * Check by reading /proc//status as calling waitpid causes + * stdout/stderr to be closed and data lost. + */ + sprintf(filename, "/proc/%d/status", cmd->pid); + status_file =3D fopen(filename, "r"); + if (status_file =3D=3D NULL) { + /* Open failed assume finish_command was called. */ + return true; + } + while (fgets(status_line, sizeof(status_line), status_file) !=3D NULL) { + char *p; + + if (strncmp(status_line, "State:", 6)) + continue; + + fclose(status_file); + p =3D status_line + 6; + while (isspace(*p)) + p++; + return *p =3D=3D 'Z'; + } + /* Read failed assume finish_command was called. */ + fclose(status_file); + return true; +#else wait_or_whine(cmd, /*block=3D*/false); return cmd->finished; +#endif } =20 int finish_command(struct child_process *cmd) --=20 2.45.2.803.g4e1b14247a-goog From nobody Sun Feb 8 07:17:14 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 1A3064597B for ; Mon, 1 Jul 2024 04:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719808966; cv=none; b=Qd2CnRV9ZAWXZ64qDwHqVVgYqYwnZFfl1cDVn6HordHKz5jrU2A1KAwESj4fI7JKCxnXLk5IFUBhqsvZ0CEX75QHheLjfAC4nGih5sN87UYU9p1yJ1eqgk6YHfm5lE21xvUuu2AIqHyvgojMBKS2zyK82lVOSQkFB/k33qlRyBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719808966; c=relaxed/simple; bh=E1yTNX0dXLqWoEgNrMX++wv2NEf2cNCY9AWmz0zGb1c=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JfUxyQqMpZgb9tSmV6bqQZjeWkkv1btzhIy32XUTZ9lyRdBubpb5kbkPZ7w8oPBjWE+ClN7SKf8H8RTUtQhX+pD6/DDOOzBpkQ1BoNgIwmsCMbkdAe1n5UqM1ihYRV0M1IYR1w2XCVsYfLDClVr0QZluFOQFZWlFlcJf0bEYBmQ= 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=JYbkvPCT; arc=none smtp.client-ip=209.85.215.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="JYbkvPCT" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-71a56a55252so2448662a12.3 for ; Sun, 30 Jun 2024 21:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719808964; x=1720413764; 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=qpc0+W6wY0DZse4YqiD5xoHyNTb+DGq1jJFsO9RewJY=; b=JYbkvPCTS25KAdGLH7pVkhPjjAlkzYr+WpMIU9qPHMnUhZ4ICf12TFmz0lWmmAuLqH kGkZh3KAU6VKrNel271GmhsdxKdNHLYGMT5cI5smfbwfNBJjbUXHgQB1dPArvXSRMBZu r6L7hltK7lQWwtJH0Y3yeI6tOfzVfCUFaYq9SKYRqqT3XpHd4GvPLrCTmf+KZmoDQQR3 stc/BE6tM4gEeQRzzxkAIUglRjy6NzARTQZ9jesrmI8gf7wq4M49hITNfU+ZQbUb1vS3 axaTgVtBWfvupEAO1OaCI1HChUq/6h2wXWgOW51Spl/iKd2p+amudR5hQdmqRPr/OLMJ Mv8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719808964; x=1720413764; 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=qpc0+W6wY0DZse4YqiD5xoHyNTb+DGq1jJFsO9RewJY=; b=peXaKXuEuFusk0Fhhq0A5OiAviDdyl3DR+0N5RzXETtBk4c2+miZuxRi06nq4Kd8XO aHlC0vtPMJRQTUoX/WLF7UOzf5XsyZkOZw3wRi2epitvo2zum1JBpJUFmDIb1JpTQi/o yeGqMWzpglHdktfD4sOkurHsFmHEIF6wdwdbfLeK9QRpRYCH3wdkuxAxnWWMebWVs/bR TP5abYO5dcD96nzsAqS/ks5QDbwN+HUTnt0Og28G2BwiBX3VEiRSXCxxit+dIMPlkoil voB6xhTYsyXBhHqD5pOmSiBinLfsK/1VwocNmcj8kznEMulqf3J2V/ePfTPUIvC00JYu Ze9Q== X-Forwarded-Encrypted: i=1; AJvYcCVJmWV7Wh9Kss/qIQQ3XqptHst39xAU2AAGm814R/ya/4xckKs1ebInRxi+K16/8wL/7Pv9YpgXM1Uh7yTrHav4uFe7p0SAzuVMi3sx X-Gm-Message-State: AOJu0YyHgywx3FyYhTjahTFb1/Uiv/fjlwQXt2swN65yBTrgadGZH90f gcWpSAzTusY/VMXHGtwh19A4E6/nmZbs8weJXCX+rrWv5EeS63to7duSdD2qrhf9ZWgLRop4jkr uM+y1nA== X-Google-Smtp-Source: AGHT+IGw+TlXIzVyrzKmNehwKL4ocMvf8JKml3ao1L9vvx3M6JYQQgnsvntxw6Ya/r18frr7R0Xwpt5wJqkL X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7bcd:6ae9:263e:82ff]) (user=irogers job=sendgmr) by 2002:a63:2b48:0:b0:6bc:b210:c1dd with SMTP id 41be03b00d2f7-73cfd125c80mr17613a12.8.1719808964338; Sun, 30 Jun 2024 21:42:44 -0700 (PDT) Date: Sun, 30 Jun 2024 21:42:36 -0700 In-Reply-To: <20240701044236.475098-1-irogers@google.com> Message-Id: <20240701044236.475098-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: <20240701044236.475098-1-irogers@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Subject: [PATCH v2 2/2] perf test: Display number of remaining 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 , 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 ( remaining)" where the number of remaining tests is determined by iterating over the remaining tests and seeing which return true for check_if_command_finished. After the delay, erase the line and either update it with the new number of remaining tests, or print the test's result. This allows a user to know a test is running and in parallel mode (default) how many of the tests are waiting to complete. If color mode is disabled then avoid displaying the "Running" message. Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 77 ++++++++++++++++++++++----------- tools/perf/util/color.h | 1 + 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index c3d84b67ca8e..23be9139f229 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -241,7 +241,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 remaining) { if (has_subtests(t)) { int subw =3D width > 2 ? width - 2 : width; @@ -251,6 +254,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 remaining)\n", re= maining); + break; case TEST_OK: pr_info(" Ok\n"); break; @@ -272,13 +278,15 @@ 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 ret; =20 @@ -293,7 +301,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)) @@ -307,29 +315,48 @@ 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 tests_in_progress =3D running_test; + + for (int y =3D running_test; y < child_test_num; y++) { + if (check_if_command_finished(&child_tests[y]->process)) + tests_in_progress++; + } + print_test_result(t, i, subi, TEST_RUNNING, width, + child_test_num - tests_in_progress); + } + + 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) { + /* Erase "Running (.. remaining)" 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) { + if (verbose > 1 || (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)); @@ -338,7 +365,7 @@ static int finish_test(struct child_test *child_test, i= nt width) 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, /*remaining=3D*/0); if (err > 0) close(err); return 0; @@ -354,7 +381,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, /*remaining=3D*/0); return 0; } =20 @@ -379,7 +406,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) \ @@ -464,7 +491,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 01f7bed21c9b..4b9f8d5d4439 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.45.2.803.g4e1b14247a-goog