Skip to content

Commit

Permalink
Add profiling code to leapp
Browse files Browse the repository at this point in the history
Also import StringIO from six.
  • Loading branch information
drehak committed Nov 2, 2020
1 parent 59c4f1b commit eb8fc97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
15 changes: 15 additions & 0 deletions leapp/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import os
import socket
# profiling
import cProfile
import pstats
import six

from leapp.utils.clicmd import command, command_opt
from leapp.cli import upgrade
Expand All @@ -12,7 +16,18 @@ def cli(args): # noqa; pylint: disable=unused-argument


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()
for cmd in [upgrade.list_runs, upgrade.preupgrade, upgrade.upgrade, upgrade.answer]:
cli.command.add_sub(cmd.command)
cli.command.execute('leapp version {}'.format(VERSION))
if profile_enabled:
pr.disable()
s = six.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print(s.getvalue())
11 changes: 2 additions & 9 deletions leapp/snactor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import os
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
import six

from leapp.utils.i18n import _ # noqa; pylint: disable=redefined-builtin
from leapp.snactor import commands
Expand Down Expand Up @@ -93,7 +86,7 @@ def main():
cli.command.execute(version=_('snactor version {}').format(VERSION))
if profile_enabled:
pr.disable()
s = StringIO()
s = six.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
Expand Down

0 comments on commit eb8fc97

Please sign in to comment.