diff --git a/leapp/snactor/__init__.py b/leapp/snactor/__init__.py index db7a096fd..bd097b4d4 100644 --- a/leapp/snactor/__init__.py +++ b/leapp/snactor/__init__.py @@ -2,6 +2,17 @@ import pkgutil import socket +# for profilling +import cProfile +import pstats +try: + from StringIO import StringIO +except ImportError: + # TODO: low possibility of the problem with encoding with Python3; + # # but it should not be so problematic in this case, so keeping now just + # # like that to keep it simple + from io import StringIO + from leapp.utils.i18n import _ from leapp.snactor import commands from leapp.snactor.commands import workflow @@ -68,6 +79,17 @@ def cli(args): def main(): + profile_enabled = os.environ.get('LEAPP_CPROFILE', '0') == '1' + if profile_enabled: + pr = cProfile.Profile() + pr.enable() os.environ['LEAPP_HOSTNAME'] = socket.getfqdn() load_commands() cli.command.execute(version=_('snactor version {}').format(VERSION)) + if profile_enabled: + pr.disable() + s = StringIO.StringIO() + sortby = 'cumulative' + ps = pstats.Stats(pr, stream=s).sort_stats(sortby) + ps.print_stats() + print(s.getvalue())