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 B85911384B4 for ; Fri, 18 Dec 2015 01:53:37 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4F201E080C; Fri, 18 Dec 2015 01:53:35 +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 B8874E080C for ; Fri, 18 Dec 2015 01:53:34 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 59D2433F9D2 for ; Fri, 18 Dec 2015 01:53:33 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0D155A0E for ; Fri, 18 Dec 2015 01:53:31 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1450403602.f36f7adc0bdd0c60e78d0e4a3d366cac61568e3a.vapier@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/main.py X-VCS-Directories: catalyst/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: f36f7adc0bdd0c60e78d0e4a3d366cac61568e3a X-VCS-Branch: master Date: Fri, 18 Dec 2015 01:53:31 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: ecd96b65-a914-449e-bfb5-9660207ee046 X-Archives-Hash: 22d9992e8cbfe7fffe986744c896f8c2 commit: f36f7adc0bdd0c60e78d0e4a3d366cac61568e3a Author: Mike Frysinger gentoo org> AuthorDate: Mon Nov 23 11:57:19 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri Dec 18 01:53:22 2015 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=f36f7adc main: add a --trace option 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: