From: Gabriele Monaco <gmonaco@redhat.com>
To: Nam Cao <namcao@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>,
linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: john.ogness@linutronix.de
Subject: Re: [PATCH v2 07/22] verification/dot2k: Replace is_container() hack with subparsers
Date: Fri, 11 Apr 2025 10:56:32 +0200 [thread overview]
Message-ID: <03f2bf17986dd2811e02bace17fadf6f36c7080a.camel@redhat.com> (raw)
In-Reply-To: <76c013727c81db5979f8f22c41794371bbaa5ba5.1744355018.git.namcao@linutronix.de>
On Fri, 2025-04-11 at 09:37 +0200, Nam Cao wrote:
> 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.
>
Yeah, that's much neater, thanks!
Reviewed-by: Gabriele Monaco <gmonaco@redhat.com>
> 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
>
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> ---
> tools/verification/dot2/dot2/dot2k.py | 2 +-
> tools/verification/dot2/dot2k | 37 +++++++++++++++----------
> --
> 2 files changed, 21 insertions(+), 18 deletions(-)
>
> diff --git a/tools/verification/dot2/dot2/dot2k.py
> b/tools/verification/dot2/dot2/dot2k.py
> index 0922754454b9..9ec99e297012 100644
> --- a/tools/verification/dot2/dot2/dot2k.py
> +++ b/tools/verification/dot2/dot2/dot2k.py
> @@ -19,7 +19,7 @@ class dot2k(Dot2c):
> monitor_type = "per_cpu"
>
> def __init__(self, file_path, MonitorType, extra_params={}):
> - self.container = extra_params.get("container")
> + self.container = extra_params.get("subcmd") == "container"
> self.parent = extra_params.get("parent")
> self.__fill_rv_templates_dir()
>
> 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__ == '__main__':
> import argparse
> import sys
>
> - def is_container():
> - """Should work even before parsing the arguments"""
> - return "-c" in sys.argv or "--container" in sys.argv
> -
> parser = argparse.ArgumentParser(description='transform .dot
> file into kernel rv monitor')
> - parser.add_argument('-d', "--dot", dest="dot_file", required=not
> is_container())
> - parser.add_argument('-t', "--monitor_type", dest="monitor_type",
> required=not is_container(),
> - help=f"Available options: {',
> '.join(dot2k.monitor_types.keys())}")
> - parser.add_argument('-n', "--model_name", dest="model_name",
> required=is_container())
> parser.add_argument("-D", "--description", dest="description",
> required=False)
> parser.add_argument("-a", "--auto_patch", dest="auto_patch",
> action="store_true", required=False,
> help="Patch the kernel in place")
> - parser.add_argument("-p", "--parent", dest="parent",
> - required=False, help="Create a monitor
> nested to parent")
> - parser.add_argument("-c", "--container", dest="container",
> - action="store_true", required=False,
> - help="Create an empty monitor to be used as
> a container")
> +
> + subparsers = parser.add_subparsers(dest="subcmd", required=True)
> +
> + monitor_parser = subparsers.add_parser("monitor")
> + monitor_parser.add_argument('-n', "--model_name",
> dest="model_name")
> + monitor_parser.add_argument("-p", "--parent", dest="parent",
> + required=False, help="Create a
> monitor nested to parent")
> + monitor_parser.add_argument('-d', "--dot", dest="dot_file")
> + monitor_parser.add_argument('-t', "--monitor_type",
> dest="monitor_type",
> + help=f"Available options: {',
> '.join(dot2k.monitor_types.keys())}")
> +
> + container_parser = subparsers.add_parser("container")
> + container_parser.add_argument('-n', "--model_name",
> dest="model_name", required=True)
> +
> params = parser.parse_args()
>
> - if not is_container():
> - print("Opening and parsing the dot file %s" %
> params.dot_file)
> try:
> - monitor=dot2k(params.dot_file, params.monitor_type,
> vars(params))
> + if params.subcmd == "monitor":
> + print("Opening and parsing the dot file %s" %
> params.dot_file)
> + monitor = dot2k(params.dot_file, params.monitor_type,
> vars(params))
> + else:
> + monitor = dot2k(None, None, vars(params))
> except Exception as e:
> print('Error: '+ str(e))
> print("Sorry : :-(")
> @@ -45,7 +48,7 @@ if __name__ == '__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 == "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())
next prev parent reply other threads:[~2025-04-11 8:56 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 7:37 [PATCH v2 00/22] RV: Linear temporal logic monitors for RT application Nam Cao
2025-04-11 7:37 ` [PATCH v2 01/22] rv: Fix out-of-bound memory access in rv_is_container_monitor() Nam Cao
2025-04-11 7:37 ` [PATCH v2 02/22] rv: Add #undef TRACE_INCLUDE_FILE Nam Cao
2025-04-11 7:37 ` [PATCH v2 03/22] rv: Let the reactors take care of buffers Nam Cao
2025-04-11 8:39 ` Gabriele Monaco
2025-04-15 9:32 ` Petr Mladek
2025-04-15 9:53 ` Nam Cao
2025-04-11 7:37 ` [PATCH v2 04/22] verification/dot2k: Make it possible to invoke dot2k without installation Nam Cao
2025-04-11 9:23 ` Gabriele Monaco
2025-04-11 14:04 ` Nam Cao
2025-04-11 14:56 ` Gabriele Monaco
2025-04-11 7:37 ` [PATCH v2 05/22] verification/dot2k: Make a separate dot2k_templates/Kconfig_container Nam Cao
2025-04-11 8:54 ` Gabriele Monaco
2025-04-11 7:37 ` [PATCH v2 06/22] verification/dot2k: Remove __buff_to_string() Nam Cao
2025-04-11 8:53 ` Gabriele Monaco
2025-04-11 7:37 ` [PATCH v2 07/22] verification/dot2k: Replace is_container() hack with subparsers Nam Cao
2025-04-11 8:56 ` Gabriele Monaco [this message]
2025-04-11 7:37 ` [PATCH v2 08/22] rv: rename CONFIG_DA_MON_EVENTS to CONFIG_RV_MON_EVENTS Nam Cao
2025-04-11 10:37 ` Gabriele Monaco
2025-04-11 7:37 ` [PATCH v2 09/22] verification/dot2k: Prepare the frontend for LTL inclusion Nam Cao
2025-04-11 7:37 ` [PATCH v2 10/22] Documentation/rv: Prepare monitor synthesis document " Nam Cao
2025-04-11 9:28 ` Gabriele Monaco
2025-04-11 7:37 ` [PATCH v2 11/22] verification/rvgen: Prepare the templates " Nam Cao
2025-04-11 7:37 ` [PATCH v2 12/22] verification/rvgen: Restructure the classes to prepare " Nam Cao
2025-04-11 7:37 ` [PATCH v2 13/22] rv: Add support for LTL monitors Nam Cao
2025-04-11 11:17 ` Gabriele Monaco
2025-04-11 14:15 ` Nam Cao
2025-04-15 13:22 ` Gabriele Monaco
2025-04-16 3:55 ` Nam Cao
2025-04-11 7:37 ` [PATCH v2 14/22] rv: Add rtapp container monitor Nam Cao
2025-04-11 7:37 ` [PATCH v2 15/22] x86/tracing: Remove redundant trace_pagefault_key Nam Cao
2025-04-11 7:37 ` [PATCH v2 16/22] x86/tracing: Move page fault trace points to generic Nam Cao
2025-04-11 7:37 ` [PATCH v2 17/22] arm64: mm: Add page fault trace points Nam Cao
2025-04-11 7:37 ` [PATCH v2 18/22] riscv: " Nam Cao
2025-04-11 7:37 ` [PATCH v2 19/22] rv: Add rtapp_pagefault monitor Nam Cao
2025-04-15 12:31 ` Gabriele Monaco
2025-04-15 12:38 ` Nam Cao
2025-04-15 12:47 ` Gabriele Monaco
2025-04-11 7:37 ` [PATCH v2 20/22] rv: Add rtapp_sleep monitor Nam Cao
2025-04-11 7:37 ` [PATCH v2 21/22] rv: Add documentation for rtapp monitor Nam Cao
2025-04-15 13:12 ` Gabriele Monaco
2025-04-16 4:37 ` Nam Cao
2025-04-11 7:37 ` [PATCH v2 22/22] rv: Allow to configure the number of per-task monitor Nam Cao
2025-04-11 12:31 ` Gabriele Monaco
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=03f2bf17986dd2811e02bace17fadf6f36c7080a.camel@redhat.com \
--to=gmonaco@redhat.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=namcao@linutronix.de \
--cc=rostedt@goodmis.org \
/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;
as well as URLs for NNTP newsgroup(s).