xref: /linux/tools/verification/dot2/dot2k (revision 88221ac0d560700b50493aedc768f728aa585141)
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0-only
3#
4# Copyright (C) 2019-2022 Red Hat, Inc. Daniel Bristot de Oliveira <bristot@kernel.org>
5#
6# dot2k: transform dot files into a monitor for the Linux kernel.
7#
8# For further information, see:
9#   Documentation/trace/rv/da_monitor_synthesis.rst
10
11if __name__ == '__main__':
12    from dot2.dot2k import dot2k
13    import argparse
14    import sys
15
16    def is_container():
17        """Should work even before parsing the arguments"""
18        return "-c" in sys.argv or "--container" in sys.argv
19
20    parser = argparse.ArgumentParser(description='transform .dot file into kernel rv monitor')
21    parser.add_argument('-d', "--dot", dest="dot_file", required=not is_container())
22    parser.add_argument('-t', "--monitor_type", dest="monitor_type", required=not is_container(),
23                        help=f"Available options: {', '.join(dot2k.monitor_types.keys())}")
24    parser.add_argument('-n', "--model_name", dest="model_name", required=is_container())
25    parser.add_argument("-D", "--description", dest="description", required=False)
26    parser.add_argument("-a", "--auto_patch", dest="auto_patch",
27                        action="store_true", required=False,
28                        help="Patch the kernel in place")
29    parser.add_argument("-p", "--parent", dest="parent",
30                        required=False, help="Create a monitor nested to parent")
31    parser.add_argument("-c", "--container", dest="container",
32                        action="store_true", required=False,
33                        help="Create an empty monitor to be used as a container")
34    params = parser.parse_args()
35
36    if not is_container():
37        print("Opening and parsing the dot file %s" % params.dot_file)
38    try:
39        monitor=dot2k(params.dot_file, params.monitor_type, vars(params))
40    except Exception as e:
41        print('Error: '+ str(e))
42        print("Sorry : :-(")
43        sys.exit(1)
44
45    print("Writing the monitor into the directory %s" % monitor.name)
46    monitor.print_files()
47    print("Almost done, checklist")
48    if not is_container():
49        print("  - Edit the %s/%s.c to add the instrumentation" % (monitor.name, monitor.name))
50        print(monitor.fill_tracepoint_tooltip())
51    print(monitor.fill_makefile_tooltip())
52    print(monitor.fill_kconfig_tooltip())
53    print(monitor.fill_monitor_tooltip())
54