public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
From: Brian Dolbec <dolsen@gentoo.org>
To: gentoo-catalyst@lists.gentoo.org
Subject: Re: [gentoo-catalyst] [PATCH 2/2] main: add a --profile option
Date: Tue, 15 Dec 2015 09:26:35 -0800	[thread overview]
Message-ID: <20151215092635.1bd6808c.dolsen@gentoo.org> (raw)
In-Reply-To: <1448280461-12506-2-git-send-email-vapier@gentoo.org>

On Mon, 23 Nov 2015 07:07:41 -0500
Mike Frysinger <vapier@gentoo.org> 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 <dolsen>



  parent reply	other threads:[~2015-12-15 17:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-23 12:07 [gentoo-catalyst] [PATCH 1/2] main: add a --trace option Mike Frysinger
2015-11-23 12:07 ` [gentoo-catalyst] [PATCH 2/2] main: add a --profile option Mike Frysinger
2015-11-23 12:15   ` Mike Frysinger
2015-12-15 17:26   ` Brian Dolbec [this message]
2015-11-23 12:13 ` [gentoo-catalyst] [PATCH 1/2] main: add a --trace option Mike Frysinger
2015-12-15 17:26 ` Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151215092635.1bd6808c.dolsen@gentoo.org \
    --to=dolsen@gentoo.org \
    --cc=gentoo-catalyst@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox