Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enable profilling when env LEAPP_CPROFILE == '1' #482

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of this try/except use:

from six 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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cold you tourn the check of env var to fuction and move it to stdlib config?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I +1 the idea, I was just thinking about this and I am wondering - Is it relevant that you know it's on for others that this? This is the only use case right now, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This place is the only use case so far. I was thinking if it's worth it to move it to stdlib and I'm kind of indecisive. Maybe it could be moved there if another use case appears. So feel free to dismiss this sugeestion.

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()
pirat89 marked this conversation as resolved.
Show resolved Hide resolved
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print(s.getvalue())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather like to see this being printed to stderr

@AloisMahdal what's your take on this?