Skip to content

Commit

Permalink
Remove --profile support
Browse files Browse the repository at this point in the history
The handrolled profile logging support in sos hasn't been widely
used in a long time and is a problem better solved with external
profiling and coverage tools.

Rip out all the support and documentation. This shortens and
simplifies numerous Plugin class methods.

Fixes Issue #244.

Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
  • Loading branch information
bmr-cymru committed Mar 25, 2014
1 parent eb2b77c commit 4553f09
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 71 deletions.
5 changes: 1 addition & 4 deletions man/en/sosreport.1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sosreport \- Collect and package diagnostic and support data
[--report] [--config-file conf] [--batch]\fR
[--build] [--name name] [--ticket-number number]
[--debug] [--tmp-dir directory]\fR
[--profile] [--help]\fR
[--help]\fR
.SH DESCRIPTION
\fBsosreport\fR generates a compressed tar archive of diagnostic
information from the running system. The archive may be stored
Expand Down Expand Up @@ -84,9 +84,6 @@ archive as a temporary file or directory tree.
Enable interactive debugging using the python debugger. Exceptions in
sos or plug-in code will cause a trap to the pdb shell.
.TP
.B \--profile
Enable profiler logging.
.TP
.B \--help
Display usage message.
.SH MAINTAINER
Expand Down
30 changes: 0 additions & 30 deletions sos/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def __init__(self, commons):
self.collect_cmds = []

self.soslog = self.commons['soslog'] if 'soslog' in self.commons else logging.getLogger('sos')
self.proflog = self.commons['proflog'] if 'proflog' in self.commons else logging.getLogger('sosprofile')

# get the option list into a dictionary
for opt in self.option_list:
Expand Down Expand Up @@ -171,9 +170,6 @@ def do_cmd_output_sub(self, cmd, regexp, subst):
This function returns the number of replacements made.
'''
if self.commons['cmdlineopts'].profiler:
start_time = time()

globstr = '*' + cmd + '*'
self.soslog.debug("substituting '%s' for '%s' in commands matching %s"
% (subst, regexp, globstr))
Expand All @@ -200,11 +196,6 @@ def do_cmd_output_sub(self, cmd, regexp, subst):
msg = 'regex substitution failed for %s in plugin %s with: "%s"'
self.soslog.error(msg % (called['exe'], self.name(), e))
replacements = None

if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time
self.proflog.debug("subst: %-75s time: %f"
% (globstr, time_passed))
return replacements

def do_file_sub(self, srcpath, regexp, subst):
Expand All @@ -215,9 +206,6 @@ def do_file_sub(self, srcpath, regexp, subst):
This function returns the number of replacements made.
'''
if self.commons['cmdlineopts'].profiler:
start_time = time()

