-
Notifications
You must be signed in to change notification settings - Fork 71
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
There was a problem hiding this comment.
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: