From nobody Mon Oct 6 03:11:22 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BB7225B301 for ; Fri, 25 Jul 2025 20:34:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753475659; cv=none; b=jNySdnrjgGFPhOC66c/UAhuUUH4XBKkpnitjw8AnHy3yRfGMBtgIPVk6lPN5tsRWyfIpagTtcV/j0paRdWqOJ+A4oTpNa12dE4GilIYsD0c2P53AnSE6EIS9DP6ptMBw7wkPnpI68L9/sPS6ZEqCxZNQ8o1rPFc6Xg11NcUq6+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753475659; c=relaxed/simple; bh=+9pg9Dd6aGe5iyXDhhHxg3GB3DTvajjJM8WZNONOvJs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=g8V2PULbuyL1hWiz83JTpe5DO3ULo4Q0NiWb+qq/laz12GfYVhvNAhNVg9P/NerXokjsPwBj8FEKonmfH4vWdRI6opvyjCy7goPKfky0hv6sNOcsrUL7yZ+gvCGy4Vl5bwZUGjdHgMyqGOg2CQ0KIcr9CD+HzCtaitqNv0Nul4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T5KFRLHI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T5KFRLHI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9D0FC4CEEF; Fri, 25 Jul 2025 20:34:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753475659; bh=+9pg9Dd6aGe5iyXDhhHxg3GB3DTvajjJM8WZNONOvJs=; h=Date:From:To:Cc:Subject:References:From; b=T5KFRLHITpXBupmdmBL8oLBAPdspJbTfR/4pY5ms+wjiylUYFPSmuesmW9MwqBdRm sTvfIEHxQhlM1BNgjHmGVU+QnPPDB1quONoW/fEAzbEzeEuKu8uexHf9nmRA2faENu YUUV34Vxpwy7zmIjn3V24MSIn5D9a7xlRdW77a5QfmVD6Z0UVtuB6Wb/ASXCuBZm5P rOTtK6k8pOeLzlemIYmmu73ZyxKIKAH0Pbjux6xsMPuAqE0sa4V7bGuSMi7416kWBl 6sIbIDYUKfZB78q60Y0iBk0ozOaR5JlBq2tlc4EfGCi/bapUmVDfVeZSq/eAcqYXxa BGLjVk8eiv+oQ== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1ufP7Z-00000001Qeo-0Mt0; Fri, 25 Jul 2025 16:34:25 -0400 Message-ID: <20250725203424.945032683@kernel.org> User-Agent: quilt/0.68 Date: Fri, 25 Jul 2025 16:34:03 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Tomas Glozar , John Kacur , Masami Hiramatsu , Mathieu Desnoyers , Gabriele Monaco , Nam Cao Subject: [for-next][PATCH 06/25] verification/dot2k: Replace is_container() hack with subparsers References: <20250725203357.087558746@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Nam Cao dot2k is used for both generating deterministic automaton (DA) monitor and generating container monitor. Generating DA monitor and generating container requires different parameters. This is implemented by peeking at sys.argv and check whether "--container" is specified, and use that information to make some parameters optional or required. This works, but is quite hacky and ugly. Replace this hack with Python's built-in subparsers. The old commands: python3 dot2/dot2k -d wip.dot -t per_cpu python3 dot2/dot2k -n sched --container are equivalent to the new commands: python3 dot2/dot2k monitor -d wip.dot -t per_cpu python3 dot2/dot2k container -n sched Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Link: https://lore.kernel.org/23c4e3c6e10c39e86d8e6a289208dde407efc4a8.1751= 634289.git.namcao@linutronix.de Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao Signed-off-by: Steven Rostedt (Google) --- tools/verification/dot2/dot2k | 37 +++++++++++++++++--------------- tools/verification/dot2/dot2k.py | 2 +- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tools/verification/dot2/dot2k b/tools/verification/dot2/dot2k index 767064f415e7..133fb17d9d47 100644 --- a/tools/verification/dot2/dot2k +++ b/tools/verification/dot2/dot2k @@ -13,30 +13,33 @@ if __name__ =3D=3D '__main__': import argparse import sys =20 - def is_container(): - """Should work even before parsing the arguments""" - return "-c" in sys.argv or "--container" in sys.argv - parser =3D argparse.ArgumentParser(description=3D'transform .dot file = into kernel rv monitor') - parser.add_argument('-d', "--dot", dest=3D"dot_file", required=3Dnot i= s_container()) - parser.add_argument('-t', "--monitor_type", dest=3D"monitor_type", req= uired=3Dnot is_container(), - help=3Df"Available options: {', '.join(dot2k.monit= or_types.keys())}") - parser.add_argument('-n', "--model_name", dest=3D"model_name", require= d=3Dis_container()) parser.add_argument("-D", "--description", dest=3D"description", requi= red=3DFalse) parser.add_argument("-a", "--auto_patch", dest=3D"auto_patch", action=3D"store_true", required=3DFalse, help=3D"Patch the kernel in place") - parser.add_argument("-p", "--parent", dest=3D"parent", - required=3DFalse, help=3D"Create a monitor nested = to parent") - parser.add_argument("-c", "--container", dest=3D"container", - action=3D"store_true", required=3DFalse, - help=3D"Create an empty monitor to be used as a co= ntainer") + + subparsers =3D parser.add_subparsers(dest=3D"subcmd", required=3DTrue) + + monitor_parser =3D subparsers.add_parser("monitor") + monitor_parser.add_argument('-n', "--model_name", dest=3D"model_name") + monitor_parser.add_argument("-p", "--parent", dest=3D"parent", + required=3DFalse, help=3D"Create a monitor= nested to parent") + monitor_parser.add_argument('-d', "--dot", dest=3D"dot_file") + monitor_parser.add_argument('-t', "--monitor_type", dest=3D"monitor_ty= pe", + help=3Df"Available options: {', '.join(dot= 2k.monitor_types.keys())}") + + container_parser =3D subparsers.add_parser("container") + container_parser.add_argument('-n', "--model_name", dest=3D"model_name= ", required=3DTrue) + params =3D parser.parse_args() =20 - if not is_container(): - print("Opening and parsing the dot file %s" % params.dot_file) try: - monitor=3Ddot2k(params.dot_file, params.monitor_type, vars(params)) + if params.subcmd =3D=3D "monitor": + print("Opening and parsing the dot file %s" % params.dot_file) + monitor =3D dot2k(params.dot_file, params.monitor_type, vars(p= arams)) + else: + monitor =3D dot2k(None, None, vars(params)) except Exception as e: print('Error: '+ str(e)) print("Sorry : :-(") @@ -45,7 +48,7 @@ if __name__ =3D=3D '__main__': print("Writing the monitor into the directory %s" % monitor.name) monitor.print_files() print("Almost done, checklist") - if not is_container(): + if params.subcmd =3D=3D "monitor": print(" - Edit the %s/%s.c to add the instrumentation" % (monitor= .name, monitor.name)) print(monitor.fill_tracepoint_tooltip()) print(monitor.fill_makefile_tooltip()) diff --git a/tools/verification/dot2/dot2k.py b/tools/verification/dot2/dot= 2k.py index 0922754454b9..9ec99e297012 100644 --- a/tools/verification/dot2/dot2k.py +++ b/tools/verification/dot2/dot2k.py @@ -19,7 +19,7 @@ class dot2k(Dot2c): monitor_type =3D "per_cpu" =20 def __init__(self, file_path, MonitorType, extra_params=3D{}): - self.container =3D extra_params.get("container") + self.container =3D extra_params.get("subcmd") =3D=3D "container" self.parent =3D extra_params.get("parent") self.__fill_rv_templates_dir() =20 --=20 2.47.2