Skip to content

Commit

Permalink
Enable profilling when env LEAPP_CPROFILE == '1'
Browse files Browse the repository at this point in the history
Currently on some machines the run of the leapp / snactor is too
slow. Especially framework itself should be fast but sometimes the
time differences are in order of tens seconds. From this point,
it seems useful to be able to start profilling based on the env
variable when it is needed.
  • Loading branch information
pirat89 committed Apr 5, 2019
1 parent 3a9e34a commit 844d696
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions leapp/snactor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())

0 comments on commit 844d696

Please sign in to comment.