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 3FAE31384B4 for ; Tue, 15 Dec 2015 17:27:27 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 844F4E0894; Tue, 15 Dec 2015 17:27:26 +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 28173E0894 for ; Tue, 15 Dec 2015 17:27:26 +0000 (UTC) Received: from professor-x (S010634bdfa9ecf80.vc.shawcable.net [96.49.31.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dolsen) by smtp.gentoo.org (Postfix) with ESMTPSA id 491453405BB for ; Tue, 15 Dec 2015 17:27:25 +0000 (UTC) Date: Tue, 15 Dec 2015 09:26:35 -0800 From: Brian Dolbec To: gentoo-catalyst@lists.gentoo.org Subject: Re: [gentoo-catalyst] [PATCH 2/2] main: add a --profile option Message-ID: <20151215092635.1bd6808c.dolsen@gentoo.org> In-Reply-To: <1448280461-12506-2-git-send-email-vapier@gentoo.org> References: <1448280461-12506-1-git-send-email-vapier@gentoo.org> <1448280461-12506-2-git-send-email-vapier@gentoo.org> Organization: Gentoo 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 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archives-Salt: ea292428-638c-4581-bf62-4840374cb583 X-Archives-Hash: ae0d4b6905d146deac5c3c4529534fa7 On Mon, 23 Nov 2015 07:07:41 -0500 Mike Frysinger wrote: > 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) > Profiling is good :) -- Brian Dolbec