From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 0BAF51384B4 for ; Mon, 23 Nov 2015 12:07:46 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6878F21C0BB; Mon, 23 Nov 2015 12:07:45 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E468621C0BB for ; Mon, 23 Nov 2015 12:07:44 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id D8386340691 for ; Mon, 23 Nov 2015 12:07:42 +0000 (UTC) From: Mike Frysinger To: gentoo-catalyst@lists.gentoo.org Subject: [gentoo-catalyst] [PATCH 1/2] main: add a --trace option Date: Mon, 23 Nov 2015 07:07:40 -0500 Message-Id: <1448280461-12506-1-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 2.6.2 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Archives-Salt: 8cf98160-47b9-4b24-adab-0636556d65e7 X-Archives-Hash: d56d5b5bd1ea4b793503f2d8f0682cdf This helps a lot with debugging as you can quickly get a transcript of the python code paths that are taken by catalyst. --- catalyst/main.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/catalyst/main.py b/catalyst/main.py index f48293e..3550809 100644 --- a/catalyst/main.py +++ b/catalyst/main.py @@ -170,6 +170,11 @@ $ catalyst -f stage1-specfile.spec""" dest='color', action='store_false', help='never colorize output all the time (default: detect)') + group = parser.add_argument_group('Developer options') + group.add_argument('--trace', + default=False, action='store_true', + help='trace program output (akin to `sh -x`)') + group = parser.add_argument_group('Temporary file management') group.add_argument('-a', '--clear-autoresume', default=False, action='store_true', @@ -203,10 +208,54 @@ $ catalyst -f stage1-specfile.spec""" return parser +def trace(func, *args, **kwargs): + """Run |func| through the trace module (akin to `sh -x`)""" + import trace + + # Ignore common system modules we use. + ignoremods = set(( + 'argparse', + 'genericpath', 'gettext', + 'locale', + 'os', + 'posixpath', + 're', + 'sre_compile', 'sre_parse', 'sys', + 'tempfile', 'threading', + 'UserDict', + )) + + # Ignore all the system modules. + ignoredirs = set(sys.path) + # But try to strip out the catalyst paths. + try: + ignoredirs.remove(os.path.dirname(os.path.dirname( + os.path.realpath(__file__)))) + except KeyError: + pass + + tracer = trace.Trace( + count=False, + trace=True, + timing=True, + ignoremods=ignoremods, + ignoredirs=ignoredirs) + return tracer.runfunc(func, *args, **kwargs) + + def main(argv): + """The main entry point for frontends to use""" parser = get_parser() opts = parser.parse_args(argv) + if opts.trace: + return trace(_main, parser, opts) + else: + return _main(parser, opts) + + +def _main(parser, opts): + """The "main" main function so we can trace/profile.""" # Initialize the logger before anything else. log_level = opts.log_level if log_level is None: -- 2.6.2