From patchwork Wed Apr 16 06:51:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 14053361 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 898D922D4D9; Wed, 16 Apr 2025 06:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744786322; cv=none; b=kNya+5M+n/iL2n8A9J6yX5KJji31Cor0Q99jVDu/NQFqRBO44cZc8+IH2hKOkecLNzd9WLm5O3TUn4VA42csY6iAY7fjN++QStnZuWQLOiH/Qjm7OMHm6G2LaLCeTh4jbIy1QcUO7sR5Mw9fQ9CoDLIANudKRava1mtTJmwG/p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744786322; c=relaxed/simple; bh=H9V8DEOULiOnbQER9jdq86jI9UV0AVKo/mqnQ8wukQU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QaL2LBH9gNEFo/hYt4nqtZ+yawnGBnR9NQ/tMWTBNX7IN9AqxJ0VCZS6I/fitSuKCu3QYEk4jEY4dUvfWApmGKx5Hf1d0JNoDe5U1vUFCa3K6gOMaGdzmjuV8hXMkuRkzJQk3eP/u+i6A+6/7o3NHaAkV5tGfSdrAEFJxFLjZzU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=U9z6yc/O; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0lDo9cQv; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="U9z6yc/O"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0lDo9cQv" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744786317; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CbJkEpwB3OdGpjoifJXvu2A5D6lki3gos/XOzAV2UjA=; b=U9z6yc/O5uV0Gs51CV4au27gYHgXZOcZ2ZEsY+HB36wMZLYfzljK1Q9aB6MyMouqYeVVS+ EAR62rAGYg7055AtQ7fkrXtE6TtcM/aJ/AQ2DLmYJdUHcwnwWa0Jmk92Gip9kNkwUXfdKJ L0ri+TJq0nxNtEYWijlb8riCLLHSWIaWp/kb92ZLgC3QVWb8CJOtokKlaac9sYASeMrOit HAzCjvrImkq1k8I8rGikpEGo0KDm7IjG3z8TKH1UVcZKKxVHzUlxxa6ErHAjnHzjxjpp37 jZuVTB/qb9QtHS9XjgdC7NUkLxhDgpi6nanMq1vOx7rmv+WpJKzTI3wBljGpHg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744786317; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CbJkEpwB3OdGpjoifJXvu2A5D6lki3gos/XOzAV2UjA=; b=0lDo9cQvyKyTQ3/ixTggGfR/aQlbQci6IPHnPXHpBzFk7QSExed2LzmIbEp4BPqpH7lWkV OvA1UaQawpJQYXCQ== To: Steven Rostedt , Gabriele Monaco , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: john.ogness@linutronix.de, Nam Cao Subject: [PATCH v3 07/22] verification/dot2k: Replace is_container() hack with subparsers Date: Wed, 16 Apr 2025 08:51:13 +0200 Message-Id: <6c587d3723a8fc2cf220441d8d7ed1614218c392.1744785335.git.namcao@linutronix.de> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Gabriele Monaco Signed-off-by: Nam Cao --- 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__ == '__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()) diff --git a/tools/verification/dot2/dot2k.py b/tools/verification/dot2/dot2k.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 = "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()