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 454211388C1 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 A9CA021C0C3; 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 1287121C0C2 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 ECBA7340688 for ; Mon, 23 Nov 2015 12:07:43 +0000 (UTC) From: Mike Frysinger To: gentoo-catalyst@lists.gentoo.org Subject: [gentoo-catalyst] [PATCH 2/2] main: add a --profile option Date: Mon, 23 Nov 2015 07:07:41 -0500 Message-Id: <1448280461-12506-2-git-send-email-vapier@gentoo.org> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1448280461-12506-1-git-send-email-vapier@gentoo.org> References: <1448280461-12506-1-git-send-email-vapier@gentoo.org> 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: b6bc0647-43be-4acd-9bf3-115ccc028c17 X-Archives-Hash: dd5548e97e09644c0326c71a251e6b93 When things get slow, this option helps narrow down where things are getting hung up. --- catalyst/main.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/catalyst/main.py b/catalyst/main.py index 3550809..cb90e66 100644 --- a/catalyst/main.py +++ b/catalyst/main.py @@ -174,6 +174,9 @@ $ catalyst -f stage1-specfile.spec""" group.add_argument('--trace', default=False, action='store_true', help='trace program output (akin to `sh -x`)') + group.add_argument('--profile', + default=False, action='store_true', + help='profile program execution') group = parser.add_argument_group('Temporary file management') group.add_argument('-a', '--clear-autoresume', @@ -243,6 +246,25 @@ def trace(func, *args, **kwargs): return tracer.runfunc(func, *args, **kwargs) +def profile(func, *args, **kwargs): + """Run |func| through the profile module""" + # Should make this an option. + sort_keys = ('time',) + + # Collect the profile. + import cProfile + profiler = cProfile.Profile(subcalls=True, builtins=True) + try: + ret = profiler.runcall(func, *args, **kwargs) + finally: + # Then process the results. + import pstats + stats = pstats.Stats(profiler, stream=sys.stderr) + stats.strip_dirs().sort_stats(*sort_keys).print_stats() + + return ret + + def main(argv): """The main entry point for frontends to use""" parser = get_parser() @@ -250,6 +272,8 @@ def main(argv): if opts.trace: return trace(_main, parser, opts) + elif opts.profile: + return profile(_main, parser, opts) else: return _main(parser, opts) -- 2.6.2