try:
path = self._get_dest_for_srcpath(srcpath)
self.soslog.debug("substituting '%s' for '%s' in %s"
Expand All @@ -234,10 +222,6 @@ def do_file_sub(self, srcpath, regexp, subst):
msg = 'regex substitution failed for %s in plugin %s with: "%s"'
self.soslog.error(msg % (path, self.name(), e))
replacements = 0
if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time
self.proflog.debug("subst : %-75s time: %f"
% (srcpath, time_passed))
return replacements

def do_regex_find_all(self, regex, fname):
Expand Down Expand Up @@ -314,10 +298,6 @@ def do_copy_file_or_dir(self, srcpath, dest=None, sub=None):
/etc/my_file.conf the file would end up at
/configurations/my_file.conf.
'''

if self.commons['cmdlineopts'].profiler:
start_time = time()

if self._path_in_path_list(srcpath, self.forbidden_paths):
self.soslog.debug("%s is in the forbidden path list" % srcpath)
return ''
Expand Down Expand Up @@ -358,9 +338,6 @@ def do_copy_file_or_dir(self, srcpath, dest=None, sub=None):
'dstpath':dest,
'symlink':"no"})

if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time
self.proflog.debug("copied: %-75s time: %f" % (srcpath, time_passed))
except Exception as e:
self.soslog.error("Unable to copy %s to %s" % (srcpath, dest))
self.soslog.error(traceback.format_exc())
Expand Down Expand Up @@ -560,9 +537,6 @@ def get_cmd_output_now(self, exe, suggest_filename=None, root_symlink=False, tim
"""Execute a command and save the output to a file for inclusion in the
report.
"""
if self.commons['cmdlineopts'].profiler:
start_time = time()

# pylint: disable-msg = W0612
status, shout, runtime = self.get_command_output(exe, timeout=timeout)
if (status == 127):
Expand All @@ -582,10 +556,6 @@ def get_cmd_output_now(self, exe, suggest_filename=None, root_symlink=False, tim
self.executed_commands.append({'exe': exe, 'file':outfn_strip}) # save in our list
self.commons['xmlreport'].add_command(cmdline=exe,exitcode=status,f_stdout=outfn_strip,runtime=runtime)

if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time
self.proflog.debug("output: %-75s time: %f" % (exe, time_passed))

return os.path.join(self.archive.get_archive_path(), outfn)

# For adding output
Expand Down
35 changes: 1 addition & 34 deletions sos/sosreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ class SoSOptions(object):
_config_file = ""
_tmp_dir = ""
_report = True
_profiler = False
_compression_type = 'auto'

_options = None
Expand Down Expand Up @@ -430,19 +429,6 @@ def report(self, value):
raise TypeError("SoSOptions.report expects a boolean")
self._report = value

@property
def profiler(self):
if self._options != None:
return self._options.profiler
return self._profiler

@profiler.setter
def profiler(self, value):
self._check_options_initialized()
if not isinstance(value, bool):
raise TypeError("SoSOptions.profiler expects a boolean")
self._profiler = value

@property
def compression_type(self):
if self._options != None:
Expand Down Expand Up @@ -508,9 +494,6 @@ def _parse_args(self, args):
parser.add_option("--no-report", action="store_true",
dest="report",
help="Disable HTML/XML reporting", default=False)
parser.add_option("--profile", action="store_true",
dest="profiler",
help="turn on profiling", default=False)
parser.add_option("-z", "--compression-type", dest="compression_type",
help="compression technology to use [auto, zip, gzip, bzip2, xz] (default=auto)",
default="auto")
Expand Down Expand Up @@ -563,7 +546,6 @@ def get_commons(self):
'rptdir': self.rptdir,
'tmpdir': self.tmpdir,
'soslog': self.soslog,
'proflog' : self.proflog,
'policy': self.policy,
'verbosity': self.opts.verbosity,
'xmlreport': self.xml_report,
Expand Down Expand Up @@ -680,32 +662,17 @@ def _setup_logging(self):
ui_console.setLevel(logging.INFO)
self.ui_log.addHandler(ui_console)

# profile logging
if self.opts.profiler:
self.proflog = logging.getLogger('sosprofile')
self.proflog.setLevel(logging.DEBUG)
self.sos_profile_log_file = self.get_temp_file()
plog = logging.FileHandler(self.sos_profile_log_file.name)
plog.setFormatter(logging.Formatter('%(message)s'))
plog.setLevel(logging.DEBUG)
self.proflog.addHandler(plog)
else:
self.proflog = logging.getLogger('sosprofile')
self.proflog.setLevel(logging.FATAL)

def _finish_logging(self):
logging.shutdown()

# the logging module seems to persist in the jython/jboss/eap world
# so the handlers need to be removed
for logger in [logging.getLogger(x) for x in ('sos', 'sosprofile', 'sos_ui')]:
for logger in [logging.getLogger(x) for x in ('sos', 'sos_ui')]:
for h in logger.handlers:
logger.removeHandler(h)

if getattr(self, "sos_log_file", None):
self.archive.add_file(self.sos_log_file.name, dest=os.path.join('sos_logs', 'sos.log'))
if getattr(self, "sos_profile_log_file", None):
self.archive.add_file(self.sos_profile_log_file.name, dest=os.path.join('sos_logs', 'profile.log'))
if getattr(self, "sos_ui_log_file", None):
self.archive.add_file(self.sos_ui_log_file.name, dest=os.path.join('sos_logs', 'ui.log'))

Expand Down
4 changes: 1 addition & 3 deletions tests/plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def is_installed(self, pkg):


class MockOptions(object):

profiler = False

pass


class PluginToolTests(unittest.TestCase):
Expand Down

0 comments on commit 4553f09

Please sign in to comment.