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

Draft: Add profiling to leapp and snactor #676

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 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,19 @@ def cli(args): # noqa; pylint: disable=unused-argument


def main():
os.environ['LEAPP_CPROFILE'] = os.environ.get('LEAPP_CPROFILE', '0')
profile_enabled = os.environ['LEAPP_CPROFILE'] == '1'
Comment on lines +19 to +20
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
os.environ['LEAPP_CPROFILE'] = os.environ.get('LEAPP_CPROFILE', '0')
profile_enabled = os.environ['LEAPP_CPROFILE'] == '1'
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())
16 changes: 16 additions & 0 deletions leapp/snactor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import os
import pkgutil
import socket
# for profilling
import cProfile
import pstats
import six

from leapp.utils.i18n import _ # noqa; pylint: disable=redefined-builtin
from leapp.snactor import commands
Expand Down Expand Up @@ -73,6 +77,18 @@ def cli(args):


def main():
os.environ['LEAPP_CPROFILE'] = os.environ.get('LEAPP_CPROFILE', '0')
profile_enabled = os.environ['LEAPP_CPROFILE'] == '1'
Comment on lines +80 to +81
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
os.environ['LEAPP_CPROFILE'] = os.environ.get('LEAPP_CPROFILE', '0')
profile_enabled = os.environ['LEAPP_CPROFILE'] == '1'
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 = six.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print(s.getvalue())
5 changes: 5 additions & 0 deletions man/leapp.1
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ Skip actions that use Red Hat Subscription Manager. Equivalent to \fB--no-rhsm\f
For each XFS partition created with \fIftype=0\fR, leapp creates an overlay file in order to proceed. This option sets the size (in MB) of every such file. Defaults to \fB2048\fR.
.RE

.B LEAPP_CPROFILE
.RS 4
Enables profiling.
.RE


.SS Developer variables
These variables shouldn't be needed under typical circumstances.
Expand Down
5 changes: 5 additions & 0 deletions man/snactor.1
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ Enables debug logging. See \fB--debug\fR for more information.
Enables verbose logging. See \fB--verbose\fR for more information.
.RE

.B LEAPP_CPROFILE
.RS 4
Enables profiling.
.RE


.SH "REPORTING BUGS"
Report bugs to bugzilla (\fIhttps://bugzilla.redhat.com\fR) under the `Red Hat Enterprise Linux 7` product and the `leapp-repository` component.
Expand Down