1 |
On Mon, 23 Nov 2015 07:07:40 -0500 |
2 |
Mike Frysinger <vapier@g.o> wrote: |
3 |
|
4 |
> This helps a lot with debugging as you can quickly get a transcript |
5 |
> of the python code paths that are taken by catalyst. |
6 |
> --- |
7 |
> catalyst/main.py | 49 |
8 |
> +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 |
9 |
> insertions(+) |
10 |
> |
11 |
> diff --git a/catalyst/main.py b/catalyst/main.py |
12 |
> index f48293e..3550809 100644 |
13 |
> --- a/catalyst/main.py |
14 |
> +++ b/catalyst/main.py |
15 |
> @@ -170,6 +170,11 @@ $ catalyst -f stage1-specfile.spec""" |
16 |
> dest='color', action='store_false', |
17 |
> help='never colorize output all the time (default: |
18 |
> detect)') |
19 |
> + group = parser.add_argument_group('Developer options') |
20 |
> + group.add_argument('--trace', |
21 |
> + default=False, action='store_true', |
22 |
> + help='trace program output (akin to `sh -x`)') |
23 |
> + |
24 |
> group = parser.add_argument_group('Temporary file |
25 |
> management') group.add_argument('-a', '--clear-autoresume', |
26 |
> default=False, action='store_true', |
27 |
> @@ -203,10 +208,54 @@ $ catalyst -f stage1-specfile.spec""" |
28 |
> return parser |
29 |
> |
30 |
> |
31 |
> +def trace(func, *args, **kwargs): |
32 |
> + """Run |func| through the trace module (akin to `sh -x`)""" |
33 |
> + import trace |
34 |
> + |
35 |
> + # Ignore common system modules we use. |
36 |
> + ignoremods = set(( |
37 |
> + 'argparse', |
38 |
> + 'genericpath', 'gettext', |
39 |
> + 'locale', |
40 |
> + 'os', |
41 |
> + 'posixpath', |
42 |
> + 're', |
43 |
> + 'sre_compile', 'sre_parse', 'sys', |
44 |
> + 'tempfile', 'threading', |
45 |
> + 'UserDict', |
46 |
> + )) |
47 |
> + |
48 |
> + # Ignore all the system modules. |
49 |
> + ignoredirs = set(sys.path) |
50 |
> + # But try to strip out the catalyst paths. |
51 |
> + try: |
52 |
> + ignoredirs.remove(os.path.dirname(os.path.dirname( |
53 |
> + os.path.realpath(__file__)))) |
54 |
> + except KeyError: |
55 |
> + pass |
56 |
> + |
57 |
> + tracer = trace.Trace( |
58 |
> + count=False, |
59 |
> + trace=True, |
60 |
> + timing=True, |
61 |
> + ignoremods=ignoremods, |
62 |
> + ignoredirs=ignoredirs) |
63 |
> + return tracer.runfunc(func, *args, **kwargs) |
64 |
> + |
65 |
> + |
66 |
> def main(argv): |
67 |
> + """The main entry point for frontends to use""" |
68 |
> parser = get_parser() |
69 |
> opts = parser.parse_args(argv) |
70 |
> |
71 |
> + if opts.trace: |
72 |
> + return trace(_main, parser, opts) |
73 |
> + else: |
74 |
> + return _main(parser, opts) |
75 |
> + |
76 |
> + |
77 |
> +def _main(parser, opts): |
78 |
> + """The "main" main function so we can trace/profile.""" |
79 |
> # Initialize the logger before anything else. |
80 |
> log_level = opts.log_level |
81 |
> if log_level is None: |
82 |
|
83 |
|
84 |
Yeah, looks good. Not sure I'll use it yet, but... |
85 |
-- |
86 |
Brian Dolbec <dolsen> |